Search code examples
jsonpaypaltimeoutpaypal-sandboxpaypal-subscriptions

Paypal create subscription onApproval GET times out


I am trying to access the response json after creating a subscription in Paypal.

This is the code - it uses the Paypal javascript SDK (it is derived from the SDK documentation and this answer):

   createSubscription: function (data, actions) {
   return actions.subscription.create({
      'plan_id': 'xxx'
      });
   },

   onApprove: function (data, actions) {
      return actions.subscription.get().then(function (details) {
                        console.log(details)
   });

},

The subscription is created ok but the onApprove actions.subscription.get() line times out with the console message:

b.sbox.stats.paypal.com/v2/counter.cgi?p=uid_xxx&s=SMART_PAYMENT_BUTTONS:1 GET https://b.sbox.stats.paypal.com/v2/counter.cgi?p=uid_xxx&s=SMART_PAYMENT_BUTTONS net::ERR_CONNECTION_TIMED_OUT

Am I using the right code to get the json? If so, why is it timing out?

EDIT: After searching the Paypal community again I altered the code as follows:

return actions.subscription.get(data.subscriptionID).then(function (details) {
console.log(details)

});

Which results in a slightly different error message:

b.sbox.stats.paypal.com/v2/counter.cgi?p=uid_bf756f1ba7_mdg6ntk6mjm&s=SMART_PAYMENT_BUTTONS:1 Failed to load resource: net::ERR_CONNECTION_TIMED_OUT


Solution

  • For Subscriptions, there's no reason to do a 'get' in onApprove. Use the information you already have in data.

    Since onApprove is client-side and occurs after a subscription has been activated, no business critical logic should depend on this code path being executed, since it may not.

    If you have anything that must execute, set up a webhook listener for BILLING.PLAN.ACTIVATED (plan creation) and/or PAYMENT.SALE.COMPLETED (a payment occurs)