@opengis/pay 2.0.4 → 2.0.5

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/pay",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "type": "module",
5
5
  "description": "pay plugins for billing",
6
6
  "main": "plugin.js",
@@ -17,7 +17,7 @@ export default async function createTransaction({
17
17
  }, pg = pgClients.client) {
18
18
  if (!service) throw new Error('not enough params: service');
19
19
  if (!controller[service]) { throw new Error('invalid params: service'); }
20
- if (amount && !uid) throw new Error('not enough params: uid');
20
+ if (!amount || !uid || !referer) throw new Error('not enough params: uid / amount / referer');
21
21
 
22
22
  if (currency && !['uah', 'usd', 'eur'].includes(currency)) {
23
23
  throw new Error('invalid params: currency');
@@ -8,7 +8,7 @@ import dataUpdate from '../crud/dataUpdate.js';
8
8
  import createPayment from './createPayment.js';
9
9
 
10
10
  const { prefix = '/api' } = config;
11
- const { table = 'pay.transactions', backUrl: bUrl } = config.integrations?.pay || {};
11
+ const { table = 'pay.transactions', backUrl } = config.integrations?.pay || {};
12
12
 
13
13
  const {
14
14
  host = 'https://www.liqpay.ua',
@@ -20,7 +20,7 @@ const liqpay = new LiqPay(publicKey, privateKey);
20
20
  export default async function liqpayCreateTransaction({
21
21
  id, orderId, amount, referer, uid, debug, expiredDate, description, paytypes, action = 'pay', currency = 'uah', language = 'uk', deliveryEmails,
22
22
  }, pg = pgClients.client) {
23
- const backUrl = bUrl || referer?.slice?.(0, referer.indexOf('/', 7));
23
+ const rootUrl = referer.slice(0, referer.indexOf('/', 7));
24
24
 
25
25
  if (!publicKey || !privateKey) {
26
26
  throw new Error('invalid liqpay integration settings');
@@ -78,6 +78,8 @@ export default async function liqpayCreateTransaction({
78
78
  return paymentData.redirect_url;
79
79
  }
80
80
 
81
+ const resultUrl = `${rootUrl}${backUrl ? backUrl.replace(/{{service}}/, 'liqpay').replace(/{{id}}/, paymentData.id) : `${prefix}/liqpay/${paymentData.id}/success`}`;
82
+
81
83
  const paymentOptions = {
82
84
  action,
83
85
  amount: paymentAmount,
@@ -88,8 +90,8 @@ export default async function liqpayCreateTransaction({
88
90
  language,
89
91
  paytypes,
90
92
  expired_date: expiredDate && new Date(expiredDate) ? new Date(expiredDate).toISOString().split('.')[0].replace('T', ' ') : undefined,
91
- // server_url: `${backUrl}${prefix}/liqpay/${paymentData.id}/success`, // update payment info - api url, does not work on sdk package out of the box
92
- result_url: `${backUrl}${prefix}/liqpay/${paymentData.id}/success`, // redirect user after payment - page url
93
+ // server_url: resultUrl, // update payment info - api url, does not work on sdk package out of the box
94
+ result_url: resultUrl, // redirect user after payment - page url
93
95
  rro_info: Array.isArray(deliveryEmails) && deliveryEmails.length ? {
94
96
  delivery_emails: deliveryEmails,
95
97
  } : undefined,
@@ -5,7 +5,7 @@ import dataUpdate from '../crud/dataUpdate.js';
5
5
  import createPayment from './createPayment.js';
6
6
 
7
7
  const { prefix = '/api' } = config;
8
- const { table = 'pay.transactions', backUrl: bUrl } = config.integrations?.pay || {};
8
+ const { table = 'pay.transactions', backUrl } = config.integrations?.pay || {};
9
9
 
10
10
  const {
11
11
  host = 'https://api.monobank.ua',
@@ -24,9 +24,9 @@ const ccyObj = {
24
24
  export default async function monopayCreateTransaction({
25
25
  id, orderId, amount, referer, uid, debug, expiredDate, description, action, currency, language,
26
26
  }, pg = pgClients.client) {
27
- const backUrl = bUrl || referer?.slice?.(0, referer.indexOf('/', 7));
27
+ const rootUrl = referer.slice(0, referer.indexOf('/', 7));
28
28
 
29
- if (!host || !token || !backUrl) {
29
+ if (!host || !token) {
30
30
  throw new Error('invalid monopay integration settings');
31
31
  }
32
32
 
@@ -74,7 +74,7 @@ export default async function monopayCreateTransaction({
74
74
  }
75
75
 
76
76
  // redirect to api to check payment status and redirect user to page afterwards
77
- const serverUrl = `${backUrl}${prefix}/monopay/${paymentData.id}/success`;
77
+ const resultUrl = `${rootUrl}${backUrl ? backUrl.replace(/{{service}}/, 'monopay').replace(/{{id}}/, paymentData.id) : `${prefix}/monopay/${paymentData.id}/success`}`;
78
78
 
79
79
  const validity = expiredDate && new Date(expiredDate) ? Math.max(((new Date(expiredDate).setHours(0, 0, 0, 0) - new Date().setHours(0, 0, 0, 0)) / 1000 || 0), 86400) : 86400;
80
80
 
@@ -82,9 +82,9 @@ export default async function monopayCreateTransaction({
82
82
  amount: paymentAmount * 100, // amount=1 === 0.01 uah
83
83
  ccy: ccyObj[currency] || 980, // ISO 4217, 980 = UAH
84
84
  merchantPaymInfo,
85
- redirectUrl: serverUrl,
85
+ redirectUrl: resultUrl,
86
86
  // redirectUrl: (paymentRedirect ? `${rootPageUrl}${paymentRedirect.replace(/{{id}}/g, paymentData.id)}` : headers?.referer) || rootPageUrl,
87
- webHookUrl: serverUrl,
87
+ webHookUrl: resultUrl,
88
88
  validity, // 1 day by default, then invalid
89
89
  paymentType: 'debit',
90
90
  // displayType: 'iframe', // default = null > url to mono
@@ -8,15 +8,15 @@ import createPayment from './createPayment.js';
8
8
 
9
9
  const { prefix = '/api' } = config;
10
10
 
11
- const { table = 'pay.transactions', backUrl: bUrl } = config.integrations?.pay || {};
11
+ const { table = 'pay.transactions', backUrl } = config.integrations?.pay || {};
12
12
  const { host = 'https://www.portmone.com.ua', payeeId } = config.integrations?.portmone || {};
13
13
 
14
14
  export default async function portmoneCreateTransaction({
15
15
  id, orderId, amount, referer, uid, debug, expiredDate, description, action, currency = 'uah', language = 'uk', paytypes,
16
16
  }, pg = pgClients.client) {
17
- const backUrl = bUrl || referer?.slice?.(0, referer.indexOf('/', 7));
17
+ const rootUrl = referer.slice(0, referer.indexOf('/', 7));
18
18
 
19
- if (!payeeId || !backUrl) {
19
+ if (!payeeId) {
20
20
  throw new Error('invalid portmone integration settings');
21
21
  }
22
22
 
@@ -64,6 +64,8 @@ export default async function portmoneCreateTransaction({
64
64
  throw new Error('Transaction date already expired');
65
65
  }
66
66
 
67
+ const resultUrl = `${rootUrl}${backUrl ? backUrl.replace(/{{service}}/, 'portmone').replace(/{{id}}/, paymentData.id) : `${prefix}/portmone/${paymentData.id}/success`}`;
68
+
67
69
  if (id && paymentData?.redirect_url) {
68
70
  return paymentData.redirect_url;
69
71
  }
@@ -74,8 +76,8 @@ export default async function portmoneCreateTransaction({
74
76
  shop_order_number: paymentData.id,
75
77
  bill_amount: paymentAmount,
76
78
  bill_currency: currency.toUpperCase(),
77
- success_url: `${backUrl}${prefix}/portmone/${paymentData.id}/success`,
78
- failure_url: `${backUrl}${prefix}/portmone/${paymentData.id}/error`,
79
+ success_url: resultUrl,
80
+ failure_url: resultUrl.replace(/\/success$/, '/error'),
79
81
  lang: language === 'uk' ? 'ua' : language,
80
82
  };
81
83