@opengis/pay 1.1.0 → 1.1.2
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/module/pay/card/billing.accounts.table/general_info.hbs +10 -10
- package/module/pay/card/billing.accounts.table/index.yml +15 -15
- package/module/pay/card/billing.accounts.table/users.hbs +11 -11
- package/module/pay/card/billing.payments.table/general_info.hbs +12 -12
- package/module/pay/card/billing.payments.table/index.yml +9 -9
- package/module/pay/card/billing.users.table/general_info.hbs +10 -10
- package/module/pay/card/billing.users.table/index.yml +9 -9
- package/module/pay/form/billing.account_user.form.json +14 -14
- package/module/pay/form/billing.accounts.form.json +30 -30
- package/module/pay/form/billing.payment.form.json +22 -22
- package/module/pay/form/billing.users.form.json +38 -38
- package/module/pay/menu.json +24 -24
- package/module/pay/pt/marketplace-service-payment-client-template.html +3 -3
- package/module/pay/table/billing.accounts.table.json +60 -60
- package/module/pay/table/billing.payments.table.json +67 -67
- package/module/pay/table/billing.users.table.json +70 -70
- package/package.json +1 -1
- package/plugin.js +0 -5
- package/server/migrations/1_users.sql +120 -120
- package/server/migrations/2_accounts.sql +59 -59
- package/server/migrations/3_utils.sql +73 -73
- package/server/migrations/4_subscriptions.sql +35 -35
- package/server/migrations/5_payments.sql +36 -36
- package/server/migrations/6_invoices.sql +54 -54
- package/server/routes/portmone.redirect.js +30 -13
- package/server/routes/portmone.status.js +17 -7
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import request from 'request-promise';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
config, pgClients, logger, dataInsert,
|
|
4
|
+
config, pgClients, logger, dataInsert, dataUpdate,
|
|
5
5
|
} from '@opengis/fastify-table/utils.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Апі перенаправлює до стороннього сервісу оплати карткою онлайн
|
|
9
9
|
*
|
|
10
|
-
* @method GET
|
|
10
|
+
* @method GET
|
|
11
11
|
* @alias PortmonePaymentRedirect
|
|
12
12
|
* @summary redirect на сервіс оплати карткою
|
|
13
13
|
* @type api
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
|
|
23
23
|
export default async function PortmoneRedirect(req, reply) {
|
|
24
24
|
const {
|
|
25
|
-
pg = pgClients.client, user = {}, query = {}, headers = {},
|
|
25
|
+
pg = pgClients.client, user = {}, query = {}, headers = {},
|
|
26
26
|
} = req;
|
|
27
27
|
|
|
28
28
|
if (!user?.uid) {
|
|
@@ -30,6 +30,7 @@ export default async function PortmoneRedirect(req, reply) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const { host, payeeId } = config.integration?.portmone || {};
|
|
33
|
+
const domain = `${req.protocol}://${req.hostname}`;
|
|
33
34
|
|
|
34
35
|
if (!host) {
|
|
35
36
|
return { message: 'empty integration host', status: 400 };
|
|
@@ -39,25 +40,42 @@ export default async function PortmoneRedirect(req, reply) {
|
|
|
39
40
|
return { message: 'empty integration payeeId', status: 400 };
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
const data =
|
|
43
|
+
const data = query.id ? await pg.query('select payment_id, account_id, payment_amount, payment_status from billing.payments where payment_id=$1', [query.id])
|
|
44
|
+
.then(el => el.rows?.[0] || {}) : {};
|
|
45
|
+
|
|
46
|
+
if (data.payment_status && data.payment_status === 'success') {
|
|
47
|
+
return { message: 'already processed', status: 400 };
|
|
48
|
+
}
|
|
43
49
|
|
|
44
|
-
const paymentAmount = data
|
|
50
|
+
const paymentAmount = data.payment_amount || query.price;
|
|
45
51
|
|
|
46
52
|
if (!paymentAmount) {
|
|
47
53
|
return { message: 'price is required', status: 400 };
|
|
48
54
|
}
|
|
49
55
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
.then(el => el.rows?.[0] || {});
|
|
56
|
+
const accountId = data.account_id
|
|
57
|
+
|| await pg.query('select account_id from billing.account_user where user_id=$1 limit 1', [user.uid])
|
|
58
|
+
.then(el => el.rows?.[0]?.account_id);
|
|
54
59
|
|
|
55
60
|
if (!accountId) {
|
|
56
61
|
return { message: 'account_id is required', status: 400 };
|
|
57
62
|
}
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
if (!headers?.referer || !headers.referer.includes(domain)) {
|
|
65
|
+
logger.file('payments/warn', { message: 'invalid referer', referer: headers?.referer, uid: user.uid });
|
|
66
|
+
return { message: 'access restricted', status: 403 };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const { payment_id: paymentId } = data.payment_id
|
|
70
|
+
? await dataUpdate({
|
|
71
|
+
table: 'billing.payments',
|
|
72
|
+
id: data.payment_id,
|
|
73
|
+
data: {
|
|
74
|
+
referer_url: headers?.referer,
|
|
75
|
+
payment_status: 'inprogress',
|
|
76
|
+
},
|
|
77
|
+
uid: user.uid,
|
|
78
|
+
})
|
|
61
79
|
: await dataInsert({
|
|
62
80
|
table: 'billing.payments',
|
|
63
81
|
data: {
|
|
@@ -70,10 +88,9 @@ export default async function PortmoneRedirect(req, reply) {
|
|
|
70
88
|
}).then(el => el.rows?.[0] || {});
|
|
71
89
|
|
|
72
90
|
if (!paymentId) {
|
|
73
|
-
return { message: '
|
|
91
|
+
return { message: 'payment not found', status: 404 };
|
|
74
92
|
}
|
|
75
93
|
|
|
76
|
-
const domain = `${req.protocol}://${req.hostname}`;
|
|
77
94
|
const formData = {
|
|
78
95
|
payee_id: payeeId,
|
|
79
96
|
description: `Послуга - поповнення рахунку на суму ${paymentAmount} грн`,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
config, logger, pgClients, getSelectVal,
|
|
3
|
-
dataUpdate,
|
|
2
|
+
config, logger, pgClients, getSelectVal, dataUpdate, getTemplate,
|
|
4
3
|
} from '@opengis/fastify-table/utils.js';
|
|
5
4
|
|
|
6
5
|
import { sendNotification } from '@opengis/admin/utils.js';
|
|
@@ -68,14 +67,23 @@ export default async function portmoneStatus(req, reply) {
|
|
|
68
67
|
|
|
69
68
|
// request portmone trx info to recheck request data is valid?
|
|
70
69
|
if (!config.debug && !origin?.startsWith(host)) {
|
|
71
|
-
logger.file('
|
|
72
|
-
|
|
70
|
+
logger.file('payments/warn', {
|
|
71
|
+
type: 'status',
|
|
72
|
+
origin,
|
|
73
|
+
uid: user.uid,
|
|
74
|
+
refill,
|
|
75
|
+
message: 'invalid referer',
|
|
73
76
|
});
|
|
74
77
|
return { message: 'access restricted', status: 403 };
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
logger.file('
|
|
78
|
-
|
|
80
|
+
logger.file('payments', {
|
|
81
|
+
type: 'status',
|
|
82
|
+
origin,
|
|
83
|
+
uid: user.uid,
|
|
84
|
+
refill,
|
|
85
|
+
body,
|
|
86
|
+
params,
|
|
79
87
|
});
|
|
80
88
|
|
|
81
89
|
// last trx contains total balance
|
|
@@ -111,16 +119,18 @@ export default async function portmoneStatus(req, reply) {
|
|
|
111
119
|
|
|
112
120
|
Object.assign(data, {
|
|
113
121
|
domain: req.hostname,
|
|
122
|
+
total_balance: +(refill || 0) + (+totalBalance || 0),
|
|
114
123
|
account_id_text: accountId ? cls2?.[accountId] || accountId : 'Інформація відсутня',
|
|
115
124
|
payment_status_text: trxStatus ? cls3?.[trxStatus] || trxStatus : 'Інформація відсутня',
|
|
116
125
|
});
|
|
117
126
|
|
|
118
127
|
if (to) {
|
|
128
|
+
const pt = await getTemplate('pt', 'marketplace-service-payment-client-template');
|
|
119
129
|
const options = {
|
|
120
130
|
pg,
|
|
121
131
|
to,
|
|
122
132
|
title: `Поповнення рахунку на порталі ${req.hostname}`,
|
|
123
|
-
template:
|
|
133
|
+
template: pt?.html || pt,
|
|
124
134
|
data,
|
|
125
135
|
nocache: config?.local,
|
|
126
136
|
};
|