multivendor-wallet 0.0.7 → 0.0.8

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/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { e as WalletPluginConfig, f as WalletPlugin, I as IWalletPaymentProvider } from './types-D1Q4XCwx.mjs';
2
- export { D as DeliveredContext, O as OrderPaidContext, P as PaymentProviderWallet, R as RefundContext, S as SettlementDebitContext, g as WALLET_PLUGIN_TOKEN, h as WalletAdminMutationEvent, i as WalletConfig, C as WalletCreatePaymentInput, j as WalletDuplicateOrderDebitInfo, k as WalletDuplicateOrderDebitKind, l as WalletFeatureFlags, m as WalletHttpConfig, n as WalletLedgerClient, W as WalletLifecycleHooks, b as WalletOrderPaidLine, o as WalletReconciliationConfig } from './types-D1Q4XCwx.mjs';
3
- import { W as WalletAccountType } from './store-nWCfzvwf.mjs';
4
- export { B as BalanceDeltas, d as CancelHoldParams, C as CreditParams, D as DebitParams, G as GetTransactionsParams, H as HoldParams, f as HoldStatus, I as IWalletStore, g as IWalletStoreTx, h as LedgerEntryType, L as LedgerMutationResult, R as ReleaseParams, T as TransferParams, b as WalletAccount, c as WalletBalance, i as WalletHold, e as WalletLedgerEntry, j as WalletReference, a as WalletStoreContext } from './store-nWCfzvwf.mjs';
1
+ import { e as WalletPluginConfig, f as WalletPlugin, I as IWalletPaymentProvider } from './types-D0mhOXHk.mjs';
2
+ export { D as DeliveredContext, O as OrderPaidContext, P as PaymentProviderWallet, R as RefundContext, S as SettlementDebitContext, g as WALLET_PLUGIN_TOKEN, h as WalletAdminMutationEvent, i as WalletConfig, C as WalletCreatePaymentInput, j as WalletDuplicateOrderDebitInfo, k as WalletDuplicateOrderDebitKind, l as WalletFeatureFlags, m as WalletHttpConfig, n as WalletLedgerClient, W as WalletLifecycleHooks, b as WalletOrderPaidLine, o as WalletReconciliationConfig } from './types-D0mhOXHk.mjs';
3
+ import { W as WalletAccountType } from './store-vIkNzYjM.mjs';
4
+ export { B as BalanceDeltas, d as CancelHoldParams, C as CreditParams, D as DebitParams, G as GetTransactionsParams, H as HoldParams, f as HoldStatus, I as IWalletStore, g as IWalletStoreTx, h as LedgerEntryType, L as LedgerMutationResult, R as ReleaseParams, T as TransferParams, b as WalletAccount, c as WalletBalance, i as WalletHold, e as WalletLedgerEntry, j as WalletReference, a as WalletStoreContext } from './store-vIkNzYjM.mjs';
5
5
  export { AddOrderCustomerDebitUnique1790000001000, CreateWalletTables1790000000000, TypeOrmWalletStore, WalletAccountEntity, WalletHoldEntity, WalletLedgerEntryEntity, getWalletOrmMetadata } from './typeorm/index.mjs';
6
6
  import { Router } from 'express';
7
7
  import 'typeorm';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { e as WalletPluginConfig, f as WalletPlugin, I as IWalletPaymentProvider } from './types-B4R1zaTK.js';
2
- export { D as DeliveredContext, O as OrderPaidContext, P as PaymentProviderWallet, R as RefundContext, S as SettlementDebitContext, g as WALLET_PLUGIN_TOKEN, h as WalletAdminMutationEvent, i as WalletConfig, C as WalletCreatePaymentInput, j as WalletDuplicateOrderDebitInfo, k as WalletDuplicateOrderDebitKind, l as WalletFeatureFlags, m as WalletHttpConfig, n as WalletLedgerClient, W as WalletLifecycleHooks, b as WalletOrderPaidLine, o as WalletReconciliationConfig } from './types-B4R1zaTK.js';
3
- import { W as WalletAccountType } from './store-nWCfzvwf.js';
4
- export { B as BalanceDeltas, d as CancelHoldParams, C as CreditParams, D as DebitParams, G as GetTransactionsParams, H as HoldParams, f as HoldStatus, I as IWalletStore, g as IWalletStoreTx, h as LedgerEntryType, L as LedgerMutationResult, R as ReleaseParams, T as TransferParams, b as WalletAccount, c as WalletBalance, i as WalletHold, e as WalletLedgerEntry, j as WalletReference, a as WalletStoreContext } from './store-nWCfzvwf.js';
1
+ import { e as WalletPluginConfig, f as WalletPlugin, I as IWalletPaymentProvider } from './types-nBZ_GHJQ.js';
2
+ export { D as DeliveredContext, O as OrderPaidContext, P as PaymentProviderWallet, R as RefundContext, S as SettlementDebitContext, g as WALLET_PLUGIN_TOKEN, h as WalletAdminMutationEvent, i as WalletConfig, C as WalletCreatePaymentInput, j as WalletDuplicateOrderDebitInfo, k as WalletDuplicateOrderDebitKind, l as WalletFeatureFlags, m as WalletHttpConfig, n as WalletLedgerClient, W as WalletLifecycleHooks, b as WalletOrderPaidLine, o as WalletReconciliationConfig } from './types-nBZ_GHJQ.js';
3
+ import { W as WalletAccountType } from './store-vIkNzYjM.js';
4
+ export { B as BalanceDeltas, d as CancelHoldParams, C as CreditParams, D as DebitParams, G as GetTransactionsParams, H as HoldParams, f as HoldStatus, I as IWalletStore, g as IWalletStoreTx, h as LedgerEntryType, L as LedgerMutationResult, R as ReleaseParams, T as TransferParams, b as WalletAccount, c as WalletBalance, i as WalletHold, e as WalletLedgerEntry, j as WalletReference, a as WalletStoreContext } from './store-vIkNzYjM.js';
5
5
  export { AddOrderCustomerDebitUnique1790000001000, CreateWalletTables1790000000000, TypeOrmWalletStore, WalletAccountEntity, WalletHoldEntity, WalletLedgerEntryEntity, getWalletOrmMetadata } from './typeorm/index.js';
6
6
  import { Router } from 'express';
7
7
  import 'typeorm';
package/dist/index.js CHANGED
@@ -525,22 +525,28 @@ var _WalletLedgerClient = class _WalletLedgerClient {
525
525
  };
526
526
  }
527
527
  const hold = await this.requireActiveHold(tx, params.reference);
528
+ const reduceBy = params.amount != null && Number.isInteger(params.amount) && params.amount > 0 ? Math.min(params.amount, hold.amount) : hold.amount;
528
529
  await tx.lockAccount(hold.sourceAccountId);
529
530
  await tx.lockAccount(hold.targetAccountId);
530
531
  const sourceUpdated = await tx.updateBalances(hold.sourceAccountId, {
531
- availableDelta: hold.amount
532
+ availableDelta: reduceBy
532
533
  });
533
534
  const targetUpdated = await tx.updateBalances(hold.targetAccountId, {
534
- heldDelta: -hold.amount
535
+ heldDelta: -reduceBy
535
536
  });
536
- const cancelledHold = await tx.upsertHold({
537
+ const remaining = hold.amount - reduceBy;
538
+ const nextHold = remaining > 0 ? await tx.upsertHold({
539
+ ...hold,
540
+ amount: remaining,
541
+ status: HoldStatus.ACTIVE
542
+ }) : await tx.upsertHold({
537
543
  ...hold,
538
544
  status: HoldStatus.CANCELLED
539
545
  });
540
546
  await tx.appendLedgerEntry({
541
547
  accountId: hold.sourceAccountId,
542
548
  entryType: LedgerEntryType.CANCEL_HOLD,
543
- amount: hold.amount,
549
+ amount: reduceBy,
544
550
  balanceAfterAvailable: sourceUpdated.availableBalance,
545
551
  balanceAfterHeld: sourceUpdated.heldBalance,
546
552
  idempotencyKey: `${params.idempotencyKey}:source`,
@@ -551,7 +557,7 @@ var _WalletLedgerClient = class _WalletLedgerClient {
551
557
  const entry = await tx.appendLedgerEntry({
552
558
  accountId: hold.targetAccountId,
553
559
  entryType: LedgerEntryType.CANCEL_HOLD,
554
- amount: hold.amount,
560
+ amount: reduceBy,
555
561
  balanceAfterAvailable: targetUpdated.availableBalance,
556
562
  balanceAfterHeld: targetUpdated.heldBalance,
557
563
  idempotencyKey: params.idempotencyKey,
@@ -562,7 +568,7 @@ var _WalletLedgerClient = class _WalletLedgerClient {
562
568
  return {
563
569
  entry,
564
570
  account: targetUpdated,
565
- hold: cancelledHold
571
+ hold: nextHold
566
572
  };
567
573
  }
568
574
  toBalance(account) {
@@ -692,7 +698,7 @@ function walletCreditRupees(ctx) {
692
698
  __name(walletCreditRupees, "walletCreditRupees");
693
699
  function idempotencyPrefix(ctx) {
694
700
  const scope = ctx.idempotencyScope ?? String(ctx.orderProductId);
695
- return ctx.refundReason === "return" ? `return:${scope}` : `refund:${ctx.orderProductId}`;
701
+ return ctx.refundReason === "return" ? `return:${scope}` : `refund:${scope}`;
696
702
  }
697
703
  __name(idempotencyPrefix, "idempotencyPrefix");
698
704
  function createRefundHooks(runtime) {
@@ -705,13 +711,27 @@ function createRefundHooks(runtime) {
705
711
  }
706
712
  const keyPrefix = idempotencyPrefix(ctx);
707
713
  if (!ctx.skipEscrow) {
708
- await client.cancelHold({
709
- reference: {
710
- referenceType: "vendor_order",
711
- referenceId: String(ctx.vendorOrderId)
712
- },
713
- idempotencyKey: `${keyPrefix}:cancel_hold`
714
- });
714
+ if (ctx.sellerNetClawbackRupees != null) {
715
+ const clawbackPaise = toMinorUnit(ctx.sellerNetClawbackRupees);
716
+ if (clawbackPaise > 0) {
717
+ await client.cancelHold({
718
+ reference: {
719
+ referenceType: "vendor_order",
720
+ referenceId: String(ctx.vendorOrderId)
721
+ },
722
+ idempotencyKey: `${keyPrefix}:cancel_hold`,
723
+ amount: clawbackPaise
724
+ });
725
+ }
726
+ } else {
727
+ await client.cancelHold({
728
+ reference: {
729
+ referenceType: "vendor_order",
730
+ referenceId: String(ctx.vendorOrderId)
731
+ },
732
+ idempotencyKey: `${keyPrefix}:cancel_hold`
733
+ });
734
+ }
715
735
  }
716
736
  const refundPaise = toMinorUnit(ctx.lineTotalRupees);
717
737
  if (refundPaise > 0) {