Workflow with PayKey using Paypal Adaptive Payment - paypal

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!

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":"seller_1288085303_biz#gmail.com"}]},
"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

Related

Paypal Chained Payment - Pay Key & IPN

I recently converted from basic Paypal payments to Chained Payments...and I have a few questions if you guys would be so kind to help out.
First, when I setup a PayRequest, I also create an order record in the database. Previously with my basic Paypal implementation, I passed that OrderId in the custom field as part of the form post to Paypal. I would then get that OrderId back in the IPN handler and use it to mark the order as paid or whatever based on the response from Paypal IPN.
Now I am wondering what is a good unique value for my locally created order? Should I use the paykey to look up the order on the IPN callback? Or should I just set the trackingId property of the PayRequest to be the order id and pick up in the IPN callback Request object?
Secondly, there is a returnUrl and ipnNotificationUrl for the PayRequest. Should the returnUrl process the IPN callback or does the ipnNotificationUrl only should do that?
The reason why I ask is because the return url must be able to show the buyer the status of their payment and the transaction info, the same data that I get in the IPN callback.
Thanks for the input guys, once I get these two minor details ironed out, I'll be good to go!
I would add your record ID into the tracking ID parameter of the Pay request like you mentioned. That way you'll get it back in your IPN similar to what you're doing with the custom parameter now.
The IPN notification URL is what you want to set in order to trigger IPNs for the Pay request. You do not want to use the same URL for return because then the script would actually run twice.

PayPal Express Checkout Validating Payment

How can we validate a payment Success/failure using response Token from Paypal in PayPal Express Check Out.
The DoExpressCheckoutPayment response (if Successful) will include a PAYMENTINFO_n_PAYMENTSTATUS parameter that you can check to see if the payment associated with the API call is actually completed or not.
If this param has a value of "Completed" then you know you're good to go. It could be "Pending", though, in cases where an e-check is used for payment, fraud filters flag the transaction, etc.
Because of this it is recommended that you use Instant Payment Notification (IPN) in order to handle all post-transaction processing tasks like updating your database, sending email notifications, etc.
PayPal responds with a message, such as the one shown below. Note the status, which should include ACK set to Success, and a token that is used in subsequent steps.
TIMESTAMP=2007%2d04%2d05T23%3a23%3a07Z
&CORRELATIONID=63cdac0b67b50
&ACK=Success
&VERSION=XX%2e000000
&BUILD=1%2e0006
&TOKEN=EC%2d1NK66318YB717835M
Source

Paypal Subscription Details

Can you help me. I need to know if PayPal has an API call to get subscription details like the enddate of the subscription?
I do the request to PayPal and get the response,
SUCCESS
transaction_subject=Name20
payment_date=10%3A42%3A50+Mar+28%2C+2014+PDT
txn_type=subscr_payment
subscr_id=I-MWMMATTBSY2M
last_name=jls
....
but I need details from suscription as enddate.
Sounds like you're using Standard Subscriptions and the "response" you're referring to would be an Instant Payment Notification (IPN)..??
Unfortunately, the standard subscriptions system doesn't have any API's to access details directly. You could switch to Express Checkout and the Recurring Payments API, though, and this would give you access to API's to obtain details and manage the profiles programatically.
If you're working with PHP you can setup Express Checkout and Recurring Payments very easily using my class library for PayPal.
The flow you'll be setting up would be as follows...
1) Call SetExpressCheckout to obtain a token and redirect the user to PayPal. The SEC request will also include a ReturnURL which is where PayPal sends the user after they've signed in and agreed to continue. You also need to make sure to include the Billing Agreement parameters in your SEC request so that the token you get will be compatible with recurring payments.
2) The user ends up back at your ReturnURL, and this is where you'll call GetExpressCheckoutDetails to obtain details about the buyer that the system now knows since they've signed in. This gives you info like the payer's name, email, address, etc. It also gives you the Payer ID you'll need for the final request.
3) Right after obtaining the details via GECD you'll call CreateRecurringPaymentsProfile to finalize the subscription profile creation.

Paypal shipment details

I am using PayPal Adaptive payments (chained payments).
If I set:
1. CREATE payment
2. In the SetPaymentOptions -> Requires shipping address selection = true
3. When I redirect user for the https://www.sandbox.paypal.com/webscr&cmd=_ap-payment&paykey=[PA KEY] user after authentication is not shown any prompt for shipping address
why?
Accordingly to the
https://www.x.com/developers/paypal/documentation-tools/api/pay-api-operation
when using CREATE I should do: CREATE – Use this option to set up the payment instructions with SetPaymentOptions and then execute the payment at a later time with the ExecutePayment.
But as soon as I try to run ExecutePayment I get the following information:
This payment request must be authorized by the sender
How can I set additional payment options then?
The ExecutePayment call would only be used if you're utilizing delayed chained payments. Otherwise, the payment still happens as soon as the buyer logs in and approves it, so there is no need for ExecutePayment. Calling it at that point results in the error you're getting, that the paykey was already used.
Did the sender actually authorize the payment?
The flow should be like:
Call Pay API operation with actionType as CREATE
If paymentExecStatus=CREATED and ack=SUCCESS, obtain payKey (here, keep detailLevel=ReturnAll in RequestEnvelope field of your Pay API request)
Redirect user to Paypal https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=YOUR_PAYKEY_ABOVE
If user approves payment, you will be redirected to your returnURL sent as a part of Pay API request
Verify approval status using PaymentDetails API operation
Later you can execute the payment thus setup in step 4 using ExecutePayment API operation. Send the same payKey you obtained in step 2.
You have got error code 550001 since the user approval seems to be not yet done successfully. It may be due to:
The application did not redirect user/sender to Paypal for authorization
OR
The user did not enter correct login details
OR
There were not sufficient funds available
etc.

Paypal NVP with IPN for confirmation - what ties them together

I am using PayPal with NVP API (using PHP) for express checkout. I am creating an invoice record in the database before redirecting the user to Paypal. In case the user doesn't return to my site after processing, I am using IPN to confirm the purchase and then update the invoice record that the payment is confirmed. I am still in the sandbox mode and trying to figure out how I will tie the transaction started with NVP to the confirmation I get with IPN.
I need to verify if the "PAYMENTREQUEST_n_INVNUM" sent in the NVP will come back as "invoice" in the IPN post.
It appears I cannot actually test this until I am live since the Sandbox IPN does not seem to be active with NVP initiated sandbox transactions - is this correct?
Thanks for your help.
You can test this in Sandbox. But if you're using "PayPal NVP", I assume you're using PayPal Express Checkout and calling the SetExpressCheckout and DoExpressCheckoutPayment API's.
If that's the case, you don't really need IPN, because a transaction will only be completed as soon as you call DoExpressCheckoutPayment.
In other words, buyers will always be redirected to the RETURNURL you specified in SetExpressCheckout, and the transaction is completed (or not) when you call DoExpressCheckoutPayment on this return page.
To get the invoice number, you could call GetExpressCheckoutDetails and supply the TOKEN you retrieved earlier (it's also appended to the GET of the RETURNURL).
Finally, check PAYMENTSTATUS=Completed in the DoExpressCheckoutPayment API response to see whether the transaction has completed or not.
Thank you Robert for the clarity on the process - especially useraction=commit.
I finally realized that I could turn on IPN in the Sandbox for my test seller and test NVP with IPN together. I was able to verify that PAYMENTREQUEST_0_INVNUM matches the 'INVOICE' parameter in the IPN POST.
I will use the custom field to pass customer email from my system in case they use a different email to log into paypal with, therefore allowing me to have email/invoice number pair for confirmation.