@fantastic.dev/better-stripe 0.29.0 → 0.30.1
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 +8 -0
- package/README.md +10 -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 +26 -6
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +13 -3
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.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/payoutQualification.js +1 -1
- 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 +13 -3
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.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/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 +72 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/earnings/triggers.d.ts +12 -4
- 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 +3 -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/mutations.d.ts +59 -0
- package/dist/component/payoutRelease/mutations.d.ts.map +1 -1
- package/dist/component/payoutRelease/mutations.js +25 -80
- 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.map +1 -1
- package/dist/component/payoutRelease/planning.js +5 -2
- package/dist/component/payoutRelease/planning.js.map +1 -1
- package/dist/component/payoutRelease/queries.d.ts +2 -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/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 +31 -19
- package/dist/component/payoutSnapshots/financial.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/financial.js +28 -14
- package/dist/component/payoutSnapshots/financial.js.map +1 -1
- package/dist/component/payoutSnapshots/localState.d.ts +20 -16
- package/dist/component/payoutSnapshots/localState.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/localState.js +13 -4
- package/dist/component/payoutSnapshots/localState.js.map +1 -1
- package/dist/component/payoutSnapshots/mutations.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/mutations.js +1 -1
- package/dist/component/payoutSnapshots/mutations.js.map +1 -1
- package/dist/component/payoutSnapshots/queries.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/queries.js +6 -4
- package/dist/component/payoutSnapshots/queries.js.map +1 -1
- package/dist/component/payoutSnapshots/schema.d.ts +5 -1
- package/dist/component/payoutSnapshots/schema.d.ts.map +1 -1
- package/dist/component/payoutSnapshots/schema.js +2 -0
- package/dist/component/payoutSnapshots/schema.js.map +1 -1
- package/dist/component/schema.d.ts +13 -3
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/lib/payout-format.d.ts +5 -0
- package/dist/react/lib/payout-format.d.ts.map +1 -0
- package/dist/react/lib/payout-format.js +13 -0
- package/dist/react/lib/payout-format.js.map +1 -0
- package/dist/react/workflows/Payouts.js +4 -4
- package/dist/react/workflows/Payouts.js.map +1 -1
- package/docs/react-workflows.md +9 -4
- package/docs/settlement.md +61 -8
- 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/payoutLargeAdoption.test.ts +541 -0
- package/src/client/connect/payoutLargeAdoptionTestHelpers.ts +74 -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/payoutQualification.ts +10 -4
- package/src/client/connect/payoutReconciliation.ts +86 -7
- package/src/client/connect/payoutResumableProof.ts +41 -0
- package/src/client/connect/transferReceipt.ts +3 -2
- package/src/client/connect/transferReceiptBaseline.test.ts +55 -0
- package/src/client/payoutPolicy.ts +37 -23
- package/src/component/_generated/api.ts +4 -0
- package/src/component/_generated/component.ts +85 -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/mutations.ts +26 -96
- package/src/component/payoutRelease/outcome.ts +119 -0
- package/src/component/payoutRelease/planning.ts +5 -2
- package/src/component/payoutRelease/queries.ts +2 -0
- package/src/component/payoutSnapshots/adoption.ts +73 -0
- package/src/component/payoutSnapshots/financial.ts +33 -20
- package/src/component/payoutSnapshots/localState.ts +17 -3
- package/src/component/payoutSnapshots/mutations.ts +8 -1
- package/src/component/payoutSnapshots/queries.ts +8 -6
- package/src/component/payoutSnapshots/schema.ts +2 -0
- package/src/react/index.ts +1 -0
- package/src/react/lib/payout-format.ts +16 -0
- package/src/react/workflows/Payouts.tsx +7 -5
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collectLargePayoutInput,
|
|
3
|
+
discardQualificationInput,
|
|
4
|
+
type CollectionRef,
|
|
5
|
+
} from "./payoutCollectedInput.js";
|
|
6
|
+
import {
|
|
7
|
+
adoptionCollectionKey,
|
|
8
|
+
discardAdoptionProof,
|
|
9
|
+
} from "./payoutAdoptionCollection.js";
|
|
1
10
|
import type Stripe from "stripe";
|
|
2
11
|
import type { Infer } from "convex/values";
|
|
3
12
|
import type { Component, RunCtx } from "../helpers.js";
|
|
@@ -44,58 +53,119 @@ export async function collectAdoptionProof(
|
|
|
44
53
|
| { status: "verified"; proof: Infer<typeof adoptionProof> }
|
|
45
54
|
| { status: "held"; reason: string }
|
|
46
55
|
> {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
56
|
+
let retained: CollectionRef | undefined;
|
|
57
|
+
let collection:
|
|
58
|
+
| {
|
|
59
|
+
snapshotId: Infer<typeof adoptionProof>["snapshotId"];
|
|
60
|
+
collectionKey: string;
|
|
61
|
+
}
|
|
62
|
+
| undefined;
|
|
63
|
+
let handedOff = false,
|
|
64
|
+
keepPending = false;
|
|
65
|
+
try {
|
|
66
|
+
const request = { stripeAccount: scope.accountId };
|
|
67
|
+
const initial = await stripe.balance.retrieve(undefined, request);
|
|
68
|
+
const first = await stripe.balanceTransactions.list({ limit: 1 }, request);
|
|
69
|
+
const queue = new Set([
|
|
70
|
+
...configuredCurrencies,
|
|
71
|
+
...initial.available.map((t) => t.currency),
|
|
72
|
+
...initial.pending.map((t) => t.currency),
|
|
73
|
+
...(first.data[0] ? [first.data[0].currency] : []),
|
|
74
|
+
]);
|
|
75
|
+
const completed = new Set<string>();
|
|
76
|
+
let observations: Infer<typeof adoptionProof>["observations"] = [],
|
|
77
|
+
oldestHeldAt: number | undefined;
|
|
78
|
+
for (const currency of queue) {
|
|
79
|
+
if (completed.size >= 50)
|
|
80
|
+
return { status: "held", reason: "currency_history_incomplete" };
|
|
81
|
+
const result = await adoptRecipientPayouts(
|
|
82
|
+
stripe,
|
|
83
|
+
component,
|
|
84
|
+
ctx,
|
|
85
|
+
{ ...scope, currency, expectedRevision, payouts: [] },
|
|
86
|
+
true,
|
|
87
|
+
);
|
|
88
|
+
if (result.status !== "adopted") return result;
|
|
89
|
+
if (result.collection) {
|
|
90
|
+
if (
|
|
91
|
+
retained &&
|
|
92
|
+
retained.operationKey !== result.collection.operationKey
|
|
93
|
+
)
|
|
94
|
+
await discardQualificationInput(component, ctx, retained);
|
|
95
|
+
retained = result.collection;
|
|
96
|
+
}
|
|
97
|
+
completed.add(currency);
|
|
98
|
+
for (const c of result.historyCurrencies) queue.add(c);
|
|
99
|
+
observations = result.observations;
|
|
100
|
+
if (result.oldestHeldAt !== undefined)
|
|
101
|
+
oldestHeldAt = Math.min(oldestHeldAt ?? Infinity, result.oldestHeldAt);
|
|
102
|
+
}
|
|
103
|
+
let snapshot = (await ctx.runQuery(
|
|
104
|
+
componentRef(component, "payoutRelease/queries/snapshot"),
|
|
105
|
+
{ accountId: scope.accountId, ownerKey: scope.ownerKey },
|
|
106
|
+
)) as
|
|
107
|
+
| { status: "ready"; claims: Infer<typeof claimDoc>[] }
|
|
108
|
+
| { status: "held"; reason: string };
|
|
109
|
+
if (snapshot.status !== "ready" || retained) {
|
|
110
|
+
const policy = (await ctx.runQuery(
|
|
111
|
+
componentRef(component, "payoutPolicy/queries/get"),
|
|
112
|
+
{ accountId: scope.accountId, ownerKey: scope.ownerKey },
|
|
113
|
+
)) as { operationKey: string };
|
|
114
|
+
const key =
|
|
115
|
+
retained?.operationKey ??
|
|
116
|
+
(await adoptionCollectionKey(scope, policy.operationKey, "activation"));
|
|
117
|
+
const large = await collectLargePayoutInput(
|
|
118
|
+
component,
|
|
119
|
+
ctx,
|
|
120
|
+
{ ...scope, operationKey: key },
|
|
121
|
+
10,
|
|
122
|
+
);
|
|
123
|
+
if (large.status !== "ready") {
|
|
124
|
+
keepPending = large.reason === "collection_pending";
|
|
125
|
+
if (large.reason !== "collection_pending" && large.collection)
|
|
126
|
+
await discardAdoptionProof(component, ctx, scope, {
|
|
127
|
+
snapshotId: large.collection.snapshotId,
|
|
128
|
+
collectionKey: key,
|
|
129
|
+
});
|
|
130
|
+
return { status: "held", reason: large.reason };
|
|
131
|
+
}
|
|
132
|
+
collection = {
|
|
133
|
+
snapshotId: large.collection.snapshotId,
|
|
134
|
+
collectionKey: key,
|
|
135
|
+
};
|
|
136
|
+
snapshot = large;
|
|
137
|
+
}
|
|
138
|
+
const balance = await stripe.balance.retrieve(undefined, request);
|
|
139
|
+
const latest = await stripe.balanceTransactions.list({ limit: 1 }, request);
|
|
140
|
+
if (
|
|
141
|
+
balanceIdentity(initial) !== balanceIdentity(balance) ||
|
|
142
|
+
transactionIdentity(first.data[0]) !== transactionIdentity(latest.data[0])
|
|
143
|
+
) {
|
|
144
|
+
await discardAdoptionProof(component, ctx, scope, collection);
|
|
145
|
+
return { status: "held", reason: "provider_changed" };
|
|
146
|
+
}
|
|
147
|
+
handedOff = true;
|
|
148
|
+
return {
|
|
149
|
+
status: "verified",
|
|
150
|
+
proof: {
|
|
151
|
+
// All discovered currencies completed verification. The final provider
|
|
152
|
+
// head and balances still match the initial account snapshot after local collection.
|
|
153
|
+
observations: observations.map((o) => ({
|
|
154
|
+
...o,
|
|
155
|
+
observedAt: Date.now(),
|
|
156
|
+
})),
|
|
157
|
+
...collection,
|
|
158
|
+
claims: snapshot.claims.map((c) => ({
|
|
159
|
+
operationKey: c.operationKey,
|
|
160
|
+
fingerprint: payoutClaimFingerprint(c),
|
|
161
|
+
})),
|
|
162
|
+
...(oldestHeldAt !== undefined ? { oldestHeldAt } : {}),
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
} finally {
|
|
166
|
+
if (!handedOff && !keepPending) {
|
|
167
|
+
await discardQualificationInput(component, ctx, retained);
|
|
168
|
+
await discardAdoptionProof(component, ctx, scope, collection);
|
|
169
|
+
}
|
|
75
170
|
}
|
|
76
|
-
const balance = await stripe.balance.retrieve(undefined, request);
|
|
77
|
-
const latest = await stripe.balanceTransactions.list({ limit: 1 }, request);
|
|
78
|
-
if (
|
|
79
|
-
balanceIdentity(initial) !== balanceIdentity(balance) ||
|
|
80
|
-
transactionIdentity(first.data[0]) !== transactionIdentity(latest.data[0])
|
|
81
|
-
)
|
|
82
|
-
return { status: "held", reason: "provider_changed" };
|
|
83
|
-
const snapshot = (await ctx.runQuery(
|
|
84
|
-
componentRef(component, "payoutRelease/queries/snapshot"),
|
|
85
|
-
{ accountId: scope.accountId, ownerKey: scope.ownerKey },
|
|
86
|
-
)) as
|
|
87
|
-
| { status: "ready"; claims: Infer<typeof claimDoc>[] }
|
|
88
|
-
| { status: "held"; reason: string };
|
|
89
|
-
if (snapshot.status !== "ready") return snapshot;
|
|
90
|
-
return {
|
|
91
|
-
status: "verified",
|
|
92
|
-
proof: {
|
|
93
|
-
observations,
|
|
94
|
-
claims: snapshot.claims.map((c) => ({
|
|
95
|
-
operationKey: c.operationKey,
|
|
96
|
-
fingerprint: payoutClaimFingerprint(c),
|
|
97
|
-
})),
|
|
98
|
-
...(oldestHeldAt !== undefined ? { oldestHeldAt } : {}),
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
171
|
}
|