Search code examples
node.jspaypalpaypal-sandboxpaypal-rest-sdkpaypal-subscriptions

How to create a PayPal subscription order?


I'm using PayPal Checkout API SDK and I successfully created an order using the smart buttons, so when the user click on the paypal button an order is created. Here's my code for the final capture:

let request = new paypal.orders.OrdersCreateRequest();
    request.requestBody({
        "intent": "CAPTURE",
        "purchase_units": [{
            "amount": {
                "currency_code": 'EUR',
                "value": '15.00', 
            },
            "redirect_urls": {
                "return_url": `${process.env.APP_DOMAIN}/pay/success?session_id={CHECKOUT_SESSION_ID}`,
                "cancel_url": `${process.env.APP_DOMAIN}/pay/cancel?session_id={CHECKOUT_SESSION_ID}`,
            }
        }]
    });

What I don't understand is: how can I actually create a subscription order? I need to make a monthly subscription, but I can't find anything in the documentation that allows me to create such a checkout


Solution

  • The Subscriptions API is newer and most SDKs don't support it yet (and if they do support billing plan calls, it's for an older, incompatible version, generally)

    So you probably need to implement direct HTTPS API calls (no SDK) to create the necessary Product and Plan. All those curl calls you see in the documentation? Do the equivalent from node.

    Then in the last step you pass the resulting plan object to the client-side SPB js.