@opengis/pay 1.1.4 → 1.1.6
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
|
@@ -25,10 +25,6 @@ export default async function PortmoneRedirect(req, reply) {
|
|
|
25
25
|
pg = pgClients.client, user = {}, query = {}, headers = {},
|
|
26
26
|
} = req;
|
|
27
27
|
|
|
28
|
-
if (!user?.uid) {
|
|
29
|
-
return { message: 'access restricted', status: 403 };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
28
|
const { host, payeeId } = config.integrations?.pay || {};
|
|
33
29
|
const domain = `${req.protocol}://${req.hostname.split(':').shift()}`;
|
|
34
30
|
|
|
@@ -54,8 +50,7 @@ export default async function PortmoneRedirect(req, reply) {
|
|
|
54
50
|
}
|
|
55
51
|
|
|
56
52
|
const accountId = data.account_id
|
|
57
|
-
|| await pg.query('select account_id from billing.account_user where user_id=$1 limit 1', [user
|
|
58
|
-
.then(el => el.rows?.[0]?.account_id);
|
|
53
|
+
|| (user?.uid ? await pg.query('select account_id from billing.account_user where user_id=$1 limit 1', [user?.uid]).then(el => el.rows?.[0]?.account_id) : null);
|
|
59
54
|
|
|
60
55
|
if (!accountId) {
|
|
61
56
|
return { message: 'account_id is required', status: 400 };
|
|
@@ -63,7 +58,7 @@ export default async function PortmoneRedirect(req, reply) {
|
|
|
63
58
|
|
|
64
59
|
if (!headers?.referer || !headers.referer.includes(domain)) {
|
|
65
60
|
logger.file('payments/warn', {
|
|
66
|
-
message: 'invalid referer', domain, referer: headers?.referer, uid: user
|
|
61
|
+
message: 'invalid referer', domain, referer: headers?.referer, uid: user?.uid,
|
|
67
62
|
});
|
|
68
63
|
return { message: 'access restricted', status: 403 };
|
|
69
64
|
}
|
|
@@ -76,7 +71,7 @@ export default async function PortmoneRedirect(req, reply) {
|
|
|
76
71
|
referer_url: headers?.referer,
|
|
77
72
|
payment_status: 'inprogress',
|
|
78
73
|
},
|
|
79
|
-
uid: user
|
|
74
|
+
uid: user?.uid || '0',
|
|
80
75
|
})
|
|
81
76
|
: await dataInsert({
|
|
82
77
|
table: 'billing.payments',
|
|
@@ -86,7 +81,7 @@ export default async function PortmoneRedirect(req, reply) {
|
|
|
86
81
|
referer_url: headers?.referer,
|
|
87
82
|
payment_status: 'inprogress',
|
|
88
83
|
},
|
|
89
|
-
uid: user
|
|
84
|
+
uid: user?.uid || '0',
|
|
90
85
|
}).then(el => el.rows?.[0] || {});
|
|
91
86
|
|
|
92
87
|
if (!paymentId) {
|
|
@@ -110,7 +105,7 @@ export default async function PortmoneRedirect(req, reply) {
|
|
|
110
105
|
accountId,
|
|
111
106
|
price: paymentAmount,
|
|
112
107
|
domain,
|
|
113
|
-
uid: user
|
|
108
|
+
uid: user?.uid || '0',
|
|
114
109
|
};
|
|
115
110
|
|
|
116
111
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
config, logger, pgClients,
|
|
2
|
+
config, logger, pgClients, dataUpdate, getTemplate,
|
|
3
3
|
} from '@opengis/fastify-table/utils.js';
|
|
4
4
|
|
|
5
5
|
import { sendNotification } from '@opengis/admin/utils.js';
|
|
@@ -23,13 +23,8 @@ import { sendNotification } from '@opengis/admin/utils.js';
|
|
|
23
23
|
|
|
24
24
|
export default async function portmoneStatus(req, reply) {
|
|
25
25
|
const {
|
|
26
|
-
pg = pgClients.client, params = {}, headers = {}, body = {}, user,
|
|
26
|
+
pg = pgClients.client, params = {}, headers = {}, body = {}, user = {},
|
|
27
27
|
} = req;
|
|
28
|
-
|
|
29
|
-
if (!user?.uid) {
|
|
30
|
-
return { message: 'access restricted', status: 403 };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
28
|
const { host } = config.integrations?.pay || {};
|
|
34
29
|
|
|
35
30
|
if (!host) {
|
|
@@ -53,8 +48,12 @@ export default async function portmoneStatus(req, reply) {
|
|
|
53
48
|
} = data;
|
|
54
49
|
|
|
55
50
|
if (trxStatus === 'success') {
|
|
56
|
-
logger.file('
|
|
57
|
-
|
|
51
|
+
logger.file('payments/skip', {
|
|
52
|
+
type: 'status',
|
|
53
|
+
paymentId,
|
|
54
|
+
origin,
|
|
55
|
+
uid: user?.uid || '0',
|
|
56
|
+
message: 'Transaction was already processed',
|
|
58
57
|
});
|
|
59
58
|
return { message: 'Transaction was already processed', status: 400 };
|
|
60
59
|
}
|
|
@@ -66,11 +65,12 @@ export default async function portmoneStatus(req, reply) {
|
|
|
66
65
|
const refill = body?.billAmount || refillSum || 0;
|
|
67
66
|
|
|
68
67
|
// request portmone trx info to recheck request data is valid?
|
|
69
|
-
if (!config.debug && !origin?.startsWith(host)) {
|
|
68
|
+
if (!config.debug && !origin?.startsWith(host) && !config.disableRestricted) {
|
|
70
69
|
logger.file('payments/warn', {
|
|
71
70
|
type: 'status',
|
|
71
|
+
paymentId,
|
|
72
72
|
origin,
|
|
73
|
-
uid: user
|
|
73
|
+
uid: user?.uid || '0',
|
|
74
74
|
refill,
|
|
75
75
|
message: 'invalid referer',
|
|
76
76
|
});
|
|
@@ -79,8 +79,9 @@ export default async function portmoneStatus(req, reply) {
|
|
|
79
79
|
|
|
80
80
|
logger.file('payments', {
|
|
81
81
|
type: 'status',
|
|
82
|
+
paymentId,
|
|
82
83
|
origin,
|
|
83
|
-
uid: user
|
|
84
|
+
uid: user?.uid || '0',
|
|
84
85
|
refill,
|
|
85
86
|
body,
|
|
86
87
|
params,
|
|
@@ -100,7 +101,7 @@ export default async function portmoneStatus(req, reply) {
|
|
|
100
101
|
success_date: new Date(),
|
|
101
102
|
},
|
|
102
103
|
id: paymentId,
|
|
103
|
-
uid: user
|
|
104
|
+
uid: user?.uid || '0',
|
|
104
105
|
});
|
|
105
106
|
|
|
106
107
|
const { account_email: to } = await pg.query('select account_email from billing.accounts where account_id=$1', [accountId])
|
|
@@ -108,20 +109,17 @@ export default async function portmoneStatus(req, reply) {
|
|
|
108
109
|
|
|
109
110
|
logger.file('payments', {
|
|
110
111
|
type: 'status',
|
|
112
|
+
paymentId,
|
|
113
|
+
responseStatus,
|
|
111
114
|
to,
|
|
115
|
+
origin,
|
|
112
116
|
redirect: redirectUrl,
|
|
113
|
-
|
|
114
|
-
uid: user.uid,
|
|
117
|
+
uid: user.uid || '0',
|
|
115
118
|
});
|
|
116
119
|
|
|
117
|
-
const cls2 = await getSelectVal({ pg, name: 'billing.account_id', values: [accountId] });
|
|
118
|
-
const cls3 = await getSelectVal({ pg, name: 'billing.payment_status', values: [trxStatus] });
|
|
119
|
-
|
|
120
120
|
Object.assign(data, {
|
|
121
121
|
domain: req.hostname,
|
|
122
122
|
total_balance: +(refill || 0) + (+totalBalance || 0),
|
|
123
|
-
account_id_text: accountId ? cls2?.[accountId] || accountId : 'Інформація відсутня',
|
|
124
|
-
payment_status_text: trxStatus ? cls3?.[trxStatus] || trxStatus : 'Інформація відсутня',
|
|
125
123
|
});
|
|
126
124
|
|
|
127
125
|
if (to) {
|
|
@@ -136,23 +134,16 @@ export default async function portmoneStatus(req, reply) {
|
|
|
136
134
|
};
|
|
137
135
|
await sendNotification(options);
|
|
138
136
|
}
|
|
139
|
-
logger.file('payments', {
|
|
140
|
-
type: 'status',
|
|
141
|
-
to,
|
|
142
|
-
redirect: redirectUrl,
|
|
143
|
-
paymentId,
|
|
144
|
-
responseStatus,
|
|
145
|
-
uid: user.uid,
|
|
146
|
-
});
|
|
147
137
|
return reply.redirect(redirectUrl || '/');
|
|
148
138
|
}
|
|
149
139
|
catch (err) {
|
|
150
140
|
logger.file('payments/error', {
|
|
151
141
|
type: 'status',
|
|
152
|
-
error: err.toString(),
|
|
153
|
-
uid: user.uid,
|
|
154
142
|
paymentId,
|
|
143
|
+
origin,
|
|
155
144
|
responseStatus,
|
|
145
|
+
uid: user?.uid || '0',
|
|
146
|
+
error: err.toString(),
|
|
156
147
|
});
|
|
157
148
|
return { error: err.toString(), status: 500 };
|
|
158
149
|
}
|