skip to Main Content

I’m trying to upgrade a legacy system that uses Paypal for subscriptions. The older way redirects to Paypal (Checkout?) and the new way is trying to use their JavaScript SDK:

https://developer.paypal.com/sdk/js/reference/

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

The older system created Payment Plans on the fly, and so the payer was able to adjust the amount rather than sticking with the amount stored in a pre-made plan. I hope to replicate this behaviour using the JS sdk.

The above pages links to here: https://developer.paypal.com/api/subscriptions/v1/#subscriptions_create "for allowed options defined in the request body."

One of the parameters within the subscription creation is:
plan [object] "An inline plan object to customise the subscription. You can override plan level default attributes by providing customised values for the subscription in this object."

This seems like the thing I am after but I am unable to get Papal to use anything I put inside there, ie:

plan_id: plan_id,
custom_id: "Does this thing work?",
plan_overridden: true,
plan: {name: "Testing ABC123 Special"}

"Does this thing work?" will carry but nothing within the plan.

One other thing of note is that the older system didn’t pass a plan_id, which doesn’t seem possible with the JS SDK.

I think the older way is using Checkout, are these two methods completely imcompatible?

Thank you so much!

2

Answers


  1. Chosen as BEST ANSWER

    My answer was found on this page: https://developer.paypal.com/docs/multiparty/subscriptions/customize/bill/

                      billing_cycles: [
                        {
                          sequence: 1,
                          total_cycles: 0,
                          pricing_scheme: {
                            fixed_price: {
                              value: "8",
                              currency_code: "USD",
                            },
                          },
                        },
                      ],
    

    It didn't make the name change but it did make the amount change which is actually all I care about :)


  2. name cannot be overridden.

    Keys that can be overridden are documented in the plan_override object.


    If you need to customize more plan details, create the subscription on the server side and return its id to the calling JS (within that server route, the plan_id can first be created on the fly if one doesn’t already exist for the name you need)

      <script src="https://www.paypal.com/sdk/js?client-id=XXXXXXXXXXXXX&amp;vault=true&amp;intent=subscription&amp;currency=USD"></script>
    
      <div id="paypal-button-container"></div>
    
      <script>
        paypal.Buttons({
          style: {
              label:'subscribe'  //Optional text in button
          },
          createSubscription: function(data, actions) {
              return fetch('/path/on/your/server/paypal/subscription/create/', {
                  method: 'post'
              }).then(function(res) {
                  return res.json();
              }).then(function(serverData) {
                  console.log(serverData);
                  return serverData.id;
              });
          },
    
          onApprove: function(data, actions) {
          /*  Optional: At this point, notify your server of the activated subscription...
    
              fetch('/path/on/your/server/paypal/subscription/activated/' + data.subscriptionID , {
                  method: 'post'
              }).then(function(res) {
                  return res.json();
              }).then(function(serverData) {
                  //
              });
          */
              //You could additionally subscribe to a webhook for the BILLING.SUBSCRIPTION.ACTIVATED event (just in case), as well as other future subscription events
              //Ref: https://developer.paypal.com/docs/api-basics/notifications/webhooks/event-names/#subscriptions
    
              // Show a message to the buyer, or redirect to a success page
              alert('You successfully subscribed! ' + data.subscriptionID);
          }
    
        }).render('#paypal-button-container');
      </script>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search