@opengis/pay 1.0.0 → 1.1.0

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 (38) hide show
  1. package/README.md +7 -6
  2. package/module/pay/card/billing.accounts.table/general_info.hbs +11 -0
  3. package/module/pay/card/billing.accounts.table/index.yml +15 -0
  4. package/module/pay/card/billing.accounts.table/users.hbs +12 -0
  5. package/module/pay/card/billing.payments.table/general_info.hbs +13 -0
  6. package/module/pay/card/billing.payments.table/index.yml +10 -0
  7. package/module/pay/card/billing.users.table/general_info.hbs +11 -0
  8. package/module/pay/card/billing.users.table/index.yml +10 -0
  9. package/module/pay/cls/billing.payment_status.json +17 -0
  10. package/module/pay/form/billing.account_user.form.json +15 -0
  11. package/module/pay/form/billing.accounts.form.json +31 -0
  12. package/module/pay/form/billing.payment.form.json +23 -0
  13. package/module/pay/form/billing.users.form.json +39 -0
  14. package/module/pay/menu.json +24 -0
  15. package/{server/templates → module/pay}/pt/marketplace-service-payment-client-template.html +6 -8
  16. package/module/pay/select/billing.account_id.sql +1 -0
  17. package/module/pay/select/billing.user_id.sql +1 -0
  18. package/module/pay/table/billing.accounts.table.json +61 -0
  19. package/module/pay/table/billing.payments.table.json +68 -0
  20. package/module/pay/table/billing.users.table.json +71 -0
  21. package/package.json +8 -12
  22. package/plugin.js +17 -16
  23. package/server/migrations/1_users.sql +121 -0
  24. package/server/migrations/2_accounts.sql +59 -0
  25. package/server/migrations/3_utils.sql +74 -0
  26. package/server/migrations/4_subscriptions.sql +36 -0
  27. package/server/migrations/5_payments.sql +37 -0
  28. package/server/migrations/6_invoices.sql +55 -0
  29. package/server/routes/portmone.redirect.js +124 -0
  30. package/server/routes/portmone.status.js +149 -0
  31. package/config.js +0 -7
  32. package/controllers/portmone/portmone.redirect.js +0 -80
  33. package/controllers/portmone/portmone.status.js +0 -113
  34. package/server/migrations/users.sql +0 -89
  35. package/server/plugins/hook.js +0 -16
  36. package/server/templates/cls/billing.trx_status.json +0 -14
  37. package/server/templates/select/billing.account_id.sql +0 -5
  38. /package/{server/templates → module/pay}/select/billing.service_id.sql +0 -0
package/config.js DELETED
@@ -1,7 +0,0 @@
1
- import { existsSync, readFileSync } from 'fs';
2
-
3
- const config = existsSync('config.json') ? JSON.parse(readFileSync('config.json')) : {};
4
- // console.log(config);
5
- config.storageList = {};
6
-
7
- export default config;
@@ -1,80 +0,0 @@
1
- const q = `insert into billing.trx(refill_sum, account_id, uid, referer_url, trx_status)
2
- select $1::numeric, $2, $3, $4, 'inprogress' returning trx_id`;
3
- const q1 = 'select account_id from billing.account_user where client_uid=$1 limit 1';
4
-
5
- import request from 'request-promise';
6
-
7
- /**
8
- * Апі перенаправлює до стороннього сервісу оплати карткою онлайн
9
- *
10
- * @method GET|POST
11
- * @alias PortmonePaymentRedirect
12
- * @summary redirect на сервіс оплати карткою
13
- * @type api
14
- * @param {String} price - Сума поповнення рахунку
15
- * @returns {Number} status - номер помилки. Повертається, якщо була допущенна помилка в отриманих параметрах, або з бази. Це може бути 400 або 500
16
- * @returns {String} error - опис помилки
17
- * @returns {String} redirect - шлях до переадресації
18
- * @returns {String} message - повідомлення про успішне виконання і передача певних даних або помилку
19
- * @returns {String} headers - заголовки HTTP
20
- * @returns {String} file - шлях файла або його назва
21
- */
22
-
23
- export default async function PortmoneRedirect(req, res) {
24
- const {
25
- pg, funcs, user = {}, query = {}, headers = {}, log,
26
- } = req;
27
-
28
- if (!user?.uid) {
29
- return { message: 'uid is required', status: 403 };
30
- }
31
-
32
- if (!query?.price) {
33
- return { message: 'price is required', status: 400 };
34
- }
35
-
36
- const {
37
- host = 'https://www.portmone.com.ua',
38
- payeeId = 1185, // test account payee id
39
- } = funcs.config?.integration?.portmone || {};
40
-
41
- const { account_id: accountId } = await pg.query(q1, [user.uid]).then((res1) => res1.rows?.[0] || {});
42
-
43
- const args = [query?.price, accountId, user.uid, headers?.referer];
44
- const { trx_id: trxId } = await pg.query(q, args).then((res1) => res1.rows?.[0] || {});
45
-
46
- if (!trxId) {
47
- return { message: 'Не вірне замовлення', status: 400 };
48
- }
49
-
50
- const domain = `${req.protocol}://${req.hostname}`;
51
- const body = {
52
- payee_id: payeeId,
53
- description: `Послуга - поповнення рахунку на суму ${query?.price} грн`,
54
- shop_order_number: trxId,
55
- bill_refill_sum: query?.price,
56
- success_url: `${domain}${funcs.config?.prefix || '/api'}/portmone/${trxId}/success`,
57
- failure_url: `${domain}${funcs.config?.prefix || '/api'}/portmone/${trxId}/error`,
58
- lang: 'ua',
59
- };
60
- try {
61
- const data = await request({
62
- url: `${host}/gateway/`,
63
- method: 'POST',
64
- formData: body,
65
- followAllRedirects: false,
66
- jar: true,
67
- timeout: 6000,
68
- });
69
- log.info('integrations/portmone/redirect', {
70
- payeeId, trxId, accountId, price: query?.price, domain, response: data, status: 302,
71
- });
72
- return res.redirect(data);
73
- }
74
- catch (err) {
75
- log.info('integrations/portmone/redirect', {
76
- payeeId, trxId, accountId, price: query?.price, domain, response: err.response.headers?.location, status: err.statusCode,
77
- });
78
- return res.redirect(err.response.headers?.location);
79
- }
80
- }
@@ -1,113 +0,0 @@
1
- const template = 'marketplace-service-payment-client-template';
2
- const q = 'select trx_id as trx, refill_sum, referer_url, trx_status, account_id from billing.trx where trx_id=$1';
3
- const q1 = `select total_balance from billing.trx where account_id=$1
4
- and total_balance is not null order by cdate desc limit 1`;
5
- const q2 = 'select email from crm_acc.crm_account where account_id=$1';
6
-
7
- import getSelectVal from '@opengis/fastify-table/table/funcs/metaFormat/getSelectVal.js';
8
-
9
- /**
10
- * Апі перенаправлює з portmone назад на сторінку замовлення
11
- *
12
- * @method POST
13
- * @alias PortmoneStatus
14
- * @summary redirect з portmone на сторінку замовлення
15
- * @type api
16
- * @param {String} trxId - Ідентифікатор замовлення
17
- * @param {String} refillSum - Сума поповнення рахунку
18
- * @returns {Number} status - номер помилки. Повертається, якщо була допущенна помилка в отриманих параметрах, або з бази. Це може бути 400 або 500
19
- * @returns {String} error - опис помилки
20
- * @returns {String} redirect - шлях до переадресації
21
- * @returns {String} message - повідомлення про успішне виконання і передача певних даних або помилку
22
- * @returns {String} headers - заголовки HTTP
23
- * @returns {String} file - шлях файла або його назва
24
- */
25
-
26
- export default async function portmoneStatus(req, res) {
27
- const {
28
- body = {}, pg, log, params = {}, funcs = {}, headers = {},
29
- } = req;
30
-
31
- const {
32
- host = 'https://www.portmone.com.ua',
33
- } = funcs.config?.integration?.portmone || {};
34
-
35
- const origin = headers?.origin || headers?.referer;
36
- log.debug('integrations/portmone/status', { body, params, origin });
37
-
38
- const responseStatus = body?.status || params?.status;
39
- const trxId = body?.shopOrderNumber || params?.id;
40
-
41
- const updateTrx = `
42
- update billing.trx
43
- set payment_data=$2, trx_status=$3
44
- ${responseStatus === 'success'
45
- ? ',transaction_success_date=now(),refill_sum=$4,total_balance=( $4::numeric + coalesce($5::numeric,0) ) '
46
- : ''}
47
- where trx_id=$1`;
48
-
49
- try {
50
- const {
51
- trx, refill_sum: refillSum, referer_url: redirectUrl, trx_status: trxStatus, account_id: accountId,
52
- } = await pg.query(q, [trxId]).then((res1) => res1.rows?.[0] || {});
53
-
54
- if (!trx) {
55
- return { message: 'Transaction not found', status: 400 };
56
- }
57
-
58
- const refill = body?.billAmount || refillSum || 0;
59
-
60
- // request portmone trx info to recheck request data is valid?
61
- if (!req.unittest && !origin?.startsWith(host) && false) {
62
- return { message: 'access restricted', status: 403 };
63
- }
64
-
65
- // last trx contains total balance
66
- const { total_balance: totalBalance } = await pg.query(q1, [accountId]).then((res1) => res1.rows?.[0] || {});
67
-
68
- if (trxStatus === 'success') {
69
- return { message: 'Transaction was already processed', status: 400 };
70
- }
71
-
72
- await pg.query(updateTrx, [trxId, JSON.stringify(body), responseStatus, refill, totalBalance]);
73
-
74
- const { email } = await pg.query(q2, [accountId]).then((res1) => res1.rows?.[0] || {});
75
-
76
- log.debug('integrations/portmone/status', {
77
- email, redirect: redirectUrl, template, trxId,
78
- });
79
-
80
- const data = await pg.one('select * from billing.trx where trx_id=$1', [trxId]);
81
-
82
- const cls1 = await getSelectVal({ name: 'billing.service_id', values: [data.service_id] });
83
- const cls2 = await getSelectVal({ name: 'billing.account_id', values: [data.account_id] });
84
- const cls3 = await getSelectVal({ name: 'billing.trx_status', values: [data.trx_status] });
85
-
86
- Object.assign(data, {
87
- domain: req.hostname,
88
- service_id_text: data.service_id ? cls1?.[data.service_id] || data.service_id : 'Інформація відсутня',
89
- account_id_text: data.account_id ? cls2?.[data.account_id] || data.account_id : 'Інформація відсутня',
90
- trx_status_text: data.trx_status ? cls3?.[data.trx_status] || data.trx_status : 'Інформація відсутня',
91
- });
92
- if (email) {
93
- const options = {
94
- pg,
95
- funcs,
96
- log,
97
- to: email,
98
- title: `Поповнення рахунку на порталі ${req.hostname}`,
99
- template,
100
- data,
101
- // table: 'billing.trx',
102
- // id: trxId,
103
- nocache: funcs.config?.local,
104
- };
105
- await funcs.notification(options);
106
- }
107
- return res.redirect(redirectUrl);
108
- }
109
- catch (err) {
110
- log.debug('integrations/portmone/status', { trxId, responseStatus, error: err.toString() });
111
- return { error: err.toString(), status: 500 };
112
- }
113
- }
@@ -1,89 +0,0 @@
1
- create schema if not exists admin;
2
-
3
- -- DROP TABLE is exists admin.users;
4
- CREATE TABLE if not exists admin.users();
5
- ALTER TABLE admin.users add column if not exists uid text NOT NULL DEFAULT next_id();
6
- ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_uid_pkey cascade;
7
- ALTER TABLE admin.users DROP CONSTRAINT if exists user_pk cascade;
8
-
9
- ALTER TABLE admin.users add column if not exists login text;
10
- ALTER TABLE admin.users add column if not exists password text NOT NULL DEFAULT ''::text;
11
- ALTER TABLE admin.users add column if not exists user_name text;
12
- ALTER TABLE admin.users add column if not exists sur_name text;
13
- ALTER TABLE admin.users add column if not exists father_name text;
14
- ALTER TABLE admin.users add column if not exists email text;
15
- ALTER TABLE admin.users add column if not exists phone text;
16
- ALTER TABLE admin.users add column if not exists avatar text;
17
- ALTER TABLE admin.users add column if not exists enabled boolean;
18
- ALTER TABLE admin.users add column if not exists user_personal_code text;
19
- ALTER TABLE admin.users add column if not exists last_activity_date timestamp without time zone;
20
- ALTER TABLE admin.users add column if not exists user_type text DEFAULT 'regular'::text;
21
- ALTER TABLE admin.users add column if not exists salt text;
22
- ALTER TABLE admin.users add column if not exists cdate timestamp without time zone DEFAULT date_trunc('seconds'::text, now());
23
- ALTER TABLE admin.users add column if not exists editor_id text;
24
- ALTER TABLE admin.users add column if not exists editor_date timestamp without time zone;
25
-
26
- ALTER TABLE admin.users add CONSTRAINT admin_user_uid_pkey PRIMARY KEY (uid);
27
-
28
- COMMENT ON TABLE admin.users IS 'Користувачі';
29
-
30
- COMMENT ON COLUMN admin.users.uid IS 'ID користувача';
31
- COMMENT ON COLUMN admin.users.login IS 'Логін користувача';
32
- COMMENT ON COLUMN admin.users.password IS 'Пароль користувача';
33
- COMMENT ON COLUMN admin.users.user_name IS 'Ім''я користувача';
34
- COMMENT ON COLUMN admin.users.sur_name IS 'Прізвище користувача';
35
- COMMENT ON COLUMN admin.users.father_name IS 'По-батькові користувача';
36
- COMMENT ON COLUMN admin.users.email IS 'Ел. пошта користувача';
37
- COMMENT ON COLUMN admin.users.phone IS 'Номер телефону користувача';
38
- COMMENT ON COLUMN admin.users.avatar IS 'Аватар';
39
- COMMENT ON COLUMN admin.users.enabled IS 'On / Off';
40
- COMMENT ON COLUMN admin.users.last_activity_date IS 'Дата останньої активності';
41
- COMMENT ON COLUMN admin.users.user_type IS 'Тип користувача';
42
- COMMENT ON COLUMN admin.users.salt IS 'Сіль';
43
-
44
- CREATE EXTENSION if not exists pgcrypto SCHEMA public VERSION "1.3";
45
- CREATE OR REPLACE FUNCTION admin.crypt(text, text) RETURNS text AS '$libdir/pgcrypto', 'pg_crypt' LANGUAGE c IMMUTABLE STRICT COST 1;
46
-
47
- -- DROP FUNCTION admin.insert_update_user_before();
48
- CREATE OR REPLACE FUNCTION admin.insert_update_user_before()
49
- RETURNS trigger AS
50
-
51
- $BODY$
52
- DECLARE
53
-
54
- iterations int;
55
- hash character varying;
56
-
57
- BEGIN
58
-
59
- if(TG_OP='INSERT' or (TG_OP='UPDATE' and new.password<>old.password)) then
60
- if(char_length(new.password) <> 0 and char_length(new.password) < 8) then
61
- --raise exception 'password must be longer than 8 characters';
62
- end if;
63
- new.salt=md5(now()::text);
64
- --raise exception '%','change pass';
65
- if(new.salt ='') then
66
- new.salt=gen_salt('md5');
67
- end if;
68
- iterations = 10;
69
- hash='';
70
-
71
- loop
72
- if iterations=0 then
73
- exit;
74
- end if;
75
- hash = md5(new.password||hash||new.salt);
76
- iterations=iterations-1;
77
- end loop;
78
- new.password=admin.crypt(hash,new.salt);
79
-
80
- end if;
81
- RETURN new;
82
- END
83
- $BODY$
84
-
85
- LANGUAGE plpgsql VOLATILE COST 100;
86
-
87
- DROP TRIGGER if exists insert_update_user_before on admin.users;
88
- CREATE TRIGGER insert_update_user_before BEFORE INSERT OR UPDATE ON admin.users FOR EACH ROW
89
- EXECUTE PROCEDURE admin.insert_update_user_before();
@@ -1,16 +0,0 @@
1
- import fp from 'fastify-plugin';
2
-
3
- // import pgClients from '@opengis/fastify-table/pg/pgClients.js';
4
- // import getTemplate from '@opengis/fastify-table/table/controllers/utils/getTemplate.js';
5
-
6
- async function plugin(fastify) {
7
- fastify.addHook('onListen', async () => {
8
- if (fastify.execMigrations) {
9
- await fastify.execMigrations();
10
- }
11
- });
12
-
13
- // fastify.addHook('onListen', async () => {});
14
- }
15
-
16
- export default fp(plugin);
@@ -1,14 +0,0 @@
1
- [
2
- {
3
- "id": "inprogress",
4
- "text": "Не оплачено"
5
- },
6
- {
7
- "id": "success",
8
- "text": "Оплачено"
9
- },
10
- {
11
- "id": "error",
12
- "text": "Помилка при оплаті"
13
- }
14
- ]
@@ -1,5 +0,0 @@
1
- select account_id, account_name from billing.account b
2
- left join lateral (
3
- select account_name from crm_acc.crm_account where account_id=b.account_id limit 1
4
- )c on 1=1
5
- order by account_name