@fantastic.dev/better-stripe 0.28.6 → 0.30.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 +16 -0
- package/MIGRATION.md +14 -0
- package/README.md +7 -1
- package/dist/client/connect/payoutActivationProof.d.ts.map +1 -1
- package/dist/client/connect/payoutActivationProof.js +88 -42
- package/dist/client/connect/payoutActivationProof.js.map +1 -1
- package/dist/client/connect/payoutAdoption.d.ts +3 -0
- package/dist/client/connect/payoutAdoption.d.ts.map +1 -1
- package/dist/client/connect/payoutAdoption.js +218 -183
- package/dist/client/connect/payoutAdoption.js.map +1 -1
- package/dist/client/connect/payoutAdoptionCollection.d.ts +21 -0
- package/dist/client/connect/payoutAdoptionCollection.d.ts.map +1 -0
- package/dist/client/connect/payoutAdoptionCollection.js +44 -0
- package/dist/client/connect/payoutAdoptionCollection.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +54 -14
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutCollectedInput.d.ts +110 -0
- package/dist/client/connect/payoutCollectedInput.d.ts.map +1 -0
- package/dist/client/connect/payoutCollectedInput.js +70 -0
- package/dist/client/connect/payoutCollectedInput.js.map +1 -0
- package/dist/client/connect/payoutExecution.d.ts +1 -0
- package/dist/client/connect/payoutExecution.d.ts.map +1 -1
- package/dist/client/connect/payoutExecution.js +94 -67
- package/dist/client/connect/payoutExecution.js.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +29 -7
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.js +9 -6
- package/dist/client/connect/payoutExecutionTestHelpers.js.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +3745 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.js +55 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.js.map +1 -0
- package/dist/client/connect/payoutOutcomeBatches.d.ts +5 -0
- package/dist/client/connect/payoutOutcomeBatches.d.ts.map +1 -0
- package/dist/client/connect/payoutOutcomeBatches.js +21 -0
- package/dist/client/connect/payoutOutcomeBatches.js.map +1 -0
- package/dist/client/connect/payoutPolicyState.d.ts +14 -0
- package/dist/client/connect/payoutPolicyState.d.ts.map +1 -0
- package/dist/client/connect/payoutPolicyState.js +19 -0
- package/dist/client/connect/payoutPolicyState.js.map +1 -0
- package/dist/client/connect/payoutPreview.d.ts +1 -0
- package/dist/client/connect/payoutPreview.d.ts.map +1 -1
- package/dist/client/connect/payoutPreview.js +31 -19
- package/dist/client/connect/payoutPreview.js.map +1 -1
- package/dist/client/connect/payoutQualification.d.ts +7 -1
- package/dist/client/connect/payoutQualification.d.ts.map +1 -1
- package/dist/client/connect/payoutQualification.js +34 -19
- package/dist/client/connect/payoutQualification.js.map +1 -1
- package/dist/client/connect/payoutReconciliation.d.ts +11 -6
- package/dist/client/connect/payoutReconciliation.d.ts.map +1 -1
- package/dist/client/connect/payoutReconciliation.js +62 -16
- package/dist/client/connect/payoutReconciliation.js.map +1 -1
- package/dist/client/connect/payoutResumableProof.d.ts +17 -0
- package/dist/client/connect/payoutResumableProof.d.ts.map +1 -0
- package/dist/client/connect/payoutResumableProof.js +25 -0
- package/dist/client/connect/payoutResumableProof.js.map +1 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +27 -7
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutWorker.d.ts.map +1 -1
- package/dist/client/connect/payoutWorker.js +4 -1
- package/dist/client/connect/payoutWorker.js.map +1 -1
- package/dist/client/connect/transferReceipt.d.ts +6 -2
- package/dist/client/connect/transferReceipt.d.ts.map +1 -1
- package/dist/client/connect/transferReceipt.js +3 -3
- package/dist/client/connect/transferReceipt.js.map +1 -1
- package/dist/client/costRecovery.d.ts +5 -0
- package/dist/client/costRecovery.d.ts.map +1 -1
- package/dist/client/costRecovery.js +5 -0
- package/dist/client/costRecovery.js.map +1 -1
- package/dist/client/payoutPolicy.d.ts +4 -0
- package/dist/client/payoutPolicy.d.ts.map +1 -1
- package/dist/client/payoutPolicy.js +24 -14
- package/dist/client/payoutPolicy.js.map +1 -1
- package/dist/component/_generated/component.d.ts +247 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/costRecovery/mutations.js +1 -1
- package/dist/component/costRecovery/queries.d.ts +9 -0
- package/dist/component/costRecovery/queries.d.ts.map +1 -1
- package/dist/component/costRecovery/queries.js +20 -0
- package/dist/component/costRecovery/queries.js.map +1 -1
- package/dist/component/earnings/triggers.d.ts +28 -10
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/payoutPolicy/adoption.d.ts.map +1 -1
- package/dist/component/payoutPolicy/adoption.js +12 -7
- package/dist/component/payoutPolicy/adoption.js.map +1 -1
- package/dist/component/payoutPolicy/mutations.d.ts +12 -0
- package/dist/component/payoutPolicy/mutations.d.ts.map +1 -1
- package/dist/component/payoutPolicy/queries.d.ts +2 -0
- package/dist/component/payoutPolicy/queries.d.ts.map +1 -1
- package/dist/component/payoutPolicy/schema.d.ts +31 -7
- package/dist/component/payoutPolicy/schema.d.ts.map +1 -1
- package/dist/component/payoutPolicy/schema.js +2 -0
- package/dist/component/payoutPolicy/schema.js.map +1 -1
- package/dist/component/payoutRelease/adoption.d.ts +9 -1
- package/dist/component/payoutRelease/adoption.d.ts.map +1 -1
- package/dist/component/payoutRelease/adoption.js +33 -16
- package/dist/component/payoutRelease/adoption.js.map +1 -1
- package/dist/component/payoutRelease/fees.d.ts.map +1 -1
- package/dist/component/payoutRelease/fees.js +7 -0
- package/dist/component/payoutRelease/fees.js.map +1 -1
- package/dist/component/payoutRelease/helpers.d.ts +4 -1
- package/dist/component/payoutRelease/helpers.d.ts.map +1 -1
- package/dist/component/payoutRelease/helpers.js +17 -10
- package/dist/component/payoutRelease/helpers.js.map +1 -1
- package/dist/component/payoutRelease/mutations.d.ts +79 -0
- package/dist/component/payoutRelease/mutations.d.ts.map +1 -1
- package/dist/component/payoutRelease/mutations.js +38 -81
- package/dist/component/payoutRelease/mutations.js.map +1 -1
- package/dist/component/payoutRelease/outcome.d.ts +69 -0
- package/dist/component/payoutRelease/outcome.d.ts.map +1 -0
- package/dist/component/payoutRelease/outcome.js +94 -0
- package/dist/component/payoutRelease/outcome.js.map +1 -0
- package/dist/component/payoutRelease/planning.d.ts +4 -0
- package/dist/component/payoutRelease/planning.d.ts.map +1 -1
- package/dist/component/payoutRelease/planning.js +8 -3
- package/dist/component/payoutRelease/planning.js.map +1 -1
- package/dist/component/payoutRelease/preview.d.ts +2 -0
- package/dist/component/payoutRelease/preview.d.ts.map +1 -1
- package/dist/component/payoutRelease/preview.js +2 -0
- package/dist/component/payoutRelease/preview.js.map +1 -1
- package/dist/component/payoutRelease/queries.d.ts +13 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/payoutRelease/queries.js +2 -0
- package/dist/component/payoutRelease/queries.js.map +1 -1
- package/dist/component/payoutRelease/schema.d.ts +17 -2
- package/dist/component/payoutRelease/schema.d.ts.map +1 -1
- package/dist/component/payoutRelease/schema.js +3 -0
- package/dist/component/payoutRelease/schema.js.map +1 -1
- package/dist/component/payoutSnapshots/adoption.d.ts +88 -0
- package/dist/component/payoutSnapshots/adoption.d.ts.map +1 -0
- package/dist/component/payoutSnapshots/adoption.js +49 -0
- package/dist/component/payoutSnapshots/adoption.js.map +1 -0
- package/dist/component/payoutSnapshots/financial.d.ts +47 -0
- package/dist/component/payoutSnapshots/financial.d.ts.map +1 -0
- package/dist/component/payoutSnapshots/financial.js +103 -0
- package/dist/component/payoutSnapshots/financial.js.map +1 -0
- package/dist/component/payoutSnapshots/liabilities.d.ts +7 -0
- package/dist/component/payoutSnapshots/liabilities.d.ts.map +1 -0
- package/dist/component/payoutSnapshots/liabilities.js +18 -0
- package/dist/component/payoutSnapshots/liabilities.js.map +1 -0
- package/dist/component/payoutSnapshots/localState.d.ts +22 -16
- package/dist/component/payoutSnapshots/localState.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/localState.js +19 -7
- package/dist/component/payoutSnapshots/localState.js.map +1 -1
- package/dist/component/payoutSnapshots/mutations.d.ts +6 -0
- package/dist/component/payoutSnapshots/mutations.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/mutations.js +3 -1
- package/dist/component/payoutSnapshots/mutations.js.map +1 -1
- package/dist/component/payoutSnapshots/queries.d.ts +133 -0
- package/dist/component/payoutSnapshots/queries.d.ts.map +1 -0
- package/dist/component/payoutSnapshots/queries.js +86 -0
- package/dist/component/payoutSnapshots/queries.js.map +1 -0
- package/dist/component/payoutSnapshots/revisions.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/revisions.js +19 -0
- package/dist/component/payoutSnapshots/revisions.js.map +1 -1
- package/dist/component/payoutSnapshots/schema.d.ts +20 -6
- package/dist/component/payoutSnapshots/schema.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/schema.js +5 -1
- package/dist/component/payoutSnapshots/schema.js.map +1 -1
- package/dist/component/payoutWorker/mutations.d.ts.map +1 -1
- package/dist/component/payoutWorker/mutations.js +3 -1
- package/dist/component/payoutWorker/mutations.js.map +1 -1
- package/dist/component/schema.d.ts +27 -7
- package/dist/react/workflows/payout-attempt-state.d.ts.map +1 -1
- package/dist/react/workflows/payout-attempt-state.js +3 -0
- package/dist/react/workflows/payout-attempt-state.js.map +1 -1
- package/dist/react/workflows/payout-progress-state.d.ts.map +1 -1
- package/dist/react/workflows/payout-progress-state.js +3 -0
- package/dist/react/workflows/payout-progress-state.js.map +1 -1
- package/docs/settlement.md +136 -24
- package/package.json +1 -1
- package/src/client/connect/payoutActivationProof.ts +123 -53
- package/src/client/connect/payoutAdoption.ts +299 -215
- package/src/client/connect/payoutAdoptionCollection.ts +78 -0
- package/src/client/connect/payoutAdoptionConcurrency.test.ts +266 -0
- package/src/client/connect/payoutCacheIdentity.test.ts +93 -0
- package/src/client/connect/payoutCollectedInput.ts +120 -0
- package/src/client/connect/payoutExecution.ts +116 -84
- package/src/client/connect/payoutExecutionTestHelpers.ts +19 -6
- package/src/client/connect/payoutLargeAdoption.test.ts +541 -0
- package/src/client/connect/payoutLargeAdoptionTestHelpers.ts +74 -0
- package/src/client/connect/payoutLargeHistory.test.ts +222 -0
- package/src/client/connect/payoutLiabilityVersion.test.ts +221 -0
- package/src/client/connect/payoutOutcomeBatches.test.ts +40 -0
- package/src/client/connect/payoutOutcomeBatches.ts +24 -0
- package/src/client/connect/payoutPolicyState.ts +36 -0
- package/src/client/connect/payoutPreview.ts +42 -24
- package/src/client/connect/payoutQualification.ts +68 -21
- package/src/client/connect/payoutReconciliation.ts +86 -7
- package/src/client/connect/payoutResumableProof.ts +41 -0
- package/src/client/connect/payoutWorker.ts +4 -1
- package/src/client/connect/transferReceipt.ts +3 -2
- package/src/client/connect/transferReceiptBaseline.test.ts +55 -0
- package/src/client/costRecovery.ts +8 -0
- package/src/client/payoutPolicy.ts +37 -23
- package/src/component/_generated/api.ts +10 -0
- package/src/component/_generated/component.ts +288 -0
- package/src/component/costRecovery/mutations.ts +1 -1
- package/src/component/costRecovery/queries.ts +21 -0
- package/src/component/payout-snapshots.test.ts +45 -1
- package/src/component/payoutPolicy/adoption.ts +20 -7
- package/src/component/payoutPolicy/schema.ts +2 -0
- package/src/component/payoutRelease/adoption.ts +57 -27
- package/src/component/payoutRelease/fees.ts +9 -0
- package/src/component/payoutRelease/helpers.ts +19 -11
- package/src/component/payoutRelease/mutations.ts +43 -96
- package/src/component/payoutRelease/outcome.ts +119 -0
- package/src/component/payoutRelease/planning.ts +11 -2
- package/src/component/payoutRelease/preview.ts +2 -0
- package/src/component/payoutRelease/queries.ts +2 -0
- package/src/component/payoutRelease/schema.ts +3 -0
- package/src/component/payoutSnapshots/adoption.ts +73 -0
- package/src/component/payoutSnapshots/financial.ts +134 -0
- package/src/component/payoutSnapshots/liabilities.ts +25 -0
- package/src/component/payoutSnapshots/localState.ts +24 -6
- package/src/component/payoutSnapshots/mutations.ts +10 -1
- package/src/component/payoutSnapshots/queries.ts +104 -0
- package/src/component/payoutSnapshots/revisions.ts +26 -0
- package/src/component/payoutSnapshots/schema.ts +5 -0
- package/src/component/payoutWorker/mutations.ts +3 -1
- package/src/react/workflows/payout-attempt-state.ts +6 -0
- package/src/react/workflows/payout-progress-state.ts +6 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { discardQualificationInput } from "./payoutCollectedInput.js";
|
|
1
2
|
import type Stripe from "stripe";
|
|
2
3
|
import type { Infer } from "convex/values";
|
|
3
4
|
import type { Component, RunCtx } from "../helpers.js";
|
|
@@ -20,6 +21,7 @@ export type PayoutReleaseOptions = {
|
|
|
20
21
|
currency: string;
|
|
21
22
|
/** Host supplies all authorized off-provider debts/reserves, without double counting provider receipt debits. */
|
|
22
23
|
independentLiabilities: number;
|
|
24
|
+
liabilityRevision?: number;
|
|
23
25
|
maxPages?: number;
|
|
24
26
|
};
|
|
25
27
|
type Held = { status: "held"; reason: string };
|
|
@@ -62,11 +64,20 @@ export async function releaseRecipientPayout(
|
|
|
62
64
|
if (existing) {
|
|
63
65
|
if (existing.currency !== opts.currency)
|
|
64
66
|
throw new Error("Payout claim currency cannot be changed.");
|
|
65
|
-
if (existing.attemptedAt !== undefined || existing.status !== "reserved")
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
if (existing.attemptedAt !== undefined || existing.status !== "reserved") {
|
|
68
|
+
try {
|
|
69
|
+
return await reconcileRecipientPayout(stripe, component, ctx, {
|
|
70
|
+
...identity,
|
|
71
|
+
maxPages,
|
|
72
|
+
});
|
|
73
|
+
} finally {
|
|
74
|
+
if (existing.snapshotId)
|
|
75
|
+
await discardQualificationInput(component, ctx, {
|
|
76
|
+
...identity,
|
|
77
|
+
snapshotId: existing.snapshotId,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
70
81
|
// A crash before the attempt has no provider side effect. Release its exact
|
|
71
82
|
// reservations; the next scheduled operation must collect fresh receipts.
|
|
72
83
|
const claim = (await runMutationOrThrow(
|
|
@@ -74,6 +85,11 @@ export async function releaseRecipientPayout(
|
|
|
74
85
|
componentRef(component, "payoutRelease/mutations/cancelUnattempted"),
|
|
75
86
|
identity,
|
|
76
87
|
)) as Claim;
|
|
88
|
+
if (existing.snapshotId)
|
|
89
|
+
await discardQualificationInput(component, ctx, {
|
|
90
|
+
...identity,
|
|
91
|
+
snapshotId: existing.snapshotId,
|
|
92
|
+
});
|
|
77
93
|
return { status: "terminal", claim };
|
|
78
94
|
}
|
|
79
95
|
const controls = await verify();
|
|
@@ -86,93 +102,109 @@ export async function releaseRecipientPayout(
|
|
|
86
102
|
opts,
|
|
87
103
|
maxPages,
|
|
88
104
|
);
|
|
89
|
-
if (proof.status !== "verified") return proof;
|
|
90
|
-
const claim = (await runMutationOrThrow(
|
|
91
|
-
ctx,
|
|
92
|
-
componentRef(component, "payoutRelease/mutations/claim"),
|
|
93
|
-
{
|
|
94
|
-
...identity,
|
|
95
|
-
expectedRevision: controls.policy.revision,
|
|
96
|
-
currency: opts.currency,
|
|
97
|
-
destinationId: proof.destinationId,
|
|
98
|
-
providerAvailable: proof.providerAvailable,
|
|
99
|
-
independentLiabilities: opts.independentLiabilities,
|
|
100
|
-
observations: proof.observations,
|
|
101
|
-
},
|
|
102
|
-
)) as Claim | Held;
|
|
103
|
-
if (claim.status === "held") return claim;
|
|
104
|
-
// Another caller can win this operation while receipts were being collected.
|
|
105
|
-
if (claim.attemptedAt !== undefined || claim.status !== "reserved")
|
|
106
|
-
return reconcileRecipientPayout(stripe, component, ctx, {
|
|
107
|
-
...identity,
|
|
108
|
-
maxPages,
|
|
109
|
-
});
|
|
110
|
-
const latest = await verify();
|
|
111
|
-
if (
|
|
112
|
-
latest.status !== "verified" ||
|
|
113
|
-
!("policy" in latest) ||
|
|
114
|
-
latest.policy.revision !== controls.policy.revision
|
|
115
|
-
) {
|
|
116
|
-
await runMutationOrThrow(
|
|
117
|
-
ctx,
|
|
118
|
-
componentRef(component, "payoutRelease/mutations/cancelUnattempted"),
|
|
119
|
-
identity,
|
|
120
|
-
);
|
|
121
|
-
return {
|
|
122
|
-
status: "held",
|
|
123
|
-
reason: latest.status === "verified" ? "policy_changed" : latest.status,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
await runMutationOrThrow(
|
|
127
|
-
ctx,
|
|
128
|
-
componentRef(component, "payoutRelease/mutations/beginAttempt"),
|
|
129
|
-
identity,
|
|
130
|
-
);
|
|
131
|
-
let payout: Stripe.Payout;
|
|
132
105
|
try {
|
|
133
|
-
|
|
134
|
-
{
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
method: "standard",
|
|
139
|
-
source_type: "card",
|
|
140
|
-
metadata: { bsPayoutClaim: claim.operationKey },
|
|
141
|
-
},
|
|
106
|
+
if (proof.status !== "verified")
|
|
107
|
+
return { status: "held", reason: proof.reason };
|
|
108
|
+
const claim = (await runMutationOrThrow(
|
|
109
|
+
ctx,
|
|
110
|
+
componentRef(component, "payoutRelease/mutations/claim"),
|
|
142
111
|
{
|
|
143
|
-
|
|
144
|
-
|
|
112
|
+
...identity,
|
|
113
|
+
expectedRevision: controls.policy.revision,
|
|
114
|
+
currency: opts.currency,
|
|
115
|
+
destinationId: proof.destinationId,
|
|
116
|
+
providerAvailable: proof.providerAvailable,
|
|
117
|
+
independentLiabilities: opts.independentLiabilities,
|
|
118
|
+
observations: proof.observations,
|
|
119
|
+
...(opts.liabilityRevision === undefined
|
|
120
|
+
? {}
|
|
121
|
+
: { liabilityRevision: opts.liabilityRevision }),
|
|
122
|
+
...(proof.collection
|
|
123
|
+
? { snapshotId: proof.collection.snapshotId }
|
|
124
|
+
: {}),
|
|
145
125
|
},
|
|
146
|
-
);
|
|
147
|
-
|
|
126
|
+
)) as Claim | Held;
|
|
127
|
+
if (claim.status === "held") return claim;
|
|
128
|
+
// Another caller can win this operation while receipts were being collected.
|
|
129
|
+
if (claim.attemptedAt !== undefined || claim.status !== "reserved")
|
|
130
|
+
return reconcileRecipientPayout(stripe, component, ctx, {
|
|
131
|
+
...identity,
|
|
132
|
+
maxPages,
|
|
133
|
+
});
|
|
134
|
+
const latest = await verify();
|
|
148
135
|
if (
|
|
149
|
-
|
|
150
|
-
"
|
|
151
|
-
|
|
152
|
-
"code" in error &&
|
|
153
|
-
["balance_insufficient", "amount_too_small"].includes(
|
|
154
|
-
String(error.code),
|
|
155
|
-
) &&
|
|
156
|
-
"requestId" in error &&
|
|
157
|
-
typeof error.requestId === "string" &&
|
|
158
|
-
/^req_\w+$/.test(error.requestId)
|
|
136
|
+
latest.status !== "verified" ||
|
|
137
|
+
!("policy" in latest) ||
|
|
138
|
+
latest.policy.revision !== controls.policy.revision
|
|
159
139
|
) {
|
|
160
|
-
|
|
140
|
+
await runMutationOrThrow(
|
|
161
141
|
ctx,
|
|
162
|
-
componentRef(component, "payoutRelease/mutations/
|
|
142
|
+
componentRef(component, "payoutRelease/mutations/cancelUnattempted"),
|
|
143
|
+
identity,
|
|
144
|
+
);
|
|
145
|
+
return {
|
|
146
|
+
status: "held",
|
|
147
|
+
reason: latest.status === "verified" ? "policy_changed" : latest.status,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
await runMutationOrThrow(
|
|
151
|
+
ctx,
|
|
152
|
+
componentRef(component, "payoutRelease/mutations/beginAttempt"),
|
|
153
|
+
identity,
|
|
154
|
+
);
|
|
155
|
+
let payout: Stripe.Payout;
|
|
156
|
+
try {
|
|
157
|
+
payout = await stripe.payouts.create(
|
|
163
158
|
{
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
159
|
+
amount: claim.amount,
|
|
160
|
+
currency: claim.currency,
|
|
161
|
+
destination: claim.destinationId,
|
|
162
|
+
method: "standard",
|
|
163
|
+
source_type: "card",
|
|
164
|
+
metadata: { bsPayoutClaim: claim.operationKey },
|
|
167
165
|
},
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
{
|
|
167
|
+
stripeAccount: claim.accountId,
|
|
168
|
+
idempotencyKey: `bs:payout-release:${claim.operationKey}`,
|
|
169
|
+
},
|
|
170
|
+
);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
if (
|
|
173
|
+
error instanceof Error &&
|
|
174
|
+
"type" in error &&
|
|
175
|
+
error.type === "StripeInvalidRequestError" &&
|
|
176
|
+
"code" in error &&
|
|
177
|
+
["balance_insufficient", "amount_too_small"].includes(
|
|
178
|
+
String(error.code),
|
|
179
|
+
) &&
|
|
180
|
+
"requestId" in error &&
|
|
181
|
+
typeof error.requestId === "string" &&
|
|
182
|
+
/^req_\w+$/.test(error.requestId)
|
|
183
|
+
) {
|
|
184
|
+
const saved = (await runMutationOrThrow(
|
|
185
|
+
ctx,
|
|
186
|
+
componentRef(component, "payoutRelease/mutations/recordRejection"),
|
|
187
|
+
{
|
|
188
|
+
...identity,
|
|
189
|
+
requestId: error.requestId,
|
|
190
|
+
code: error.code,
|
|
191
|
+
},
|
|
192
|
+
)) as Claim;
|
|
193
|
+
return { status: "terminal", claim: saved };
|
|
194
|
+
}
|
|
195
|
+
throw error;
|
|
170
196
|
}
|
|
171
|
-
|
|
197
|
+
return await reconcileRecipientPayout(stripe, component, ctx, {
|
|
198
|
+
...identity,
|
|
199
|
+
stripePayoutId: payout.id,
|
|
200
|
+
maxPages,
|
|
201
|
+
});
|
|
202
|
+
} finally {
|
|
203
|
+
await discardQualificationInput(
|
|
204
|
+
component,
|
|
205
|
+
ctx,
|
|
206
|
+
proof.collection,
|
|
207
|
+
proof.status === "held" && proof.reason === "collection_pending",
|
|
208
|
+
);
|
|
172
209
|
}
|
|
173
|
-
return reconcileRecipientPayout(stripe, component, ctx, {
|
|
174
|
-
...identity,
|
|
175
|
-
stripePayoutId: payout.id,
|
|
176
|
-
maxPages,
|
|
177
|
-
});
|
|
178
210
|
}
|
|
@@ -111,12 +111,25 @@ export async function setup(amounts = [600, 400]) {
|
|
|
111
111
|
}),
|
|
112
112
|
},
|
|
113
113
|
balanceTransactions: {
|
|
114
|
-
list: vi.fn(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
114
|
+
list: vi.fn(
|
|
115
|
+
async (params: {
|
|
116
|
+
source?: string;
|
|
117
|
+
limit?: number;
|
|
118
|
+
currency?: string;
|
|
119
|
+
starting_after?: string;
|
|
120
|
+
}) => {
|
|
121
|
+
const rows = transactions.filter(
|
|
122
|
+
(t) =>
|
|
123
|
+
(!params.source || t.source === params.source) &&
|
|
124
|
+
(!params.currency || t.currency === params.currency),
|
|
125
|
+
);
|
|
126
|
+
const start = params.starting_after
|
|
127
|
+
? rows.findIndex((t) => t.id === params.starting_after) + 1
|
|
128
|
+
: 0;
|
|
129
|
+
const data = rows.slice(start, start + (params.limit ?? 100));
|
|
130
|
+
return { data, has_more: start + data.length < rows.length };
|
|
131
|
+
},
|
|
132
|
+
),
|
|
120
133
|
retrieve: vi.fn(async (id: string) =>
|
|
121
134
|
transactions.find((t) => t.id === id),
|
|
122
135
|
),
|