@opengis/pay 1.1.5 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/pay",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "type": "module",
5
5
  "description": "pay plugins for billing",
6
6
  "main": "plugin.js",
@@ -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.uid])
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.uid,
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.uid,
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.uid,
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.uid,
108
+ uid: user?.uid || '0',
114
109
  };
115
110
 
116
111
  try {
@@ -52,7 +52,7 @@ export default async function portmoneStatus(req, reply) {
52
52
  type: 'status',
53
53
  paymentId,
54
54
  origin,
55
- uid: user.uid,
55
+ uid: user?.uid || '0',
56
56
  message: 'Transaction was already processed',
57
57
  });
58
58
  return { message: 'Transaction was already processed', status: 400 };
@@ -65,12 +65,12 @@ export default async function portmoneStatus(req, reply) {
65
65
  const refill = body?.billAmount || refillSum || 0;
66
66
 
67
67
  // request portmone trx info to recheck request data is valid?
68
- if (!config.debug && !origin?.startsWith(host)) {
68
+ if (!config.debug && !origin?.startsWith(host) && !config.disableRestricted) {
69
69
  logger.file('payments/warn', {
70
70
  type: 'status',
71
71
  paymentId,
72
72
  origin,
73
- uid: user.uid,
73
+ uid: user?.uid || '0',
74
74
  refill,
75
75
  message: 'invalid referer',
76
76
  });
@@ -81,7 +81,7 @@ export default async function portmoneStatus(req, reply) {
81
81
  type: 'status',
82
82
  paymentId,
83
83
  origin,
84
- uid: user.uid,
84
+ uid: user?.uid || '0',
85
85
  refill,
86
86
  body,
87
87
  params,
@@ -101,7 +101,7 @@ export default async function portmoneStatus(req, reply) {
101
101
  success_date: new Date(),
102
102
  },
103
103
  id: paymentId,
104
- uid: user.uid,
104
+ uid: user?.uid || '0',
105
105
  });
106
106
 
107
107
  const { account_email: to } = await pg.query('select account_email from billing.accounts where account_id=$1', [accountId])
@@ -114,7 +114,7 @@ export default async function portmoneStatus(req, reply) {
114
114
  to,
115
115
  origin,
116
116
  redirect: redirectUrl,
117
- uid: user.uid,
117
+ uid: user.uid || '0',
118
118
  });
119
119
 
120
120
  Object.assign(data, {
@@ -142,7 +142,7 @@ export default async function portmoneStatus(req, reply) {
142
142
  paymentId,
143
143
  origin,
144
144
  responseStatus,
145
- uid: user.uid,
145
+ uid: user?.uid || '0',
146
146
  error: err.toString(),
147
147
  });
148
148
  return { error: err.toString(), status: 500 };