@opengis/pay 2.0.6 → 2.0.8
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.checkStatus.js +10 -18
- package/server/plugins/payment/liqpay.createTransaction.js +2 -1
- package/server/plugins/payment/liqpay.sendReceipt.js +27 -0
- package/server/plugins/payment/monopay.createTransaction.js +2 -1
- package/server/plugins/payment/portmone.createTransaction.js +2 -1
- package/server/plugins/payment/processTransaction.js +2 -2
- package/server/plugins/payment/sendReceipt.js +36 -0
- package/server/routes/liqpay/controllers/liqpay.redirect.js +1 -1
- package/server/routes/monopay/controllers/monopay.redirect.js +1 -1
- package/utils.js +3 -2
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
|
}
|
|
@@ -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
|
}
|
|
@@ -18,7 +18,7 @@ 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
23
|
if (!referer) {
|
|
24
24
|
throw new Error('not enough params: referer required');
|
|
@@ -60,6 +60,7 @@ export default async function liqpayCreateTransaction({
|
|
|
60
60
|
currency,
|
|
61
61
|
language,
|
|
62
62
|
paytypes,
|
|
63
|
+
optionalParams,
|
|
63
64
|
});
|
|
64
65
|
|
|
65
66
|
if (!paymentData?.id) {
|
|
@@ -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
|
+
}
|
|
@@ -22,7 +22,7 @@ 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
27
|
if (!referer) {
|
|
28
28
|
throw new Error('not enough params: referer required');
|
|
@@ -55,6 +55,7 @@ export default async function monopayCreateTransaction({
|
|
|
55
55
|
action,
|
|
56
56
|
currency,
|
|
57
57
|
language,
|
|
58
|
+
optionalParams,
|
|
58
59
|
});
|
|
59
60
|
|
|
60
61
|
if (!paymentData?.id) {
|
|
@@ -12,7 +12,7 @@ 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
17
|
if (!referer) {
|
|
18
18
|
throw new Error('not enough params: referer required');
|
|
@@ -50,6 +50,7 @@ export default async function portmoneCreateTransaction({
|
|
|
50
50
|
currency,
|
|
51
51
|
language,
|
|
52
52
|
paytypes,
|
|
53
|
+
optionalParams,
|
|
53
54
|
});
|
|
54
55
|
|
|
55
56
|
if (!paymentData?.id) {
|
|
@@ -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
|
+
}
|
|
@@ -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
|
};
|
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
|
};
|