-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaytabs.js
58 lines (57 loc) · 1.36 KB
/
paytabs.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
var axios = require("axios").default;
class PayTabs {
baseUrl = "https://secure-iraq.paytabs.com/payment/request";
constructor({
Authorization,
callback,
returnUrl,
profile_id,
tran_class,
tran_type,
}) {
this.Account = {
baseUrl: this.baseUrl,
Authorization,
callback,
returnUrl,
profile_id,
tran_type,
tran_class,
};
}
checkout = async ({ orderId, description, amount }) => {
try {
const headers = {
"Content-Type": "application/json",
Authorization: this.Account.Authorization, //FROM DEV
};
const response = await axios.post(
this.Account.baseUrl,
{
profile_id: this.Account.profile_id,
tran_type: this.Account.tran_type,
tran_class: this.Account.tran_class,
cart_id: orderId,
cart_description: description,
cart_currency: "IQD",
cart_amount: amount,
callback: this.Account.callback,
return: this.Account.returnUrl,
},
{ headers }
);
if (response)
return {
status: true,
transactionId: response.data.tran_ref,
url: response.data.redirect_url,
};
} catch (error) {
return {
status: false,
error: error.response.data,
};
}
};
}
module.exports = PayTabs;