@fantastic.dev/better-stripe 0.23.2 → 0.25.0
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/CHANGELOG.md +27 -2
- package/README.md +46 -5
- package/dist/client/affiliateRecovery/disputes.d.ts +18 -0
- package/dist/client/affiliateRecovery/disputes.d.ts.map +1 -0
- package/dist/client/affiliateRecovery/disputes.js +33 -0
- package/dist/client/affiliateRecovery/disputes.js.map +1 -0
- package/dist/client/affiliateRecovery/engine.d.ts +29 -0
- package/dist/client/affiliateRecovery/engine.d.ts.map +1 -0
- package/dist/client/affiliateRecovery/engine.js +116 -0
- package/dist/client/affiliateRecovery/engine.js.map +1 -0
- package/dist/client/affiliateRecovery/payoutGate.d.ts +24 -0
- package/dist/client/affiliateRecovery/payoutGate.d.ts.map +1 -0
- package/dist/client/affiliateRecovery/payoutGate.js +30 -0
- package/dist/client/affiliateRecovery/payoutGate.js.map +1 -0
- package/dist/client/affiliateRecovery/provider.d.ts +14 -0
- package/dist/client/affiliateRecovery/provider.d.ts.map +1 -0
- package/dist/client/affiliateRecovery/provider.js +96 -0
- package/dist/client/affiliateRecovery/provider.js.map +1 -0
- package/dist/client/affiliateRecovery/review.d.ts +28 -0
- package/dist/client/affiliateRecovery/review.d.ts.map +1 -0
- package/dist/client/affiliateRecovery/review.js +86 -0
- package/dist/client/affiliateRecovery/review.js.map +1 -0
- package/dist/client/affiliateRecovery/validators.d.ts +402 -0
- package/dist/client/affiliateRecovery/validators.d.ts.map +1 -0
- package/dist/client/affiliateRecovery/validators.js +27 -0
- package/dist/client/affiliateRecovery/validators.js.map +1 -0
- package/dist/client/affiliateRecovery.d.ts +131 -0
- package/dist/client/affiliateRecovery.d.ts.map +1 -0
- package/dist/client/affiliateRecovery.js +69 -0
- package/dist/client/affiliateRecovery.js.map +1 -0
- package/dist/client/billing/checkout.d.ts +3 -43
- package/dist/client/billing/checkout.d.ts.map +1 -1
- package/dist/client/billing/checkout.js +5 -260
- package/dist/client/billing/checkout.js.map +1 -1
- package/dist/client/billing/checkoutRequest.d.ts +129 -0
- package/dist/client/billing/checkoutRequest.d.ts.map +1 -0
- package/dist/client/billing/checkoutRequest.js +263 -0
- package/dist/client/billing/checkoutRequest.js.map +1 -0
- package/dist/client/billing/preparedCheckout.d.ts +22 -0
- package/dist/client/billing/preparedCheckout.d.ts.map +1 -0
- package/dist/client/billing/preparedCheckout.js +86 -0
- package/dist/client/billing/preparedCheckout.js.map +1 -0
- package/dist/client/checkoutRequests.d.ts +80 -0
- package/dist/client/checkoutRequests.d.ts.map +1 -0
- package/dist/client/checkoutRequests.js +28 -0
- package/dist/client/checkoutRequests.js.map +1 -0
- package/dist/client/connect/commissionReceipts.d.ts +4 -0
- package/dist/client/connect/commissionReceipts.d.ts.map +1 -0
- package/dist/client/connect/commissionReceipts.js +17 -0
- package/dist/client/connect/commissionReceipts.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +958 -2
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutCollection.d.ts +21 -0
- package/dist/client/connect/payoutCollection.d.ts.map +1 -0
- package/dist/client/connect/payoutCollection.js +47 -0
- package/dist/client/connect/payoutCollection.js.map +1 -0
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +1805 -0
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -0
- package/dist/client/connect/payoutExecutionTestHelpers.js +194 -0
- package/dist/client/connect/payoutExecutionTestHelpers.js.map +1 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +479 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutWorker.d.ts +48 -0
- package/dist/client/connect/payoutWorker.d.ts.map +1 -0
- package/dist/client/connect/payoutWorker.js +78 -0
- package/dist/client/connect/payoutWorker.js.map +1 -0
- package/dist/client/connect/payouts.d.ts +3 -1
- package/dist/client/connect/payouts.d.ts.map +1 -1
- package/dist/client/connect/payouts.js +45 -12
- package/dist/client/connect/payouts.js.map +1 -1
- package/dist/client/connect/refundPrincipal.d.ts +4 -0
- package/dist/client/connect/refundPrincipal.d.ts.map +1 -0
- package/dist/client/connect/refundPrincipal.js +21 -0
- package/dist/client/connect/refundPrincipal.js.map +1 -0
- package/dist/client/connect/reversalExecution.d.ts +47 -0
- package/dist/client/connect/reversalExecution.d.ts.map +1 -0
- package/dist/client/connect/reversalExecution.js +84 -0
- package/dist/client/connect/reversalExecution.js.map +1 -0
- package/dist/client/connect/transfers.d.ts +8 -4
- package/dist/client/connect/transfers.d.ts.map +1 -1
- package/dist/client/connect/transfers.js +52 -57
- package/dist/client/connect/transfers.js.map +1 -1
- package/dist/client/index.d.ts +7 -11
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +10 -10
- package/dist/client/index.js.map +1 -1
- package/dist/client/payoutPolicy.d.ts +67 -0
- package/dist/client/payoutPolicy.d.ts.map +1 -1
- package/dist/client/payoutPolicy.js +10 -0
- package/dist/client/payoutPolicy.js.map +1 -1
- package/dist/client/readContracts.d.ts +11 -1
- package/dist/client/readContracts.d.ts.map +1 -1
- package/dist/client/readContracts.js +10 -0
- package/dist/client/readContracts.js.map +1 -1
- package/dist/client/settlement/execution.d.ts.map +1 -1
- package/dist/client/settlement/execution.js +30 -3
- package/dist/client/settlement/execution.js.map +1 -1
- package/dist/client/settlement/reconciliation.d.ts.map +1 -1
- package/dist/client/settlement/reconciliation.js +16 -2
- package/dist/client/settlement/reconciliation.js.map +1 -1
- package/dist/client/webhooks/disputeRecovery.d.ts +4 -0
- package/dist/client/webhooks/disputeRecovery.d.ts.map +1 -0
- package/dist/client/webhooks/disputeRecovery.js +40 -0
- package/dist/client/webhooks/disputeRecovery.js.map +1 -0
- package/dist/client/webhooks/processors.d.ts.map +1 -1
- package/dist/client/webhooks/processors.js +14 -29
- package/dist/client/webhooks/processors.js.map +1 -1
- package/dist/component/_generated/component.d.ts +784 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/affiliateEarnings/mutations.d.ts +22 -0
- package/dist/component/affiliateEarnings/mutations.d.ts.map +1 -0
- package/dist/component/affiliateEarnings/mutations.js +160 -0
- package/dist/component/affiliateEarnings/mutations.js.map +1 -0
- package/dist/component/affiliatePayouts/mutations.d.ts +25 -0
- package/dist/component/affiliatePayouts/mutations.d.ts.map +1 -0
- package/dist/component/affiliatePayouts/mutations.js +104 -0
- package/dist/component/affiliatePayouts/mutations.js.map +1 -0
- package/dist/component/affiliatePayouts/queries.d.ts +23 -0
- package/dist/component/affiliatePayouts/queries.d.ts.map +1 -0
- package/dist/component/affiliatePayouts/queries.js +23 -0
- package/dist/component/affiliatePayouts/queries.js.map +1 -0
- package/dist/component/affiliatePayouts/recipientGuard.d.ts +12 -0
- package/dist/component/affiliatePayouts/recipientGuard.d.ts.map +1 -0
- package/dist/component/affiliatePayouts/recipientGuard.js +26 -0
- package/dist/component/affiliatePayouts/recipientGuard.js.map +1 -0
- package/dist/component/affiliateRecovery/accounting.d.ts +28 -0
- package/dist/component/affiliateRecovery/accounting.d.ts.map +1 -0
- package/dist/component/affiliateRecovery/accounting.js +71 -0
- package/dist/component/affiliateRecovery/accounting.js.map +1 -0
- package/dist/component/affiliateRecovery/mutations.d.ts +65 -0
- package/dist/component/affiliateRecovery/mutations.d.ts.map +1 -0
- package/dist/component/affiliateRecovery/mutations.js +250 -0
- package/dist/component/affiliateRecovery/mutations.js.map +1 -0
- package/dist/component/affiliateRecovery/queries.d.ts +305 -0
- package/dist/component/affiliateRecovery/queries.d.ts.map +1 -0
- package/dist/component/affiliateRecovery/queries.js +113 -0
- package/dist/component/affiliateRecovery/queries.js.map +1 -0
- package/dist/component/affiliateRecovery/schema.d.ts +171 -0
- package/dist/component/affiliateRecovery/schema.d.ts.map +1 -0
- package/dist/component/affiliateRecovery/schema.js +71 -0
- package/dist/component/affiliateRecovery/schema.js.map +1 -0
- package/dist/component/connect/mutations.d.ts +36 -23
- package/dist/component/connect/mutations.d.ts.map +1 -1
- package/dist/component/connect/mutations.js +7 -124
- package/dist/component/connect/mutations.js.map +1 -1
- package/dist/component/connect/queries.d.ts +10 -0
- package/dist/component/connect/queries.d.ts.map +1 -1
- package/dist/component/connect/queries.js +3 -40
- package/dist/component/connect/queries.js.map +1 -1
- package/dist/component/connect/reversalClaims.d.ts +169 -0
- package/dist/component/connect/reversalClaims.d.ts.map +1 -0
- package/dist/component/connect/reversalClaims.js +176 -0
- package/dist/component/connect/reversalClaims.js.map +1 -0
- package/dist/component/connect/reversalDiagnostics.d.ts +59 -0
- package/dist/component/connect/reversalDiagnostics.d.ts.map +1 -0
- package/dist/component/connect/reversalDiagnostics.js +50 -0
- package/dist/component/connect/reversalDiagnostics.js.map +1 -0
- package/dist/component/connect/reversalReceipts.d.ts +27 -0
- package/dist/component/connect/reversalReceipts.d.ts.map +1 -0
- package/dist/component/connect/reversalReceipts.js +85 -0
- package/dist/component/connect/reversalReceipts.js.map +1 -0
- package/dist/component/connect/schema.d.ts +31 -1
- package/dist/component/connect/schema.d.ts.map +1 -1
- package/dist/component/connect/schema.js +3 -1
- package/dist/component/connect/schema.js.map +1 -1
- package/dist/component/connect/validators.d.ts +49 -1
- package/dist/component/connect/validators.d.ts.map +1 -1
- package/dist/component/connect/validators.js +2 -0
- package/dist/component/connect/validators.js.map +1 -1
- package/dist/component/core/mutations.d.ts.map +1 -1
- package/dist/component/core/mutations.js +2 -0
- package/dist/component/core/mutations.js.map +1 -1
- package/dist/component/core/resetSafety.d.ts +4 -0
- package/dist/component/core/resetSafety.d.ts.map +1 -0
- package/dist/component/core/resetSafety.js +54 -0
- package/dist/component/core/resetSafety.js.map +1 -0
- package/dist/component/earnings/triggers.d.ts +828 -2
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/earnings/triggers.js +2 -0
- package/dist/component/earnings/triggers.js.map +1 -1
- package/dist/component/payoutPolicy/schema.d.ts +2 -0
- package/dist/component/payoutPolicy/schema.d.ts.map +1 -1
- package/dist/component/payoutPolicy/schema.js +3 -1
- package/dist/component/payoutPolicy/schema.js.map +1 -1
- package/dist/component/payoutRelease/mutations.d.ts.map +1 -1
- package/dist/component/payoutRelease/mutations.js +7 -1
- package/dist/component/payoutRelease/mutations.js.map +1 -1
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/payoutRelease/queries.js +3 -1
- package/dist/component/payoutRelease/queries.js.map +1 -1
- package/dist/component/payoutRelease/schema.d.ts +1 -0
- package/dist/component/payoutRelease/schema.d.ts.map +1 -1
- package/dist/component/payoutRelease/schema.js +1 -0
- package/dist/component/payoutRelease/schema.js.map +1 -1
- package/dist/component/payoutSnapshots/localState.d.ts +89 -0
- package/dist/component/payoutSnapshots/localState.d.ts.map +1 -0
- package/dist/component/payoutSnapshots/localState.js +186 -0
- package/dist/component/payoutSnapshots/localState.js.map +1 -0
- package/dist/component/payoutSnapshots/mutations.d.ts +108 -0
- package/dist/component/payoutSnapshots/mutations.d.ts.map +1 -0
- package/dist/component/payoutSnapshots/mutations.js +263 -0
- package/dist/component/payoutSnapshots/mutations.js.map +1 -0
- package/dist/component/payoutSnapshots/revisions.d.ts +12 -0
- package/dist/component/payoutSnapshots/revisions.d.ts.map +1 -0
- package/dist/component/payoutSnapshots/revisions.js +173 -0
- package/dist/component/payoutSnapshots/revisions.js.map +1 -0
- package/dist/component/payoutSnapshots/schema.d.ts +285 -0
- package/dist/component/payoutSnapshots/schema.d.ts.map +1 -0
- package/dist/component/payoutSnapshots/schema.js +108 -0
- package/dist/component/payoutSnapshots/schema.js.map +1 -0
- package/dist/component/payoutSnapshots/scope.d.ts +7 -0
- package/dist/component/payoutSnapshots/scope.d.ts.map +1 -0
- package/dist/component/payoutSnapshots/scope.js +8 -0
- package/dist/component/payoutSnapshots/scope.js.map +1 -0
- package/dist/component/payoutWorker/helpers.d.ts +30 -0
- package/dist/component/payoutWorker/helpers.d.ts.map +1 -0
- package/dist/component/payoutWorker/helpers.js +21 -0
- package/dist/component/payoutWorker/helpers.js.map +1 -0
- package/dist/component/payoutWorker/mutations.d.ts +68 -0
- package/dist/component/payoutWorker/mutations.d.ts.map +1 -0
- package/dist/component/payoutWorker/mutations.js +161 -0
- package/dist/component/payoutWorker/mutations.js.map +1 -0
- package/dist/component/payoutWorker/queries.d.ts +123 -0
- package/dist/component/payoutWorker/queries.d.ts.map +1 -0
- package/dist/component/payoutWorker/queries.js +61 -0
- package/dist/component/payoutWorker/queries.js.map +1 -0
- package/dist/component/payoutWorker/schema.d.ts +91 -0
- package/dist/component/payoutWorker/schema.d.ts.map +1 -0
- package/dist/component/payoutWorker/schema.js +27 -0
- package/dist/component/payoutWorker/schema.js.map +1 -0
- package/dist/component/schema.d.ts +479 -1
- package/dist/component/schema.js +19 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/settlement/clawbackSchema.d.ts +161 -0
- package/dist/component/settlement/clawbackSchema.d.ts.map +1 -0
- package/dist/component/settlement/clawbackSchema.js +73 -0
- package/dist/component/settlement/clawbackSchema.js.map +1 -0
- package/dist/component/settlement/clawbacks.d.ts +55 -0
- package/dist/component/settlement/clawbacks.d.ts.map +1 -0
- package/dist/component/settlement/clawbacks.js +146 -0
- package/dist/component/settlement/clawbacks.js.map +1 -0
- package/dist/component/settlement/mutations.d.ts +16 -0
- package/dist/component/settlement/mutations.d.ts.map +1 -1
- package/dist/component/settlement/mutations.js +48 -0
- package/dist/component/settlement/mutations.js.map +1 -1
- package/dist/component/settlement/queries.d.ts +53 -0
- package/dist/component/settlement/queries.d.ts.map +1 -1
- package/dist/component/settlement/queries.js +26 -0
- package/dist/component/settlement/queries.js.map +1 -1
- package/dist/react/workflows/AffiliateRecovery.d.ts +46 -0
- package/dist/react/workflows/AffiliateRecovery.d.ts.map +1 -0
- package/dist/react/workflows/AffiliateRecovery.js +84 -0
- package/dist/react/workflows/AffiliateRecovery.js.map +1 -0
- package/dist/react/workflows/index.d.ts +2 -0
- package/dist/react/workflows/index.d.ts.map +1 -1
- package/dist/react/workflows/index.js +1 -0
- package/dist/react/workflows/index.js.map +1 -1
- package/dist/testing/affiliate-recovery.d.ts +10 -0
- package/dist/testing/affiliate-recovery.d.ts.map +1 -0
- package/dist/testing/affiliate-recovery.js +126 -0
- package/dist/testing/affiliate-recovery.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/docs/affiliate-clawbacks.md +306 -0
- package/docs/read-contracts.md +48 -0
- package/docs/settlement.md +145 -1
- package/package.json +2 -1
- package/src/client/affiliateRecovery/disputes.ts +62 -0
- package/src/client/affiliateRecovery/engine.ts +196 -0
- package/src/client/affiliateRecovery/payoutGate.ts +65 -0
- package/src/client/affiliateRecovery/provider.ts +127 -0
- package/src/client/affiliateRecovery/review.ts +117 -0
- package/src/client/affiliateRecovery/validators.ts +38 -0
- package/src/client/affiliateRecovery.ts +173 -0
- package/src/client/billing/checkout.ts +11 -359
- package/src/client/billing/checkoutRequest.ts +362 -0
- package/src/client/billing/prepared-checkout.test.ts +430 -0
- package/src/client/billing/preparedCheckout.ts +143 -0
- package/src/client/checkoutRequests.ts +40 -0
- package/src/client/connect/commissionReceipts.test.ts +157 -0
- package/src/client/connect/commissionReceipts.ts +23 -0
- package/src/client/connect/payoutCollection.test.ts +74 -0
- package/src/client/connect/payoutCollection.ts +82 -0
- package/src/client/connect/payoutExecution.test.ts +1 -211
- package/src/client/connect/payoutExecutionTestHelpers.ts +213 -0
- package/src/client/connect/payoutWorker.test.ts +145 -0
- package/src/client/connect/payoutWorker.ts +144 -0
- package/src/client/connect/payouts.ts +75 -15
- package/src/client/connect/refundPrincipal.test.ts +46 -0
- package/src/client/connect/refundPrincipal.ts +26 -0
- package/src/client/connect/reversalExecution.ts +130 -0
- package/src/client/connect/transfers.test.ts +3 -3
- package/src/client/connect/transfers.ts +93 -92
- package/src/client/index.ts +16 -28
- package/src/client/payoutPolicy.ts +26 -1
- package/src/client/readContracts.ts +23 -0
- package/src/client/settlement/execution.test.ts +5 -0
- package/src/client/settlement/execution.ts +50 -3
- package/src/client/settlement/reconciliation.ts +20 -2
- package/src/client/webhooks/disputeRecovery.ts +74 -0
- package/src/client/webhooks/processors.test.ts +36 -53
- package/src/client/webhooks/processors.ts +18 -31
- package/src/component/_generated/api.ts +40 -0
- package/src/component/_generated/component.ts +975 -1
- package/src/component/affiliate-clawbacks.test.ts +370 -0
- package/src/component/affiliate-component-pagination.test.ts +83 -0
- package/src/component/affiliate-direct-payout.test.ts +160 -0
- package/src/component/affiliate-recovery-lifecycle.test.ts +587 -0
- package/src/component/affiliateEarnings/mutations.ts +196 -0
- package/src/component/affiliatePayouts/mutations.ts +121 -0
- package/src/component/affiliatePayouts/queries.ts +28 -0
- package/src/component/affiliatePayouts/recipientGuard.ts +42 -0
- package/src/component/affiliateRecovery/accounting.ts +111 -0
- package/src/component/affiliateRecovery/mutations.ts +275 -0
- package/src/component/affiliateRecovery/queries.ts +138 -0
- package/src/component/affiliateRecovery/schema.ts +86 -0
- package/src/component/connect/mutations.ts +9 -160
- package/src/component/connect/queries.ts +4 -47
- package/src/component/connect/reversalClaims.ts +232 -0
- package/src/component/connect/reversalDiagnostics.ts +61 -0
- package/src/component/connect/reversalReceipts.ts +147 -0
- package/src/component/connect/schema.ts +3 -3
- package/src/component/connect/validators.ts +2 -0
- package/src/component/core/mutations.ts +2 -0
- package/src/component/core/resetSafety.ts +67 -0
- package/src/component/earnings/triggers.ts +2 -0
- package/src/component/payout-recovery-integration.test.ts +172 -0
- package/src/component/payout-reset-safety.test.ts +148 -0
- package/src/component/payout-revisions.test.ts +125 -0
- package/src/component/payout-snapshots.test.ts +395 -0
- package/src/component/payout-worker.test.ts +165 -0
- package/src/component/payoutPolicy/schema.ts +3 -1
- package/src/component/payoutRelease/mutations.ts +10 -1
- package/src/component/payoutRelease/queries.ts +3 -1
- package/src/component/payoutRelease/schema.ts +1 -0
- package/src/component/payoutSnapshots/localState.ts +238 -0
- package/src/component/payoutSnapshots/mutations.ts +275 -0
- package/src/component/payoutSnapshots/revisions.ts +247 -0
- package/src/component/payoutSnapshots/schema.ts +125 -0
- package/src/component/payoutSnapshots/scope.ts +7 -0
- package/src/component/payoutWorker/helpers.ts +30 -0
- package/src/component/payoutWorker/mutations.ts +181 -0
- package/src/component/payoutWorker/queries.ts +64 -0
- package/src/component/payoutWorker/schema.ts +26 -0
- package/src/component/public.test.ts +2 -2
- package/src/component/schema.ts +36 -0
- package/src/component/settlement/clawbackSchema.ts +78 -0
- package/src/component/settlement/clawbacks.ts +233 -0
- package/src/component/settlement/mutations.ts +54 -0
- package/src/component/settlement/queries.ts +35 -0
- package/src/component/summary-arithmetic.test.ts +9 -4
- package/src/react/workflows/AffiliateRecovery.test.tsx +106 -0
- package/src/react/workflows/AffiliateRecovery.tsx +273 -0
- package/src/react/workflows/index.ts +9 -0
- package/src/testing/affiliate-recovery.ts +137 -0
- package/src/testing/index.ts +2 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { reclaimReversalClaim } from "./transfers.js";
|
|
2
|
+
import type Stripe from "stripe";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { findCommissionReversal } from "./commissionReceipts.js";
|
|
5
|
+
import { executeClaimedSlices } from "./reversalExecution.js";
|
|
6
|
+
import type { Component, RunCtx } from "../helpers.js";
|
|
7
|
+
|
|
8
|
+
const component = new Proxy(
|
|
9
|
+
{},
|
|
10
|
+
{
|
|
11
|
+
get: (_t, p) =>
|
|
12
|
+
p === Symbol.for("toReferencePath") ? "betterStripe" : component,
|
|
13
|
+
},
|
|
14
|
+
) as Component;
|
|
15
|
+
const claim = {
|
|
16
|
+
replay: false,
|
|
17
|
+
slices: [
|
|
18
|
+
{
|
|
19
|
+
stripeTransferId: "tr_1",
|
|
20
|
+
from: 0,
|
|
21
|
+
to: 501,
|
|
22
|
+
confirmed: 0,
|
|
23
|
+
commissionTracked: true,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
const fixture = () => {
|
|
28
|
+
const receipts: {
|
|
29
|
+
id: string;
|
|
30
|
+
amount: number;
|
|
31
|
+
metadata: Record<string, string>;
|
|
32
|
+
}[] = [];
|
|
33
|
+
const stripe = {
|
|
34
|
+
transfers: {
|
|
35
|
+
createReversal: vi.fn(
|
|
36
|
+
async (
|
|
37
|
+
_id: string,
|
|
38
|
+
params: { amount: number; metadata: Record<string, string> },
|
|
39
|
+
) => {
|
|
40
|
+
const receipt = { id: "trr_1", ...params };
|
|
41
|
+
receipts.push(receipt);
|
|
42
|
+
return receipt;
|
|
43
|
+
},
|
|
44
|
+
),
|
|
45
|
+
listReversals: vi.fn(() =>
|
|
46
|
+
(async function* () {
|
|
47
|
+
yield* receipts;
|
|
48
|
+
})(),
|
|
49
|
+
),
|
|
50
|
+
retrieve: vi.fn(),
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const ctx = { runMutation: vi.fn().mockResolvedValue(null) };
|
|
54
|
+
const run = (replay = false, confirmed = 0) =>
|
|
55
|
+
executeClaimedSlices(
|
|
56
|
+
stripe as unknown as Stripe,
|
|
57
|
+
component,
|
|
58
|
+
ctx as unknown as RunCtx,
|
|
59
|
+
"re_1",
|
|
60
|
+
{ ...claim, replay, slices: [{ ...claim.slices[0], confirmed }] },
|
|
61
|
+
);
|
|
62
|
+
return { stripe, ctx, receipts, run };
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
describe("commission reversal receipt reconciliation", () => {
|
|
66
|
+
it("recovers a provider success after the ledger confirmation crashed, even beyond the idempotency window", async () => {
|
|
67
|
+
const f = fixture();
|
|
68
|
+
f.ctx.runMutation.mockRejectedValueOnce(new Error("ledger offline"));
|
|
69
|
+
await expect(f.run()).rejects.toThrow("ledger offline");
|
|
70
|
+
expect(f.receipts).toHaveLength(1);
|
|
71
|
+
await f.run(true);
|
|
72
|
+
await f.run(true, 501);
|
|
73
|
+
expect(f.stripe.transfers.createReversal).toHaveBeenCalledTimes(1);
|
|
74
|
+
expect(f.ctx.runMutation).toHaveBeenLastCalledWith(expect.anything(), {
|
|
75
|
+
stripeTransferId: "tr_1",
|
|
76
|
+
reversedAmount: 501,
|
|
77
|
+
receipt: { stripeReversalId: "trr_1", operationId: "re_1", amount: 501 },
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("does not mistake another operation's aggregate reversal for this receipt", async () => {
|
|
82
|
+
const f = fixture();
|
|
83
|
+
f.receipts.push({
|
|
84
|
+
id: "trr_other",
|
|
85
|
+
amount: 501,
|
|
86
|
+
metadata: { bsReversalOperation: "re_other" },
|
|
87
|
+
});
|
|
88
|
+
await expect(f.run(true, 501)).rejects.toThrow(
|
|
89
|
+
"requires receipt reconciliation",
|
|
90
|
+
);
|
|
91
|
+
expect(f.stripe.transfers.retrieve).not.toHaveBeenCalled();
|
|
92
|
+
expect(f.stripe.transfers.createReversal).not.toHaveBeenCalled();
|
|
93
|
+
expect(f.ctx.runMutation).not.toHaveBeenCalled();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("retries a failed provider attempt with byte-identical parameters and operation identity", async () => {
|
|
97
|
+
const f = fixture();
|
|
98
|
+
f.stripe.transfers.createReversal.mockRejectedValueOnce(
|
|
99
|
+
new Error("network offline"),
|
|
100
|
+
);
|
|
101
|
+
await expect(f.run()).rejects.toThrow("network offline");
|
|
102
|
+
await f.run(true);
|
|
103
|
+
expect(f.stripe.transfers.createReversal.mock.calls[0]).toEqual(
|
|
104
|
+
f.stripe.transfers.createReversal.mock.calls[1],
|
|
105
|
+
);
|
|
106
|
+
expect(f.receipts).toHaveLength(1);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("rejects a mismatching receipt amount without confirming money", async () => {
|
|
110
|
+
const f = fixture();
|
|
111
|
+
f.receipts.push({
|
|
112
|
+
id: "trr_bad",
|
|
113
|
+
amount: 500,
|
|
114
|
+
metadata: { bsReversalOperation: "re_1" },
|
|
115
|
+
});
|
|
116
|
+
await expect(f.run(true)).rejects.toThrow("amount mismatch");
|
|
117
|
+
expect(f.ctx.runMutation).not.toHaveBeenCalled();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("fails explicitly when the bounded receipt search cannot establish success", async () => {
|
|
121
|
+
const f = fixture();
|
|
122
|
+
for (let i = 0; i < 1001; i++)
|
|
123
|
+
f.receipts.push({ id: `trr_${i}`, amount: 1, metadata: {} });
|
|
124
|
+
await expect(
|
|
125
|
+
findCommissionReversal(
|
|
126
|
+
f.stripe as unknown as Stripe,
|
|
127
|
+
"tr_1",
|
|
128
|
+
"re_1",
|
|
129
|
+
501,
|
|
130
|
+
),
|
|
131
|
+
).rejects.toThrow("lookup limit exceeded");
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("operator re-execution delegates tracked commissions to the durable recovery engine", async () => {
|
|
136
|
+
const f = fixture();
|
|
137
|
+
const runQuery = vi
|
|
138
|
+
.fn()
|
|
139
|
+
.mockResolvedValueOnce({
|
|
140
|
+
operationId: "re_1",
|
|
141
|
+
sourceChargeId: "ch_1",
|
|
142
|
+
_creationTime: 0,
|
|
143
|
+
slices: [{ stripeTransferId: "tr_1", from: 0, to: 501 }],
|
|
144
|
+
commissionExposure: { kind: "refund" },
|
|
145
|
+
})
|
|
146
|
+
.mockResolvedValueOnce({ role: "affiliate", reversedAmount: 0 });
|
|
147
|
+
await reclaimReversalClaim(
|
|
148
|
+
f.stripe as unknown as Stripe,
|
|
149
|
+
component,
|
|
150
|
+
{ ...f.ctx, runQuery } as unknown as RunCtx,
|
|
151
|
+
{ operationId: "re_1" },
|
|
152
|
+
);
|
|
153
|
+
expect(f.stripe.transfers.createReversal).not.toHaveBeenCalled();
|
|
154
|
+
expect(runQuery).toHaveBeenLastCalledWith(expect.anything(), {
|
|
155
|
+
sourceChargeId: "ch_1",
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
|
|
3
|
+
/** Locate the exact receipt, never infer operation success from an aggregate. */
|
|
4
|
+
export async function findCommissionReversal(
|
|
5
|
+
stripe: Stripe,
|
|
6
|
+
stripeTransferId: string,
|
|
7
|
+
operationId: string,
|
|
8
|
+
amount: number,
|
|
9
|
+
) {
|
|
10
|
+
let count = 0;
|
|
11
|
+
for await (const receipt of stripe.transfers.listReversals(stripeTransferId, {
|
|
12
|
+
limit: 100,
|
|
13
|
+
})) {
|
|
14
|
+
if (++count > 1000)
|
|
15
|
+
throw new Error("Commission reversal receipt lookup limit exceeded.");
|
|
16
|
+
if (receipt.metadata?.bsReversalOperation === operationId) {
|
|
17
|
+
if (receipt.amount !== amount)
|
|
18
|
+
throw new Error("Commission reversal receipt amount mismatch.");
|
|
19
|
+
return receipt;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// @vitest-environment edge-runtime
|
|
2
|
+
import { convexTest } from "convex-test";
|
|
3
|
+
import { makeFunctionReference } from "convex/server";
|
|
4
|
+
import { expect, it, vi } from "vitest";
|
|
5
|
+
import schema from "../../component/schema.js";
|
|
6
|
+
import type { Component, RunCtx } from "../helpers.js";
|
|
7
|
+
import { PayoutPolicyClient } from "../payoutPolicy.js";
|
|
8
|
+
const modules = import.meta.glob("../../component/**/*.*s");
|
|
9
|
+
const symbol = Symbol.for("toReferencePath");
|
|
10
|
+
const component = {
|
|
11
|
+
payoutPolicy: {
|
|
12
|
+
queries: { get: { [symbol]: "betterStripe/payoutPolicy/queries/get" } },
|
|
13
|
+
},
|
|
14
|
+
} as unknown as Component;
|
|
15
|
+
it("collects, resumes and discards local account state through the public API without Stripe I/O", async () => {
|
|
16
|
+
const t = convexTest(schema, modules);
|
|
17
|
+
await t.run(async (ctx) => {
|
|
18
|
+
for (let i = 0; i < 205; i++)
|
|
19
|
+
await ctx.db.insert("transfers", {
|
|
20
|
+
stripeTransferId: `tr_${i}`,
|
|
21
|
+
destinationAccountId: "acct_one",
|
|
22
|
+
amount: 1000,
|
|
23
|
+
currency: "usd",
|
|
24
|
+
role: "store",
|
|
25
|
+
status: "paid",
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
const path = (r: Record<symbol, string>) =>
|
|
29
|
+
r[symbol].replace("betterStripe/", "").replace(/\/(\w+)$/, ":$1");
|
|
30
|
+
const ctx = {
|
|
31
|
+
runQuery: (r: Record<symbol, string>, args: never) =>
|
|
32
|
+
t.query(makeFunctionReference<"query">(path(r)), args),
|
|
33
|
+
runMutation: (r: Record<symbol, string>, args: never) =>
|
|
34
|
+
t.mutation(makeFunctionReference<"mutation">(path(r)), args),
|
|
35
|
+
} as unknown as RunCtx;
|
|
36
|
+
const provider = vi.fn(() => {
|
|
37
|
+
throw Error("Unexpected provider I/O");
|
|
38
|
+
});
|
|
39
|
+
const client = new PayoutPolicyClient(component, provider);
|
|
40
|
+
const opts = {
|
|
41
|
+
accountId: "acct_one",
|
|
42
|
+
ownerKey: "owner",
|
|
43
|
+
operationKey: "read-only",
|
|
44
|
+
expectedRevision: -1,
|
|
45
|
+
currency: "usd",
|
|
46
|
+
};
|
|
47
|
+
let state = await client.collectSnapshot(ctx, opts);
|
|
48
|
+
for (
|
|
49
|
+
let i = 0;
|
|
50
|
+
i < 100 && state.phase !== "local_ready" && state.phase !== "invalidated";
|
|
51
|
+
i++
|
|
52
|
+
)
|
|
53
|
+
state = await client.collectSnapshot(ctx, {
|
|
54
|
+
...opts,
|
|
55
|
+
expectedStep: state.step,
|
|
56
|
+
});
|
|
57
|
+
expect(state).toMatchObject({
|
|
58
|
+
phase: "local_ready",
|
|
59
|
+
readOnly: true,
|
|
60
|
+
sourceCount: 205,
|
|
61
|
+
});
|
|
62
|
+
expect(state).not.toHaveProperty("amount");
|
|
63
|
+
let cleanup = await client.discardSnapshot(ctx, opts);
|
|
64
|
+
for (let i = 0; i < 100 && cleanup; i++)
|
|
65
|
+
cleanup = await client.discardSnapshot(ctx, opts);
|
|
66
|
+
expect(cleanup).toBeNull();
|
|
67
|
+
expect(provider).not.toHaveBeenCalled();
|
|
68
|
+
expect(
|
|
69
|
+
await t.run((ctx) => ctx.db.query("payoutSnapshotSources").collect()),
|
|
70
|
+
).toEqual([]);
|
|
71
|
+
expect(
|
|
72
|
+
await t.run((ctx) => ctx.db.query("transfers").collect()),
|
|
73
|
+
).toHaveLength(205);
|
|
74
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Infer } from "convex/values";
|
|
2
|
+
import type { snapshotDoc } from "../../component/payoutSnapshots/schema.js";
|
|
3
|
+
import type { Component, RunCtx } from "../helpers.js";
|
|
4
|
+
import { runMutationOrThrow } from "../helpers.js";
|
|
5
|
+
import { componentRef } from "../webhooks/helpers.js";
|
|
6
|
+
import { validateIdentity } from "../../component/payoutRelease/helpers.js";
|
|
7
|
+
export type PayoutCollectionState = Infer<typeof snapshotDoc>;
|
|
8
|
+
export type PayoutCollectionScope = {
|
|
9
|
+
accountId: string;
|
|
10
|
+
ownerKey: string;
|
|
11
|
+
operationKey: string;
|
|
12
|
+
};
|
|
13
|
+
export type PayoutCollectionOptions = PayoutCollectionScope & {
|
|
14
|
+
expectedRevision: number;
|
|
15
|
+
expectedStep?: number;
|
|
16
|
+
batchSize?: number;
|
|
17
|
+
};
|
|
18
|
+
/** Resume one bounded local-ledger step. local_ready does not authorize a payout. */
|
|
19
|
+
export async function collectPayoutSnapshot(
|
|
20
|
+
component: Component,
|
|
21
|
+
ctx: RunCtx,
|
|
22
|
+
opts: PayoutCollectionOptions,
|
|
23
|
+
): Promise<PayoutCollectionState> {
|
|
24
|
+
validateIdentity(opts);
|
|
25
|
+
if (
|
|
26
|
+
!Number.isSafeInteger(opts.expectedRevision) ||
|
|
27
|
+
opts.expectedRevision < -1 ||
|
|
28
|
+
(opts.expectedStep !== undefined &&
|
|
29
|
+
(!Number.isSafeInteger(opts.expectedStep) || opts.expectedStep < 0)) ||
|
|
30
|
+
(opts.batchSize !== undefined &&
|
|
31
|
+
(!Number.isInteger(opts.batchSize) ||
|
|
32
|
+
opts.batchSize < 1 ||
|
|
33
|
+
opts.batchSize > 25))
|
|
34
|
+
)
|
|
35
|
+
throw new Error("Invalid local collection revision, step or batch.");
|
|
36
|
+
const scope = {
|
|
37
|
+
accountId: opts.accountId,
|
|
38
|
+
ownerKey: opts.ownerKey,
|
|
39
|
+
operationKey: opts.operationKey,
|
|
40
|
+
};
|
|
41
|
+
const state = (await runMutationOrThrow(
|
|
42
|
+
ctx,
|
|
43
|
+
componentRef(component, "payoutSnapshots/mutations/begin"),
|
|
44
|
+
{ ...scope, expectedRevision: opts.expectedRevision },
|
|
45
|
+
)) as PayoutCollectionState;
|
|
46
|
+
if (!state.readOnly) throw new Error("Collection is financially bound.");
|
|
47
|
+
if (opts.expectedStep === undefined) return state;
|
|
48
|
+
return (await runMutationOrThrow(
|
|
49
|
+
ctx,
|
|
50
|
+
componentRef(component, "payoutSnapshots/mutations/advance"),
|
|
51
|
+
{
|
|
52
|
+
...scope,
|
|
53
|
+
expectedStep: opts.expectedStep,
|
|
54
|
+
...(opts.batchSize !== undefined ? { batchSize: opts.batchSize } : {}),
|
|
55
|
+
},
|
|
56
|
+
)) as PayoutCollectionState;
|
|
57
|
+
}
|
|
58
|
+
/** Delete only read-only cache state in bounded batches; never financial records. */
|
|
59
|
+
export async function discardPayoutSnapshot(
|
|
60
|
+
component: Component,
|
|
61
|
+
ctx: RunCtx,
|
|
62
|
+
opts: PayoutCollectionScope & { batchSize?: number },
|
|
63
|
+
): Promise<PayoutCollectionState | null> {
|
|
64
|
+
validateIdentity(opts);
|
|
65
|
+
if (
|
|
66
|
+
opts.batchSize !== undefined &&
|
|
67
|
+
(!Number.isInteger(opts.batchSize) ||
|
|
68
|
+
opts.batchSize < 1 ||
|
|
69
|
+
opts.batchSize > 100)
|
|
70
|
+
)
|
|
71
|
+
throw new Error("Invalid collection cleanup batch.");
|
|
72
|
+
return (await runMutationOrThrow(
|
|
73
|
+
ctx,
|
|
74
|
+
componentRef(component, "payoutSnapshots/mutations/discard"),
|
|
75
|
+
{
|
|
76
|
+
accountId: opts.accountId,
|
|
77
|
+
ownerKey: opts.ownerKey,
|
|
78
|
+
operationKey: opts.operationKey,
|
|
79
|
+
...(opts.batchSize !== undefined ? { batchSize: opts.batchSize } : {}),
|
|
80
|
+
},
|
|
81
|
+
)) as PayoutCollectionState | null;
|
|
82
|
+
}
|
|
@@ -1,216 +1,6 @@
|
|
|
1
1
|
// @vitest-environment edge-runtime
|
|
2
|
-
import { convexTest } from "convex-test";
|
|
3
|
-
import { makeFunctionReference } from "convex/server";
|
|
4
2
|
import { expect, it, vi } from "vitest";
|
|
5
|
-
import
|
|
6
|
-
import schema from "../../component/schema.js";
|
|
7
|
-
import type { Component, RunCtx } from "../helpers.js";
|
|
8
|
-
import { releaseRecipientPayout } from "./payoutExecution.js";
|
|
9
|
-
const modules = import.meta.glob("../../component/**/*.*s");
|
|
10
|
-
const symbol = Symbol.for("toReferencePath");
|
|
11
|
-
const component = {
|
|
12
|
-
payoutPolicy: {
|
|
13
|
-
queries: { get: { [symbol]: "betterStripe/payoutPolicy/queries/get" } },
|
|
14
|
-
},
|
|
15
|
-
} as unknown as Component;
|
|
16
|
-
const scope = {
|
|
17
|
-
accountId: "acct_recipient",
|
|
18
|
-
ownerKey: "owner",
|
|
19
|
-
operationKey: "release-1",
|
|
20
|
-
currency: "usd",
|
|
21
|
-
independentLiabilities: 0,
|
|
22
|
-
};
|
|
23
|
-
async function setup(amounts = [600, 400]) {
|
|
24
|
-
const t = convexTest(schema, modules);
|
|
25
|
-
await t.run(async (ctx) => {
|
|
26
|
-
await ctx.db.insert("payoutPolicies", {
|
|
27
|
-
accountId: scope.accountId,
|
|
28
|
-
ownerKey: scope.ownerKey,
|
|
29
|
-
mode: "custom",
|
|
30
|
-
status: "ready",
|
|
31
|
-
revision: 0,
|
|
32
|
-
operationKey: "enable",
|
|
33
|
-
country: "US",
|
|
34
|
-
thresholds: [{ currency: "usd", amount: 1000 }],
|
|
35
|
-
holdDeadline: Date.now() + 86400000,
|
|
36
|
-
});
|
|
37
|
-
for (let i = 0; i < amounts.length; i++)
|
|
38
|
-
await ctx.db.insert("transfers", {
|
|
39
|
-
stripeTransferId: `tr_${i}`,
|
|
40
|
-
destinationAccountId: scope.accountId,
|
|
41
|
-
sourceChargeId: `ch_${i}`,
|
|
42
|
-
amount: amounts[i],
|
|
43
|
-
currency: "usd",
|
|
44
|
-
status: "paid",
|
|
45
|
-
role: i % 2 ? "affiliate" : "store",
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
const path = (ref: Record<symbol, string>) =>
|
|
49
|
-
ref[symbol].replace("betterStripe/", "").replace(/\/(\w+)$/, ":$1");
|
|
50
|
-
const ctx = {
|
|
51
|
-
runQuery: (ref: Record<symbol, string>, args: never) =>
|
|
52
|
-
t.query(makeFunctionReference<"query">(path(ref)), args),
|
|
53
|
-
runMutation: (ref: Record<symbol, string>, args: never) =>
|
|
54
|
-
t.mutation(makeFunctionReference<"mutation">(path(ref)), args),
|
|
55
|
-
} as unknown as RunCtx;
|
|
56
|
-
let transactions = amounts.map((amount, i) => ({
|
|
57
|
-
id: `txn_${i}`,
|
|
58
|
-
source: `py_${i}`,
|
|
59
|
-
amount,
|
|
60
|
-
fee: 0,
|
|
61
|
-
net: amount,
|
|
62
|
-
currency: "usd",
|
|
63
|
-
created: 100,
|
|
64
|
-
available_on: 200,
|
|
65
|
-
status: "available",
|
|
66
|
-
type: "payment",
|
|
67
|
-
exchange_rate: null,
|
|
68
|
-
}));
|
|
69
|
-
let payout: Record<string, unknown> | undefined;
|
|
70
|
-
const provider = {
|
|
71
|
-
accounts: {
|
|
72
|
-
listExternalAccounts: vi.fn(async () => ({
|
|
73
|
-
data: [
|
|
74
|
-
{
|
|
75
|
-
id: "ba_one",
|
|
76
|
-
object: "bank_account",
|
|
77
|
-
currency: "usd",
|
|
78
|
-
default_for_currency: true,
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
has_more: false,
|
|
82
|
-
})),
|
|
83
|
-
},
|
|
84
|
-
transfers: {
|
|
85
|
-
retrieve: vi.fn(async (id: string) => {
|
|
86
|
-
const i = Number(id.slice(3));
|
|
87
|
-
return {
|
|
88
|
-
id,
|
|
89
|
-
destination: scope.accountId,
|
|
90
|
-
destination_payment: `py_${i}`,
|
|
91
|
-
source_transaction: `ch_${i}`,
|
|
92
|
-
amount: amounts[i],
|
|
93
|
-
currency: "usd",
|
|
94
|
-
amount_reversed: 0,
|
|
95
|
-
};
|
|
96
|
-
}),
|
|
97
|
-
listReversals: vi.fn(async () => ({ data: [], has_more: false })),
|
|
98
|
-
},
|
|
99
|
-
charges: {
|
|
100
|
-
retrieve: vi.fn(async (id: string) => {
|
|
101
|
-
const i = Number(id.slice(3));
|
|
102
|
-
return {
|
|
103
|
-
id,
|
|
104
|
-
source_transfer: `tr_${i}`,
|
|
105
|
-
amount: amounts[i],
|
|
106
|
-
currency: "usd",
|
|
107
|
-
paid: true,
|
|
108
|
-
status: "succeeded",
|
|
109
|
-
balance_transaction: `txn_${i}`,
|
|
110
|
-
};
|
|
111
|
-
}),
|
|
112
|
-
},
|
|
113
|
-
balanceTransactions: {
|
|
114
|
-
list: vi.fn(async (params: { source?: string; limit?: number }) => ({
|
|
115
|
-
data: params.source
|
|
116
|
-
? transactions.filter((t) => t.source === params.source)
|
|
117
|
-
: transactions.slice(0, params.limit),
|
|
118
|
-
has_more: false,
|
|
119
|
-
})),
|
|
120
|
-
retrieve: vi.fn(async (id: string) =>
|
|
121
|
-
transactions.find((t) => t.id === id),
|
|
122
|
-
),
|
|
123
|
-
},
|
|
124
|
-
balance: {
|
|
125
|
-
retrieve: vi.fn(async () => ({
|
|
126
|
-
available: [
|
|
127
|
-
{
|
|
128
|
-
currency: "usd",
|
|
129
|
-
amount: transactions
|
|
130
|
-
.filter((t) => t.status === "available")
|
|
131
|
-
.reduce((a, t) => a + t.net, 0),
|
|
132
|
-
source_types: {
|
|
133
|
-
card: transactions
|
|
134
|
-
.filter((t) => t.status === "available")
|
|
135
|
-
.reduce((a, t) => a + t.net, 0),
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
pending: [],
|
|
140
|
-
})),
|
|
141
|
-
},
|
|
142
|
-
payouts: {
|
|
143
|
-
list: vi.fn(async () => ({
|
|
144
|
-
data: payout ? [payout] : [],
|
|
145
|
-
has_more: false,
|
|
146
|
-
})),
|
|
147
|
-
retrieve: vi.fn(async () => payout),
|
|
148
|
-
create: vi.fn(
|
|
149
|
-
async (params: {
|
|
150
|
-
amount: number;
|
|
151
|
-
currency: string;
|
|
152
|
-
metadata: object;
|
|
153
|
-
}) => {
|
|
154
|
-
payout = {
|
|
155
|
-
id: "po_one",
|
|
156
|
-
...params,
|
|
157
|
-
status: "paid",
|
|
158
|
-
automatic: false,
|
|
159
|
-
method: "standard",
|
|
160
|
-
type: "bank_account",
|
|
161
|
-
source_type: "card",
|
|
162
|
-
destination: "ba_one",
|
|
163
|
-
created: Math.floor(Date.now() / 1000),
|
|
164
|
-
arrival_date: Math.floor(Date.now() / 1000),
|
|
165
|
-
balance_transaction: "txn_debit",
|
|
166
|
-
failure_balance_transaction: null,
|
|
167
|
-
reversed_by: null,
|
|
168
|
-
};
|
|
169
|
-
transactions = [
|
|
170
|
-
{
|
|
171
|
-
id: "txn_debit",
|
|
172
|
-
source: "po_one",
|
|
173
|
-
amount: -params.amount,
|
|
174
|
-
fee: 0,
|
|
175
|
-
net: -params.amount,
|
|
176
|
-
currency: "usd",
|
|
177
|
-
created: Math.floor(Date.now() / 1000),
|
|
178
|
-
available_on: Math.floor(Date.now() / 1000),
|
|
179
|
-
status: "available",
|
|
180
|
-
type: "payout",
|
|
181
|
-
exchange_rate: null,
|
|
182
|
-
},
|
|
183
|
-
...transactions,
|
|
184
|
-
];
|
|
185
|
-
return payout;
|
|
186
|
-
},
|
|
187
|
-
),
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
const verify = vi.fn(async () => ({
|
|
191
|
-
status: "verified" as const,
|
|
192
|
-
policy: (await t.run((ctx) => ctx.db.query("payoutPolicies").first()))!,
|
|
193
|
-
}));
|
|
194
|
-
const run = (extra = {}) =>
|
|
195
|
-
releaseRecipientPayout(
|
|
196
|
-
provider as unknown as Stripe,
|
|
197
|
-
component,
|
|
198
|
-
ctx,
|
|
199
|
-
{ ...scope, ...extra },
|
|
200
|
-
verify,
|
|
201
|
-
);
|
|
202
|
-
return {
|
|
203
|
-
t,
|
|
204
|
-
ctx,
|
|
205
|
-
provider,
|
|
206
|
-
verify,
|
|
207
|
-
run,
|
|
208
|
-
setTransactions: (rows: typeof transactions) => {
|
|
209
|
-
transactions = rows;
|
|
210
|
-
},
|
|
211
|
-
transactions: () => transactions,
|
|
212
|
-
};
|
|
213
|
-
}
|
|
3
|
+
import { setup, scope } from "./payoutExecutionTestHelpers.js";
|
|
214
4
|
it("automatically releases combined creator and affiliate funds exactly once", async () => {
|
|
215
5
|
const s = await setup();
|
|
216
6
|
expect(await s.run()).toMatchObject({
|