Using Paypal REST API with Classic ASP

半世苍凉 提交于 2020-01-13 20:39:09

问题


I am trying to make a simple call to Paypal API with the follow code:

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. I am in localhost and Im not using a SSL on my site (dont know if its affect).


回答1:


To solve my problem I am using the NVP API and now I am doing something like this

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




回答2:


Solved: We finally managed to talk to REST, thanks to the Paypal support and our ISP. The use of a certificate is required, for specifying certificates you need the ServerXMLHTTP object.

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

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. In order to make the ServerXMLHTTP object support TLSv1.2, you need to run Classic ASP in 64bit instead of 32bit.



来源:https://stackoverflow.com/questions/38504148/using-paypal-rest-api-with-classic-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!