How to capture success on Paypal's Smart Checkout and return a Serial Key?

Viewed 173

Introduction

Hello I'm going to sell a software using serial keys. Any person can go into my webpage and click on the paypal button to buy a serial key, they don't need to register.

What I'm trying to achieve

I need to let any person use the button and receive a serial key when the payment is done.

So the workflow would be something like:

  1. Any person (non-registered) clicks on the button.
  2. The paypal page shows up.
  3. The user pays and gets redirected to a page that shows something like "Congratulations, here is your serial key: {{serialKey}}" and also receives the same serialKey via email.

What I tried

I'm trying to use Paypal's Smart Checkout but I don't understand how to implement what I need.

Right now I'm able to:

  • Render the button.
  • The button performs a request to my back to get the price (so the user can't change it and trick me).
  • The paypal page shows up.
  • On success it performs a request to my back.
  • On failure it restarts.

What I'm missing:

  • How can I check that the payment did actually succeed on the back, I mean that I received the money? Is there any way that I can post to paypal using the ID and see if I that transaction was correct?

Additional question

Is this the right approach? All I need is to let anyone click the button, pay and receive a serial key ONLY if the payment was correct. Right now it seems too complex for what I need. I don't understand everything I see on the paypal docs, if you follow it line by line the examples don't work, you have to adapt a lot of the code and I'm not sure about what I'm doing.

I also read IPN's docs but using it I won't be able to redirect the user because everything would be done in the back without the user even knowing what is happening.

Final text

Any help is appreciated. I'm asking here because I saw a lot of another questions about paypal like this one that were upvoted.

1 Answers

The most robust approach is to combine the PayPal Checkout front-end with a v2/orders backend for payment setup and capture.

This way the capture happens from your server, so you have an immediate success/failure API response -- and can immediately do whatever you need to do to handle the business logic of the digital good purchase (serial key activation/distribution)


Once you have everything working well for the happy path, don't neglect to handle funding source failures, so that if the capture fails due to e.g. the buyer's first card being declined, this is propagated back to the UI and the buyer can select a different funding source.

Related