@opengis/pay 2.0.7 → 2.0.9
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/createTransaction.js +5 -0
- package/server/plugins/payment/liqpay.checkStatus.js +10 -18
- package/server/plugins/payment/liqpay.createTransaction.js +13 -0
- package/server/plugins/payment/liqpay.sendReceipt.js +27 -0
- package/server/plugins/payment/processTransaction.js +2 -2
- package/server/plugins/payment/sendReceipt.js +36 -0
- package/server/routes/core/index.mjs +11 -9
- package/server/routes/liqpay/index.mjs +33 -26
- package/server/routes/monopay/index.mjs +20 -15
- package/server/routes/portmone/index.mjs +33 -25
- package/utils.js +3 -2
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@ const controller = {
|
|
|
14
14
|
|
|
15
15
|
export default async function createTransaction({
|
|
16
16
|
orderId, amount, referer, uid, debug, service, expiredDate, description, action, language, paytypes, currency, deliveryEmails, optionalParams,
|
|
17
|
+
splitRules, splitTicketsDynamicRequisites, splitTicketsOnly,
|
|
17
18
|
}, pg = pgClients.client) {
|
|
18
19
|
if (!service) throw new Error('not enough params: service');
|
|
19
20
|
if (!controller[service]) { throw new Error('invalid params: service'); }
|
|
@@ -38,8 +39,12 @@ export default async function createTransaction({
|
|
|
38
39
|
description,
|
|
39
40
|
language,
|
|
40
41
|
paytypes,
|
|
42
|
+
currency,
|
|
41
43
|
deliveryEmails,
|
|
42
44
|
optionalParams,
|
|
45
|
+
splitRules,
|
|
46
|
+
splitTicketsDynamicRequisites,
|
|
47
|
+
splitTicketsOnly,
|
|
43
48
|
}, pg);
|
|
44
49
|
return result;
|
|
45
50
|
}
|
|
@@ -3,6 +3,7 @@ import request from 'request-promise';
|
|
|
3
3
|
|
|
4
4
|
import config from '../../../config.js';
|
|
5
5
|
import pgClients from '../pg/pgClients.js';
|
|
6
|
+
import sendReceipt from './liqpay.sendReceipt.js';
|
|
6
7
|
|
|
7
8
|
const { table = 'pay.transactions' } = config.integrations?.pay || {};
|
|
8
9
|
const { host = 'https://www.liqpay.ua', publicKey, privateKey } = config.integrations?.liqpay || {};
|
|
@@ -11,7 +12,7 @@ const liqpay = new LiqPay(publicKey, privateKey);
|
|
|
11
12
|
|
|
12
13
|
const pg = pgClients.client;
|
|
13
14
|
|
|
14
|
-
export default async function liqpayCheckStatus(id, { origin } = {}) {
|
|
15
|
+
export default async function liqpayCheckStatus(id, { email, origin } = {}) {
|
|
15
16
|
if (!id) throw new Error('not enough params: id');
|
|
16
17
|
if (!publicKey || !privateKey) throw new Error('empty integration params: liqpay');
|
|
17
18
|
|
|
@@ -29,6 +30,10 @@ export default async function liqpayCheckStatus(id, { origin } = {}) {
|
|
|
29
30
|
const isValidOrigin = origin && origin === host;
|
|
30
31
|
|
|
31
32
|
if (process.env.NODE_ENV === 'test' && isValidOrigin) {
|
|
33
|
+
if (email) {
|
|
34
|
+
const res = await sendReceipt(id, email);
|
|
35
|
+
console.log('receipt delivery', res, email);
|
|
36
|
+
}
|
|
32
37
|
const amount = pg?.pk?.[table] ? await pg.query(`select amount from ${table} where ${pg?.pk?.[table]}=$1`, [id]).then(el => el.rows?.[0]?.amount) : 0;
|
|
33
38
|
return { unittest: true, amount, status: 'success' };
|
|
34
39
|
}
|
|
@@ -43,23 +48,10 @@ export default async function liqpayCheckStatus(id, { origin } = {}) {
|
|
|
43
48
|
|
|
44
49
|
const result = response?.startsWith?.('{') ? JSON.parse(response) : response;
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
order_id: id,
|
|
51
|
-
email: 'email@gmail.com',
|
|
52
|
-
language: result?.language || 'uk',
|
|
53
|
-
})).toString('base64');
|
|
54
|
-
const signature1 = liqpay.str_to_sign(privateKey + data1 + privateKey);
|
|
55
|
-
|
|
56
|
-
const response1 = await request(`${host}/api/request`, {
|
|
57
|
-
method: 'POST',
|
|
58
|
-
form: { data: data1, signature: signature1 },
|
|
59
|
-
headers: {
|
|
60
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
61
|
-
},
|
|
62
|
-
}); */
|
|
51
|
+
if (email) {
|
|
52
|
+
const res = await sendReceipt(id, email, result?.language);
|
|
53
|
+
console.log('receipt delivery', res, email);
|
|
54
|
+
}
|
|
63
55
|
|
|
64
56
|
return result;
|
|
65
57
|
}
|
|
@@ -19,6 +19,7 @@ const liqpay = new LiqPay(publicKey, privateKey);
|
|
|
19
19
|
|
|
20
20
|
export default async function liqpayCreateTransaction({
|
|
21
21
|
id, orderId, amount, referer, uid, debug, expiredDate, description, paytypes, action = 'pay', currency = 'uah', language = 'uk', deliveryEmails, optionalParams,
|
|
22
|
+
splitRules, splitTicketsDynamicRequisites, splitTicketsOnly,
|
|
22
23
|
}, pg = pgClients.client) {
|
|
23
24
|
if (!referer) {
|
|
24
25
|
throw new Error('not enough params: referer required');
|
|
@@ -102,6 +103,18 @@ export default async function liqpayCreateTransaction({
|
|
|
102
103
|
} : undefined,
|
|
103
104
|
};
|
|
104
105
|
|
|
106
|
+
if (splitTicketsDynamicRequisites) {
|
|
107
|
+
paymentOptions.split_tickets_dynamic_requisites = true;
|
|
108
|
+
}
|
|
109
|
+
if (splitTicketsOnly) {
|
|
110
|
+
paymentOptions.split_tickets_only = true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// regular split rules are optional[], refer to LiqPay documentation
|
|
114
|
+
if (Array.isArray(splitRules) && splitRules.length) {
|
|
115
|
+
paymentOptions.split_rules = splitRules;
|
|
116
|
+
}
|
|
117
|
+
|
|
105
118
|
// html interface for debug via browser only
|
|
106
119
|
if (process.env.NODE_ENV !== 'test' && debug) {
|
|
107
120
|
return liqpay.cnb_form(paymentOptions);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import LiqPay from 'liqpayjs-sdk';
|
|
2
|
+
import request from 'request-promise';
|
|
3
|
+
|
|
4
|
+
import config from '../../../config.js';
|
|
5
|
+
|
|
6
|
+
const { host = 'https://www.liqpay.ua', publicKey, privateKey } = config.integrations?.liqpay || {};
|
|
7
|
+
|
|
8
|
+
const liqpay = new LiqPay(publicKey, privateKey);
|
|
9
|
+
|
|
10
|
+
export default async function sendReceipt(id, email, language = 'uk') {
|
|
11
|
+
const data1 = Buffer.from(JSON.stringify({
|
|
12
|
+
action: 'ticket',
|
|
13
|
+
version: '3',
|
|
14
|
+
order_id: id,
|
|
15
|
+
email,
|
|
16
|
+
language,
|
|
17
|
+
})).toString('base64');
|
|
18
|
+
const signature1 = liqpay.str_to_sign(privateKey + data1 + privateKey);
|
|
19
|
+
const response1 = await request(`${host}/api/request`, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
form: { data: data1, signature: signature1 },
|
|
22
|
+
headers: {
|
|
23
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
return response1;
|
|
27
|
+
}
|
|
@@ -23,7 +23,7 @@ const { table = 'pay.transactions' } = config.integrations?.pay || {};
|
|
|
23
23
|
|
|
24
24
|
const pg = pgClients.client;
|
|
25
25
|
|
|
26
|
-
export default async function processTransaction(id, { body, origin } = {}) {
|
|
26
|
+
export default async function processTransaction(id, { email, body, origin } = {}) {
|
|
27
27
|
if (!id) throw new Error('not enough params: id');
|
|
28
28
|
|
|
29
29
|
const {
|
|
@@ -41,7 +41,7 @@ export default async function processTransaction(id, { body, origin } = {}) {
|
|
|
41
41
|
throw new Error('Transaction was already processed');
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
const result = await controller[service](id, { origin, body });
|
|
44
|
+
const result = await controller[service](id, { email, origin, body });
|
|
45
45
|
|
|
46
46
|
const { status = 'error', err_description: err } = result || {};
|
|
47
47
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import config from '../../../config.js';
|
|
2
|
+
import pgClients from '../pg/pgClients.js';
|
|
3
|
+
|
|
4
|
+
import liqpaySendReceipt from './liqpay.sendReceipt.js';
|
|
5
|
+
|
|
6
|
+
const controller = {
|
|
7
|
+
liqpay: liqpaySendReceipt,
|
|
8
|
+
// monopay: monopaySendReceipt,
|
|
9
|
+
// portmone: portmoneSendReceipt,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const { table = 'pay.transactions' } = config.integrations?.pay || {};
|
|
13
|
+
|
|
14
|
+
const pg = pgClients.client;
|
|
15
|
+
|
|
16
|
+
export default async function sendReceipt(id, email, language = 'uk') {
|
|
17
|
+
if (!id) throw new Error('not enough params: id');
|
|
18
|
+
|
|
19
|
+
const { id: paymentId, service } = pg.pk?.[table]
|
|
20
|
+
? await pg.query(`select ${pg.pk?.[table]} as id, * from ${table} where ${pg.pk?.[table]}=$1`, [id]).then(el => el.rows?.[0] || {})
|
|
21
|
+
: {};
|
|
22
|
+
|
|
23
|
+
if (!paymentId) {
|
|
24
|
+
return { message: 'payment not found', status: 404 };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!service) {
|
|
28
|
+
return { message: 'payment service not defined', status: 400 };
|
|
29
|
+
}
|
|
30
|
+
if (!controller[service]) {
|
|
31
|
+
return { message: `unsupported service: ${service}`, status: 400 };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const result = await controller[service](id, email, language);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import paymentInfo from './controllers/payment.info.js';
|
|
2
2
|
|
|
3
|
-
export default
|
|
4
|
-
app.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
export default function plugin(app, { prefix = '/api' } = {}) {
|
|
4
|
+
if (!app.hasRoute({ method: 'GET', url: `${prefix}/payment-info/:id` })) {
|
|
5
|
+
app.route({
|
|
6
|
+
method: 'GET',
|
|
7
|
+
url: '/payment-info/:id',
|
|
8
|
+
config: {
|
|
9
|
+
policy: 'L1',
|
|
10
|
+
},
|
|
11
|
+
handler: paymentInfo,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
12
14
|
}
|
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
import liqpayRedirect from './controllers/liqpay.redirect.js';
|
|
2
2
|
import liqpayStatus from './controllers/liqpay.status.js';
|
|
3
3
|
|
|
4
|
-
export default
|
|
5
|
-
app.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
4
|
+
export default function plugin(app, { prefix = '/api' } = {}) {
|
|
5
|
+
if (!app.hasRoute({ method: 'GET', url: `${prefix}/liqpay-redirect` })) {
|
|
6
|
+
app.route({
|
|
7
|
+
method: 'GET',
|
|
8
|
+
url: '/liqpay-redirect',
|
|
9
|
+
config: {
|
|
10
|
+
policy: 'L1',
|
|
11
|
+
},
|
|
12
|
+
handler: liqpayRedirect,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!app.hasRoute({ method: 'POST', url: `${prefix}/liqpay/:id/:status` })) {
|
|
17
|
+
app.route({
|
|
18
|
+
method: 'POST',
|
|
19
|
+
url: '/liqpay/:id/:status',
|
|
20
|
+
config: {
|
|
21
|
+
policy: 'L0',
|
|
22
|
+
},
|
|
23
|
+
handler: liqpayStatus,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!app.hasRoute({ method: 'GET', url: `${prefix}/liqpay/:id/:status` })) {
|
|
28
|
+
app.route({
|
|
29
|
+
method: 'GET',
|
|
30
|
+
url: '/liqpay/:id/:status',
|
|
31
|
+
config: {
|
|
32
|
+
policy: 'L0',
|
|
33
|
+
},
|
|
34
|
+
handler: liqpayStatus,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
30
37
|
}
|
|
@@ -14,19 +14,24 @@ const schema = {
|
|
|
14
14
|
},
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export default
|
|
18
|
-
app.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
export default function plugin(app, { prefix = '/api' } = {}) {
|
|
18
|
+
if (!app.hasRoute({ method: 'GET', url: `${prefix}/monopay-redirect` })) {
|
|
19
|
+
app.route({
|
|
20
|
+
method: 'GET',
|
|
21
|
+
url: '/monopay-redirect',
|
|
22
|
+
config: { policy: 'L1' },
|
|
23
|
+
schema,
|
|
24
|
+
handler: monopayRedirect,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!app.hasRoute({ method: 'GET', url: `${prefix}/monopay/:id/:status` })) {
|
|
29
|
+
app.route({
|
|
30
|
+
method: 'GET',
|
|
31
|
+
url: '/monopay/:id/:status',
|
|
32
|
+
config: { policy: 'L0' },
|
|
33
|
+
schema,
|
|
34
|
+
handler: monopayStatus,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
32
37
|
}
|
|
@@ -1,29 +1,37 @@
|
|
|
1
1
|
import portmoneRedirect from './controllers/portmone.redirect.js';
|
|
2
2
|
import portmoneStatus from './controllers/portmone.status.js';
|
|
3
3
|
|
|
4
|
-
export default
|
|
5
|
-
app.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
4
|
+
export default function plugin(app, { prefix = '/api' } = {}) {
|
|
5
|
+
if (!app.hasRoute({ method: 'GET', url: `${prefix}/portmone-redirect` })) {
|
|
6
|
+
app.route({
|
|
7
|
+
method: 'GET',
|
|
8
|
+
url: '/portmone-redirect',
|
|
9
|
+
config: {
|
|
10
|
+
policy: 'L1',
|
|
11
|
+
},
|
|
12
|
+
handler: portmoneRedirect,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!app.hasRoute({ method: 'POST', url: `${prefix}/portmone/:id/:status` })) {
|
|
17
|
+
app.route({
|
|
18
|
+
method: 'POST',
|
|
19
|
+
url: '/portmone/:id/:status',
|
|
20
|
+
config: {
|
|
21
|
+
policy: 'L0',
|
|
22
|
+
},
|
|
23
|
+
handler: portmoneStatus,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!app.hasRoute({ method: 'GET', url: `${prefix}/portmone/:id/:status` })) {
|
|
28
|
+
app.route({
|
|
29
|
+
method: 'GET',
|
|
30
|
+
url: '/portmone/:id/:status',
|
|
31
|
+
config: {
|
|
32
|
+
policy: 'L0',
|
|
33
|
+
},
|
|
34
|
+
handler: portmoneStatus,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
29
37
|
}
|
package/utils.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import paymentInfo from './server/plugins/payment/paymentInfo.js';
|
|
2
2
|
import processTransaction from './server/plugins/payment/processTransaction.js';
|
|
3
3
|
import createTransaction from './server/plugins/payment/createTransaction.js';
|
|
4
|
+
import sendReceipt from './server/plugins/payment/sendReceipt.js';
|
|
4
5
|
|
|
5
6
|
export {
|
|
6
|
-
paymentInfo, processTransaction, createTransaction,
|
|
7
|
+
paymentInfo, processTransaction, createTransaction, sendReceipt,
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
export default {
|
|
10
|
-
paymentInfo, processTransaction, createTransaction,
|
|
11
|
+
paymentInfo, processTransaction, createTransaction, sendReceipt,
|
|
11
12
|
};
|