Paypal API说明


PAYPAL API说明

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

既然是Core Programmer,那么其他话就不说了,单表API,此PAYPAL的API是WEB Service,用来编程解决自定义购物车的解决方案.但其文档洋洋洒洒6,7个80大页的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的不同,位置可能会有不同.
        我的OS是win2003是在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 ToolCopyright® Microsoft Corporation 2001.Matching Certificate:C=xxS=xxL=xxxxxxxxxOU=xxxxxxxxO=xxxxxxxCN= 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 = "<?xml version='1.0' encoding='UTF-8'?>"

SoapStr = SoapStr & "<SOAP-ENV:Envelope "

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 & "<SOAP-ENV:Header>"

SoapStr = SoapStr & "<RequesterCredentials "

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

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

SoapStr = SoapStr & "<Credentials xmlns='urn:ebay:apis:eBLBaseComponents'>"

SoapStr = SoapStr & "<Username>"&username &"</Username>"

SoapStr = SoapStr & "<Password>"&password &"</Password>"

SoapStr = SoapStr & "<Subject></Subject>"

SoapStr = SoapStr & "</Credentials>"

SoapStr = SoapStr & "</RequesterCredentials>"

SoapStr = SoapStr & "</SOAP-ENV:Header>"

SoapStr = SoapStr & "<SOAP-ENV:Body>"

' Actions Below Here

SoapStr = SoapStr & "<DoDirectPaymentReq xmlns='urn:ebay:api:PayPalAPI'>"

SoapStr = SoapStr & "<DoDirectPaymentRequest xsi:type='nsoDirectPaymentRequestType'>"

SoapStr = SoapStr & "<Version xmlns='urn:ebay:apis:eBLBaseComponents' xsi:type='xsd:string'>1.0</Version>"

SoapStr = SoapStr & "<DoDirectPaymentRequestDetails xmlns='urn:ebay:apis:eBLBaseComponents'>"

SoapStr = SoapStr & "<PaymentAction>Sale</PaymentAction>"

SoapStr = SoapStr & "<PaymentDetails>"

SoapStr = SoapStr & "<OrderTotal currencyID='USD'>60</OrderTotal>"

SoapStr = SoapStr & "</PaymentDetails>"

SoapStr = SoapStr & "<CreditCard>"

SoapStr = SoapStr & "<CreditCardType>Visa</CreditCardType>"

SoapStr = SoapStr & "<CreditCardNumber>4250614840518960</CreditCardNumber>"

SoapStr = SoapStr & "<ExpMonth>05</ExpMonth>"

SoapStr = SoapStr & "<ExpYear>2008</ExpYear>"

SoapStr = SoapStr & "<CardOwner>"

SoapStr = SoapStr & "<PayerName>"

SoapStr = SoapStr & "<FirstName>Joe</FirstName>"

SoapStr = SoapStr & "<LastName>Smith</LastName>"

SoapStr = SoapStr & "</PayerName>"

SoapStr = SoapStr & "<Address>"

SoapStr = SoapStr & "<Street1>

SoapStr = SoapStr & "<CityName>San Jose</CityName>"

SoapStr = SoapStr & "<StateOrProvince>CA</StateOrProvince>"

SoapStr = SoapStr & "<Country>US</Country>"

SoapStr = SoapStr & "<PostalCode>95131</PostalCode>"

SoapStr = SoapStr & "</Address>"

SoapStr = SoapStr & "</CardOwner>"

SoapStr = SoapStr & "</CreditCard>"

SoapStr = SoapStr & "<IPAddress>123.123.123.123</IPAddress>"

SoapStr = SoapStr & "</DoDirectPaymentRequestDetails>"

SoapStr = SoapStr & "</DoDirectPaymentRequest>"

SoapStr = SoapStr & "</DoDirectPaymentReq>"

SoapStr = SoapStr & "</SOAP-ENV:Body>"

SoapStr = SoapStr & "</SOAP-ENV:Envelope>"

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的差不多.
上述代码除了修改USERNAME和PASSWORD以外,需要改https://api.paypal.com/2.0/为"https://api.sandbox.paypal.com/2.0/"
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1 Main St
</Street1>"

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值