PHP Development method for parsing PayPal payment Interface _php Tutorial

Source: Internet
Author: User
Tags form post new set
Apply for PayPal registration website: https://www.paypal.com/

The PayPal interface is somewhat different from the other interfaces, slightly more complicated. In fact, the bank interface is also considered a site plug-in.

The so-called PayPal IPN (Instant Payment Notification) is a mechanism that PayPal develops to proactively inform third-party seller systems of trading status. The principle of IPN is very simple, that is, when the trading status changes after a transaction has occurred, such as when a user has paid, or refunds, or cancellations, PayPal uses the usual HTTP POST method to submit some variables of the transaction to a page of the website (called IPN Handler). When this page accepts the request, the data is added to the interface address that indicates the verification of cmd=_notify-validate,post back to PayPal, if the data is correct, then PayPal returns the string verified, otherwise invalid, If the result is verified, then your program can use that data to manipulate it.

Open Sandbox Account

But code debugging is a very painful thing, because as a third-party developer, it is impossible to open two accounts, each test also to trade some money, so PayPal specifically developed a sandbox for developers to develop, first to https:// developer.paypal.com/sign up for a Development account, and then go into the sandbox. Set up a test PayPal virtual account (at least one business and one personal), which The same as the PayPal process, the information can be fake, including the bank account number, credit card (in fact, the PayPal sandbox will automatically generate some random numbers). Next you need to activate the PayPal sandbox's virtual account, note that no matter what email address you fill in the PayPal sanbox registration, any email sent to the virtual account will be stored in the email page (available on the navigation bar) in the admin interface of the Development Account. Login Sandbox virtual PayPal environment, also need to verify the virtual account of the bank, where you can fill in, and then add funds to the account to recharge (how much you want to fill 920-203 920-533). Then, you also need to activate the IPN option, in the Business Account profile Settings page, click, and then click the Edit button to open IPN, here if you are using a fixed IPN Handle, you can directly fill in the address.

Next, when we test, we should set the address of the PayPal interface to HTTPS://WWW.SANDBOX.PAYPAL.COM/CGI-BIN/WEBSCR

The basic process

When the customer pays you, PayPal sends a notification to the server at the specified URL (type= "hidden" name= "Notify_url" value= "). This notification will include all of your customer's payment information (for example, customer name, amount), and a piece of encryption code. When the server receives a notification, it then sends the information (including the encryption code) back to the secure PayPal URL. PayPal will authenticate the transaction by checking the encrypted string. This transfer of IPN data back to PayPal prevents "spoofing", so you can ensure that IPN comes from PayPal. At the time of verification, PayPal will send a confirmation of its legitimacy back to your server.

Tip: To enable instant payment notifications, you will need to enter a URL through which you can receive notifications from your user information.

With instant payment notifications enabled, each time you receive a payment, your server receives a notification that it will be sent to the specified URL as a hidden "form POST" and will include all payment information. The FORM variable for the notification is listed at the bottom of this page.

Each time you receive IPN from PayPal, you must complete the notification confirmation process as described below before implementing the order. Confirming the information listed will ensure that the transaction is legal.

Notification Confirmation IPN

To ensure that the payment has entered your PayPal account, you must verify that the e-mail address used as "Receiver_email" has been registered and confirmed in your PayPal account.

After the server receives an instant payment notification, you will need to confirm it by building an HTTP POST sent to PayPal. Your POST should be sent to HTTPS://WWW.PAYPAL.COM/CGI-BIN/WEBSCR

You must send all received form variables exactly as they were when you received the form variable. You will also need to append a variable named "_notify-validate" with a value of "cmd" (for example, Cmd=_notify-validate) to the POST string.

PayPal will reply to the POST and include a word "verified" or "INVALID" in the body of the reply. When you receive a verified reply, you need to perform several checks before the order is implemented:

Verify that "Payment_status" is "completed" because the system also sends IPN for other results, such as "Pending" or "Failed".

Check if "txn_id" is not duplicated to prevent fraudsters from reusing old, completed transactions.

Verify that "Receiver_email" is an email address that has been registered in your PayPal account to prevent payment from being sent to the fraudster's account.

Check other transaction details (such as item number and price) to confirm that the price has not changed after you have completed the above checks, you can use the IPN data to update your database and process your purchases.

If an "invalid" notification is received, it should be treated as a suspicious notification and should be investigated.

Main parameters:

When you submit a paste code to PayPal, you should include the following 4 hidden variables and a picture, which means that the minimum required code you paste into PayPal should be as follows:

< form action="HTTPS://WWW.PAYPAL.COM/ROW/CGI-BIN/WEBSCR" method = "POST" >

< input type = "hidden" name = "cmd" value = "_xclick" ; //"_xclick" Buy now

< input type = "hidden" name = "business" value = "you@youremail.com"
//paypal e-mail address on the account

< input type = "hidden" name = "Item_name" value = "Item Name" ;
//Item name (or shopping cart name)

< input type = "hidden" name = "Currency_code" value = "USD" ;
//Define currencies to indicate currency variable values can be "USD", "EUR", "GBP" , "CAD", "JPY".

< input type="hidden" name="Amount" value="0.00">
//The price of the item (the total price of all items in the shopping cart, as is the _xclick mode)
<input type="Image " src = "http://www.paypal.com/zh_XC/i/btn/x-click-but01.
GIF " name=" Submit " alt=" Please pay with PayPal! ">

form>

Available variables

Business email address on your PayPal account

Quantity number of items. Greater than 1 o'clock, multiplied by the amount

Item_name Item name (or shopping cart name). Must be an alphanumeric character, up to 127 characters

Item_Number Optional pass-through variable used to track payments. Must be an alphanumeric character, up to 127 characters

The price of the amount item (the total price of all items in the shopping cart)

Shipping the cost of transporting the item

SHIPPING2 shipping costs for each additional item

Handling Handling Fee

Tax based on the transaction. If this variable is used, the pass-through value overrides all user information tax settings, regardless of the buyer's location.

no_shipping shipping address. If set to "1", your customer will not be asked to provide a shipping address. The variable is optional; if omitted or set to "0", your customer will be prompted to enter the shipping address

CN optional tab, displayed on the cue bar (up to 40 characters)

No_note add a hint for payment. If set to "1", your customer is not prompted for input. The variable is optional, and if omitted or set to "0", your customer will be prompted to enter a prompt.

On0 the first option bar name. Maximum of 64 characters

Os0 the first set of option values. A maximum of 200 characters. "On0" must be defined in order to identify "Os0".

On1 the second option bar name. Maximum of 64 characters

OS1 the second set of option values. A maximum of 200 characters. "On1" must be defined in order to identify "OS1".

Custom will never display an optional transmit variable to your customer. Can be used to track inventory

Invoice will never display an optional transmit variable to your customer. Can be used to track bill numbers

Notify_url is only used with IPN. Internet URL to send IPN Form Post

Return the Internet URL after your customer completes the payment

Cancel_return the Internet URL that will be returned after your customer cancels the payment

Image_url the Internet URL of the picture you want to use as an icon, the image size is 50 pixels

CS sets the background color of your payment page. If set to "1", the background color will be black. The variable is optional; if omitted or set to "0", the background color will be white

Extended variables

PayPal allows you to paste an extension variable, provided the following "CMD" value is changed:

To:

With the above "cmd" value modification, you can also use the following variables:

Extended variables

Email address of customer

First_Name the name of the customer. Must be an alphanumeric character, up to 32 characters

Last_Name the last name of the customer. Must be an alphanumeric character, up to 64 characters

Address1 the country or region where the customer's address is located. Must be an alphanumeric character, up to 100 characters

Address2 the second line of the customer address. Must be an alphanumeric character, up to 100 characters

City where the customer address is located. Must be an alphanumeric character, up to 100 characters

State where the customer address is located. Must be a formal 2-letter abbreviation

ZIP code for customer address

Night_phone_a the area code of the customer's night contact phone number

Night_phone_b Customer Night Contact phone number first three digits

Day_phone_a the area code of the customer's daytime contact telephone number

Day_phone_b Customer Day Contact phone number first three digits

Tip: To change the default shipping and handling settings in user information, go to your user information, edit your shipping charges calculation, and then click the "Allow transaction-based shipping charges" check box.

Pass a single item to PayPal

If your third-party shopping cart is set up to deliver a single item to PayPal, information about the item will be added to the record log and system notification of the buyer and seller. To add information to this item, you will need to paste the HTML formatting elements into the new version of the PayPal shopping cart process. The process is very similar to the one described in #1 section, "Passing the total shopping cart quantity to PayPal", except that:

Set the "CMD" variable to "_cart"

Replace the necessary HTML lines

And

Add a new variable called "Upload"

<表格> Add the following lines between the and tags:

Define Item Details

For each of the following specific item parameters, define a new set of values corresponding to the items purchased through your partner's shopping cart. Append "_x" to the variable name, where x is the item number, starting with 1 and adding one per item.

Item_name_x (item #x need) The name of the item #x in the shopping cart. Must be an alphanumeric character, up to 127 characters

Item_number_x Optional transfer variable associated with the item #x in the shopping cart. Must be an alphanumeric character, up to 127 characters

amount_x (goods #x need) price of goods #x

Shipping_x cost of the first piece of Goods #x (Qty 1)

Shipping2_x the shipping cost for each additional item #x (2 or more)

Handling_x disposal cost of goods #x

on0_x the first option bar name for the item #x. Maximum of 64 characters

Os0_x the first set of option values for an item #x. A maximum of 200 characters. "On0_x" must be defined in order to identify "os0_x".

on1_x the second option bar name for the item #x. Maximum of 64 characters

Os1_x the second set of option values for the item #x. A maximum of 200 characters. "On1_x" must be defined in order to identify "os1_x".

Repeat this setting for each item in your shopping cart

Add a set of required variables and any option variables from the table above for each item in your buyer's shopping cart. The first item in the cart must be defined as "_1″", such as "Item_name_1″," Amount_1″, etc. Similarly, the second item is named after the variable "Item_name_2″," Amount_2″, and so on. Tip: The "_x" value must be incremented in increments of one unit for identification. If you jump from item #1 to item #3 and do not define item #2, the third item is ignored.

To specify a currency: All currency variables (amount, freight, shipping 2, handling fee, tax) are displayed in the currency specified in the "currency_code" variable that is pasted on the payment. Because it is not different from the item, you do not need to append "_x" to the variable name. If you do not paste the "currency_code" variable, we will assume that the value of all currency variables is USD.

The above is the main operating procedure of using PHP to develop PayPal payment interface in this article.

http://www.bkjia.com/PHPjc/322635.html www.bkjia.com true http://www.bkjia.com/PHPjc/322635.html techarticle apply for PayPal registration URL: Https://www.paypal.com/paypal interface is somewhat different from other interfaces, slightly more complicated. In fact, the bank interface is also considered a site plug-in. The so-called PayPal ...

  • 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.