Frnak
Frnak

Reputation: 6812

Paypal Adaptive / Chained Payments Workflow

first of all, i'm kinda new to paypal adaptive payments, until now I only used the REST api.

I have problems understanding the complete flow of the applications when implementing adaptive payments.

In the REST api I navigate the user to the paypal page where he pays and get's redirected to my page where I can react on the result.

Using the adaptive Payments the user does not get redirected directly after the payment. Therefore I cannot guarantee he will open the given redirect page.

It seems like ipn is the solution for this, however I'm not sure on how to implement this correctly.

I used an example i found and logged the result which iresults in the following log entry. I have problmens to interpret the result. It is generated using the ipn simulator.

[2016-05-02 20:17 UTC] HTTP request of validation request:POST /cgi-bin/webscr HTTP/1.1
Host: www.sandbox.paypal.com
Accept: */*
Connection: Close
Content-Length: 943
Content-Type: application/x-www-form-urlencoded

 for IPN payload: cmd=_notify-validate&payment_type=instant&payment_date=Mon+May+02+2016+22%3A17%3A33+GMT%2B0200+%28Mitteleurop%C3%A4ische+Sommerzeit%29&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer%40paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John+Smith&address_country=United+States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San+Jose&address_street=123+any+street&business=seller%40paypalsandbox.com&receiver_email=seller%40paypalsandbox.com&receiver_id=seller%40paypalsandbox.com&residence_country=US&item_name1=something&item_number1=AK-1234&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross_1=12.34&mc_handling=2.06&mc_handling1=1.67&mc_shipping=3.02&mc_shipping1=1.02&txn_type=cart&txn_id=250343399&notify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AIR-7FrBuOZZqJMDr8d5DxEI9rpG
[2016-05-02 20:17 UTC] HTTP response of validation request: HTTP/1.1 200 OK
Date: Mon, 02 May 2016 20:17:42 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Set-Cookie: c9MWDuvPtT9GIMyPc3jwol1VSlO=vKsQ6Wsa8-CKaGYKLQkEziH8epLey-sigvcn6CGIx_BbN7f2lkSe4OGhXkrOoD98VscO4s-IeGzIJCQSjGbkN5Zy8ggokZMUzKgmU3DXPZQ12IS1gqWwws-ZbEZwuGYp75eS0cS94sdZ7NduMDdd-wj9neb47z6x3sZOBs76MeZAu3aVS0hQFhfLWtTs5kGfVtFWpDMlA-h6xzEk1jTOteInNMwwvIKfcctwTP0lq7HdBsSpBOxgGkj5aGqanty9RiMlioT_7_3I93WK2S1pTJuN5HIIuS4Ci3HuXUkgin6ian6oEhLnCPodUjWa_VIVmAUkxmVcrb1AOxLDa0lBYfV5b7vnHTHWkxtct-r7YQKX6un7_RyfeOrlSODOK-1FPcaQl6R5W7bQEuvm98K4kECj_EkvIFeUcjZWQ7wUx5Lc-Sja3yZDfFrWSvS; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: cookie_check=yes; expires=Thu, 30-Apr-2026 20:17:42 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navlns=0.0; expires=Wed, 02-May-2018 20:17:42 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: Apache=10.72.108.11.1462220262202022; path=/; expires=Wed, 25-Apr-46 20:17:42 GMT
Vary: Accept-Encoding,User-Agent
Connection: close
HTTP_X_PP_AZ_LOCATOR: sandbox.slc
Paypal-Debug-Id: ed99d0b22cb7d
Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.WEB.1%26silo_version%3D1880%26app%3Dappdispatcher%26TIME%3D3870631767%26HTTP_X_PP_AZ_LOCATOR%3Dsandbox.slc; Expires=Mon, 02 May 2016 20:47:42 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
Strict-Transport-Security: max-age=14400
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

INVALID
[2016-05-02 20:17 UTC] Invalid IPN: cmd=_notify-validate&payment_type=instant&payment_date=Mon+May+02+2016+22%3A17%3A33+GMT%2B0200+%28Mitteleurop%C3%A4ische+Sommerzeit%29&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer%40paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John+Smith&address_country=United+States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San+Jose&address_street=123+any+street&business=seller%40paypalsandbox.com&receiver_email=seller%40paypalsandbox.com&receiver_id=seller%40paypalsandbox.com&residence_country=US&item_name1=something&item_number1=AK-1234&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross_1=12.34&mc_handling=2.06&mc_handling1=1.67&mc_shipping=3.02&mc_shipping1=1.02&txn_type=cart&txn_id=250343399&notify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AIR-7FrBuOZZqJMDr8d5DxEI9rpG

Upvotes: 2

Views: 107

Answers (1)

Kris Bonev
Kris Bonev

Reputation: 552

Yes, the answer you are looking for is IPN. There are steps to implement the flow.

First, in your sandbox settings - you should enable the Instant Payment Notification and provide url for it. Now, you can just enter a dummy link, cause you can overwrite it with the actual call for the payment. Have in mind, that you should provide a real url, because PayPal is unable to see your localhost.

Next, you should implement an IPN listener in your code. I think this should help you with it. I did it in C#, so cannot provide you with the exact code. It is important for you to include some information for the payment in the payment call to paypal, so you can receive it in the IPN and detect for which payment you are receiving a notification.

Btw, you can specify ReturnURL and CancelURL in the payment call to paypal, so the user is automatically redirected to where you want, after he has completed his payment.

Upvotes: 1

Related Questions