user2133694
user2133694

Reputation: 23

Paypal recurring Smart Payment Button

Is it possible with the Smart Payment Button for Paypal recurring payments to pass additional parameters like an invoice id for example.

paypal.Buttons({

  createSubscription: function(data, actions) {

    return actions.subscription.create({

      'plan_id': 'P-2UF78835G6983425GLSM44AM'

    });

  },


  onApprove: function(data, actions) {

    alert('You have successfully created subscription ' + data.subscriptionID);

  }


}).render('#paypal-button-container');

This is the example code from https://developer.paypal.com/docs/subscriptions/integrate/#4-create-a-subscription and it says:

But I can't pass anything besides the plan_id.

Upvotes: 0

Views: 963

Answers (2)

Preston PHX
Preston PHX

Reputation: 30457

The underlying API is /v1/billing/subscriptions

Here is the reference: https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create

It does not appear to have a field for an invoice_id -- so, the answer to your question is No, it is not possible.


You will get a unique PayPal subscription profile ID in the resulting response, e.g. "id": "I-BW452GLLEP1G" -- So, what you can do is store that profile ID in your own invoice record.


Example of a createSubscription function that calls a server that can check for pre-existing active duplicates before creating the subscription (or return an error otherwise)

      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;
          });
      },

Upvotes: 1

Fausto R.
Fausto R.

Reputation: 1334

You can add the custom_id field as explained on this page

In that case, your code would look like

return actions.subscription.create({
   'custom_id': 'my-custom-code-for-integration',
   'plan_id': 'P-2UF78835G6983425GLSM44AM'
 });

Upvotes: 2

Related Questions