From the Paypal Developer Docs website – https://developer.paypal.com/docs/business/subscriptions/add-capabilities/customize/

This guide wasn’t very clear on how to do this with Javascript (Integrating with the Smart Paypal Button) , so I worked it out myself and thought I would share.

From the Basic Integration Docs – https://developer.paypal.com/docs/subscriptions/integrate/#create-the-subscription

createSubscription: function(data, actions) {
    return actions.subscription.create({
        'plan_id': 'P-2UF78835G6983425GLSM44MA'
    });
},

Change to below to set Fixed/Variable Amount for the Discount.

createSubscription: function(data, actions) {
    return actions.subscription.create({
        'plan_id': 'P-7JQ21929HK674142HLY15JHY' //Your Plan ID here
        "plan": { //discount stuff
            "billing_cycles": [{
                "sequence": 1,
                "total_cycles": 0,
                "pricing_scheme": {
                    "fixed_price": {
                        "value": Amount*0.75, //Example of 25% discount or can put in fixed value e.g. "15" if originally cost 20.
                        "currency_code": "USD"
                    }
                }
            }]
        },
    });
},

You could also add in an HTML Input box for checking a discount code via Javascript and an AJAX call to a DB of Discount codes correlating to the discounted %.
Comment below to say thanks if this helped you and/or reach out in the Contact Form for any help/queries.

Thanks 🤓


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.