1. register a development account in the https://developer.paypal.com, and then enter Sandbox to create a testing Paypal virtual account (at least a Business and a Personal should be created), information can be false, note: at least two test accounts are created in your development account. do not register an error;
2. testing is very troublesome, but it is essential, because if the customer buys an error once, it will not come for the second time, so it is very important to spend half a day testing;
Using System;
Using System. IO;
Using System. Text;
Using System. Net;
Using System. Web;
Public partial class csIPNexample: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
// Post back to either sandbox or live
String strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr ";
String strLive = "https://www.paypal.com/cgi-bin/webscr ";
HttpWebRequest req = (HttpWebRequest) WebRequest. Create (strSandbox );
// Set values for the request back
Req. Method = "POST ";
Req. ContentType = "application/x-www-form-urlencoded ";
Byte [] param = Request. BinaryRead (HttpContext. Current. Request. ContentLength );
String strRequest = Encoding. ASCII. GetString (param );
StrRequest + = "& cmd = _ policy-validate ";
Req. ContentLength = strRequest. Length;
// For proxy
// WebProxy proxy = new WebProxy (new Uri ("http: // url: port #"));
// Req. Proxy = proxy;
// Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter (req. GetRequestStream (), System. Text. Encoding. ASCII );
StreamOut. Write (strRequest );
StreamOut. Close ();
StreamReader streamIn = new StreamReader (req. GetResponse (). GetResponseStream ());
String strResponse = streamIn. ReadToEnd ();
StreamIn. Close ();
If (strResponse = "VERIFIED ")
{
// Check the payment_status is Completed
// Check that txn_id has not been previusly processed
// Check that receiver_email is your Primary PayPal email
// Check that payment_amount/payment_currency are correct
// Process payment
}
Else if (strResponse = "INVALID ")
{
// Log for manual investigation
}
Else
{
// Log response/ipn data for manual investigation
}
}
}
1. The buyer and seller must be registered users of paypal.
2. It is also called recharge. Since then, online payment is no longer related to bank cards.
Online Shopping
The seller obtains the button from the paypal website.
Main parameters:
Add: only one product can be purchased at a time.
Upload: You can purchase a variety of products
Shopping Cart
<Input type = "hidden" name = "cmd" value = "_ cart">
Seller's account
<Input type = "hidden" name = "business" value = "jiangjun_0_1999@163.com">
Product Name
<Input type = "hidden" name = "item_name" value = "Java">
Product NO.
<Input type = "hidden" name = "item_number" value = "1001">
Product Price
<Input type = "hidden" name = "amount" value = "1.00">
Item quantity-for each item
<Input type = "hidden" name = "quantity" value = "2">
Currency type CNY: RMB, USD: USD
<Input type = "hidden" name = "currency_code" value = "CNY">
Cancel the transaction and return the location
<Input type = "hidden" name = "cancel_return" value = "http: // localhost/wwwShop. php">
Position automatically returned after Transaction completion
<Input type = "hidden" name = "return" value = "http: // localhost/wwwShop. php">
Payment data transmission (PDT)
Returned Parameters
Atm: transaction amount
Tx: transaction number
St: status value = Completed indicates the Transaction completion.
Cc = CNY: it should be a currency type
Cm =
Sig =
Secondary return
The second return is executed in the program.
Cmd = _ policy-synch (this must be written). The combination of tx and at is used for parameters returned twice,
At is the identity tag, not the returned parameter, but must be manually added.
Instance:
Buy. php
<Input type = "hidden" name = "return" value = "http: // localhost/paypal. php">
Paypal. php
<?
$ Req = 'cmd = _ policy-synch ';
$ Tx_token = $ _ GET ['tx '];
$ Auth_token = "SJIKB64NeDhAFQg_h1H2YjTrW4EoLeDYXx-iWOvQ3uvhZs5zER1aL8EZbvW ";
$ Req. = "& tx = $ tx_token & at = $ auth_token ";
// Post back to PayPal system to validate
$ Header. = "POST/cgi-bin/webscr HTTP/1.0 ";
$ Header. = "User-Agent: PHP/". phpversion ()."";
$ Header. = "Content-Type: application/x-www-form-urlencoded ";
$ Header. = "Content-Length:". strlen ($ req )."";
$ Fp = fsockopen ('www .paypal.com ', 80, $ errno, $ errstr, 30 );
?>
Parameters returned twice
Success mark
SUCCESS
First_name = % E8 % 80% 81
Last_name = % E7 % 89% 87
Address_status = unconfirmed
Address_zip = 100001
Address_street:
Address_country = China
Address_country_code = CN
Address_name = % E7 % 89% 87% E8 % 80% 81
Address_city = % E5 % 8C % 97% E4 % BA % AC
Address_state = % E5 % 8C % 97% E4 % BA % AC
Contact_phone = 01058472654
Payer_email = jinold_2 % 40163.com
Tax = 0.00
Payer_id = T85NNQLW2BHJQ
Payment_date = 22% 3A35% 3A00 + Sep + 09% 2C + 2006 + PDT
Payment_status = Completed
Charset = UTF-8
Custom =
Payer_status = unverified
Business = jiangjun_0_1999 % 40163.com merchant account
Receiver_email = jiangjun_0_1999 % 40163.com email registered in the merchant account
Txn_id = 28267733YJ662041W unique PayPal transaction number, meaning the same as tx
Payment_type = instant
Receiver_id = 8LFB8Q7WADTW4
Txn_type = cart
Mc_currency = CNY
Residence_country = CN
Payment_gross =
Product Information
Num_cart_items = 3 product type
Mc_gross = 3.00 total
Mc_shipping = 0.00
Mc_handling = 0.00
Item_number1 = 1001 Item 1 No.
Item_number2 = 1002
Item_number3 = 1003
Item_name1 = Name of Java Item 1
Item_name2 = C % 2B % 2B
Item_name3 = Oracle
Quantity1 = 1 quantity of Item 1
Quantity2 = 1
Quantity3 = 1
Mc_shipping1 = 0.00
Mc_shipping2 = 0.00
Mc_shipping3 = 0.00
Mc_handling1 = 0.00
Mc_handling2 = 0.00
Mc_handling3 = 0.00
Mc_gross_1 = 1.00 total Item 1
Mc_gross_2 = 1.00
Mc_gross_3 = 1.00
Sample Code
Payment Data Transmission
Https://www.paypal.com/us/cgi-bin/webscr? Cmd = p/xcl/rec/pdt-code
Instant payment notification-IPN sample code
Https://www.paypal.com/cn/cgi-bin/webscr? Cmd = p/xcl/rec/ipn-code
Instant payment notification tool *
Https://www.paypal.com/cn/cgi-bin/webscr? Cmd = p/pdn/3p-solutions-ipntools
I also wrote Paypal_end.php, although not very good. But it will be helpful. According to the Code provided by paypal, the 302 redirection error may occur. I failed to solve the problem, so I applied the online search content.
Re-purchase
About repeated purchases
Paypal does not allow sellers to automatically deduct buyer funds. However, you will be notified of the payment by sending a regular email.
Tel: 02128913401
Correct: difference between paypal and paypal
Paypal is a branch established by paypal in Shanghai.
The functions are different from those of paypal.
Mainly: paypal only supports RMB business, while paypal supports multinational currencies (more than 50)
Paypal does not support leasing and subscription payment, but paypal does.
Paypal proposes to contact paypal for more details.
Pay-as-you-go and re-purchase (refer to "rental fee and pay-as-you-go manual")
Lease: it is a long-term lease of a product. During the long-term lease process, the rental fee needs to be paid on a regular basis. This function can be used to achieve repeated purchases. In fact, our tags or categories are rented to users. In addition, you can only rent one instance at a time and cannot perform batch operations like buying items. If you want to rent several tags or categories, You need to rent them multiple times.
Main parameters:
<Input type = "hidden" name = "cmd" value = "_ xclick-subscriptions"> it must be written in this way, indicating that this is a lease
<Input type = "hidden" name = "business" value = "jinold_1@126.com">
<Input type = "hidden" name = "item_name" value = "C # Book">
<Input type = "hidden" name = "item_number" value = "20001">
<Input type = "hidden" name = "a1" value = "0.01">
<Input type = "hidden" name = "p1" value = "1">
<Input type = "hidden" name = "t1" value = "D">
<Input type = "hidden" name = "a2" value = "0.01">
<Input type = "hidden" name = "p2" value = "1">
<Input type = "hidden" name = "t2" value = "D">
<Input type = "hidden" name = "a3" value = "0.01">
<Input type = "hidden" name = "p3" value = "1">
<Input type = "hidden" name = "t3" value = "D">
* Note: if you do not need a trial, you can use 3 directly. 1 and 2 are optional.
<Input type = "hidden" name = "src" value = "1">
<Input type = "hidden" name = "sra" value = "1">
<Input type = "hidden" name = "srt" value = "5">
One Return Value
Tx = 0HN606257Y398373R &
St = Completed &
Amt = 1.00 &
Cc =
Cm = &
Sig =
Secondary Return Value
SUCCESS
Payment_date = 00% 3A21% 3A18 + Sep + 14% 2C + 2006 + PDT
Txn_type = subscr_payment
Subscr_id = S-5XR56068625362743 lease number
Last_name = jin
Residence_country = C2
Item_name = C % 23 Book
Payment ment_gross = 1.00
Mc_currency = USD
Business = jinold_1 % 40126.com merchant account
Payment_type = instant
Payer_status = unverified
Payer_email = jinold_2 % 40126.com User Account
Txn_id = 0HN606257Y398373R transaction No.
Receiver_email = jinold_1 % 40126.com
First_name = old
Payer_id = K89UE33TA6M3W
Receiver_id = LVKVBHZKL8MFY
Contact_phone = % 2b86+ 58472654
Item_numbers = 20001
Payment_status = Completed
Payment_timeout = 0.33
Mc_133 = 0.33
Mc_gross= 1.00
Charset = gb2312