PayPal IPN Interface Development Summary

Source: Internet
Author: User
Tags install openssl
PayPal IPN Interface Development Summary: Jan

Recently, we finally completed the damn PayPal IPN, and made some notes here.
Therefore, PayPal IPN (instant payment notification) is a mechanism developed by PayPal to actively notify third-party sellers of the transaction status. The principle of IPN is very simple, that is, when a transaction is generated and the transaction status changes, such as the user has already paid, refunded, or revoked, PayPal uses the common http post method, submit some transaction variables to a website page (called IPN handler). When the page receives the request, add cmd = _ policy-validate indicating verification to the original data and post the interface address to PayPal. If the data is correct, PayPal returns the string verified; otherwise, it is invalid, if the result is verified, your program can use the data for operations.
However, code debugging is a very painful task, because as a third-party developer, it is impossible to open two accounts and trade some money between each test, so PayPal specially developed sandbox for developers to develop, first to the https://developer.paypal.com/register a development account, after that, go to sandbox and create a PayPal virtual account for testing (at least one business account and one personal account should be created). This account registration method is the same as that of PayPal, information can be fake, including bank accounts and credit cards (in fact, PayPal sandbox will automatically generate some random numbers ). Next, activate the virtual account of the PayPal sandbox. Note that no matter what email address you enter when registering the PayPal sanbox, any emails sent to the email address entered by the virtual account are saved on the email page (on the navigation bar) of the Development Account Management Interface. Log on to the virtual PayPal environment of sandbox and verify the bank of the virtual account. You can fill in the field here and add funds to recharge your account (How much do you want to fill in ). Then, you also need to activate the IPN option. On the Profile Settings page of the business account, click, and then click the edit button to open IPN, if you are using a fixed IPN handle, you can enter the address directly.
Next, we should set the address of the PayPal interface to https://www.sandbox.paypal.com/cgi-bin/webscr during the test
The basic process is as follows:

The user selects products on our website, puts them in the shopping cart, and then checks for the preparation and payment
The website generates a Paypal payment form based on the items in the shopping cart (which is also the address of the PayPal interface used for submission to IPN ), contains some information about this transaction (next time I will look for a special opportunity to explain it ). And generate an order record in your database.
PayPal records the transaction information in the session.
Use a PayPal account to log on to PayPal (sandbox's virtual account), review details, and click pay.
PayPal handles transactions. If our PayPal account has no problems with the account to be accepted (there is no special need to "accept" on the Interface), the transaction is completed, then PayPal will send an IPN and send a prompt email.
Our IPN handler receives the information and first checks the information with Paypal. If the information is correct, it compares the information with the information in its own database. If the information is correct, it can save the payment information, and modify the order status.
Then, PayPal will display an interface indicating that the transaction is complete. If you click "return", PayPal will send the user back to the specified location on our website.
Our website welcomes the user back, expresses thanks to the user, reminds me, and gives the order number.

The entire process is basically as follows, but there are many points to note:

We can see that the interface address starts with HTTPS, that is, SSL is required for connection. In fact, PayPal sandbox can use HTTP, but the actual PayPal interface does not support HTTP, therefore, if you use PHP to write IPN handler scripts, it is useless to simply use tools such as fopen and http_request in the Code section of the verification information. php socks libraries do not support SSL, there are two methods to use curl. One is to use libcurl in the PHP extension, which is used in the SDK officially released by PayPal, but the SDK of Paypal is very complicated, if you want to write it on your own, you can use Snoopy, a simple and practical PHP request library (which simulates browser behavior), and uses the executable file of curl, the results are obtained through the pipeline, rather than the PHP libcurl. Therefore, you may need to install OpenSSL when downloading an SSL-supported compilation version on your own curl homepage. However, for Linux systems, you may need This will all be included.
In the payment form, you can set the policy_url field to specify where the transaction information should be sent, so that we can overwrite the settings in the profile. In addition, urlencode is required for this field.
In the obtained IPN information, the status corresponds to the transaction status. For example, if complete indicates completion, the initial letter is capitalized, and the verification result is verifiey or invalid. All are capitalized. The specific content is as follows, you can refer to the official documentation of PayPal Order Management Integration guide.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.