1

I am making PayPal payment via redirection to PayPal. This means that payment will take place in the user's browser and get me the details of the payment on the front-side. After the payment happened, I need to store details so for later use, I will know that the user has paid already. As soon as the payment happens on the front-end, I make an API call to my server to store the details of the payment.

Question: What if payment takes place on the front-side and when making an api call to my server after that, it goes to error. I'm left with the scenario that the user hasn't paid for the product, even though he did. What can I do in this situation?

Pritesh
  • 1,066
  • 3
  • 15
  • 35
Nika Kurashvili
  • 6,006
  • 8
  • 57
  • 123
  • 1
    Do you use IPN (Instant Payment Notification)? And if not, why not? – NineBerry Aug 02 '19 at 10:00
  • As I understand, I should have instant payment notification set on my api. which will listen to events that users paid. If this is it, what if user paid, paypal sent the form to my listener and my api was offline. It's the same thing as me doing the api call after user paid on front-end. – Nika Kurashvili Aug 02 '19 at 10:04
  • IPN Notifications will be resent automatically if they are not acknowledged as succesful by the receiving endpoint – NineBerry Aug 02 '19 at 10:12

1 Answers1

1

Implement IPN (Instant Payment Notification).

From the documentation:

PDT has a major weakness: it sends order confirmations once and only once. As a result, when PDT sends a confirmation, your site must be running; otherwise, it will never receive the message.

With IPN, in contrast, delivery of order confirmations is virtually guaranteed since IPN resends a confirmation until your site acknowledges receipt. For this reason, PayPal recommends that you implement IPN rather than PDT.

[...]

Note: If your site must be notified of payments immediately, you can implement both IPN and PDT. However, if you do, your site will receive two order confirmations for each sale. As a result, you must be careful to take action (say, ship a product) on just one copy of a given confirmation message.


Instead of IPN, you can also implement Web Hooks which are basically a reworked variant of IPN that uses more modern technologies and a more streamlined interface. See also When to use IPN and when WebHooks in PayPal as a notification mechanism?

NineBerry
  • 26,306
  • 3
  • 62
  • 93
  • Cool. Now I get it. But a little vague is that i should have set up event listener in php right? so that it listens paypal? – Nika Kurashvili Aug 02 '19 at 10:13
  • @NikaKurashvili Your comment is not clear. Read the documentation https://developer.paypal.com/docs/classic/products/instant-payment-notification/ in depth to understand how it works. You can use any programming language that works on the server to implement IPN – NineBerry Aug 02 '19 at 10:17
  • Last question if you don't mind. So user made the transaction, paypal throws that to my url. how do I tell paypal NOT to send me the same transaction for 4 days ? i looked through the code, but couldn't find it. – Nika Kurashvili Aug 02 '19 at 10:30
  • @NikaKurashvili See "PN listener request-response flow" at https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNImplementation/ - You return a status code of 200 and then call an API of PayPal to acknowledge receipt. For most common server programming environments, there are libraries you can use to implement IPN interaction. – NineBerry Aug 02 '19 at 10:37
  • Hi @NineBerry I've been reading and realizing this stuff. IPN is great because it can send the same transaction until you acknowledge it. what about webhooks? what if my server is turned off at the time it's sending the info or maybe it sent the event, but saving to my database got failed? i am left with no transaction in any of these cases. could you say a little bit of what i can do in these situations? – Nika Kurashvili Aug 04 '19 at 18:46