var paypal require paypal-rest-sdk var express require express paypal

 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
var paypal = require('paypal-rest-sdk');
var express = require('express');
paypal.configure({
'mode': 'sandbox', //sandbox or live
'client_id': 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM',
'client_secret': 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM'
});
function getTotal(callback) {
paypal.invoice.list(function(error, invoices) {
if (error) {
throw error;
} else {
var sum = 0;
for (var i = 0; i < invoices.invoices.length; ++i) {
sum += parseInt(invoices.invoices[i].total_amount.value);
}
callback(sum);
}
});
}
var app = express();
app.get('/', function(req, res) {
getTotal(function(result) {
res.write('<html><body>Total amount:' + result + '</body></html>');
});
});
app.listen(8080);