payment-kit 1.22.31 → 1.22.32
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.
|
@@ -97,7 +97,7 @@ router.get('/', authMine, async (req, res) => {
|
|
|
97
97
|
if (query.customer_id) {
|
|
98
98
|
where[Op.and] = where[Op.and] || [];
|
|
99
99
|
where[Op.and].push(
|
|
100
|
-
Sequelize.where(Sequelize.
|
|
100
|
+
Sequelize.where(Sequelize.literal("json_extract(payload, '$.customer_id')"), query.customer_id)
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -427,9 +427,18 @@ export class CreditGrant extends Model<InferAttributes<CreditGrant>, InferCreati
|
|
|
427
427
|
targetCurrencyIds = grantsWithCurrency.map((grant: any) => grant.currency_id);
|
|
428
428
|
}
|
|
429
429
|
|
|
430
|
+
const currencies = await PaymentCurrency.scope('withRechargeConfig').findAll({
|
|
431
|
+
where: {
|
|
432
|
+
id: {
|
|
433
|
+
[Op.in]: Array.from(new Set(targetCurrencyIds)),
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
const currencyMap = new Map(currencies.map((c) => [c.id, c]));
|
|
438
|
+
|
|
430
439
|
await Promise.all(
|
|
431
440
|
targetCurrencyIds.map(async (currencyId: string) => {
|
|
432
|
-
const paymentCurrency =
|
|
441
|
+
const paymentCurrency = currencyMap.get(currencyId);
|
|
433
442
|
if (!paymentCurrency) {
|
|
434
443
|
return null;
|
|
435
444
|
}
|
|
@@ -373,27 +373,52 @@ export class MeterEvent extends Model<InferAttributes<MeterEvent>, InferCreation
|
|
|
373
373
|
const summary: GroupedBN = {};
|
|
374
374
|
const detail: GroupedStrList = {};
|
|
375
375
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
376
|
+
if (events.length === 0) {
|
|
377
|
+
return [summary, detail, events];
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const eventNames = [...new Set(events.map((e) => e.event_name))];
|
|
381
|
+
const meters = await Meter.findAll({
|
|
382
|
+
where: {
|
|
383
|
+
event_name: {
|
|
384
|
+
[Op.in]: eventNames,
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
});
|
|
388
|
+
const meterMap = new Map(meters.map((m) => [m.event_name, m]));
|
|
389
|
+
|
|
390
|
+
const currencyIds = [...new Set(meters.map((m) => m.currency_id).filter((id): id is string => Boolean(id)))];
|
|
391
|
+
const currencies =
|
|
392
|
+
currencyIds.length > 0
|
|
393
|
+
? await PaymentCurrency.findAll({
|
|
394
|
+
where: {
|
|
395
|
+
id: {
|
|
396
|
+
[Op.in]: currencyIds,
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
})
|
|
400
|
+
: [];
|
|
401
|
+
const currencyMap = new Map(currencies.map((c) => [c.id, c]));
|
|
402
|
+
|
|
403
|
+
events.forEach((event) => {
|
|
404
|
+
const meter = meterMap.get(event.event_name);
|
|
405
|
+
if (!meter || !meter.currency_id) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const paymentCurrency = currencyMap.get(meter.currency_id);
|
|
409
|
+
if (!paymentCurrency) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const currencyId = meter.currency_id as string;
|
|
413
|
+
if (searchCurrencyId && searchCurrencyId !== currencyId) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (!detail[currencyId]) {
|
|
417
|
+
detail[currencyId] = [];
|
|
418
|
+
}
|
|
419
|
+
summary[currencyId] = new BN(summary[currencyId] || '0').add(new BN(event.credit_pending)).toString();
|
|
420
|
+
detail[currencyId]!.push(event.id);
|
|
421
|
+
});
|
|
397
422
|
|
|
398
423
|
return [summary, detail, events];
|
|
399
424
|
}
|
|
@@ -424,14 +449,12 @@ export class MeterEvent extends Model<InferAttributes<MeterEvent>, InferCreation
|
|
|
424
449
|
if (subscriptionId) {
|
|
425
450
|
where[Op.and] = where[Op.and] || [];
|
|
426
451
|
where[Op.and].push(
|
|
427
|
-
Sequelize.where(Sequelize.
|
|
452
|
+
Sequelize.where(Sequelize.literal("json_extract(payload, '$.subscription_id')"), subscriptionId)
|
|
428
453
|
);
|
|
429
454
|
}
|
|
430
455
|
if (customerId) {
|
|
431
456
|
where[Op.and] = where[Op.and] || [];
|
|
432
|
-
where[Op.and].push(
|
|
433
|
-
Sequelize.where(Sequelize.fn('json_extract', Sequelize.col('payload'), '$.customer_id'), customerId)
|
|
434
|
-
);
|
|
457
|
+
where[Op.and].push(Sequelize.where(Sequelize.literal("json_extract(payload, '$.customer_id')"), customerId));
|
|
435
458
|
}
|
|
436
459
|
|
|
437
460
|
return this._getPendingAmounts(where, currencyId);
|
package/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.22.
|
|
3
|
+
"version": "1.22.32",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev --open",
|
|
6
6
|
"lint": "tsc --noEmit && eslint src api/src --ext .mjs,.js,.jsx,.ts,.tsx",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"@blocklet/error": "^0.3.4",
|
|
58
58
|
"@blocklet/js-sdk": "^1.17.4",
|
|
59
59
|
"@blocklet/logger": "^1.17.4",
|
|
60
|
-
"@blocklet/payment-broker-client": "1.22.
|
|
61
|
-
"@blocklet/payment-react": "1.22.
|
|
62
|
-
"@blocklet/payment-vendor": "1.22.
|
|
60
|
+
"@blocklet/payment-broker-client": "1.22.32",
|
|
61
|
+
"@blocklet/payment-react": "1.22.32",
|
|
62
|
+
"@blocklet/payment-vendor": "1.22.32",
|
|
63
63
|
"@blocklet/sdk": "^1.17.4",
|
|
64
64
|
"@blocklet/ui-react": "^3.2.11",
|
|
65
65
|
"@blocklet/uploader": "^0.3.14",
|
|
@@ -129,7 +129,7 @@
|
|
|
129
129
|
"devDependencies": {
|
|
130
130
|
"@abtnode/types": "^1.17.4",
|
|
131
131
|
"@arcblock/eslint-config-ts": "^0.3.3",
|
|
132
|
-
"@blocklet/payment-types": "1.22.
|
|
132
|
+
"@blocklet/payment-types": "1.22.32",
|
|
133
133
|
"@types/cookie-parser": "^1.4.9",
|
|
134
134
|
"@types/cors": "^2.8.19",
|
|
135
135
|
"@types/debug": "^4.1.12",
|
|
@@ -176,5 +176,5 @@
|
|
|
176
176
|
"parser": "typescript"
|
|
177
177
|
}
|
|
178
178
|
},
|
|
179
|
-
"gitHead": "
|
|
179
|
+
"gitHead": "4b5eac2af9a6a10a4f971f7dcbe220e8049d0cc7"
|
|
180
180
|
}
|