Detailed codes and instances of the Paypal payment interface implemented by ASP

Source: Internet
Author: User

ASP makes the Paypal payment interface !!

Today, the network speed is very slow. Think about the interfaces you made the previous day! Organize it! Sort it out!

In fact, PayPal can be divided into two parts:

InternationalWww.paypal.com
China
Www.paypal.com/cn

International Payment is only for US dollars! China supports RMB collection and payment!

This is clear first!

Process logic:

In fact, the PayPal account can directly get a payment interface:

<Form target = "PayPal" Action ="Https://www.paypal.com/cgi-bin/webscr"Method =" Post ">

<Input type = "image" src =" Https://www.paypal.com/zh_CN/ I /btn/x-click-but22.gif "Border =" 0 "name =" Submit "alt =" PayPal-the safest and most convenient online payment method! "> <Input type =" hidden "name =" add "value =" 1 "> <input type =" hidden "name =" cmd "value =" _ cart ">
<Input type = "hidden" name = "business" value ="
Zwfec@163.com ">
<Input type = "hidden" name = "item_name" value = "asss">
<Input type = "hidden" name = "item_number" value = "DF">
<Input type = "hidden" name = "amount" value = "10.00">
<Input type = "hidden" name = "no_shipping" value = "0">
<Input type = "hidden" name = "no_note" value = "1">
<Input type = "hidden" name = "currency_code" value = "CNY">
<Input type = "hidden" name = "weight" value = "1">
<Input type = "hidden" name = "weight_unit" value = "kgs">
<Input type = "hidden" name = "bn" value = "PP-shopcartbf">
</Form>

Directly use thisCodeInconvenient! It can only be added one by one, but think about it. This code can also be dynamically generated. It can be used in PHP or ASP, as long as some values inside are changed, the Payment Code of your product can be generated by reading the database, and you do not need to write them one by one !!

I wrote it like this: Read the database: Rs. Everyone should know it.

<Form action =" Https://www.paypal.com/cgi-bin/webscr "Method =" Post ">
<Input type = "hidden" name = "cmd" value = "_ xclick">
<Input type = "hidden" name = "business" value = "<% = RS (" email ") %> 'your PayPal account
<Input type = "hidden" name = "item_name" value = "<% = RS (" ordernum ") %>"> 'order number on the shopping cart on your website
<Input type = "hidden" name = "currency_code" value = "USD"> 'usd! Cny RMB!
<Input type = "hidden" name = "amount" value = "<% = RS (" price ") %>"> 'product price
<Input type = "hidden" name = "return" value ="
Http: // <% 'Here is the address of the message returned when the payment is successful!
Theurl = lcase (request. servervariables ("http_host") & request. servervariables ("url") theurl = left (theurl, faster Rev (theurl, "/") response. write theurl & "INC/paypalreturn. ASP "%>">
<Input type = "Submit" name = "submit3" value = "use Paypal payment"> </form>

Is this payment acceptable? If the payment is successful, make an authentication and change the order status!

This authentication is implemented on the page of paypalreturn. asp: the code is as follows: paypalreturn. asp:

<%
Mainpath = "PayPal. mdb"
Set conn = server. Createobject ("ADODB. Connection ")
Connstr = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & server. mappath (mainpath)
Conn. Open connstr

Function viate (itemnumber, paymentid, payamount, payeremail)
Set rs = server. Createobject ("ADODB. recordset") S
QL = "select * from orders where ordernum = '" & itemnumber &"'"'Here is the order table. If the payment is successful, change the order status to paid!
Rs. Open SQL, Conn, 1, 3

If not (Rs. BOF or Rs. EOF) then
RS ("orderline") = "3"
RS ("paymentid") = paymentid
RS ("payamount") = payamount
RS ("payeremail") = payeremail
RS ("paydate") = now ()
Rs. Update
Else
Response. Write "<SCRIPT> alert ('no this order number! Please contact website administrator !! '); </SCRIPT>"
End if
Rs. Close
Set rs = nothing
End Function

function urldecode (encodestr) 'This function decodes the urldecode returned by PayPal.
newstr =" "havechar = false
lastchar =" "
for I = 1 to Len (encodestr)
char_c = mid (encodestr, I, 1)
If char_c = "+" then
newstr = newstr & ""
elseif
char_c = "%" then
next_1_c = mid (encodestr, I + 1, 2)
next_1_num = CINT ("& H" & next_1_c)
If havechar then
havechar = false
newstr = newstr & CHR (CINT ("& H" & lastchar & next_rjc ))
else if ABS (next_0000num) <= 127 then
newstr = newstr & CHR (next_0000num)
else
havechar = true
lastchar = next_0000c
end if
I = I + 2
else
newstr = newstr & char_c
end if
next
urldecode = newstr
end function

str1 = trim (request. querystring ("TX")
str2 = "& AT = regular"
here is the method for obtaining the PayPal identity tag
STR = "? Tx = "& str1 &" & cmd = _ policy-synch "& str2
'https: // www.sandbox.paypal.com/cgi-bin/webscr
paypalurl = "
https://www.paypal.com/cgi-bin/webscr "
paypalurl = paypalurl & STR
'response. write "
" & paypalurl & "
"

Set objhttp = server. Createobject ("msxml2.serverxmlhttp. 3.0 ")
Objhttp. setoption 2, 13056
Objhttp. Open "Post", paypalurl, false ,"",""
Objhttp. Send ()

Responsetxt = objhttp. responsetext 'Write in the example below
Set objhttp = nothing
'------------------------------------------------- Check the obtained value
Responsetxt = urldecode (responsetxt) 'Decodes the returned value and assigns it to responsetxt.
If mid (responsetxt, 1, 7) = "success" then 'Obtain the returned value. sucess indicates that the payment is successful! Fail indicates payment failed! There are only two returned values!
Responsetxt = mid (responsetxt, 9) 'Get the return value except the first nine characters and return it to responsetxt
Sparts = Split (responsetxt, vblf) 'Return values are separated by vblf (in VB, this is the meaning of carriage return <line feed>) and assigned to an array sparts
Iparts = ubound (sparts)-1 'The values of this array are separated. You can understand them later!
Redim sresults (iparts, 1)
For I = 0 to iparts
Aparts = Split (sparts (I), "= ")
Skey = aparts (0)
Svalue = aparts (1)
Sresults (I, 0) = skey
Sresults (I, 1) = svalue

select case skey
case" first_name "
firstname = svalue
case" last_name "
lastname = svalue
case" item_name "
itemname = svalue
case "mc_gross"
mcgross = svalue
case "mc_currency"
mccurrency = svalue
case "txn_id"
liushuihao = trim (svalue)
case "payer_email"
payeremail = trim (svalue)
end select
next
call Viate (itemname, liushuihao, mcgross, payeremail) 'Call the function viate () for authentication, and update the order status!
MSG = "pay for success! Please wait for delivery! "&" \ N your order number: "& itemname &"! "
else
MSG =" Sorry! Your operating error! Please contact website administrator !! "
end if
response. write " "' after payment is completed, the user information page is returned!
%>

Responsetxt example:

Success mc_gross = 44.00 export = eligible address_status = confirmed payer_id = export tax = 0.00 address_street = 1 + main + st payment_date = 07% 3a32% 3a55 + dec + 22% 2C + 2008 + Pst payment_status = completed charset = Windows-1252 address_zip = 95131 first_name = test mc_fee = 1.58 rows = US address_name = test + User custom = payer_status = verified business = quota % 40163.com address_country = United + states address_city = san + Jose quantity = 1 payer_email = %%%%contact_phone = txn_id = transferpayment_type = instant last_name = user address_state = Ca region = %% %payment_region = 1.58 receiver_id = export txn_type = export item_name = 20081222225300 mc_currency = USD item_number = residence_country = US handling_amount = 0.00 transaction_subject = 20081222225300 payment_gross = 44.00 shipping = 0.00

Note: your PayPal account may have no money to perform the test. The Paypal account thinks very well. It is a website with a second-level domain name that features the same functionality as PayPal:

Https://developer.paypal.com/

Https://www.sandbox.paypal.com/cgi-bin/webscr Interface

After registering an account here, you can set up two test accounts in it. The money in the two test accounts is not enough. You can use them for testing! Related information: View

 

Note:

Meaning of fields and returned fields when submitting PayPal

'================================================ ========================
'Mc _ gross transaction revenue
'Address _ Status address status
'Paypal _ address_id PayPal address information ID
'Payer _ id the payer's PayPal ID
'Tax
'Address _ street communication address
'Payment _ date transaction time
'Payment _ Status Transaction Status
'Charset language Encoding
'Address _ zip code
'First _ name payer's last name
'Address _ country_code country
'Address _ name: Recipient Name
'Custom custom'
Payer_status payer account status
'Business payee PayPal account
'Address _ country mailing address country
'Address _ City: communication address City
'Quantity of goods
'Payer _ email payer email
'Txn _ id transaction ID
'Payment _ type transaction type
'Last _ name payer name
'Address _ state communication address Province
'Author Er _ email recipient email
'Address _ owner has not been published/officially Enabled
'Er _ id payee ID
'Ebay _ ssss_id eBay user address ID
'Txn _ type transaction announcement Method
'Item _ name goods name
'Mc _ currency type
'Item _ number Product NO.
'Payment _ gross transaction amount [Only applicable to USD]
'Shipping shipping fee

'================================================ ========================
'Main parameters:
'Add: only one product can be purchased at a time
'Upload: multiple items can be purchased
'Cart' <input type = "hidden" name = "cmd" value = "_ cart">
'Seller's account' <input type = "hidden" name = "business"
Value = ziyunyang1981@sina.com >
'Item name' <input type = "hidden" name = "item_name" value = "Java">
'Item number' <input type = "hidden" name = "item_number" value = "1001">
'Item 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: dollar '<input type = "hidden" name = "currency_code" value = "CNY">' location to cancel the transaction and return '<input type = "hidden" name = "cancel_return" value ="
Http://www.updateweb.cn ; ">
'Location automatically returned after the finishing' <input type = "hidden" name = "return" value ="
Http://www.updateweb.cn ">
'================================================ ======================================

 

 

---------- Completed, written for so many daysProgram, Found so many related information, that is to sum up and share with you! -----------

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.