I’m trying to implement a payment system using the new PayPal API (Adaptive Payment).
So far, I have this workflow :
- Send a request to PayPal for :
AdaptivePayments/Pay - This create a Pay request, and return a payKey that is valid 3 hours (source)
- Now, I wait that paypal sends me request through the IPN. When it will, I will get the pay_key with it
- Using this pay_key, I will call the
AdaptivePayments/PaymentDetailsto know the state of the payment.
But I was wondering, how can I do if it’s been more than 3 hours? (like in a refund?)
What is the sure way to do then?
Well I’ll answer myself on that one and after a bit of reading.
Instead of using the payKey given when calling
AdaptivePayments/Pay, and other solution is to use the trackingId.Here’s how :
First step, you create an
AdaptivePayments/Payand you specify a trackingId (must be unique) :In response, you will have the payKey that you’ll redirect your buyer to, in order to do the payment.
Then, for the whole evolution of this payment, you will be notified to your IPN url (here, “http://apigee.com/console/-1/ipn“).
When you’ll receive a (POST) request at this adress, check the validity to paypal and you’ll get a
trackingIdin the parameter. Check that this trackingId exists and then askAdaptivePayments/PaymentDetailswith that trackingId like this :And you will have a complete detailled status of your payment in return.
Now, you do the work to update your database, call your buyer, etc etc 🙂
What was helpful for me :