-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch.js
71 lines (70 loc) · 1.86 KB
/
switch.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
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
const axios = require("axios").default;
class Switch {
constructor({
production,
Authorization,
entityId,
bankBic,
bankIban,
bankCountry,
redirectUrl,
}) {
this.Account = {
Authorization,
entityId,
"bankAccount.bic": bankBic,
"bankAccount.iban": bankIban,
"bankAccount.country": bankCountry,
currency: "EUR",
paymentBrand: "GIROPAY",
paymentType: "DB",
shopperResultUrl: redirectUrl,
};
if (!production) {
this.Account.baseUrl = "https://test.oppwa.com:443/";
} else {
this.Account.baseUrl = "https://oppwa.com:443/";
}
}
/**
* @param {string} userName
* @param {string} password
* @param {string} redirectUrl
* @param {string} amount
* @param {string} orderNumber
*/
checkout = async ({ amount }) => {
const requestOptions = {
params: {
entityId: this.Account.entityId,
"bankAccount.bic": this.Account["bankAccount.bic"],
"bankAccount.iban": this.Account["bankAccount.iban"],
"bankAccount.country": this.Account["bankAccount.country"],
currency: "EUR",
paymentBrand: "GIROPAY",
paymentType: "DB",
shopperResultUrl: this.Account.redirectUrl,
amount,
},
headers: {
Authorization: this.Account.Authorization,
},
};
try {
const response = await axios.post(
this.Account.baseUrl + "v1/payments",
null,
requestOptions
);
return response.data.resultDetails
? {
status: true,
transactionId: response.data.resultDetails?.OrderId,
}
: { status: false, error: response };
} catch (e) {
return { status: false, error: e.response.data.result };
}
};
}
module.exports = Switch;