简体   繁体   English

在经典ASP中使用Paypal REST API

[英]Using Paypal REST API with Classic ASP

I am trying to make a simple call to Paypal API with the follow code: 我正在尝试使用以下代码对Paypal API进行简单调用:

On error resume next

Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.open "POST", "https://api.sandbox.paypal.com/v1/oauth2/token", False

objHTTP.setRequestHeader "Accept", "application/json"
objHTTP.setRequestHeader "Accept-Language", "en_US"
objHTTP.setRequestHeader "Authorization", "Basic " & Base64Encode("client-id:secret")
objHTTP.send "grant_type=client_credentials"

Response.Write err.description & " | " & err.number

But its returning the error: 但是它返回错误:

The download of the specified resource has failed

I can do this call with de Postman without problem. 我可以毫无问题地与de Postman进行此通话。 I am in localhost and Im not using a SSL on my site (dont know if its affect). 我在本地主机中,我未在我的网站上使用SSL(不知道它是否会影响)。

To solve my problem I am using the NVP API and now I am doing something like this 为了解决我的问题,我正在使用NVP API,现在我正在做类似的事情

Set objHTTP = CreateObject("Msxml2.ServerXMLHTTP.6.0")
objHTTP.open "POST", "https://api-3t.sandbox.paypal.com/nvp", False

Dim data
data = "USER=" & paypal_user_name &_
"&PWD=" & paypal_psw &_
"&SIGNATURE=" & paypal_signature &_
"&VERSION=204.0" &_
"&RETURNURL=" & return &_
"&CANCELURL=" & cancel &_
"&PAYMENTREQUEST_0_PAYMENTACTION=Sale" &_
"&PAYMENTREQUEST_0_AMT=" & Request.QueryString("val") &_
"&PAYMENTREQUEST_0_CURRENCYCODE=BRL" &_
"&L_PAYMENTREQUEST_0_NAME0=" & Request.QueryString("pac") &_
"&L_PAYMENTREQUEST_0_AMT0=" & Request.QueryString("val") &_
"&NOSHIPPING=1" &_
"&METHOD=SetExpressCheckout"

objHTTP.send data

And its working very fine 而且它的工作非常好

Solved: We finally managed to talk to REST, thanks to the Paypal support and our ISP. 解决了:感谢Paypal的支持和我们的ISP,我们终于设法与REST进行了交谈。 The use of a certificate is required, for specifying certificates you need the ServerXMLHTTP object. 需要使用证书,要指定证书,需要ServerXMLHTTP对象。

objHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0"); objHTTP = Server.CreateObject(“ MSXML2.ServerXMLHTTP.6.0”);

objHTTP.setOption(3, "LOCAL_MACHINE\\My\\merchant-cert_api1.paypal.com"); objHTTP.setOption(3,“ LOCAL_MACHINE \\ My \\ merchant-cert_api1.paypal.com”);

This worked out of the box with the live endpoint, but the sandbox returned: "An error occurred in the secure channel support". 这与实时终结点可以立即使用,但是沙盒返回:“安全通道支持中发生错误”。 The reason is the sandbox no longer supports TLSv1.1. 原因是沙箱不再支持TLSv1.1。 In order to make the ServerXMLHTTP object support TLSv1.2, you need to run Classic ASP in 64bit instead of 32bit. 为了使ServerXMLHTTP对象支持TLSv1.2,您需要以64位而不是32位运行Classic ASP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM