Paypal API说明

PAYPAL API说明

 

PAYPAL属于美国用来解决在线支付的中小企业的解决方案.中文网站叫做贝宝.

国际站:www.paypal.com

中文站:www.paypal.com.cn

 

既然是Core Programmer,那么其他话就不说了,单表API,PAYPALAPIWEB Service,用来编程解决自定义购物车的解决方案.但其文档洋洋洒洒6,780大页的PDF,然而不幸的是关于需要的步骤/工具,尤其是最最需要SAMPLE CODE实在是语焉不详,真正让人头痛不已.少不得查资料,看英文.味同嚼蜡.现测试成功,不免将其记录一二.

这东西国内的朋友用的肯定很少,想想既然中文站开通,以后也许会用上也说不定.且立此存照,最少留给自己当备忘.Soap封包及XML解析的部分看代码了,不详细说了.

 

 

1.       申请PAYPAL帐户

2.       激活帐户,需要

a.       确认email地址

b.       添加信用卡资料

c.       添加开户行资料

 

3.       申请Paypal Payment Pro

a.       填写相关资料

b.       申请数字证书API Certificate Request (注意记录好API NAME,类似于 xxx_api1.domain.name以及Password)

c.       下载数字证书

4.  转换为.p12证书文件

a.       下载的数字证书应该名为cert_key_pem.txt

b.       将其用NOTEPAD打开,-----BEGIN RSA PRIVATE KEY----------END RSA PRIVATE KEY-----拷贝出来另存为一个文件,例如yourdomain_key.pem

c.       将其用NOTEPAD打开,-----BEGIN CERTIFICATE---------END CERTIFICATE-----拷贝出来另存为一个文件,例如yourdomain_cer.pem

d.       http://www.paypaltech.com/tools/pem2p12.php转换为.p12文件. 也可用OpenSSL的命令行程序完成,不过太过复杂,恐怕没有人有耐心看完,就不介绍了.

 

 

5.  安装.p12证书文件

    a.  找到winhttpcertcfg实用程序,可用search,因为OS的不同,位置可能会有不同.

        我的OSwin2003是在C:/Program Files/Windows Resource Kit/tools.

        若不同,应在Inetpub/wwwroot/Certificate/

    b.  有两种不同的安装方法.建议用第一种

  

 

 

第一种:命令行

winhttpcertcfg -g -c LOCAL_MACHINE/My -s xxxxxxxxxx_api1.xxxxxxxxx.com -a Everyone

执行完命令后,会看到如下信息,这就说明安装正确了
.

Microsoft® WinHTTP Certificate Configuration Tool
Copyright® Microsoft Corporation 2001.

Matching Certificate:
C=xx
S=xx
L=xxxxxxxxx
OU=xxxxxxxx
O=xxxxxxx
CN= xxxxxxxxxx_api1.xxxxxxxxx.com

 

第二种:命令行WinHttpCertCfg -i AccountName.p12 -p Export Password -c
LOCAL_MACHINE/my -a aspnet
注意: 这个 Export Password 是生成.p12文件时所需要的密码.看到上面信息说明安装正确.

 

6.生成一个ASP文件.

本来这种WEB Service是用JAVA/.NET访问有成熟的工具的类库.

ASP使用VBScript来用的话,只好用变通的方法.

需要MS XML 4.0 +Sp2

我的是MS XML 3.0,也能用.

直接把代码放在下面.

 

<%

'/

' THIS CODE WILL NOT WORK IF YOU DID NOT GRANT THE IUSR_MACHINENAME AND IWAM_MACHINENAME ACCOUNT ACCESS PERMISSION TO THE PAYPAL API SSL CERT, BECAUSE THOSE ARE THE ACCOUNTS THAT EXECUTE ASP3 CODE (NOT THE ASPNET ACCOUNT). WORKS LIKE A CHARM

' IF YOU READ THE DIRECTIONS GOOD LUCK

'/

 

username = "xxxx_api1.vtecom.com"

password = "yourpassword"

 

Dim objXMLDOC

Dim objXMLDOM

Dim objXSLDOM

Dim SoapStr

 

SoapStr = ""

SoapStr = SoapStr & "

SoapStr = SoapStr & "xmlnssd='http://www.w3.org/1999/XMLSchema '"

SoapStr = SoapStr & "xmlnssi='http://www.w3.org/1999/XMLSchema-instance' "

SoapStr = SoapStr & "xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' "

SoapStr = SoapStr & "xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' "

SoapStr = SoapStr & "SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>"

SoapStr = SoapStr & ""

SoapStr = SoapStr & "

SoapStr = SoapStr & "xmlns='urn:ebay:api:PayPalAPI' "

SoapStr = SoapStr & "SOAP-ENV:mustUnderstand='1'>"

SoapStr = SoapStr & ""

SoapStr = SoapStr & ""&username &""

SoapStr = SoapStr & ""&password &""

SoapStr = SoapStr & ""

SoapStr = SoapStr & ""

SoapStr = SoapStr & ""

SoapStr = SoapStr & ""

SoapStr = SoapStr & ""

 

' Actions Below Here

SoapStr = SoapStr & ""

SoapStr = SoapStr & ""

SoapStr = SoapStr & "1.0"

SoapStr = SoapStr & ""

SoapStr = SoapStr & "Sale"

SoapStr = SoapStr & ""

SoapStr = SoapStr & "60"

SoapStr = SoapStr & ""

SoapStr = SoapStr & ""

SoapStr = SoapStr & "Visa"

SoapStr = SoapStr & "4250614840518960"

SoapStr = SoapStr & "05"

SoapStr = SoapStr & "2008"

SoapStr = SoapStr & ""

SoapStr = SoapStr & ""

SoapStr = SoapStr & "Joe"

SoapStr = SoapStr & "Smith"

SoapStr = SoapStr & ""

SoapStr = SoapStr & "

"

SoapStr = SoapStr & "

1 Main St
"

SoapStr = SoapStr & "San Jose"

SoapStr = SoapStr & "CA"

SoapStr = SoapStr & "US"

SoapStr = SoapStr & "95131"

SoapStr = SoapStr & "

"

SoapStr = SoapStr & ""

SoapStr = SoapStr & ""

SoapStr = SoapStr & "123.123.123.123"

SoapStr = SoapStr & ""

SoapStr = SoapStr & ""

SoapStr = SoapStr & ""

 

SoapStr = SoapStr & ""

SoapStr = SoapStr & ""

 

 

Set objXMLDOC = Server.CreateObject("Msxml2.ServerXMLHTTP")

Set objXMLDOM = Server.CreateObject("Msxml2.DomDocument")

 

objXMLDOC.setOption 3, "LOCAL_MACHINE/MY/" &username

objXMLDOC.SetOption 2, 13056

objXMLDOC.setTimeouts 10 * 100, 10 * 100, 10 * 100, 10 * 100

 

objXMLDOC.open "POST", "https://api.paypal.com/2.0/", False

objXMLDOC.setRequestHeader "Content-Type", "text/xml"

objXMLDOC.send (SoapStr)

objXMLDOM.async=false

 

objXMLDOM.loadXML objXMLDOC.responseText

 

Response.Write objXMLDOC.responseText

 

Set objXMLDOC = Nothing

Set objXMLDOM = Nothing

%>

 

 

7.如果仅仅需要测试的话,使用PAYPAL的沙箱(SandBox)即可.PAYPAL的差不多.

上述代码除了修改USERNAMEPASSWORD以外,需要改https://api.paypal.com/2.0/"https://api.sandbox.paypal.com/2.0/"

 

你可能感兴趣的:(WEB技术,ASP)