multivendor-wallet 0.0.7 → 0.0.9
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/dist/hooks/index.cjs +24 -10
- 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 +24 -10
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +36 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +36 -16
- package/dist/index.js.map +1 -1
- package/dist/{store-nWCfzvwf.d.mts → store-vIkNzYjM.d.mts} +2 -0
- package/dist/{store-nWCfzvwf.d.ts → store-vIkNzYjM.d.ts} +2 -0
- package/dist/typeorm/index.d.mts +1 -1
- package/dist/typeorm/index.d.ts +1 -1
- package/dist/{types-D1Q4XCwx.d.mts → types-D0mhOXHk.d.mts} +6 -1
- package/dist/{types-B4R1zaTK.d.ts → types-nBZ_GHJQ.d.ts} +6 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -527,22 +527,28 @@ var _WalletLedgerClient = class _WalletLedgerClient {
|
|
|
527
527
|
};
|
|
528
528
|
}
|
|
529
529
|
const hold = await this.requireActiveHold(tx, params.reference);
|
|
530
|
+
const reduceBy = params.amount != null && Number.isInteger(params.amount) && params.amount > 0 ? Math.min(params.amount, hold.amount) : hold.amount;
|
|
530
531
|
await tx.lockAccount(hold.sourceAccountId);
|
|
531
532
|
await tx.lockAccount(hold.targetAccountId);
|
|
532
533
|
const sourceUpdated = await tx.updateBalances(hold.sourceAccountId, {
|
|
533
|
-
availableDelta:
|
|
534
|
+
availableDelta: reduceBy
|
|
534
535
|
});
|
|
535
536
|
const targetUpdated = await tx.updateBalances(hold.targetAccountId, {
|
|
536
|
-
heldDelta: -
|
|
537
|
+
heldDelta: -reduceBy
|
|
537
538
|
});
|
|
538
|
-
const
|
|
539
|
+
const remaining = hold.amount - reduceBy;
|
|
540
|
+
const nextHold = remaining > 0 ? await tx.upsertHold({
|
|
541
|
+
...hold,
|
|
542
|
+
amount: remaining,
|
|
543
|
+
status: HoldStatus.ACTIVE
|
|
544
|
+
}) : await tx.upsertHold({
|
|
539
545
|
...hold,
|
|
540
546
|
status: HoldStatus.CANCELLED
|
|
541
547
|
});
|
|
542
548
|
await tx.appendLedgerEntry({
|
|
543
549
|
accountId: hold.sourceAccountId,
|
|
544
550
|
entryType: LedgerEntryType.CANCEL_HOLD,
|
|
545
|
-
amount:
|
|
551
|
+
amount: reduceBy,
|
|
546
552
|
balanceAfterAvailable: sourceUpdated.availableBalance,
|
|
547
553
|
balanceAfterHeld: sourceUpdated.heldBalance,
|
|
548
554
|
idempotencyKey: `${params.idempotencyKey}:source`,
|
|
@@ -553,7 +559,7 @@ var _WalletLedgerClient = class _WalletLedgerClient {
|
|
|
553
559
|
const entry = await tx.appendLedgerEntry({
|
|
554
560
|
accountId: hold.targetAccountId,
|
|
555
561
|
entryType: LedgerEntryType.CANCEL_HOLD,
|
|
556
|
-
amount:
|
|
562
|
+
amount: reduceBy,
|
|
557
563
|
balanceAfterAvailable: targetUpdated.availableBalance,
|
|
558
564
|
balanceAfterHeld: targetUpdated.heldBalance,
|
|
559
565
|
idempotencyKey: params.idempotencyKey,
|
|
@@ -564,7 +570,7 @@ var _WalletLedgerClient = class _WalletLedgerClient {
|
|
|
564
570
|
return {
|
|
565
571
|
entry,
|
|
566
572
|
account: targetUpdated,
|
|
567
|
-
hold:
|
|
573
|
+
hold: nextHold
|
|
568
574
|
};
|
|
569
575
|
}
|
|
570
576
|
toBalance(account) {
|
|
@@ -694,7 +700,7 @@ function walletCreditRupees(ctx) {
|
|
|
694
700
|
__name(walletCreditRupees, "walletCreditRupees");
|
|
695
701
|
function idempotencyPrefix(ctx) {
|
|
696
702
|
const scope = ctx.idempotencyScope ?? String(ctx.orderProductId);
|
|
697
|
-
return ctx.refundReason === "return" ? `return:${scope}` : `refund:${
|
|
703
|
+
return ctx.refundReason === "return" ? `return:${scope}` : `refund:${scope}`;
|
|
698
704
|
}
|
|
699
705
|
__name(idempotencyPrefix, "idempotencyPrefix");
|
|
700
706
|
function createRefundHooks(runtime) {
|
|
@@ -707,13 +713,27 @@ function createRefundHooks(runtime) {
|
|
|
707
713
|
}
|
|
708
714
|
const keyPrefix = idempotencyPrefix(ctx);
|
|
709
715
|
if (!ctx.skipEscrow) {
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
716
|
+
if (ctx.sellerNetClawbackRupees != null) {
|
|
717
|
+
const clawbackPaise = toMinorUnit(ctx.sellerNetClawbackRupees);
|
|
718
|
+
if (clawbackPaise > 0) {
|
|
719
|
+
await client.cancelHold({
|
|
720
|
+
reference: {
|
|
721
|
+
referenceType: "vendor_order",
|
|
722
|
+
referenceId: String(ctx.vendorOrderId)
|
|
723
|
+
},
|
|
724
|
+
idempotencyKey: `${keyPrefix}:cancel_hold`,
|
|
725
|
+
amount: clawbackPaise
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
} else {
|
|
729
|
+
await client.cancelHold({
|
|
730
|
+
reference: {
|
|
731
|
+
referenceType: "vendor_order",
|
|
732
|
+
referenceId: String(ctx.vendorOrderId)
|
|
733
|
+
},
|
|
734
|
+
idempotencyKey: `${keyPrefix}:cancel_hold`
|
|
735
|
+
});
|
|
736
|
+
}
|
|
717
737
|
}
|
|
718
738
|
const refundPaise = toMinorUnit(ctx.lineTotalRupees);
|
|
719
739
|
if (refundPaise > 0) {
|
|
@@ -738,8 +758,8 @@ function createRefundHooks(runtime) {
|
|
|
738
758
|
amount: toMinorUnit(creditRupees),
|
|
739
759
|
idempotencyKey: `${keyPrefix}:customer_credit`,
|
|
740
760
|
reference: {
|
|
741
|
-
referenceType: "
|
|
742
|
-
referenceId: String(ctx.
|
|
761
|
+
referenceType: "order_product",
|
|
762
|
+
referenceId: String(ctx.orderProductId)
|
|
743
763
|
}
|
|
744
764
|
});
|
|
745
765
|
}
|