1

I am implementing subscriptions to a premium service on a website using Paypal as the payment service. I have successfully created a Catalog Product and Billing Plan through the API, and I am able to get to the payment page on Paypal, but it's not clear how I'm supposed to persist a user identifier through the purchase process.

I assumed it would be something along the lines of passing a user id somewhere, but there's nothing in the Paypal documentation about this. I need to be able to let the user make a purchase and have the Paypal webhook send the confirmation to an endpoint on my site, and that's where I'd expect to get their user id to toggle the subscription on their account on my end.

Is there something I'm missing? There has to be a way to do this cause I'd imagine it's a pretty common use case. If anyone has information or has done this before, I'd love to hear. Thanks.

Snow Sailor
  • 323
  • 3
  • 13
  • Basically you use the email address as the user ID. You are given enough IPN messages that you know when to create the user, when to enroll him in the subscription, and when to enable him for another period. – user207421 Apr 18 '20 at 02:31
  • What if the user wants to pay with a credit/debit card and they don't provide an email? And what if their paypal email isn't the same as the registered email with my website? – Snow Sailor Apr 18 '20 at 02:38
  • (1) Dunno (2) Add it to his profile. – user207421 Apr 18 '20 at 02:55

2 Answers2

3

The only truly secure way I've found when using javascript SDK, is to securely generate a unique custom_id on your server side associated with the user.

Then when you create the buttons, the 'createSubscription' function takes custom_id as a parameter.

Then use a webhook to receive events from your subscription and the custom_id will be present in the body of all BILLING.SUBSCRIPTION events under resource.custom_id.

0

I am able to get to the payment page on PayPal,

You are vague about what you are doing here. There are multiple ways (and some ways have multiple versions) of accepting subscriptions via PayPal, so it is important that you provide full details about the method you are using.

The time to associate a created subscription ID with a user ID is when it is approved, in the onApprove function if you are using a Smart Payment Button: https://developer.paypal.com/docs/subscriptions/integrate/#4-create-a-subscription

Preston PHX
  • 27,642
  • 4
  • 24
  • 44
  • I did see the Smart Payment Button, but my one concern with that is if the user accidentally closes their browser tab before completing payment then they could pay without getting their service. The association wouldn't be able to occur. I did come across the `/v1/billing/subscriptions` POST endpoint, which might be what I want. I can perform that post on the server to create a "pending approval" subscription, associate the user with the subscription, and then redirect them to the `approve` link that is returned in the response so they can pay and finish the activation. Would this work? – Snow Sailor Apr 18 '20 at 05:35