multivendor-wallet 0.0.4 → 0.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/README.md +9 -0
- package/dist/hooks/index.cjs +25 -6
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.mts +3 -3
- package/dist/hooks/index.d.ts +3 -3
- package/dist/hooks/index.js +25 -6
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +347 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +41 -6
- package/dist/index.d.ts +41 -6
- package/dist/index.js +334 -29
- package/dist/index.js.map +1 -1
- package/dist/{store-By30oqos.d.mts → store-nWCfzvwf.d.mts} +1 -0
- package/dist/{store-By30oqos.d.ts → store-nWCfzvwf.d.ts} +1 -0
- package/dist/typeorm/index.cjs +174 -9
- package/dist/typeorm/index.cjs.map +1 -1
- package/dist/typeorm/index.d.mts +11 -2
- package/dist/typeorm/index.d.ts +11 -2
- package/dist/typeorm/index.js +175 -11
- package/dist/typeorm/index.js.map +1 -1
- package/dist/{types-BzaT7Aqh.d.ts → types-B4R1zaTK.d.ts} +16 -2
- package/dist/{types-D46FcrKZ.d.mts → types-D1Q4XCwx.d.mts} +16 -2
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -69,6 +69,121 @@ var _InvalidAmountError = class _InvalidAmountError extends WalletError {
|
|
|
69
69
|
__name(_InvalidAmountError, "InvalidAmountError");
|
|
70
70
|
var InvalidAmountError = _InvalidAmountError;
|
|
71
71
|
|
|
72
|
+
// src/orderCustomerDebit.ts
|
|
73
|
+
var CUSTOMER_CHECKOUT_DEBIT_PURPOSE = "customer_checkout_debit";
|
|
74
|
+
var CUSTOMER_CHECKOUT_DEBIT_REVERSAL_PURPOSE = "customer_checkout_debit_reversal";
|
|
75
|
+
var BACKFILL_SENTINEL_KEY = "customer_checkout_debit_backfill";
|
|
76
|
+
var WALLET_OPS_TABLE = "wallet_ops";
|
|
77
|
+
function orderCustomerDebitIdempotencyKey(orderId) {
|
|
78
|
+
return `wallet:order:${orderId}:customer_debit`;
|
|
79
|
+
}
|
|
80
|
+
__name(orderCustomerDebitIdempotencyKey, "orderCustomerDebitIdempotencyKey");
|
|
81
|
+
function paymentReversalIdempotencyKey(paymentNumber) {
|
|
82
|
+
return `wallet:payment-reversal:${paymentNumber}`;
|
|
83
|
+
}
|
|
84
|
+
__name(paymentReversalIdempotencyKey, "paymentReversalIdempotencyKey");
|
|
85
|
+
function paymentNumberFromWalletPaymentKey(idempotencyKey) {
|
|
86
|
+
const prefix = "wallet:payment:";
|
|
87
|
+
if (!idempotencyKey.startsWith(prefix)) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
return idempotencyKey.slice(prefix.length);
|
|
91
|
+
}
|
|
92
|
+
__name(paymentNumberFromWalletPaymentKey, "paymentNumberFromWalletPaymentKey");
|
|
93
|
+
function isCustomerCheckoutDebit(params) {
|
|
94
|
+
if (params.purpose === CUSTOMER_CHECKOUT_DEBIT_PURPOSE) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
const key = params.idempotencyKey;
|
|
98
|
+
if (key.startsWith("wallet:order:") && key.endsWith(":customer_debit")) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
if (params.referenceType !== "order") {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return isLegacyCustomerCheckoutDebitKey(key);
|
|
105
|
+
}
|
|
106
|
+
__name(isCustomerCheckoutDebit, "isCustomerCheckoutDebit");
|
|
107
|
+
function isLegacyCustomerCheckoutDebitKey(key) {
|
|
108
|
+
return key.startsWith("wallet:full:") || key.startsWith("wallet:split:") || key.startsWith("wallet:payment:");
|
|
109
|
+
}
|
|
110
|
+
__name(isLegacyCustomerCheckoutDebitKey, "isLegacyCustomerCheckoutDebitKey");
|
|
111
|
+
var UNREIMBURSED_TWIN_COUNT_SQL = `
|
|
112
|
+
SELECT COUNT(*) AS c
|
|
113
|
+
FROM wallet_ledger_entry f
|
|
114
|
+
JOIN wallet_ledger_entry p
|
|
115
|
+
ON p.account_id = f.account_id
|
|
116
|
+
AND p.reference_type = 'order'
|
|
117
|
+
AND p.reference_id = f.reference_id
|
|
118
|
+
AND p.entry_type = 'debit'
|
|
119
|
+
AND p.idempotency_key LIKE 'wallet:payment:%'
|
|
120
|
+
WHERE f.entry_type = 'debit'
|
|
121
|
+
AND f.reference_type = 'order'
|
|
122
|
+
AND (
|
|
123
|
+
f.idempotency_key LIKE 'wallet:full:%'
|
|
124
|
+
OR f.idempotency_key LIKE 'wallet:split:%'
|
|
125
|
+
)
|
|
126
|
+
AND NOT EXISTS (
|
|
127
|
+
SELECT 1 FROM wallet_ledger_entry r
|
|
128
|
+
WHERE r.entry_type = 'credit'
|
|
129
|
+
AND r.account_id = p.account_id
|
|
130
|
+
AND r.reference_type = 'order'
|
|
131
|
+
AND r.reference_id = p.reference_id
|
|
132
|
+
AND (
|
|
133
|
+
r.idempotency_key = CONCAT('wallet:payment-reversal:', SUBSTRING(p.idempotency_key, 17))
|
|
134
|
+
OR JSON_UNQUOTE(JSON_EXTRACT(r.metadata, '$.purpose')) = 'customer_checkout_debit_reversal'
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
`;
|
|
138
|
+
var UNREIMBURSED_TWIN_DETAIL_SQL = `
|
|
139
|
+
SELECT
|
|
140
|
+
f.reference_id AS order_id,
|
|
141
|
+
f.account_id,
|
|
142
|
+
f.amount AS first_paise,
|
|
143
|
+
p.amount AS second_paise,
|
|
144
|
+
f.idempotency_key AS kept_key,
|
|
145
|
+
p.idempotency_key AS duplicate_key,
|
|
146
|
+
f.created_date AS first_at,
|
|
147
|
+
p.created_date AS duplicate_at,
|
|
148
|
+
f.id AS kept_id,
|
|
149
|
+
p.id AS duplicate_id
|
|
150
|
+
FROM wallet_ledger_entry f
|
|
151
|
+
JOIN wallet_ledger_entry p
|
|
152
|
+
ON p.account_id = f.account_id
|
|
153
|
+
AND p.reference_type = 'order'
|
|
154
|
+
AND p.reference_id = f.reference_id
|
|
155
|
+
AND p.entry_type = 'debit'
|
|
156
|
+
AND p.idempotency_key LIKE 'wallet:payment:%'
|
|
157
|
+
WHERE f.entry_type = 'debit'
|
|
158
|
+
AND f.reference_type = 'order'
|
|
159
|
+
AND (
|
|
160
|
+
f.idempotency_key LIKE 'wallet:full:%'
|
|
161
|
+
OR f.idempotency_key LIKE 'wallet:split:%'
|
|
162
|
+
)
|
|
163
|
+
AND NOT EXISTS (
|
|
164
|
+
SELECT 1 FROM wallet_ledger_entry r
|
|
165
|
+
WHERE r.entry_type = 'credit'
|
|
166
|
+
AND r.account_id = p.account_id
|
|
167
|
+
AND r.reference_type = 'order'
|
|
168
|
+
AND r.reference_id = p.reference_id
|
|
169
|
+
AND (
|
|
170
|
+
r.idempotency_key = CONCAT('wallet:payment-reversal:', SUBSTRING(p.idempotency_key, 17))
|
|
171
|
+
OR JSON_UNQUOTE(JSON_EXTRACT(r.metadata, '$.purpose')) = 'customer_checkout_debit_reversal'
|
|
172
|
+
)
|
|
173
|
+
)
|
|
174
|
+
`;
|
|
175
|
+
var LEGACY_ORDER_DEBIT_SUNSET_SQL = `
|
|
176
|
+
SELECT COUNT(*) AS c
|
|
177
|
+
FROM wallet_ledger_entry
|
|
178
|
+
WHERE entry_type = 'debit'
|
|
179
|
+
AND reference_type = 'order'
|
|
180
|
+
AND (
|
|
181
|
+
idempotency_key LIKE 'wallet:full:%'
|
|
182
|
+
OR idempotency_key LIKE 'wallet:split:%'
|
|
183
|
+
OR idempotency_key LIKE 'wallet:payment:%'
|
|
184
|
+
)
|
|
185
|
+
`;
|
|
186
|
+
|
|
72
187
|
// src/types.ts
|
|
73
188
|
var WalletAccountType = /* @__PURE__ */ (function(WalletAccountType2) {
|
|
74
189
|
WalletAccountType2["CUSTOMER"] = "customer";
|
|
@@ -196,6 +311,7 @@ var _WalletLedgerClient = class _WalletLedgerClient {
|
|
|
196
311
|
async debitInTx(tx, params) {
|
|
197
312
|
const existing = await tx.findLedgerByIdempotencyKey(params.idempotencyKey);
|
|
198
313
|
if (existing) {
|
|
314
|
+
this.notifyDuplicateOrderDebit(params, existing, "idempotent_retry");
|
|
199
315
|
const account = await tx.getAccountById(existing.accountId);
|
|
200
316
|
if (!account) {
|
|
201
317
|
throw new Error(`Wallet account ${existing.accountId} not found`);
|
|
@@ -206,27 +322,85 @@ var _WalletLedgerClient = class _WalletLedgerClient {
|
|
|
206
322
|
};
|
|
207
323
|
}
|
|
208
324
|
const locked = await tx.lockAccount(params.accountId);
|
|
325
|
+
const orderId = params.reference?.referenceId;
|
|
326
|
+
const checkoutDebit = isCustomerCheckoutDebit({
|
|
327
|
+
idempotencyKey: params.idempotencyKey,
|
|
328
|
+
referenceType: params.reference?.referenceType,
|
|
329
|
+
purpose: params.metadata?.purpose
|
|
330
|
+
});
|
|
331
|
+
if (checkoutDebit && orderId) {
|
|
332
|
+
const existingPurpose = await tx.findOrderCustomerCheckoutDebit(params.accountId, orderId);
|
|
333
|
+
if (existingPurpose) {
|
|
334
|
+
const kind = existingPurpose.idempotencyKey === params.idempotencyKey ? "idempotent_retry" : "cross_key_collision";
|
|
335
|
+
this.notifyDuplicateOrderDebit(params, existingPurpose, kind);
|
|
336
|
+
return {
|
|
337
|
+
entry: existingPurpose,
|
|
338
|
+
account: locked
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
}
|
|
209
342
|
if (locked.availableBalance < params.amount) {
|
|
210
343
|
throw new InsufficientBalanceError();
|
|
211
344
|
}
|
|
212
345
|
const updated = await tx.updateBalances(params.accountId, {
|
|
213
346
|
availableDelta: -params.amount
|
|
214
347
|
});
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
348
|
+
try {
|
|
349
|
+
const entry = await tx.appendLedgerEntry({
|
|
350
|
+
accountId: params.accountId,
|
|
351
|
+
entryType: LedgerEntryType.DEBIT,
|
|
352
|
+
amount: params.amount,
|
|
353
|
+
balanceAfterAvailable: updated.availableBalance,
|
|
354
|
+
balanceAfterHeld: updated.heldBalance,
|
|
355
|
+
idempotencyKey: params.idempotencyKey,
|
|
356
|
+
referenceType: params.reference?.referenceType,
|
|
357
|
+
referenceId: params.reference?.referenceId,
|
|
358
|
+
metadata: params.metadata
|
|
359
|
+
});
|
|
360
|
+
return {
|
|
361
|
+
entry,
|
|
362
|
+
account: updated
|
|
363
|
+
};
|
|
364
|
+
} catch (error) {
|
|
365
|
+
if (error instanceof DuplicateOperationError && checkoutDebit && orderId) {
|
|
366
|
+
const dup = await tx.findOrderCustomerCheckoutDebit(params.accountId, orderId);
|
|
367
|
+
if (dup) {
|
|
368
|
+
const restored = await tx.updateBalances(params.accountId, {
|
|
369
|
+
availableDelta: params.amount
|
|
370
|
+
});
|
|
371
|
+
this.notifyDuplicateOrderDebit(params, dup, "cross_key_collision");
|
|
372
|
+
return {
|
|
373
|
+
entry: dup,
|
|
374
|
+
account: restored
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
throw error;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
notifyDuplicateOrderDebit(params, existing, kind) {
|
|
382
|
+
const orderId = params.reference?.referenceId ?? existing.referenceId;
|
|
383
|
+
if (!orderId) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const checkoutDebit = isCustomerCheckoutDebit({
|
|
221
387
|
idempotencyKey: params.idempotencyKey,
|
|
222
|
-
referenceType: params.reference?.referenceType,
|
|
223
|
-
|
|
224
|
-
metadata: params.metadata
|
|
388
|
+
referenceType: params.reference?.referenceType ?? existing.referenceType,
|
|
389
|
+
purpose: params.metadata?.purpose ?? existing.metadata?.purpose
|
|
225
390
|
});
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
391
|
+
if (!checkoutDebit) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
try {
|
|
395
|
+
this.config.onDuplicateOrderDebit?.({
|
|
396
|
+
orderId,
|
|
397
|
+
accountId: params.accountId,
|
|
398
|
+
requestedKey: params.idempotencyKey,
|
|
399
|
+
existingKey: existing.idempotencyKey,
|
|
400
|
+
kind
|
|
401
|
+
});
|
|
402
|
+
} catch {
|
|
403
|
+
}
|
|
230
404
|
}
|
|
231
405
|
async holdInTx(tx, params) {
|
|
232
406
|
const existing = await tx.findLedgerByIdempotencyKey(params.idempotencyKey);
|
|
@@ -450,10 +624,14 @@ function createOrderHooks(runtime) {
|
|
|
450
624
|
await client.debit({
|
|
451
625
|
accountId: customer.id,
|
|
452
626
|
amount: toMinorUnit(debitRupees),
|
|
453
|
-
idempotencyKey:
|
|
627
|
+
idempotencyKey: orderCustomerDebitIdempotencyKey(ctx.orderId),
|
|
454
628
|
reference: {
|
|
455
629
|
referenceType: "order",
|
|
456
630
|
referenceId: String(ctx.orderId)
|
|
631
|
+
},
|
|
632
|
+
metadata: {
|
|
633
|
+
purpose: CUSTOMER_CHECKOUT_DEBIT_PURPOSE,
|
|
634
|
+
paymentNumber: ctx.paymentNumber
|
|
457
635
|
}
|
|
458
636
|
}, txCtx);
|
|
459
637
|
}
|
|
@@ -467,7 +645,7 @@ function createOrderHooks(runtime) {
|
|
|
467
645
|
}
|
|
468
646
|
}, txCtx);
|
|
469
647
|
for (const line of ctx.lines) {
|
|
470
|
-
const vendorNetRupees = line.commissionBaseRupees - line.commissionRupees;
|
|
648
|
+
const vendorNetRupees = line.sellerNetRupees != null && Number.isFinite(Number(line.sellerNetRupees)) ? Number(line.sellerNetRupees) : line.commissionBaseRupees - line.commissionRupees;
|
|
471
649
|
if (vendorNetRupees <= 0) {
|
|
472
650
|
continue;
|
|
473
651
|
}
|
|
@@ -608,6 +786,29 @@ function resolveWalletConnection() {
|
|
|
608
786
|
return activeConnection;
|
|
609
787
|
}
|
|
610
788
|
__name(resolveWalletConnection, "resolveWalletConnection");
|
|
789
|
+
|
|
790
|
+
// src/timestamps.ts
|
|
791
|
+
function pad2(value) {
|
|
792
|
+
return String(value).padStart(2, "0");
|
|
793
|
+
}
|
|
794
|
+
__name(pad2, "pad2");
|
|
795
|
+
function nowTimestamp(date = /* @__PURE__ */ new Date()) {
|
|
796
|
+
return `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())} ${pad2(date.getHours())}:${pad2(date.getMinutes())}:${pad2(date.getSeconds())}`;
|
|
797
|
+
}
|
|
798
|
+
__name(nowTimestamp, "nowTimestamp");
|
|
799
|
+
function parseLedgerDate(value) {
|
|
800
|
+
if (value instanceof Date) {
|
|
801
|
+
return value;
|
|
802
|
+
}
|
|
803
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2}):(\d{2})/.exec(String(value));
|
|
804
|
+
if (!match) {
|
|
805
|
+
return new Date(value);
|
|
806
|
+
}
|
|
807
|
+
return new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3]), Number(match[4]), Number(match[5]), Number(match[6]));
|
|
808
|
+
}
|
|
809
|
+
__name(parseLedgerDate, "parseLedgerDate");
|
|
810
|
+
|
|
811
|
+
// src/typeorm/entities.ts
|
|
611
812
|
function _ts_decorate(decorators, target, key, desc) {
|
|
612
813
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
613
814
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -619,10 +820,6 @@ function _ts_metadata(k, v) {
|
|
|
619
820
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
620
821
|
}
|
|
621
822
|
__name(_ts_metadata, "_ts_metadata");
|
|
622
|
-
function nowTimestamp() {
|
|
623
|
-
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace("T", " ");
|
|
624
|
-
}
|
|
625
|
-
__name(nowTimestamp, "nowTimestamp");
|
|
626
823
|
var _WalletAccountEntity = class _WalletAccountEntity {
|
|
627
824
|
constructor() {
|
|
628
825
|
__publicField(this, "id");
|
|
@@ -1704,8 +1901,6 @@ function createWalletPaymentAdapter(plugin) {
|
|
|
1704
1901
|
};
|
|
1705
1902
|
}
|
|
1706
1903
|
__name(createWalletPaymentAdapter, "createWalletPaymentAdapter");
|
|
1707
|
-
|
|
1708
|
-
// src/typeorm/store.ts
|
|
1709
1904
|
function toNumber(value) {
|
|
1710
1905
|
if (value == null) {
|
|
1711
1906
|
return 0;
|
|
@@ -1734,7 +1929,7 @@ function toLedgerHold(row) {
|
|
|
1734
1929
|
referenceType: row.referenceType,
|
|
1735
1930
|
referenceId: row.referenceId,
|
|
1736
1931
|
idempotencyKey: row.idempotencyKey,
|
|
1737
|
-
createdAt:
|
|
1932
|
+
createdAt: parseLedgerDate(row.createdDate)
|
|
1738
1933
|
};
|
|
1739
1934
|
}
|
|
1740
1935
|
__name(toLedgerHold, "toLedgerHold");
|
|
@@ -1750,7 +1945,7 @@ function toLedgerEntry(row) {
|
|
|
1750
1945
|
referenceType: row.referenceType,
|
|
1751
1946
|
referenceId: row.referenceId,
|
|
1752
1947
|
metadata: row.metadata,
|
|
1753
|
-
createdAt:
|
|
1948
|
+
createdAt: parseLedgerDate(row.createdDate)
|
|
1754
1949
|
};
|
|
1755
1950
|
}
|
|
1756
1951
|
__name(toLedgerEntry, "toLedgerEntry");
|
|
@@ -1888,7 +2083,7 @@ var TypeOrmWalletStoreTx = (_a2 = class {
|
|
|
1888
2083
|
where: {
|
|
1889
2084
|
id: hold.id
|
|
1890
2085
|
}
|
|
1891
|
-
});
|
|
2086
|
+
}) ?? void 0;
|
|
1892
2087
|
}
|
|
1893
2088
|
if (!row) {
|
|
1894
2089
|
row = await repo.findOne({
|
|
@@ -1896,7 +2091,7 @@ var TypeOrmWalletStoreTx = (_a2 = class {
|
|
|
1896
2091
|
referenceType: hold.referenceType,
|
|
1897
2092
|
referenceId: hold.referenceId
|
|
1898
2093
|
}
|
|
1899
|
-
});
|
|
2094
|
+
}) ?? void 0;
|
|
1900
2095
|
}
|
|
1901
2096
|
if (!row) {
|
|
1902
2097
|
row = repo.create({
|
|
@@ -1926,6 +2121,36 @@ var TypeOrmWalletStoreTx = (_a2 = class {
|
|
|
1926
2121
|
});
|
|
1927
2122
|
return row ? toLedgerEntry(row) : null;
|
|
1928
2123
|
}
|
|
2124
|
+
async findOrderCustomerCheckoutDebit(accountId, orderId) {
|
|
2125
|
+
const canonical = orderCustomerDebitIdempotencyKey(orderId);
|
|
2126
|
+
const row = await this.em.getRepository(exports.WalletLedgerEntryEntity).createQueryBuilder("e").where("e.account_id = :accountId", {
|
|
2127
|
+
accountId
|
|
2128
|
+
}).andWhere("e.entry_type = :entryType", {
|
|
2129
|
+
entryType: "debit"
|
|
2130
|
+
}).andWhere("e.reference_type = :referenceType", {
|
|
2131
|
+
referenceType: "order"
|
|
2132
|
+
}).andWhere("e.reference_id = :orderId", {
|
|
2133
|
+
orderId
|
|
2134
|
+
}).andWhere(new typeorm.Brackets((qb) => {
|
|
2135
|
+
qb.where(`JSON_UNQUOTE(JSON_EXTRACT(e.metadata, '$.purpose')) = :purpose`, {
|
|
2136
|
+
purpose: CUSTOMER_CHECKOUT_DEBIT_PURPOSE
|
|
2137
|
+
}).orWhere("e.idempotency_key = :canonical", {
|
|
2138
|
+
canonical
|
|
2139
|
+
}).orWhere("e.idempotency_key LIKE :fullPrefix", {
|
|
2140
|
+
fullPrefix: "wallet:full:%"
|
|
2141
|
+
}).orWhere("e.idempotency_key LIKE :splitPrefix", {
|
|
2142
|
+
splitPrefix: "wallet:split:%"
|
|
2143
|
+
}).orWhere("e.idempotency_key LIKE :paymentPrefix", {
|
|
2144
|
+
paymentPrefix: "wallet:payment:%"
|
|
2145
|
+
});
|
|
2146
|
+
})).orderBy(`CASE
|
|
2147
|
+
WHEN JSON_UNQUOTE(JSON_EXTRACT(e.metadata, '$.purpose')) = :purpose THEN 0
|
|
2148
|
+
WHEN e.idempotency_key = :canonical THEN 1
|
|
2149
|
+
WHEN e.idempotency_key LIKE 'wallet:full:%' OR e.idempotency_key LIKE 'wallet:split:%' THEN 2
|
|
2150
|
+
ELSE 3
|
|
2151
|
+
END`, "ASC").addOrderBy("e.id", "ASC").setParameter("purpose", CUSTOMER_CHECKOUT_DEBIT_PURPOSE).setParameter("canonical", canonical).getOne();
|
|
2152
|
+
return row ? toLedgerEntry(row) : null;
|
|
2153
|
+
}
|
|
1929
2154
|
async listLedgerEntries(accountId, limit, offset) {
|
|
1930
2155
|
const rows = await this.em.getRepository(exports.WalletLedgerEntryEntity).find({
|
|
1931
2156
|
where: {
|
|
@@ -2062,6 +2287,84 @@ var _CreateWalletTables1790000000000 = class _CreateWalletTables1790000000000 {
|
|
|
2062
2287
|
__name(_CreateWalletTables1790000000000, "CreateWalletTables1790000000000");
|
|
2063
2288
|
var CreateWalletTables1790000000000 = _CreateWalletTables1790000000000;
|
|
2064
2289
|
|
|
2290
|
+
// src/typeorm/migrations/AddOrderCustomerDebitUnique.ts
|
|
2291
|
+
var _AddOrderCustomerDebitUnique1790000001000 = class _AddOrderCustomerDebitUnique1790000001000 {
|
|
2292
|
+
async up(queryRunner) {
|
|
2293
|
+
const opsTables = await queryRunner.query(`SELECT COUNT(*) AS c
|
|
2294
|
+
FROM information_schema.tables
|
|
2295
|
+
WHERE table_schema = DATABASE()
|
|
2296
|
+
AND table_name = ?`, [
|
|
2297
|
+
WALLET_OPS_TABLE
|
|
2298
|
+
]);
|
|
2299
|
+
if (Number(opsTables[0]?.c ?? 0) === 0) {
|
|
2300
|
+
throw new Error(`Wallet unique-index gate: ${WALLET_OPS_TABLE} is missing. Run npm run wallet:credit-duplicate-order-debits`);
|
|
2301
|
+
}
|
|
2302
|
+
const sentinel = await queryRunner.query(`SELECT status FROM \`${WALLET_OPS_TABLE}\` WHERE ops_key = ? LIMIT 1`, [
|
|
2303
|
+
BACKFILL_SENTINEL_KEY
|
|
2304
|
+
]);
|
|
2305
|
+
if (!sentinel[0] || sentinel[0].status !== "complete") {
|
|
2306
|
+
throw new Error(`Wallet unique-index gate: sentinel ${BACKFILL_SENTINEL_KEY} is missing. Run npm run wallet:credit-duplicate-order-debits`);
|
|
2307
|
+
}
|
|
2308
|
+
const twins = await queryRunner.query(UNREIMBURSED_TWIN_COUNT_SQL);
|
|
2309
|
+
const twinCount = Number(twins[0]?.c ?? 0);
|
|
2310
|
+
if (twinCount > 0) {
|
|
2311
|
+
throw new Error(`Wallet unique-index gate: unreimbursed twin COUNT is ${twinCount}. Run npm run wallet:credit-duplicate-order-debits`);
|
|
2312
|
+
}
|
|
2313
|
+
const columns = await queryRunner.query(`SELECT COUNT(*) AS c
|
|
2314
|
+
FROM information_schema.columns
|
|
2315
|
+
WHERE table_schema = DATABASE()
|
|
2316
|
+
AND table_name = 'wallet_ledger_entry'
|
|
2317
|
+
AND column_name = 'order_customer_debit_key'`);
|
|
2318
|
+
if (Number(columns[0]?.c ?? 0) === 0) {
|
|
2319
|
+
await queryRunner.query(`
|
|
2320
|
+
ALTER TABLE \`wallet_ledger_entry\`
|
|
2321
|
+
ADD COLUMN \`order_customer_debit_key\` VARCHAR(191)
|
|
2322
|
+
GENERATED ALWAYS AS (
|
|
2323
|
+
CASE
|
|
2324
|
+
WHEN \`entry_type\` = 'debit'
|
|
2325
|
+
AND \`reference_type\` = 'order'
|
|
2326
|
+
AND \`reference_id\` IS NOT NULL
|
|
2327
|
+
AND JSON_UNQUOTE(JSON_EXTRACT(\`metadata\`, '$.purpose')) = 'customer_checkout_debit'
|
|
2328
|
+
THEN CONCAT(\`account_id\`, ':', \`reference_id\`)
|
|
2329
|
+
ELSE NULL
|
|
2330
|
+
END
|
|
2331
|
+
) STORED
|
|
2332
|
+
`);
|
|
2333
|
+
}
|
|
2334
|
+
const indexes = await queryRunner.query(`SELECT COUNT(*) AS c
|
|
2335
|
+
FROM information_schema.statistics
|
|
2336
|
+
WHERE table_schema = DATABASE()
|
|
2337
|
+
AND table_name = 'wallet_ledger_entry'
|
|
2338
|
+
AND index_name = 'UQ_wallet_order_customer_debit'`);
|
|
2339
|
+
if (Number(indexes[0]?.c ?? 0) === 0) {
|
|
2340
|
+
await queryRunner.query(`
|
|
2341
|
+
CREATE UNIQUE INDEX \`UQ_wallet_order_customer_debit\`
|
|
2342
|
+
ON \`wallet_ledger_entry\` (\`order_customer_debit_key\`)
|
|
2343
|
+
`);
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
async down(queryRunner) {
|
|
2347
|
+
const indexes = await queryRunner.query(`SELECT COUNT(*) AS c
|
|
2348
|
+
FROM information_schema.statistics
|
|
2349
|
+
WHERE table_schema = DATABASE()
|
|
2350
|
+
AND table_name = 'wallet_ledger_entry'
|
|
2351
|
+
AND index_name = 'UQ_wallet_order_customer_debit'`);
|
|
2352
|
+
if (Number(indexes[0]?.c ?? 0) > 0) {
|
|
2353
|
+
await queryRunner.query(`DROP INDEX \`UQ_wallet_order_customer_debit\` ON \`wallet_ledger_entry\``);
|
|
2354
|
+
}
|
|
2355
|
+
const columns = await queryRunner.query(`SELECT COUNT(*) AS c
|
|
2356
|
+
FROM information_schema.columns
|
|
2357
|
+
WHERE table_schema = DATABASE()
|
|
2358
|
+
AND table_name = 'wallet_ledger_entry'
|
|
2359
|
+
AND column_name = 'order_customer_debit_key'`);
|
|
2360
|
+
if (Number(columns[0]?.c ?? 0) > 0) {
|
|
2361
|
+
await queryRunner.query(`ALTER TABLE \`wallet_ledger_entry\` DROP COLUMN \`order_customer_debit_key\``);
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
};
|
|
2365
|
+
__name(_AddOrderCustomerDebitUnique1790000001000, "AddOrderCustomerDebitUnique1790000001000");
|
|
2366
|
+
var AddOrderCustomerDebitUnique1790000001000 = _AddOrderCustomerDebitUnique1790000001000;
|
|
2367
|
+
|
|
2065
2368
|
// src/typeorm/metadata.ts
|
|
2066
2369
|
function getWalletOrmMetadata() {
|
|
2067
2370
|
return {
|
|
@@ -2071,7 +2374,8 @@ function getWalletOrmMetadata() {
|
|
|
2071
2374
|
exports.WalletHoldEntity
|
|
2072
2375
|
],
|
|
2073
2376
|
migrations: [
|
|
2074
|
-
CreateWalletTables1790000000000
|
|
2377
|
+
CreateWalletTables1790000000000,
|
|
2378
|
+
AddOrderCustomerDebitUnique1790000001000
|
|
2075
2379
|
]
|
|
2076
2380
|
};
|
|
2077
2381
|
}
|
|
@@ -2118,7 +2422,8 @@ var WalletPluginImpl = (_a3 = class {
|
|
|
2118
2422
|
this.resolveOrderCustomerId = config.resolveOrderCustomerId;
|
|
2119
2423
|
this.client = new WalletLedgerClient(store, {
|
|
2120
2424
|
defaultCurrency: config.defaultCurrency ?? "INR",
|
|
2121
|
-
platformOwnerId: config.platformOwnerId
|
|
2425
|
+
platformOwnerId: config.platformOwnerId,
|
|
2426
|
+
onDuplicateOrderDebit: config.onDuplicateOrderDebit
|
|
2122
2427
|
});
|
|
2123
2428
|
this.hooks = createLifecycleHooks({
|
|
2124
2429
|
client: this.client,
|
|
@@ -2170,15 +2475,23 @@ function registerWalletPlugin(config) {
|
|
|
2170
2475
|
}
|
|
2171
2476
|
__name(registerWalletPlugin, "registerWalletPlugin");
|
|
2172
2477
|
|
|
2478
|
+
exports.AddOrderCustomerDebitUnique1790000001000 = AddOrderCustomerDebitUnique1790000001000;
|
|
2479
|
+
exports.BACKFILL_SENTINEL_KEY = BACKFILL_SENTINEL_KEY;
|
|
2480
|
+
exports.CUSTOMER_CHECKOUT_DEBIT_PURPOSE = CUSTOMER_CHECKOUT_DEBIT_PURPOSE;
|
|
2481
|
+
exports.CUSTOMER_CHECKOUT_DEBIT_REVERSAL_PURPOSE = CUSTOMER_CHECKOUT_DEBIT_REVERSAL_PURPOSE;
|
|
2173
2482
|
exports.CreateWalletTables1790000000000 = CreateWalletTables1790000000000;
|
|
2174
2483
|
exports.DuplicateOperationError = DuplicateOperationError;
|
|
2175
2484
|
exports.HoldNotFoundError = HoldNotFoundError;
|
|
2176
2485
|
exports.HoldStatus = HoldStatus;
|
|
2177
2486
|
exports.InsufficientBalanceError = InsufficientBalanceError;
|
|
2178
2487
|
exports.InvalidAmountError = InvalidAmountError;
|
|
2488
|
+
exports.LEGACY_ORDER_DEBIT_SUNSET_SQL = LEGACY_ORDER_DEBIT_SUNSET_SQL;
|
|
2179
2489
|
exports.LedgerEntryType = LedgerEntryType;
|
|
2180
2490
|
exports.PaymentProviderWallet = PaymentProviderWallet;
|
|
2181
2491
|
exports.TypeOrmWalletStore = TypeOrmWalletStore;
|
|
2492
|
+
exports.UNREIMBURSED_TWIN_COUNT_SQL = UNREIMBURSED_TWIN_COUNT_SQL;
|
|
2493
|
+
exports.UNREIMBURSED_TWIN_DETAIL_SQL = UNREIMBURSED_TWIN_DETAIL_SQL;
|
|
2494
|
+
exports.WALLET_OPS_TABLE = WALLET_OPS_TABLE;
|
|
2182
2495
|
exports.WALLET_PLUGIN_TOKEN = WALLET_PLUGIN_TOKEN;
|
|
2183
2496
|
exports.WalletAccountType = WalletAccountType;
|
|
2184
2497
|
exports.WalletConfigError = WalletConfigError;
|
|
@@ -2188,6 +2501,13 @@ exports.createExpressWalletRouter = createExpressWalletRouter;
|
|
|
2188
2501
|
exports.createWalletPaymentAdapter = createWalletPaymentAdapter;
|
|
2189
2502
|
exports.fromMinorUnit = fromMinorUnit;
|
|
2190
2503
|
exports.getWalletOrmMetadata = getWalletOrmMetadata;
|
|
2504
|
+
exports.isCustomerCheckoutDebit = isCustomerCheckoutDebit;
|
|
2505
|
+
exports.isLegacyCustomerCheckoutDebitKey = isLegacyCustomerCheckoutDebitKey;
|
|
2506
|
+
exports.nowTimestamp = nowTimestamp;
|
|
2507
|
+
exports.orderCustomerDebitIdempotencyKey = orderCustomerDebitIdempotencyKey;
|
|
2508
|
+
exports.parseLedgerDate = parseLedgerDate;
|
|
2509
|
+
exports.paymentNumberFromWalletPaymentKey = paymentNumberFromWalletPaymentKey;
|
|
2510
|
+
exports.paymentReversalIdempotencyKey = paymentReversalIdempotencyKey;
|
|
2191
2511
|
exports.registerWalletPlugin = registerWalletPlugin;
|
|
2192
2512
|
exports.toMinorUnit = toMinorUnit;
|
|
2193
2513
|
//# sourceMappingURL=index.cjs.map
|