Difference between revisions of "PayPal/IPN"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
(New page: ==Overview== Instant Payment Notification (IPN) is one of two methods by which a web site may retrieve payment information from PayPal in real-time, i.e. immediately after a payment is...)
 
m (→‎Authentication: removed leftover text from when I had just figured it out)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==Overview==
 
==Overview==
Instant Payment Notification (IPN) is one of two methods by which a web site may retrieve payment information from [[PayPal]] in real-time, i.e. immediately after a payment is completed. The other method is [[../PDT|Payment Data Transfer]] (PDT).
+
Instant Payment Notification (IPN) is one of two methods by which a web site may retrieve payment information, in real time (i.e. immediately after the payment is completed), resulting from a transaction conducted on [[PayPal]]'s web site. The other method is [[../PDT|Payment Data Transfer]] (PDT).
  
 
IPN is somewhat more reliable than PDT in that PayPal's server contacts the merchant's server directly to transmit transaction data as soon as the transaction has occurred, rather than depending on the customer's browser to convey the data.
 
IPN is somewhat more reliable than PDT in that PayPal's server contacts the merchant's server directly to transmit transaction data as soon as the transaction has occurred, rather than depending on the customer's browser to convey the data.
  
 
{{seed}}
 
{{seed}}
==Example==
+
===Pages===
Sample data passed back to the merchant's server using IPN (using the PayPal [[../Sandbox|Sandbox]], not a real transaction), as collected by [[MediaWiki/SpecialLogPost|SpecialLogPost]]:
+
* [[/example]]
===HTML form code===
+
==Links==
<xml>
+
* [https://www.paypal.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html Order Integration: IPN]
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
+
** [https://www.paypal.com/us/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-pop-outside sample code]
<input type="hidden" name="cmd" value="_s-xclick">
+
* [https://www.paypal.com/us/cgi-bin/webscr?cmd=p/acc/ipn-info how it works] (login required)
<input type="hidden" name="hosted_button_id" value="14406">
+
 
<input type="hidden" name="custom" value="UserNameWouldGoHere">
+
==Authentication==
<input type="hidden" name="invoice" value="InvoiceFieldGoesHere">
+
In order to prevent spoofing of an IPN, i.e. determine that it definitely comes from PayPal rather than from a third party trying to fool your system into believing a payment has been made, each IPN should be authenticated before being trusted. The process works like this:
<input type="hidden" name="notify_url" value="http://wiki.vbz.net/Special:LogPost">
+
* PayPal generates a '''verify_sign''' code, and includes it with the IPN data
<input type="hidden" name="return" value="http://test.vbz.net/cgi-bin/runpl">
+
* Your server sends return post ''back to PayPal'' which includes the '''verify_sign''' data
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif"
+
* PayPal checks that this is the '''verify_sign''' it sent, and returns a code to let you know the result of the check
border="0" name="submit" alt="">
+
 
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
+
According to the [https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_OrderMgmt_IntegrationGuide.pdf Order Management Integration Guide] (OMIG), "The value of '''verify_sign''' is an encrypted string used to validate the authenticity of the transaction." The idea appears to be that this is a random string whose value is stored by PayPal at the time of generation; only PayPal knows what value is associated with each transaction, making it essentially impossible for a spoofer to generate a "valid" verify_sign value.
</form>
+
 
</xml>
+
Your server's return post back to PayPal ensures that PayPal is actually in the loop during this process.
===IPN POSTed data===
+
 
<pre>
+
Some sample values of '''verify_sign''':
2009-01-01 21:58:16
+
AiPC9BjkCyDFQXbSkoZcgqH3hpacAM9KNT3jv0YPjZMPbrIcmvcIcLHa
REQUEST_METHOD POST
+
A7dSYdSlxg1gCvXiSPGpzFCXqlPvAIpupa..c7qIy0mlpCpNahyX5eL7
HTTP_USER_AGENT
+
A1.T9PIMhr2k3PSwkHkiKBR19G59AqQHhQC02ybe8q549oTKvY0Bbhlh
REMOTE_ADDR 216.113.191.33
+
 
transaction_subject
+
Tentatively, it looks like a modulo-64 (upper & lowercase alpha, numerics, period = 26+26+10+1=63; presumably there's another punctuation character to make it a nice, round 64) encoded integer; with 56 digits, that means 64<sup>56</sup> (over 10<sup>101</sup>) possible values.
payment_date 18:58:14 Jan 01, 2009 PST
 
txn_type subscr_payment
 
subscr_id S-5G6357170N2927728
 
last_name User
 
residence_country US
 
item_name Full Site Access - one year
 
payment_gross 49.00
 
mc_currency USD
 
business paypal_1230320215_biz@hypertwins.org
 
payment_type instant
 
protection_eligibility Ineligible
 
verify_sign AxvQhTcd4JBdIIpB5MztE755SMD7AMz0sJLKKvdDiqzSP8TKRFoLHttM
 
payer_status verified
 
test_ipn 1
 
payer_email paypal_1230659178_per@hypertwins.org
 
txn_id 17R310755W630331M
 
receiver_email paypal_1230320215_biz@hypertwins.org
 
first_name Test
 
invoice InvoiceFieldGoesHere
 
payer_id 9AAMA7CUQ8TUN
 
receiver_id YCRD6GWFSUZ5L
 
payment_status Completed
 
payment_fee 1.72
 
mc_fee 1.72
 
btn_id 14406
 
mc_gross 49.00
 
charset windows-1252
 
notify_version 2.6
 
2009-01-01 21:58:16
 
REQUEST_METHOD POST
 
HTTP_USER_AGENT
 
REMOTE_ADDR 216.113.191.33
 
txn_type subscr_signup
 
subscr_id S-5G6357170N2927728
 
last_name User
 
residence_country US
 
mc_currency USD
 
item_name Full Site Access - one year
 
business paypal_1230320215_biz@hypertwins.org
 
amount3 49.00
 
recurring 1
 
verify_sign AdXmlE88KERMphmdMG4e.jeWGlkRAcUYzJVdMfWdteAAmuWxx9bpnguV
 
payer_status verified
 
test_ipn 1
 
payer_email paypal_1230659178_per@hypertwins.org
 
first_name Test
 
receiver_email paypal_1230320215_biz@hypertwins.org
 
payer_id 9AAMA7CUQ8TUN
 
invoice InvoiceFieldGoesHere
 
reattempt 1
 
subscr_date 18:58:12 Jan 01, 2009 PST
 
btn_id 14406
 
charset windows-1252
 
notify_version 2.6
 
period3 1 Y
 
mc_amount3 49.00
 
</pre>
 
Note that IPN returns the '''invoice''' data but not the '''custom''' data.
 

Latest revision as of 15:06, 2 March 2009

Overview

Instant Payment Notification (IPN) is one of two methods by which a web site may retrieve payment information, in real time (i.e. immediately after the payment is completed), resulting from a transaction conducted on PayPal's web site. The other method is Payment Data Transfer (PDT).

IPN is somewhat more reliable than PDT in that PayPal's server contacts the merchant's server directly to transmit transaction data as soon as the transaction has occurred, rather than depending on the customer's browser to convey the data.


This page is a seed article. You can help HTYP water it: make a request to expand a given page and/or donate to help give us more writing-hours!

Pages

Links

Authentication

In order to prevent spoofing of an IPN, i.e. determine that it definitely comes from PayPal rather than from a third party trying to fool your system into believing a payment has been made, each IPN should be authenticated before being trusted. The process works like this:

  • PayPal generates a verify_sign code, and includes it with the IPN data
  • Your server sends return post back to PayPal which includes the verify_sign data
  • PayPal checks that this is the verify_sign it sent, and returns a code to let you know the result of the check

According to the Order Management Integration Guide (OMIG), "The value of verify_sign is an encrypted string used to validate the authenticity of the transaction." The idea appears to be that this is a random string whose value is stored by PayPal at the time of generation; only PayPal knows what value is associated with each transaction, making it essentially impossible for a spoofer to generate a "valid" verify_sign value.

Your server's return post back to PayPal ensures that PayPal is actually in the loop during this process.

Some sample values of verify_sign:

AiPC9BjkCyDFQXbSkoZcgqH3hpacAM9KNT3jv0YPjZMPbrIcmvcIcLHa
A7dSYdSlxg1gCvXiSPGpzFCXqlPvAIpupa..c7qIy0mlpCpNahyX5eL7
A1.T9PIMhr2k3PSwkHkiKBR19G59AqQHhQC02ybe8q549oTKvY0Bbhlh

Tentatively, it looks like a modulo-64 (upper & lowercase alpha, numerics, period = 26+26+10+1=63; presumably there's another punctuation character to make it a nice, round 64) encoded integer; with 56 digits, that means 6456 (over 10101) possible values.