@opengis/pay 1.1.12 → 1.1.14

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.
Files changed (36) hide show
  1. package/module/pay/cls/billing.payment_status.json +8 -3
  2. package/module/pay/select/billing.subscription_id.sql +1 -0
  3. package/module/{pay → pay1}/card/billing.accounts.table/general_info.hbs +10 -10
  4. package/module/{pay → pay1}/card/billing.accounts.table/index.yml +15 -15
  5. package/module/{pay → pay1}/card/billing.accounts.table/users.hbs +11 -11
  6. package/module/{pay → pay1}/card/billing.payments.table/general_info.hbs +12 -12
  7. package/module/{pay → pay1}/card/billing.payments.table/index.yml +9 -9
  8. package/module/{pay → pay1}/card/billing.users.table/general_info.hbs +10 -10
  9. package/module/{pay → pay1}/card/billing.users.table/index.yml +9 -9
  10. package/module/pay1/cls/billing.payment_status.json +22 -0
  11. package/module/{pay → pay1}/form/billing.account_user.form.json +14 -14
  12. package/module/{pay → pay1}/form/billing.accounts.form.json +30 -30
  13. package/module/{pay → pay1}/form/billing.payment.form.json +22 -22
  14. package/module/{pay → pay1}/form/billing.users.form.json +38 -38
  15. package/module/{pay → pay1}/menu.json +24 -24
  16. package/module/pay1/pt/marketplace-service-payment-client-template.html +147 -0
  17. package/module/pay1/select/billing.account_id.sql +1 -0
  18. package/module/pay1/select/billing.service_id.sql +1 -0
  19. package/module/pay1/select/billing.subscription_id.sql +1 -0
  20. package/module/pay1/select/billing.user_id.sql +1 -0
  21. package/module/{pay → pay1}/table/billing.accounts.table.json +60 -60
  22. package/module/{pay → pay1}/table/billing.payments.table.json +67 -67
  23. package/module/{pay → pay1}/table/billing.users.table.json +70 -70
  24. package/package.json +2 -2
  25. package/plugin.js +18 -2
  26. package/server/migrations/1_users.sql +120 -120
  27. package/server/migrations/2_accounts.sql +59 -59
  28. package/server/migrations/3_utils.sql +73 -73
  29. package/server/migrations/4_subscriptions.sql +35 -35
  30. package/server/migrations/5_payments.sql +36 -36
  31. package/server/migrations/6_invoices.sql +54 -54
  32. package/server/plugins/cron.js +22 -0
  33. package/server/routes/payment.info.js +45 -0
  34. package/server/routes/portmone.redirect.js +17 -15
  35. package/server/routes/portmone.status.js +8 -4
  36. package/server/routes/utils/portmone.check.status.js +33 -0
@@ -1,37 +1,37 @@
1
- create schema if not exists billing;
2
-
3
- CREATE TABLE if not exists billing.payments();
4
- alter table billing.payments drop constraint if exists billing_payments_payment_id_pkey cascade;
5
- alter table billing.payments drop constraint if exists billing_payments_payment_id_account_id_fkey cascade;
6
-
7
- alter table billing.payments add column if not exists payment_id text NOT NULL default next_id();
8
- alter table billing.payments add column if not exists account_id text;
9
- alter table billing.payments alter column account_id drop NOT NULL;
10
- alter table billing.payments add column if not exists payment_status text NOT NULL DEFAULT 'inprogress'::text;
11
- alter table billing.payments add column if not exists success_date timestamp with time zone;
12
- alter table billing.payments add column if not exists payment_data json;
13
- alter table billing.payments add column if not exists payment_amount numeric;
14
- alter table billing.payments add column if not exists total_balance numeric;
15
- alter table billing.payments add column if not exists referer_url text;
16
- alter table billing.payments add column if not exists cdate timestamp without time zone DEFAULT now();
17
- alter table billing.payments add column if not exists uid text NOT NULL;
18
- alter table billing.payments add column if not exists editor_id text;
19
- alter table billing.payments add column if not exists editor_date timestamp without time zone;
20
- alter table billing.payments add column if not exists files json;
21
-
22
- COMMENT ON TABLE billing.payments IS 'Платежі';
23
- COMMENT ON COLUMN billing.payments.payment_id IS 'ID';
24
- COMMENT ON COLUMN billing.payments.account_id IS 'ID акаунту клієнта';
25
- COMMENT ON COLUMN billing.payments.payment_status IS 'Статус транзації';
26
- COMMENT ON COLUMN billing.payments.success_date IS 'Дата успішного завершення транзакції';
27
- COMMENT ON COLUMN billing.payments.payment_data IS 'Дані від portmone';
28
- COMMENT ON COLUMN billing.payments.payment_amount IS 'Сума поповнення рахунку';
29
- COMMENT ON COLUMN billing.payments.total_balance IS 'Поточний баланс';
30
- COMMENT ON COLUMN billing.payments.referer_url IS 'Посилання';
31
-
32
- CREATE INDEX if not exists billing_payments_account_id_btree_idx ON billing.payments USING btree (account_id COLLATE pg_catalog."default");
33
- CREATE INDEX if not exists billing_payments_account_id_trgm_idx ON billing.payments USING gin (account_id COLLATE pg_catalog."default" gin_trgm_ops);
34
- CREATE INDEX if not exists billing_payments_payments_status_btree_idx ON billing.payments USING btree (payment_status COLLATE pg_catalog."default");
35
-
36
- alter table billing.payments add CONSTRAINT billing_payments_payment_id_pkey PRIMARY KEY (payment_id);
1
+ create schema if not exists billing;
2
+
3
+ CREATE TABLE if not exists billing.payments();
4
+ alter table billing.payments drop constraint if exists billing_payments_payment_id_pkey cascade;
5
+ alter table billing.payments drop constraint if exists billing_payments_payment_id_account_id_fkey cascade;
6
+
7
+ alter table billing.payments add column if not exists payment_id text NOT NULL default next_id();
8
+ alter table billing.payments add column if not exists account_id text;
9
+ alter table billing.payments alter column account_id drop NOT NULL;
10
+ alter table billing.payments add column if not exists payment_status text NOT NULL DEFAULT 'inprogress'::text;
11
+ alter table billing.payments add column if not exists success_date timestamp with time zone;
12
+ alter table billing.payments add column if not exists payment_data json;
13
+ alter table billing.payments add column if not exists payment_amount numeric;
14
+ alter table billing.payments add column if not exists total_balance numeric;
15
+ alter table billing.payments add column if not exists referer_url text;
16
+ alter table billing.payments add column if not exists cdate timestamp without time zone DEFAULT now();
17
+ alter table billing.payments add column if not exists uid text NOT NULL;
18
+ alter table billing.payments add column if not exists editor_id text;
19
+ alter table billing.payments add column if not exists editor_date timestamp without time zone;
20
+ alter table billing.payments add column if not exists files json;
21
+
22
+ COMMENT ON TABLE billing.payments IS 'Платежі';
23
+ COMMENT ON COLUMN billing.payments.payment_id IS 'ID';
24
+ COMMENT ON COLUMN billing.payments.account_id IS 'ID акаунту клієнта';
25
+ COMMENT ON COLUMN billing.payments.payment_status IS 'Статус транзації';
26
+ COMMENT ON COLUMN billing.payments.success_date IS 'Дата успішного завершення транзакції';
27
+ COMMENT ON COLUMN billing.payments.payment_data IS 'Дані від portmone';
28
+ COMMENT ON COLUMN billing.payments.payment_amount IS 'Сума поповнення рахунку';
29
+ COMMENT ON COLUMN billing.payments.total_balance IS 'Поточний баланс';
30
+ COMMENT ON COLUMN billing.payments.referer_url IS 'Посилання';
31
+
32
+ CREATE INDEX if not exists billing_payments_account_id_btree_idx ON billing.payments USING btree (account_id COLLATE pg_catalog."default");
33
+ CREATE INDEX if not exists billing_payments_account_id_trgm_idx ON billing.payments USING gin (account_id COLLATE pg_catalog."default" gin_trgm_ops);
34
+ CREATE INDEX if not exists billing_payments_payments_status_btree_idx ON billing.payments USING btree (payment_status COLLATE pg_catalog."default");
35
+
36
+ alter table billing.payments add CONSTRAINT billing_payments_payment_id_pkey PRIMARY KEY (payment_id);
37
37
  alter table billing.payments add CONSTRAINT billing_payments_payment_id_account_id_fkey FOREIGN KEY (account_id) REFERENCES billing.accounts (account_id);
@@ -1,55 +1,55 @@
1
- create schema if not exists billing;
2
-
3
- CREATE TABLE if not exists billing.invoices();
4
- alter table billing.invoices drop constraint if exists billing_invoices_invoice_id_pkey cascade;
5
- alter table billing.invoices drop constraint if exists billing_invoices_subscription_id_fkey cascade;
6
-
7
- alter table billing.invoices add column if not exists invoice_id text NOT NULL default next_id();
8
- alter table billing.invoices add column if not exists account_id text NOT NULL;
9
- alter table billing.invoices add column if not exists subscription_id text;
10
- alter table billing.invoices add column if not exists total_amount numeric;
11
- alter table billing.invoices add column if not exists cdate timestamp without time zone DEFAULT now();
12
- alter table billing.invoices add column if not exists uid text NOT NULL;
13
- alter table billing.invoices add column if not exists editor_id text;
14
- alter table billing.invoices add column if not exists editor_date timestamp without time zone;
15
- alter table billing.invoices add column if not exists files json;
16
-
17
- COMMENT ON TABLE billing.invoices IS 'Накладні (рахунки)';
18
- COMMENT ON COLUMN billing.invoices.invoice_id IS 'ID';
19
- COMMENT ON COLUMN billing.invoices.account_id IS 'ID акаунту клієнта';
20
- COMMENT ON COLUMN billing.invoices.total_amount IS 'Сума списання';
21
- COMMENT ON COLUMN billing.invoices.subscription_id IS 'ID підписки';
22
-
23
- CREATE TABLE if not exists billing.invoices_subscribe();
24
- alter table billing.invoices_subscribe drop constraint if exists billing_invoices_subscribe_id_pkey cascade;
25
- alter table billing.invoices_subscribe drop constraint if exists billing_invoices_subscribe_invoice_id_fkey cascade;
26
-
27
- alter table billing.invoices_subscribe add column if not exists is_id text NOT NULL default next_id();
28
- alter table billing.invoices_subscribe add column if not exists invoice_id text NOT NULL;
29
- alter table billing.invoices_subscribe add column if not exists list_price numeric not null default 0;
30
- alter table billing.invoices_subscribe add column if not exists dicsounts numeric not null default 0;
31
- alter table billing.invoices_subscribe add column if not exists amount_excl_tax numeric not null default 0;
32
- alter table billing.invoices_subscribe add column if not exists tax numeric not null default 0;
33
- alter table billing.invoices_subscribe add column if not exists amount numeric not null default 0;
34
- alter table billing.invoices_subscribe add column if not exists cdate timestamp without time zone DEFAULT now();
35
- alter table billing.invoices_subscribe add column if not exists uid text NOT NULL;
36
- alter table billing.invoices_subscribe add column if not exists editor_id text;
37
- alter table billing.invoices_subscribe add column if not exists editor_date timestamp without time zone;
38
- alter table billing.invoices_subscribe add column if not exists files json;
39
-
40
- COMMENT ON TABLE billing.invoices_subscribe IS 'Складові накладних (рахунків)';
41
- COMMENT ON COLUMN billing.invoices_subscribe.is_id IS 'ID';
42
- COMMENT ON COLUMN billing.invoices_subscribe.invoice_id IS 'ID накладної (рахунку)';
43
- COMMENT ON COLUMN billing.invoices_subscribe.list_price IS 'Встановлена вартість';
44
- COMMENT ON COLUMN billing.invoices_subscribe.dicsounts IS 'Знижка';
45
- COMMENT ON COLUMN billing.invoices_subscribe.amount_excl_tax IS 'Сума, без податків';
46
- COMMENT ON COLUMN billing.invoices_subscribe.tax IS 'Сума податків';
47
- COMMENT ON COLUMN billing.invoices_subscribe.amount IS 'Сума';
48
-
49
- alter table billing.invoices add CONSTRAINT billing_invoices_invoice_id_pkey PRIMARY KEY (invoice_id);
50
- alter table billing.invoices add CONSTRAINT billing_invoices_subscription_id_fkey FOREIGN KEY (subscription_id)
51
- REFERENCES billing.subscriptions (subscription_id);
52
-
53
- alter table billing.invoices_subscribe add CONSTRAINT billing_invoices_subscribe_id_pkey PRIMARY KEY (is_id);
54
- alter table billing.invoices_subscribe add CONSTRAINT billing_invoices_subscribe_invoice_id_fkey FOREIGN KEY (invoice_id)
1
+ create schema if not exists billing;
2
+
3
+ CREATE TABLE if not exists billing.invoices();
4
+ alter table billing.invoices drop constraint if exists billing_invoices_invoice_id_pkey cascade;
5
+ alter table billing.invoices drop constraint if exists billing_invoices_subscription_id_fkey cascade;
6
+
7
+ alter table billing.invoices add column if not exists invoice_id text NOT NULL default next_id();
8
+ alter table billing.invoices add column if not exists account_id text NOT NULL;
9
+ alter table billing.invoices add column if not exists subscription_id text;
10
+ alter table billing.invoices add column if not exists total_amount numeric;
11
+ alter table billing.invoices add column if not exists cdate timestamp without time zone DEFAULT now();
12
+ alter table billing.invoices add column if not exists uid text NOT NULL;
13
+ alter table billing.invoices add column if not exists editor_id text;
14
+ alter table billing.invoices add column if not exists editor_date timestamp without time zone;
15
+ alter table billing.invoices add column if not exists files json;
16
+
17
+ COMMENT ON TABLE billing.invoices IS 'Накладні (рахунки)';
18
+ COMMENT ON COLUMN billing.invoices.invoice_id IS 'ID';
19
+ COMMENT ON COLUMN billing.invoices.account_id IS 'ID акаунту клієнта';
20
+ COMMENT ON COLUMN billing.invoices.total_amount IS 'Сума списання';
21
+ COMMENT ON COLUMN billing.invoices.subscription_id IS 'ID підписки';
22
+
23
+ CREATE TABLE if not exists billing.invoices_subscribe();
24
+ alter table billing.invoices_subscribe drop constraint if exists billing_invoices_subscribe_id_pkey cascade;
25
+ alter table billing.invoices_subscribe drop constraint if exists billing_invoices_subscribe_invoice_id_fkey cascade;
26
+
27
+ alter table billing.invoices_subscribe add column if not exists is_id text NOT NULL default next_id();
28
+ alter table billing.invoices_subscribe add column if not exists invoice_id text NOT NULL;
29
+ alter table billing.invoices_subscribe add column if not exists list_price numeric not null default 0;
30
+ alter table billing.invoices_subscribe add column if not exists dicsounts numeric not null default 0;
31
+ alter table billing.invoices_subscribe add column if not exists amount_excl_tax numeric not null default 0;
32
+ alter table billing.invoices_subscribe add column if not exists tax numeric not null default 0;
33
+ alter table billing.invoices_subscribe add column if not exists amount numeric not null default 0;
34
+ alter table billing.invoices_subscribe add column if not exists cdate timestamp without time zone DEFAULT now();
35
+ alter table billing.invoices_subscribe add column if not exists uid text NOT NULL;
36
+ alter table billing.invoices_subscribe add column if not exists editor_id text;
37
+ alter table billing.invoices_subscribe add column if not exists editor_date timestamp without time zone;
38
+ alter table billing.invoices_subscribe add column if not exists files json;
39
+
40
+ COMMENT ON TABLE billing.invoices_subscribe IS 'Складові накладних (рахунків)';
41
+ COMMENT ON COLUMN billing.invoices_subscribe.is_id IS 'ID';
42
+ COMMENT ON COLUMN billing.invoices_subscribe.invoice_id IS 'ID накладної (рахунку)';
43
+ COMMENT ON COLUMN billing.invoices_subscribe.list_price IS 'Встановлена вартість';
44
+ COMMENT ON COLUMN billing.invoices_subscribe.dicsounts IS 'Знижка';
45
+ COMMENT ON COLUMN billing.invoices_subscribe.amount_excl_tax IS 'Сума, без податків';
46
+ COMMENT ON COLUMN billing.invoices_subscribe.tax IS 'Сума податків';
47
+ COMMENT ON COLUMN billing.invoices_subscribe.amount IS 'Сума';
48
+
49
+ alter table billing.invoices add CONSTRAINT billing_invoices_invoice_id_pkey PRIMARY KEY (invoice_id);
50
+ alter table billing.invoices add CONSTRAINT billing_invoices_subscription_id_fkey FOREIGN KEY (subscription_id)
51
+ REFERENCES billing.subscriptions (subscription_id);
52
+
53
+ alter table billing.invoices_subscribe add CONSTRAINT billing_invoices_subscribe_id_pkey PRIMARY KEY (is_id);
54
+ alter table billing.invoices_subscribe add CONSTRAINT billing_invoices_subscribe_invoice_id_fkey FOREIGN KEY (invoice_id)
55
55
  REFERENCES billing.invoices (invoice_id);
@@ -0,0 +1,22 @@
1
+ import { addCron, pgClients } from '@opengis/fastify-table/utils.js';
2
+
3
+ import updateTrxStatus from '../routes/utils/portmone.check.status.js';
4
+
5
+ async function updateOldTrxsStatus() {
6
+ const inprogress = pgClients.client.pk?.['billing.payments']
7
+ ? await pgClients.client.query(`select array_agg(payment_id) as inprogress from billing.payments
8
+ where payment_status = 'inprogress' and (now() - cdate) > '1 hour'::interval`).then(el => el.rows?.[0]?.inprogress || [])
9
+ : [];
10
+
11
+ if (!inprogress?.length) return 'empty rows';
12
+
13
+ const res = await Promise.all(inprogress.map(async (paymentId) => {
14
+ const data = await updateTrxStatus({ paymentId });
15
+ return { paymentId, data };
16
+ }));
17
+ return res;
18
+ }
19
+
20
+ export default async function cron() {
21
+ // addCron(updateOldTrxsStatus, 60 * 60 * 24);
22
+ }
@@ -0,0 +1,45 @@
1
+ import { metaFormat, pgClients } from '@opengis/fastify-table/utils.js';
2
+
3
+ /**
4
+ * Апі для отримання інформації за ID
5
+ *
6
+ * @method GET
7
+ * @alias paymentInfo
8
+ * @type api
9
+ * @param {String} params.id - ID платежу
10
+ * @returns {Number} status - номер помилки. Повертається, якщо була допущенна помилка в отриманих параметрах, або з бази. Це може бути 400 або 500
11
+ * @returns {String} error - опис помилки
12
+ * @returns {String} message - повідомлення про успішне виконання і передача певних даних або помилку
13
+ */
14
+
15
+ export default async function paymentInfo({
16
+ pg = pgClients.client, user = {}, params = {},
17
+ }) {
18
+ if (!user?.uid) {
19
+ return { message: 'unauthorized', status: 401 };
20
+ }
21
+
22
+ if (!params?.id) {
23
+ return { message: 'not enough query params: id', status: 400 };
24
+ }
25
+
26
+ const { rows = [] } = await pg.query(`select
27
+ payment_id,
28
+ account_id,
29
+ payment_amount,
30
+ payment_status,
31
+ total_balance,
32
+ payment_num,
33
+ subscription_id
34
+ from billing.payments
35
+ where payment_id = $1
36
+ and account_id in (select account_id from billing.account_user where user_id = $2)`, [params.id, user.uid]);
37
+
38
+ if (!rows.length) {
39
+ return { message: 'payment not found', status: 404 };
40
+ }
41
+
42
+ await metaFormat({ rows, cls: { account_id: 'billing.account_id', payment_status: 'billing.payment_status', subscription_id: 'billing.subscription_id' } });
43
+
44
+ return rows[0];
45
+ }
@@ -1,7 +1,7 @@
1
1
  import request from 'request-promise';
2
2
 
3
3
  import {
4
- config, pgClients, logger, dataInsert, dataUpdate,
4
+ config, pgClients, logger, dataInsert, dataUpdate, handlebarsSync,
5
5
  } from '@opengis/fastify-table/utils.js';
6
6
 
7
7
  /**
@@ -25,7 +25,7 @@ export default async function PortmoneRedirect(req, reply) {
25
25
  pg = pgClients.client, user = {}, query = {}, headers = {},
26
26
  } = req;
27
27
 
28
- const { host, payeeId } = config.integrations?.pay || {};
28
+ const { host, payeeId, paymentRedirect = config.paymentRedirect } = config.integrations?.pay || {};
29
29
  const domain = req.hostname.split(':').shift();
30
30
 
31
31
  if (!host) {
@@ -63,31 +63,32 @@ export default async function PortmoneRedirect(req, reply) {
63
63
  if (!config.auth?.disableRestricted) return { message: 'access restricted: referer', status: 403 };
64
64
  }
65
65
 
66
- const { payment_id: paymentId } = data.payment_id
67
- ? await dataUpdate({
68
- table: 'billing.payments',
69
- id: data.payment_id,
70
- data: {
71
- referer_url: headers?.referer,
72
- payment_status: 'inprogress',
73
- },
74
- uid: user?.uid || '0',
75
- })
76
- : await dataInsert({
66
+ const { payment_id: paymentId } = !data.payment_id
67
+ ? await dataInsert({
77
68
  table: 'billing.payments',
78
69
  data: {
79
70
  payment_amount: paymentAmount,
80
71
  account_id: accountId,
81
- referer_url: headers?.referer,
82
72
  payment_status: 'inprogress',
83
73
  },
84
74
  uid: user?.uid || '0',
85
- }).then(el => el.rows?.[0] || {});
75
+ }).then(el => el.rows?.[0] || {})
76
+ : { payment_id: data.payment_id };
86
77
 
87
78
  if (!paymentId) {
88
79
  return { message: 'payment not found', status: 404 };
89
80
  }
90
81
 
82
+ await dataUpdate({
83
+ table: 'billing.payments',
84
+ id: paymentId,
85
+ data: {
86
+ referer_url: paymentRedirect ? handlebarsSync.compile(paymentRedirect)({ id: paymentId }) : headers?.referer,
87
+ payment_status: 'inprogress',
88
+ },
89
+ uid: user?.uid || '0',
90
+ });
91
+
91
92
  const protocol = headers?.referer.split('://').shift();
92
93
 
93
94
  const formData = {
@@ -107,6 +108,7 @@ export default async function PortmoneRedirect(req, reply) {
107
108
  accountId,
108
109
  price: paymentAmount,
109
110
  domain,
111
+ paymentRedirectUrl: paymentRedirect ? handlebarsSync.compile(paymentRedirect)({ id: paymentId }) : headers?.referer,
110
112
  uid: user?.uid || '0',
111
113
  };
112
114
 
@@ -23,7 +23,7 @@ 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 = {}, unittest,
27
27
  } = req;
28
28
  const { host } = config.integrations?.pay || {};
29
29
 
@@ -62,7 +62,7 @@ export default async function portmoneStatus(req, reply) {
62
62
  return { message: 'Transaction not found', status: 400 };
63
63
  }
64
64
 
65
- const refill = body?.billAmount || refillSum || 0;
65
+ const refill = responseStatus === 'success' ? (body?.billAmount || refillSum || 0) : 0;
66
66
 
67
67
  // request portmone trx info to recheck request data is valid?
68
68
  if (!origin?.startsWith(host)) {
@@ -89,7 +89,7 @@ export default async function portmoneStatus(req, reply) {
89
89
 
90
90
  // last trx contains total balance
91
91
  const { total_balance: totalBalance } = await pg.query(`select total_balance from billing.payments
92
- where account_id=$1 and total_balance is not null order by cdate desc limit 1`, [accountId])
92
+ where account_id=$1 and payment_status in ('success', 'error') and total_balance is not null order by cdate desc limit 1`, [accountId])
93
93
  .then(el => el.rows?.[0] || {});
94
94
 
95
95
  await dataUpdate({
@@ -97,13 +97,17 @@ export default async function portmoneStatus(req, reply) {
97
97
  data: {
98
98
  payment_data: body,
99
99
  payment_status: responseStatus,
100
- total_balance: +(refill || 0) + (+totalBalance || 0),
100
+ total_balance: +(refill) + (+totalBalance || 0),
101
101
  success_date: new Date(),
102
102
  },
103
103
  id: paymentId,
104
104
  uid: user?.uid || '0',
105
105
  });
106
106
 
107
+ if (unittest) {
108
+ console.log(`id:${trx}, status: ${responseStatus}, before: ${totalBalance || 0}, after: ${+(refill) + (+totalBalance || 0)} (${body?.billAmount || refillSum || 0})`);
109
+ }
110
+
107
111
  const { account_email: to } = await pg.query('select account_email from billing.accounts where account_id=$1', [accountId])
108
112
  .then(el => el.rows?.[0] || {});
109
113
 
@@ -0,0 +1,33 @@
1
+ import request from 'request-promise';
2
+
3
+ import { config, pgClients } from '@opengis/fastify-table/utils.js';
4
+
5
+ const { host, payeeId } = config.integrations?.pay || {};
6
+
7
+ export default async function updateTrxStatus({
8
+ pg = pgClients.client, paymentId,
9
+ }) {
10
+ const data = pg.pk?.['billing.payments'] && paymentId ? await pg.query('select * from billing.payments where payment_id=$1', [paymentId]).then(el => el.rows?.[0] || {}) : undefined;
11
+ if (!paymentId || !host || !payeeId || !data) throw new Error('not enough params');
12
+
13
+ const formData = {
14
+ method: 'result',
15
+ login: 'WDISHOP',
16
+ password: 'wdi451',
17
+ payeeId,
18
+ shopOrderNumber: paymentId,
19
+ // shopbillId,
20
+ id: paymentId,
21
+ };
22
+ const response = await request({
23
+ url: `${host}/gateway/`,
24
+ method: 'POST',
25
+ formData,
26
+ followAllRedirects: false,
27
+ jar: true,
28
+ timeout: 6000,
29
+ simple: false, // prevent not 2xx code trigger catch
30
+ resolveWithFullResponse: true,
31
+ });
32
+ return response;
33
+ }