Apply for PayPal registration URL: https://www.paypal.com/
The paypal interface is somewhat different from other interfaces and is a little more complicated. In fact, the bank interface is also a site plug-in.
The so-called paypal ipn (Instant Payment Notification) is a mechanism developed by Paypal to actively notify third-party sellers of the Transaction Status of the system. 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.
Create a Sandbox account
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, therefore, Paypal has developed Sandbox for developers. First, go to Alipay (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, then, Add Funds to recharge your account (920-203 920-533 ). 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
Basic Process
When the customer pays you, PayPal will send a notification to the server located in the specified URL (type = "hidden" name = "yy_url" value =. This notification will include all 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 message (including the encrypted code) back to a secure PayPal URL. PayPal will verify the identity of the transaction by checking the encrypted string. This operation of sending IPN data back to PayPal prevents "spoofing", so you can ensure that IPN comes from PayPal. During verification, PayPal will send the confirmation information of its validity back to your server.
Tip: To enable instant payment notification, you need to enter a URL through which you can receive notifications from your users.
After the instant payment notification is enabled, your server receives a Notification every time you receive the payment. This notification will be sent to the specified URL in a hidden form post mode, all payment information will be included. The FORM variable of the notification is listed at the bottom of this page.
Each time you receive an IPN from PayPal, you must complete the following notification confirmation process before implementing the order. Confirming the information listed will ensure that the transaction is legal.
Notification confirmation IPN
To ensure that the payment has been made to your PayPal account, you must verify that the email address used as "receiver_email" has been registered with your PayPal account and has been confirmed.
After the server receives an instant payment notification, you need to build an http post sent to PayPal to confirm it. Your POST should be sent to the https://www.paypal.com/cgi-bin/webscr
You must send all received form variables exactly as they are when you receive the form variables. You also need to append a variable named "cmd" (for example, cmd = _ policy-validate) with the value of "_ policy-validate" to the POST string.
PayPal will reply to the POST and include the word "VERIFIED" or "INVALID" in the body of the response ". When you receive a VERIFIED reply, you need to perform several checks before implementing the order:
Confirm that "payment_status" is "Completed" because the system will also send IPN for other results (such as "Pending" or "Failed.
Check whether "txn_id" is repeated to prevent the fraudster from reusing the old completed transaction.
Verify that "receiver_email" is an email address that has been registered with your PayPal account to prevent sending payments to the account of the fraudster.
After checking other transaction details (such as item numbers and prices) to confirm that the price has not changed, you can use IPN data to update your database and process the purchase.
If an "invalid" notification is received, it shall be deemed as a suspicious notification and should be investigated.
Main parameters:
When submitting the paste code to PayPal, the following four hidden variables and an image should be included. That is to say, the shortest required code for pasting to 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">
// Email address on the PayPal 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 the currency to indicate that the variable values can be "USD", "EUR", "GBP", "CAD", and "JPY ".
<Input Type="Hidden" Name="Amount" Value="0.00">
// Item price (the total price of all items in the shopping cart, because it is in the _ Xclick Mode)
<Input Type="Image" Src="Http://www.paypal.com/zh_XC/ I /btn/x-click-but01.
Gif" Name="Submit" Alt="Please pay by PayPal! ">
</Form>
Available Variables
Business your PayPal account's email address
Quantity of quantity items. If the value is greater than 1, it is multiplied by the amount.
Item_name Item Name (or shopping cart name ). It must be letters, numbers, and a maximum of 127 characters.
Item_number is an optional variable used to track payments. It must be letters, numbers, and a maximum of 127 characters.
Amount item price (total price of all items in the shopping cart)
Shipping the shipping cost of this item
Shipping2 shipping costs for each additional item
Handling fee
Tax is based on the transaction tax amount. If this variable is used, the pass value will overwrite all user information tax settings (regardless of the buyer's location ).
No_shipping: the shipping address. If it is set to "1", your customer is not required to provide the shipping address. This variable is optional. If it is omitted or set to "0", you are prompted to enter the shipping address.
The available cn tags are displayed on the prompt bar (up to 40 characters)
No_note indicates the payment addition prompt. If it is set to "1", no prompt is displayed for your customer. This variable is optional. If it is omitted or set to "0", you are prompted to enter a prompt.
The name of the first option column of on0. Up to 64 characters
The first option value of os0. It can contain a maximum of 200 characters. "On0" must be defined to identify "os0 ".
The name of the second option column of on1. Up to 64 characters
The second set of os1 option values. It can contain a maximum of 200 characters. "On1" must be defined to identify "os1 ".
Custom will never forward optional variables to your customers. Can be used to track inventory
Invoice will never forward optional variables to your customers. Used to track bill numbers
Notify_url is only used with IPN. Internet URL for sending IPN Form Post
Return the Internet URL that will be returned after your customer completes the payment
Cancel_return the Internet URL returned after your customer cancels the payment
Image_url: Internet URL of the image to be mapped. The image size is 150X50 pixels.
Cs sets the background color of your payment page. If it is set to "1", the background color is black. This variable is optional. If it is omitted or set to "0", the background color is white.
Extended variable
PayPal allows you to paste extension variables if the following "cmd" value is changed:
To:
You can also use the following variables to modify the "cmd" value:
Extended variable
Email customer's email address
The customer name of first_name. It must be letters, numbers, and a maximum of 32 characters.
Last_name. It must be letters, numbers, and a maximum of 64 characters.
Address1 the country or region where the customer address is located. It must be letters, numbers, and a maximum of 100 characters.
The second line of address2 customer address. It must be letters, numbers, and a maximum of 100 characters.
City: the city where the customer address is located. It must be letters, numbers, and a maximum of 100 characters.
State the state where the customer address is located. Must be a formal 2-letter abbreviation
Zip client address zip code
The area code of the customer's overnight contact phone number
The first three customer phone numbers at night
Day_phone_a area code of the customer's daytime contact phone number
Day_phone_ B the first three telephone numbers of the customer during the day
Tip: to change the default shipping and service fee settings in "user information", go to your user information and edit your shipping calculation, then click the "allow use of trade-based freight" check box.
Pass a single item to PayPal
If your third-party shopping cart can be set to deliver a single item to PayPal, information about the item will be included in the buyer and seller's log and system notification. To add the information of this item, you must paste the HTML elements into the new version of the PayPal Shopping Cart process. This process is similar to Section #1 "transferring the total number of shopping carts to PayPal", with the following differences:
Set the "cmd" variable to "_ cart"
Change necessary HTML lines
And
Add a new variable called "upload"
Add the following lines between <Table> and Tag:
Define item details
For the following specific item parameters, define a set of new values corresponding to each item purchased through the shopping cart of your partner. Append "_ x" to the variable name, where x is the item number. From 1, add one for each added item.
Item_name_x (item # x required) Name of item # x in the shopping cart. It must be letters, numbers, and a maximum of 127 characters.
Item_number_x: Optional variable associated with item # x in the shopping cart. It must be letters, numbers, and a maximum of 127 characters.
Amount_x (item # x required) item # price of x
Shipping_x Shipping item # cost of x first (quantity 1)
Shipping2_x each additional shipping item # x (quantity 2 or more) shipping costs
Handling_x item # x processing cost
The name of the first option column of on0_x item # x. Up to 64 characters
Os0_x item # The first option value of x. It can contain a maximum of 200 characters ." On0_x "must be defined to identify" os0_x ".
The second option column name of on1_x item # x. Up to 64 characters
Os1_x item # The second option value of x. It can contain a maximum of 200 characters ." On1_x "must be defined to identify" os1_x ".
Repeat this setting for each item in the shopping cart
Add a set of required variables and any option variables to each item in your buyer's shopping cart in the above table. The first item in the shopping cart must be defined by the parameter ending with "_ 1", such as "item_name_1" and "amount_1. Similarly, the second item is named by the Application variables "item_name_2" and "amount_2. Tip: the "_ x" value must increase in order to identify it. If you jump from item #1 to item #3 without defining item #2, the third item is ignored.
To specify the currency: All Currency variables (amount, freight, freight 2, service fee, and tax) will be displayed in the currency specified by the "currency_code" variable pasted on the payment. Because it is not different from the item, you do not need to append "_ x" to the variable name ". If the "currency_code" variable is not pasted, we assume that the values of all currency variables are USD.
The above is the main procedure of using PHP to develop the PayPal payment interface.