2

I already have an implemented CMS system where the user creates the subscription plans.

I want to integrate my CMS server with Paypal so when the user creates a plan it will be created on Paypal servers.

I can see how to do that in https://developer.paypal.com/docs/subscriptions/integrate/

But the problem is there is no documentation for the front-end side for the subscription step ! How should i redirect the customer to Paypal to login, and how will i receive the data to send it to my server ?

Note : Since i want my user to create plans only on my CMS, there is no easier way to integrate with paypal than this : https://developer.paypal.com/docs/subscriptions/integrate/ .. right? i don't want to use Smart Buttons so the only option i have is to integrate with APIs.. if there is any easier way please tell me.

1 Answers1

9

This is a bit hidden.

When you create a subscription, its status will be set to APPROVAL_PENDING. Look for the "rel": "approve" link in the response (in links). The URL will look something like this:

https://www.paypal.com/webapps/billing/subscriptions?ba_token=xyz

This is the URL you need to redirect the customer's browser to. Once they click on "Subscribe" to approve it, PayPal will redirect their browser to the return_url value you set when you created the subscription.

PayPal adds 3 extra parameters to that return URL: subscription_id (self-explanatory), ba_token (the approval token), and token (???). At that point, you can get the subscription details from PayPal, and its status should now be "ACTIVE".

Now I just need to figure out why next_billing_time is set in the past, and why I'm not receiving the PAYMENT_SALE webhooks :)

Hope this answers your question.

David Chatenay
  • 326
  • 2
  • 10
  • Yes thank you. Beside that, i can see the deprecated billing cycle for paypal [https://developer.paypal.com/docs/api/payments.billing-agreements/v1/#billing-agreements_post], and the associated SDKs for it, but i can't see any SDK for the subscription APIs we are talking about. Am i have to implement the calls in my server or there is another easier way to integrate with paypal subscriptions ? – Mohammad Makahleh Apr 30 '19 at 09:51
  • I haven't found an updated SDK for the new APIs. The new Paypal Checkout SDK doesn't seem to have wrappers for the subscriptions APIs. I just implemented a simple wrapper around the REST APIs + the servlet handlers for the payment and webhooks (to handle subscription renewal payments). – David Chatenay Apr 30 '19 at 21:39
  • @DavidChatenay, Can you please help me to find out that what happened if a payment of Subscription (created by this API https://developer.paypal.com/docs/api/subscriptions/v1/) failed due to any reason, then when Paypal retry to collect this payment and after how much time? – HarisH Sharma Aug 30 '19 at 12:18
  • @DavidChatenayhave you figured out `next_billing_time` issue? It seems consistently incorrect on Sandbox and Live, very annoying. – dgpro Jun 12 '20 at 10:00
  • @dgpro I'm curious about next_billing_time aswell. What do you mean incorrect? For me it contains the start date of subscription, instead of actually next billing cycle, so I'm worried that it won't capture the next months payment? – Sebastijan Dumančić Jun 13 '20 at 11:48
  • @dgpro sorry I can't help much. I gave up on this project after PayPal changed/deprecated a bunch of subscription APIs, which threw a wrench in my schedule. I haven't had time to redo the code since... – David Chatenay Jun 14 '20 at 06:24
  • Slightly weird how https://developer.paypal.com/docs/subscriptions/integrate/#3-create-a-plan seems to be a duplicate of https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create but with much less details!! – Antony Aug 21 '20 at 10:20