@opengis/pay 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/plugins/payment/createPayment.js +2 -1
- package/server/plugins/payment/createTransaction.js +2 -1
- package/server/plugins/payment/liqpay.createTransaction.js +6 -1
- package/server/plugins/payment/monopay.createTransaction.js +6 -1
- package/server/plugins/payment/portmone.createTransaction.js +6 -1
- package/server/plugins/payment/processTransaction.js +9 -6
- package/server/routes/liqpay/controllers/liqpay.redirect.js +1 -1
- package/server/routes/monopay/controllers/monopay.redirect.js +1 -1
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import dataInsert from '../crud/dataInsert.js';
|
|
|
5
5
|
const { table = 'pay.transactions' } = config.integrations?.pay || {};
|
|
6
6
|
|
|
7
7
|
export default async function createPayment({
|
|
8
|
-
orderId, amount, referer, uid, service, expiredDate, description, action = 'pay', currency = 'uah', language = 'uk', paytypes,
|
|
8
|
+
orderId, amount, referer, uid, service, expiredDate, description, action = 'pay', currency = 'uah', language = 'uk', paytypes, optionalParams,
|
|
9
9
|
}, pg = pgClients.client) {
|
|
10
10
|
if (!uid) { throw new Error('not enough params: uid'); }
|
|
11
11
|
if (!service) { throw new Error('not enough params: service'); }
|
|
@@ -27,6 +27,7 @@ export default async function createPayment({
|
|
|
27
27
|
language,
|
|
28
28
|
currency,
|
|
29
29
|
paytypes,
|
|
30
|
+
...(optionalParams || {}), // allow custom params to be passed
|
|
30
31
|
},
|
|
31
32
|
uid,
|
|
32
33
|
}).then(el => el.rows?.[0]);
|
|
@@ -13,7 +13,7 @@ const controller = {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export default async function createTransaction({
|
|
16
|
-
orderId, amount, referer, uid, debug, service, expiredDate, description, action, language, paytypes, currency, deliveryEmails,
|
|
16
|
+
orderId, amount, referer, uid, debug, service, expiredDate, description, action, language, paytypes, currency, deliveryEmails, optionalParams,
|
|
17
17
|
}, pg = pgClients.client) {
|
|
18
18
|
if (!service) throw new Error('not enough params: service');
|
|
19
19
|
if (!controller[service]) { throw new Error('invalid params: service'); }
|
|
@@ -39,6 +39,7 @@ export default async function createTransaction({
|
|
|
39
39
|
language,
|
|
40
40
|
paytypes,
|
|
41
41
|
deliveryEmails,
|
|
42
|
+
optionalParams,
|
|
42
43
|
}, pg);
|
|
43
44
|
return result;
|
|
44
45
|
}
|
|
@@ -18,8 +18,12 @@ const {
|
|
|
18
18
|
const liqpay = new LiqPay(publicKey, privateKey);
|
|
19
19
|
|
|
20
20
|
export default async function liqpayCreateTransaction({
|
|
21
|
-
id, orderId, amount, referer, uid, debug, expiredDate, description, paytypes, action = 'pay', currency = 'uah', language = 'uk', deliveryEmails,
|
|
21
|
+
id, orderId, amount, referer, uid, debug, expiredDate, description, paytypes, action = 'pay', currency = 'uah', language = 'uk', deliveryEmails, optionalParams,
|
|
22
22
|
}, pg = pgClients.client) {
|
|
23
|
+
if (!referer) {
|
|
24
|
+
throw new Error('not enough params: referer required');
|
|
25
|
+
}
|
|
26
|
+
|
|
23
27
|
const rootUrl = referer.slice(0, referer.indexOf('/', 7));
|
|
24
28
|
|
|
25
29
|
if (!publicKey || !privateKey) {
|
|
@@ -56,6 +60,7 @@ export default async function liqpayCreateTransaction({
|
|
|
56
60
|
currency,
|
|
57
61
|
language,
|
|
58
62
|
paytypes,
|
|
63
|
+
optionalParams,
|
|
59
64
|
});
|
|
60
65
|
|
|
61
66
|
if (!paymentData?.id) {
|
|
@@ -22,8 +22,12 @@ const ccyObj = {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export default async function monopayCreateTransaction({
|
|
25
|
-
id, orderId, amount, referer, uid, debug, expiredDate, description, action, currency, language,
|
|
25
|
+
id, orderId, amount, referer, uid, debug, expiredDate, description, action, currency, language, optionalParams,
|
|
26
26
|
}, pg = pgClients.client) {
|
|
27
|
+
if (!referer) {
|
|
28
|
+
throw new Error('not enough params: referer required');
|
|
29
|
+
}
|
|
30
|
+
|
|
27
31
|
const rootUrl = referer.slice(0, referer.indexOf('/', 7));
|
|
28
32
|
|
|
29
33
|
if (!host || !token) {
|
|
@@ -51,6 +55,7 @@ export default async function monopayCreateTransaction({
|
|
|
51
55
|
action,
|
|
52
56
|
currency,
|
|
53
57
|
language,
|
|
58
|
+
optionalParams,
|
|
54
59
|
});
|
|
55
60
|
|
|
56
61
|
if (!paymentData?.id) {
|
|
@@ -12,8 +12,12 @@ const { table = 'pay.transactions', backUrl } = config.integrations?.pay || {};
|
|
|
12
12
|
const { host = 'https://www.portmone.com.ua', payeeId } = config.integrations?.portmone || {};
|
|
13
13
|
|
|
14
14
|
export default async function portmoneCreateTransaction({
|
|
15
|
-
id, orderId, amount, referer, uid, debug, expiredDate, description, action, currency = 'uah', language = 'uk', paytypes,
|
|
15
|
+
id, orderId, amount, referer, uid, debug, expiredDate, description, action, currency = 'uah', language = 'uk', paytypes, optionalParams,
|
|
16
16
|
}, pg = pgClients.client) {
|
|
17
|
+
if (!referer) {
|
|
18
|
+
throw new Error('not enough params: referer required');
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
const rootUrl = referer.slice(0, referer.indexOf('/', 7));
|
|
18
22
|
|
|
19
23
|
if (!payeeId) {
|
|
@@ -46,6 +50,7 @@ export default async function portmoneCreateTransaction({
|
|
|
46
50
|
currency,
|
|
47
51
|
language,
|
|
48
52
|
paytypes,
|
|
53
|
+
optionalParams,
|
|
49
54
|
});
|
|
50
55
|
|
|
51
56
|
if (!paymentData?.id) {
|
|
@@ -37,7 +37,7 @@ export default async function processTransaction(id, { body, origin } = {}) {
|
|
|
37
37
|
if (!service) throw new Error('invalid payment: service required');
|
|
38
38
|
if (!controller[service]) { throw new Error('invalid params: service'); }
|
|
39
39
|
|
|
40
|
-
if (
|
|
40
|
+
if (['error', 'success'].includes(trxStatus)) {
|
|
41
41
|
throw new Error('Transaction was already processed');
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -46,7 +46,7 @@ export default async function processTransaction(id, { body, origin } = {}) {
|
|
|
46
46
|
const { status = 'error', err_description: err } = result || {};
|
|
47
47
|
|
|
48
48
|
if (status !== 'success') {
|
|
49
|
-
throw new Error(err || 'Помилка перевірки статусу платежу');
|
|
49
|
+
// throw new Error(err || 'Помилка перевірки статусу платежу');
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
const balance = await pg.query(`select balance from ${table}
|
|
@@ -55,6 +55,9 @@ export default async function processTransaction(id, { body, origin } = {}) {
|
|
|
55
55
|
and balance is not null
|
|
56
56
|
order by created_at desc limit 1`, [userId]).then(el => el.rows?.[0]?.balance || 0);
|
|
57
57
|
|
|
58
|
+
const newBalance = status === 'success' ? +result.amount + +balance : balance;
|
|
59
|
+
const successDate = status === 'success' ? newDate() : undefined;
|
|
60
|
+
|
|
58
61
|
const row = await dataUpdate({
|
|
59
62
|
table,
|
|
60
63
|
data: {
|
|
@@ -64,16 +67,16 @@ export default async function processTransaction(id, { body, origin } = {}) {
|
|
|
64
67
|
paytype: result?.paytype, // card, gpay etc
|
|
65
68
|
receipt_url: result?.receipt_url,
|
|
66
69
|
status,
|
|
67
|
-
balance:
|
|
68
|
-
success_date:
|
|
70
|
+
balance: newBalance,
|
|
71
|
+
success_date: successDate,
|
|
69
72
|
},
|
|
70
73
|
id,
|
|
71
74
|
uid: userId,
|
|
72
75
|
});
|
|
73
76
|
|
|
74
77
|
if (process.env.NODE_ENV === 'test') {
|
|
75
|
-
console.info(`id:${id}, status: ${result.status}, before: ${balance || 0}, sum: ${+result.amount}, after: ${
|
|
78
|
+
console.info(`id:${id}, status: ${result.status}, before: ${balance || 0}, sum: ${+result.amount}, after: ${newBalance}`);
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
return { ...row, balance:
|
|
81
|
+
return { ...row, balance: newBalance };
|
|
79
82
|
}
|
|
@@ -16,7 +16,7 @@ export default async function liqpayRedirect(req, reply) {
|
|
|
16
16
|
const paymentData = query.id ? await paymentInfo(query.id) : {
|
|
17
17
|
orderId: query.order_id,
|
|
18
18
|
amount: query.amount, // amount for new transtaction as is, else - preCreated
|
|
19
|
-
service: '
|
|
19
|
+
service: 'liqpay',
|
|
20
20
|
referer: headers?.referer, // redirect user after finish of transaction
|
|
21
21
|
uid: user.uid, // user id
|
|
22
22
|
};
|
|
@@ -18,7 +18,7 @@ export default async function monopayRedirect(req, reply) {
|
|
|
18
18
|
const paymentData = query.id ? await paymentInfo(query.id) : {
|
|
19
19
|
orderId: query.order_id, // order ID, optional
|
|
20
20
|
amount: query.amount, // amount for new transtaction as is, else - preCreated
|
|
21
|
-
service: '
|
|
21
|
+
service: 'monopay',
|
|
22
22
|
referer: headers?.referer, // redirect user after finish of transaction
|
|
23
23
|
uid: user.uid, // user id
|
|
24
24
|
};
|