I'm new to nodejs so this may be operator error, but I'm trying to make a POST request to PayPay's test URL. I tried using http request in nodejs, but got an odd response. I was able to get curl on the command line to work, so I figured I'd use curl in node.
When I run the following curl command in bash it works:
curl -v --data "USER=myLogin&VENDOR=myLogin&PARTNER=PayPal&PWD=QQQQQQQQQ&CREATESECURETOKEN=Y&SECURETOKENID=fb7810e9-252b-4613-a53b-6432148bfd97&TRXTYPE=S&AMT=100.00" https://pilot-payflowpro.paypal.com
I get the following results (I know the secure token was used, but its a sign the curl call worked):
* Rebuilt URL to: https://pilot-payflowpro.paypal.com/
* Trying 173.0.82.163...
* Connected to pilot-payflowpro.paypal.com (173.0.82.163) port 443 (#0)
* found 173 certificates in /etc/ssl/certs/ca-certificates.crt
* found 704 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / RSA_AES_256_CBC_SHA256
* server certificate verification OK
* server certificate status verification SKIPPED
* common name: pilot-payflowpro.paypal.com (matched)
* server certificate expiration date OK
* server certificate activation date OK
* certificate public key: RSA
* certificate version: #3* subject: C=US,ST=California,L=San Jose,O=PayPal\, Inc.,OU=Payflow Production,CN=pilot-payflowpro.paypal.com
* start date: Wed, 08 Feb 2017 00:00:00 GMT
* expire date: Thu, 28 Feb 2019 23:59:59 GMT
* issuer: C=US,O=Symantec Corporation,OU=Symantec Trust Network,CN=Symantec Class 3 Secure Server CA - G4
* compression: NULL
* ALPN, server did not agree to a protocol
> POST / HTTP/1.1
> Host: pilot-payflowpro.paypal.com
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 179
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 179 out of 179 bytes
< HTTP/1.1 200 OK
< Connection: close
< Server: VPS-3.033.00
< Date: Sat, 13 May 2017 20:13:38 GMT
< Content-type: text/namevalue
< Content-length: 121
<
* Closing connection 0
RESULT=7&RESPMSG=Field format error: Secure Token Id already beenused&SECURETOKENID=fb7810e9-252b-4613-a53b-6432148bfd97e
I then use the following nodejs code (in a method exposed through Express as a GET):
var newSId = uuid.v4();
var curl = new Curl();
var url = 'https://pilot-payflowpro.payapl.com/';
var data = {
'USER': 'myLogin',
'VENDOR': 'myLogin',
'PARTNER': 'PayPal',
'PWD': 'QQQQQQQQQQQ',
'CREATESECURETOKEN': 'Y',
'SECURETOKENID': newSId,
'TRXTYPE': 'S',
'AMT': '100.00'
};
data = qstr.stringify(data);
console.log("Data = " + data);
curl.setOpt(Curl.option.URL, url);
curl.setOpt(Curl.option.POSTFIELDS, data);
curl.setOpt(Curl.option.POST, 1);
curl.setOpt(Curl.option.VERBOSE, true);
curl.perform();
curl.on('end', function(statusCode, body){
this.close();
});
curl.on('error', curl.close.bind(curl));
When I execute the GET via a browser I get the following information dumped to console:
Data = USER=myLogin&VENDOR=myLogin&PARTNER=PayPal&PWD=QQQQQQQQ&CREATESECURETOKEN=Y&SECURETOKENID=4b8f0763-2d09-4c2a-a57e-f5a4dc5be744&TRXTYPE=S&AMT=100.00
* Trying 209.15.13.134...
* connect to 209.15.13.134 port 443 failed: Connection refused
* Failed to connect to pilot-payflowpro.payapl.com port 443: Connection refused
* Closing connection 0
For a reason I can't explain, in the node-libcurl call, a different IP address is being used. The curl command line call uses: 173.0.82.163, but node-libcurl uses: 209.15.13.134. I'm curious why. If there is a way I should have debugged this better, please let me know.
Thanks in advance!
via turnip_cyberveggie
No comments:
Post a Comment