Search code examples
paypalpaypal-rest-sdkpaypal-subscriptions

PayPal Subscriptions API - how to apply discounts


At the moment I have a relatively simple PayPal checkout that captures one-time payments using the PayPal Payments API.

As part of this, there is the option for the user to enter a voucher code and receive a discount on their order. I can do this by submitting a POST request with something like:

request_body['purchase_units'][0]['amount'] = {
    'currency_code': 'GBP',
    'value': str(payment_amount),
    'breakdown': {
        'item_total': {
            'currency_code': 'GBP',
            'value': str(membership_type.price)
        },
        'discount': {
            'currency_code': 'GBP',
            'value': str(discount)
        }
    }
}

The purchase is a semi-regular one for customers, so I am in the process of updating the checkout to move towards a subscription based system, where the user is billed automatically at a set interval, rather than manually having to go through the checkout every time as currently.

I am using the paypal Subscriptions API and have set up the Products and Plans, but I cannot see any way to offer any one-time discount when signing up to a subscription. I can see the option for a free trial, but no way to offer fine-grained control on a subscription-by-subscription basis using the API.

What I want to find out is:

  • How (if at all) can I integrate some kind of voucher/discount system whilst using the Subscription API? I can develop something custom if necessary, but I am wondering what the best approach is here. Creating a new Plan for every voucher code came to mind, but it seems a bit heavy handed.
  • If the above is not possible, can recurring transactions be processed automatically using the standard Payments API? I wouldn't have thought so otherwise there would be no need for the Subscriptions API.

In general, what is the best way of tackling regular PayPal payments, whilst being able to offer some kind of discount in particular instances?


Solution

  • To my knowledge:

    • If the pricing scheme is different, you need a new plan. If it does not make sense to pre-create all the plans you will need, you can write your code to create these on-demand as the customer is checking out and entering their selection/voucher and clicking to proceed
    • You need the PayPal Subscriptions API for automatic recurring transactions