Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workflow with PayKey using Paypal Adaptive Payment

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 throught the IPN. When it will, I will get the pay_key with it
  • Using this pay_key, I will call the AdaptivePayments/PaymentDetails to 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?

Thanks for your help!

like image 914
Cyril N. Avatar asked Jan 24 '12 19:01

Cyril N.


1 Answers

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/Pay and you specify a trackingId (must be unique) :

{
  "actionType":"PAY",
  "currencyCode":"USD",
  "receiverList":{"receiver":[{"amount":"1.00","email":"[email protected]"}]},
  "returnUrl":"http://apigee.com/console/-1/handlePaypalReturn",
  "cancelUrl":"http://apigee.com/console/-1/handlePaypalCancel?",
  "trackingId":"abcde-12345-unique-of-course",
  "ipnNotificationUrl":"http://apigee.com/console/-1/ipn",
  "requestEnvelope":{"errorLanguage":"en_US", "detailLevel":"ReturnAll"}
}

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 trackingId in the parameter. Check that this trackingId exists and then ask AdaptivePayments/PaymentDetails with that trackingId like this :

{
 "trackingId":"{put here}",
 "requestEnvelope":{"errorLanguage":"en_US", "detailLevel":"ReturnAll"}
}

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 :

  • Pay API Operation
  • PaymentDetails API Operation
  • IPN Variable Reference
  • Apigee Paypal console
like image 140
Cyril N. Avatar answered Oct 30 '22 05:10

Cyril N.