forked from CurrencyCloud/currencycloud-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_report.js
More file actions
110 lines (100 loc) · 2.92 KB
/
generate_report.js
File metadata and controls
110 lines (100 loc) · 2.92 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
'use strict';
let currencyCloud = require('../lib/currency-cloud');
const opts = {
retries: 3,
factor: 2,
minTimeout: Math.random() * 750,
maxTimeout: Math.random() * 30000 + 30000,
randomize: true,
log: true
};
let generate_report = {
conversion_report_params: {
description: "Testing JS API",
buyCurrency: "EUR",
sellCurrency: "GBP",
uniqueRequestId: "a2730264-5bc1-2313-fea6-461243f3ea5a"
},
payment_report_params:{
description: "Testing JS payment report API",
currency: "GBP",
amountFrom: "1000",
amountTo: "10000"
},
report_find_params:{
id: "c3ae0475-ef72-46ef-8a90-c2d3c2912911"
}
};
let login = () => {
return currencyCloud.retry(
() => {
return currencyCloud.authentication.login({
environment: 'demo',
loginId: 'development@currencycloud.com',
apiKey: 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
});
},
opts,
"currencyCloud.authentication.login"
);
};
let create_conversion_report = () => {
return currencyCloud.retry(
() => {
return currencyCloud.reports.create_conversion_report(generate_report.conversion_report_params)
.then((res) => {
console.log('Conversion report: ' + JSON.stringify(res, null, 2) + '\n');
});
},
opts);
};
let create_payment_report = () => {
return currencyCloud.retry(
() => {
return currencyCloud.reports.create_payment_report(generate_report.payment_report_params)
.then((res) => {
console.log('Payment report: ' + JSON.stringify(res, null, 2) + '\n');
});
},
opts);
};
let find_report = () => {
return currencyCloud.retry(
() => {
return currencyCloud.reports.find_report_request()
.then((res) => {
console.log('Found reports: ' + JSON.stringify(res, null, 2) + '\n');
});
},
opts);
};
let find_report_via_id = () =>{
return currencyCloud.retry(
() => {
return currencyCloud.reports.find_report_via_id(generate_report.report_find_params)
.then((res) => {
console.log('Found report: ' + JSON.stringify(res, null, 2) + '\n');
});
},
opts);
};
let logout = () => {
return currencyCloud.authentication.logout()
.then(() => {
console.log('logout\n');
});
};
login()
.then(create_conversion_report)
.then(create_payment_report)
.then(find_report)
.then(find_report_via_id)
.then(logout)
.catch((err) => {
if (err instanceof currencyCloud.APIerror) {
console.log(err.toYAML());
}
else {
console.log(err);
}
});