@opengis/pay 2.0.7 → 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
CHANGED
|
@@ -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
|
}
|
|
@@ -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
|
+
}
|
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
|
};
|