@opengis/pay 2.0.5 → 2.0.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/pay",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "type": "module",
5
5
  "description": "pay plugins for billing",
6
6
  "main": "plugin.js",
@@ -20,6 +20,10 @@ 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
+ if (!referer) {
24
+ throw new Error('not enough params: referer required');
25
+ }
26
+
23
27
  const rootUrl = referer.slice(0, referer.indexOf('/', 7));
24
28
 
25
29
  if (!publicKey || !privateKey) {
@@ -24,6 +24,10 @@ 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
+ if (!referer) {
28
+ throw new Error('not enough params: referer required');
29
+ }
30
+
27
31
  const rootUrl = referer.slice(0, referer.indexOf('/', 7));
28
32
 
29
33
  if (!host || !token) {
@@ -14,6 +14,10 @@ const { host = 'https://www.portmone.com.ua', payeeId } = config.integrations?.p
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
+ if (!referer) {
18
+ throw new Error('not enough params: referer required');
19
+ }
20
+
17
21
  const rootUrl = referer.slice(0, referer.indexOf('/', 7));
18
22
 
19
23
  if (!payeeId) {
@@ -37,7 +37,7 @@ export default async function processTransaction(id, { body, origin } = {}) {
37
37
  if (!service) throw new Error('invalid payment: service required');
38
38
  if (!controller[service]) { throw new Error('invalid params: service'); }
39
39
 
40
- if (trxStatus === 'success') {
40
+ if (['error', 'success'].includes(trxStatus)) {
41
41
  throw new Error('Transaction was already processed');
42
42
  }
43
43
 
@@ -46,7 +46,7 @@ export default async function processTransaction(id, { body, origin } = {}) {
46
46
  const { status = 'error', err_description: err } = result || {};
47
47
 
48
48
  if (status !== 'success') {
49
- throw new Error(err || 'Помилка перевірки статусу платежу');
49
+ // throw new Error(err || 'Помилка перевірки статусу платежу');
50
50
  }
51
51
 
52
52
  const balance = await pg.query(`select balance from ${table}
@@ -55,6 +55,9 @@ export default async function processTransaction(id, { body, origin } = {}) {
55
55
  and balance is not null
56
56
  order by created_at desc limit 1`, [userId]).then(el => el.rows?.[0]?.balance || 0);
57
57
 
58
+ const newBalance = status === 'success' ? +result.amount + +balance : balance;
59
+ const successDate = status === 'success' ? newDate() : undefined;
60
+
58
61
  const row = await dataUpdate({
59
62
  table,
60
63
  data: {
@@ -64,16 +67,16 @@ export default async function processTransaction(id, { body, origin } = {}) {
64
67
  paytype: result?.paytype, // card, gpay etc
65
68
  receipt_url: result?.receipt_url,
66
69
  status,
67
- balance: +result.amount + +balance,
68
- success_date: newDate(),
70
+ balance: newBalance,
71
+ success_date: successDate,
69
72
  },
70
73
  id,
71
74
  uid: userId,
72
75
  });
73
76
 
74
77
  if (process.env.NODE_ENV === 'test') {
75
- console.info(`id:${id}, status: ${result.status}, before: ${balance || 0}, sum: ${+result.amount}, after: ${+result.amount + +balance}`);
78
+ console.info(`id:${id}, status: ${result.status}, before: ${balance || 0}, sum: ${+result.amount}, after: ${newBalance}`);
76
79
  }
77
80
 
78
- return { ...row, balance: +result.amount + +balance };
81
+ return { ...row, balance: newBalance };
79
82
  }