-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-verify.js
44 lines (32 loc) · 978 Bytes
/
my-verify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var https = require('https');
var qs = require('querystring');
var SANDBOX_URL = 'www.sandbox.paypal.com';
var REGULAR_URL = 'www.paypal.com';
exports.verify = function verify(params, callback) {
if (typeof params === "undefined") {
return callback(true, 'No params were passed to ipn.verify');
}
var body = params;
body = body + "&cmd=_notify-validate";
//Set up the request to paypal
var req_options = {
host: SANDBOX_URL,
method: 'POST',
path: '/cgi-bin/webscr',
headers: {'Content-Length': body.length}
}
var req = https.request(req_options, function paypal_request(res) {
res.on('data', function paypal_response(d) {
var response = d.toString();
callback(response != 'VERIFIED', response);
});
});
//Add the post parameters to the request body
req.write(body);
req.end();
//Request error
req.on('error', function request_error(e) {
console.log("ERRORRRR");
callback(true, e);
});
};