Analysis of PayPal payment interface PHP Development way _php Skills

Source: Internet
Author: User
Tags form post http post new set

Application PayPal Registration URL: https://www.paypal.com/

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

The so-called PayPal IPN (Instant Payment Notification), is a PayPal development of the initiative to inform the Third-party seller system trading status of a mechanism. The principle of IPN is very simple, that is, when a transaction occurs, when the transaction status changes, such as the user has paid, or refund, revocation, PayPal use commonly used HTTP POST way, will deal with some variables to the site of a page (called IPN Handler), When the page is accepted to the request, the data is added as an indication of the authentication of the Cmd=_notify-validate,post back to the interface address PayPal, if the data is correct, then PayPal return string verified, or invalid, If the result is verified, then your program can use this data to operate.

Open Sandbox Account

But debugging the code is a very painful thing, because as a third party developers, it is impossible to open two accounts, each test also to trade some money, so PayPal specializes in the development of sandbox to developers, first to https:// developer.paypal.com/sign up for a Development Account, and then enter sandbox to build a test PayPal virtual account (at least a business and a personal), which Account registration method and the process of PayPal, the information can be false, including bank accounts, credit cards (in fact, PayPal sandbox will automatically generate some random numbers). Next need to activate the PayPal sandbox virtual account, note, here, regardless of your PayPal sanbox registration when you fill in the mail address, there are any sent to the virtual account to fill in the mailbox mail will be in the Development Account management interface of the email page (on the navigation bar). Login Sandbox virtual PayPal environment, also need to verify the virtual account of the bank, where you can easily fill in, and then through the add funds to recharge the account (want to fill in how many 920-203 920-533). Then, also need to activate the IPN option, in the Business Account profile Settings page, click, then click the Edit button, 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"). This notification will include all of your customer's payment information (for example, customer name, amount), and a section of encrypted code. When the server receives a notification, it then sends the information, including the encrypted code, back to the secure PayPal URL. PayPal will authenticate the transaction by checking the encrypted string. This will send IPN data back to PayPal operation to prevent "deception", so you can ensure that IPN from PayPal. At the time of verification, PayPal sends confirmation of its legality 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.

When instant payment notifications are enabled, each time you receive a payment, your server receives a notification that 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 an IPN from PayPal, you must complete the notification confirmation process as described below before you implement the order. Confirming that the information listed will ensure that the transaction is legal.

Notify Confirm IPN

In order to ensure payment has entered your PayPal account, you must verify that the email address used as "Receiver_email" has been registered and confirmed in your PayPal account.

Once the server receives an instant payment notification, you will need to confirm it by building an HTTP POST 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 the form variable was received. You will also need to append a "_notify-validate" variable named "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 will also send IPN for other results (such as "Pending" or "Failed").

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

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

Check other transaction details (e.g. item number and price) to confirm that the price has not changed after the above inspection, you can use IPN data to update your database and handle shopping.

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

Main parameters:

When submitting the pasted code to PayPal, you should include the following 4 hidden variables and a picture, that is to say, the shortest necessary code you paste to PayPal should be as follows:

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

<input type = "hidden" name = < Font color= "#ff0000" >value = "_xclick" span class= "tag" > >    //"_xclick" Buy now

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

<input type = "hidden" name = "Item_name" value = >
// Item name (or cart name)

<input type="hidden" name="Currency_code" value="USD" >
Define the currency to indicate that the currency variable value can be "USD", "EUR", "GBP", "CAD", "JPY".

<input type="Hidden" name="Amount" value="0.00">
//Item Price (total price for all items in the cart, because it is _xclick mode)
input type = "image" < Font color= "#ff0000" >src = http:// www.paypal.com/zh_XC/i/btn/x-click-but01.
gif name = alt =" please pay with PayPal! " '

</form>

Available variables

Business The email address on your PayPal account

Number of quantity items. is greater than 1 o'clock and is multiplied by the amount

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

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

Amount the price of the goods (the total price of all items in the shopping cart)

Shipping cost of this item

Shipping2 shipping cost per additional item

Handling Handling Fee

Tax is based on transaction tax. If you use this variable, passing values overrides all user information tax settings (regardless of where the buyer is located).

no_shipping shipping address. If set to "1", your customer is not required 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, which will be displayed on the prompt bar (up to 40 characters)

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

On0 first option column name. Up to 64 characters

Os0 the first set of option values. Up to 200 characters. "On0" must be defined in order to recognize "OS0".

On1 the second option bar name. Up to 64 characters

OS1 the second set of option values. Up to 200 characters. "On1" must be defined in order to recognize "OS1".

The optional forwarding variable that custom will never display to your customers. Can be used to track inventory

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

Notify_url is only used with IPN. Send IPN Form Post's Internet URL

Return the Internet URL after your customer completes payment

Cancel_return the Internet URL that your customer will return after canceling payment

Image_url the Internet URL for the picture you want to use as an icon, with a picture size of 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

Extension variables

PayPal allows you to paste extension variables, provided the following "CMD" values are changed:

To:

You can also use the following variables by modifying the "cmd" value above:

Extension variables

Email address of an email customer

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

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

Address1 the country or region where the customer 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 customer address. Must be an alphanumeric character, up to 100 characters

State customer address. Must be a formal 2-letter abbreviation

ZIP code for customer address

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

Night_phone_b Customer Night Contact phone number top three digits

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

Day_phone_b Customer Daytime contact telephone number top three digits

Tip: To change the default shipping and handling setting in user information, go to your user information, edit your shipping charges, and then click the "Allow Transaction based freight" check box.

Pass a single item to PayPal

If your third party shopping cart can be set to pass a single item to PayPal, information about the item will be included in the buyer's and seller's log and system notices. To add information about the item, you need to paste the HTML formatting elements into a new version of the PayPal shopping cart process. This process is very similar to the one described in the #1 section "passing the total number of cart numbers 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 < table > and Tags:

Define Item Details

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

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

item_number_x an optional pass variable associated with the item #x in the shopping cart. Must be an alphanumeric character, up to 127 characters

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

Shipping_x the cost of the first item (number 1) of goods #x shipped

shipping2_x shipping costs for each additional item #x (number 2 or more)

The cost of handling the handling_x items #x

On0_x items #x The first option bar name. Up to 64 characters

Os0_x Items #x The first set of option values. Up to 200 characters. "On0_x" must be defined in order to recognize "os0_x".

On1_x Items #x The second option bar name. Up to 64 characters

Os1_x Items #x The second set of option values. Up to 200 characters. "On1_x" must be defined in order to recognize "os1_x".

Repeat this setting for each item in your shopping cart

Add a set of required variables and any option variables in the above table for each item in your buyer's shopping cart. The first item in the cart must be used to "_1″ the end of the parameter definition, such as" Item_name_1″, "Amount_1″, etc. Similarly, the second item is named after the variable "Item_name_2″," Amount_2″. Tip: The "_x" value must be incremented in one order to identify it. If you jump from item #1 to item #3 without defining item #2, the third item is ignored.

To specify currency: All currency variables (amount, freight, freight 2, handling fee, tax) are displayed in the currency specified by 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 all currency variables are in US dollars.

The above is the introduction of the use of PHP to develop PayPal payment interface of the main operating procedures.

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.