forked from Paybear/paybear-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrencies.js
37 lines (33 loc) · 1.03 KB
/
currencies.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
var getCurrency = require('./paybear').getCurrency;
var getCurrencies = require('./paybear').getCurrencies;
const app = new (require('express').Router)();
app.get('/paybear/currencies', (req, res) => {
if(req.query.order) {
var orderId = +req.query.order;
var fiatTotal = 19.99; //get from order
var token = req.query.token;
if(token) {
getCurrency(token, orderId, true, function (curr) {
res.json(curr); //return this data to PayBear form
});
} else {
var returnCurrs = [];
getCurrencies(function(currs) {
var collectCurrencies = function (currCodes) {
if(currCodes.length === 0) {
res.json(returnCurrs);
return;
}
getCurrency(currCodes.pop(), orderId, true, function(currency) {
returnCurrs.push(currency);
collectCurrencies(currCodes);
});
};
collectCurrencies(Object.keys(currs));
});
}
} else {
res.json({error: 'send the order number'});
}
});
module.exports = app;