@fantastic.dev/better-stripe 0.9.0 → 0.10.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 +12 -0
- package/MIGRATION.md +26 -0
- package/README.md +38 -1
- package/dist/client/apiVersion.d.ts +6 -0
- package/dist/client/apiVersion.d.ts.map +1 -0
- package/dist/client/apiVersion.js +13 -0
- package/dist/client/apiVersion.js.map +1 -0
- package/dist/client/billing/checkout.d.ts +1 -0
- package/dist/client/billing/checkout.d.ts.map +1 -1
- package/dist/client/billing/checkout.js +5 -1
- package/dist/client/billing/checkout.js.map +1 -1
- package/dist/client/billing/providerReads.d.ts +18 -0
- package/dist/client/billing/providerReads.d.ts.map +1 -0
- package/dist/client/billing/providerReads.js +15 -0
- package/dist/client/billing/providerReads.js.map +1 -0
- package/dist/client/billing/subscriptions.d.ts +1 -1
- package/dist/client/billing/subscriptions.d.ts.map +1 -1
- package/dist/client/billing/subscriptions.js.map +1 -1
- package/dist/client/connect/payoutSnapshot.d.ts +28 -0
- package/dist/client/connect/payoutSnapshot.d.ts.map +1 -0
- package/dist/client/connect/payoutSnapshot.js +81 -0
- package/dist/client/connect/payoutSnapshot.js.map +1 -0
- package/dist/client/connect/transfers.d.ts.map +1 -1
- package/dist/client/connect/transfers.js +13 -32
- package/dist/client/connect/transfers.js.map +1 -1
- package/dist/client/core/accounts.d.ts +12 -23
- package/dist/client/core/accounts.d.ts.map +1 -1
- package/dist/client/core/accounts.js +5 -1
- package/dist/client/core/accounts.js.map +1 -1
- package/dist/client/core/idempotency.d.ts +5 -0
- package/dist/client/core/idempotency.d.ts.map +1 -0
- package/dist/client/core/idempotency.js +10 -0
- package/dist/client/core/idempotency.js.map +1 -0
- package/dist/client/index.d.ts +39 -37
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +47 -56
- package/dist/client/index.js.map +1 -1
- package/dist/client/previewRoutes.d.ts +9 -0
- package/dist/client/previewRoutes.d.ts.map +1 -0
- package/dist/client/previewRoutes.js +15 -0
- package/dist/client/previewRoutes.js.map +1 -0
- package/dist/client/settlement/allocation.d.ts +30 -0
- package/dist/client/settlement/allocation.d.ts.map +1 -0
- package/dist/client/settlement/allocation.js +71 -0
- package/dist/client/settlement/allocation.js.map +1 -0
- package/dist/client/settlement/commissions.d.ts +27 -0
- package/dist/client/settlement/commissions.d.ts.map +1 -0
- package/dist/client/settlement/commissions.js +69 -0
- package/dist/client/settlement/commissions.js.map +1 -0
- package/dist/client/settlement/execution.d.ts +27 -0
- package/dist/client/settlement/execution.d.ts.map +1 -0
- package/dist/client/settlement/execution.js +70 -0
- package/dist/client/settlement/execution.js.map +1 -0
- package/dist/client/settlement/reconciliation.d.ts +10 -0
- package/dist/client/settlement/reconciliation.d.ts.map +1 -0
- package/dist/client/settlement/reconciliation.js +73 -0
- package/dist/client/settlement/reconciliation.js.map +1 -0
- package/dist/client/settlement/settleSale.d.ts +21 -0
- package/dist/client/settlement/settleSale.d.ts.map +1 -0
- package/dist/client/settlement/settleSale.js +27 -0
- package/dist/client/settlement/settleSale.js.map +1 -0
- package/dist/client/settlement/verifiedSale.d.ts +25 -0
- package/dist/client/settlement/verifiedSale.d.ts.map +1 -0
- package/dist/client/settlement/verifiedSale.js +100 -0
- package/dist/client/settlement/verifiedSale.js.map +1 -0
- package/dist/client/types/options.d.ts +3 -0
- package/dist/client/types/options.d.ts.map +1 -1
- package/dist/client/utils/webhookEndpoints.d.ts +12 -8
- package/dist/client/utils/webhookEndpoints.d.ts.map +1 -1
- package/dist/client/utils/webhookEndpoints.js +41 -2
- package/dist/client/utils/webhookEndpoints.js.map +1 -1
- package/dist/client/webhooks/asyncHooks.d.ts +5 -0
- package/dist/client/webhooks/asyncHooks.d.ts.map +1 -0
- package/dist/client/webhooks/asyncHooks.js +20 -0
- package/dist/client/webhooks/asyncHooks.js.map +1 -0
- package/dist/client/webhooks/v2.d.ts.map +1 -1
- package/dist/client/webhooks/v2.js +10 -7
- package/dist/client/webhooks/v2.js.map +1 -1
- package/dist/component/_generated/component.d.ts +80 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/lib/stripeFactory.d.ts +3 -2
- package/dist/component/lib/stripeFactory.d.ts.map +1 -1
- package/dist/component/lib/stripeFactory.js +6 -5
- package/dist/component/lib/stripeFactory.js.map +1 -1
- package/dist/component/schema.d.ts +67 -0
- package/dist/component/schema.js +4 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/settlement/mutations.d.ts +47 -0
- package/dist/component/settlement/mutations.d.ts.map +1 -0
- package/dist/component/settlement/mutations.js +104 -0
- package/dist/component/settlement/mutations.js.map +1 -0
- package/dist/component/settlement/queries.d.ts +29 -0
- package/dist/component/settlement/queries.d.ts.map +1 -0
- package/dist/component/settlement/queries.js +35 -0
- package/dist/component/settlement/queries.js.map +1 -0
- package/dist/component/settlement/schema.d.ts +99 -0
- package/dist/component/settlement/schema.d.ts.map +1 -0
- package/dist/component/settlement/schema.js +35 -0
- package/dist/component/settlement/schema.js.map +1 -0
- package/dist/react/workflows/Checkout.d.ts +3 -1
- package/dist/react/workflows/Checkout.d.ts.map +1 -1
- package/dist/react/workflows/Checkout.js +3 -2
- package/dist/react/workflows/Checkout.js.map +1 -1
- package/dist/react/workflows/Payouts.d.ts +3 -18
- package/dist/react/workflows/Payouts.d.ts.map +1 -1
- package/dist/react/workflows/Payouts.js +2 -2
- package/dist/react/workflows/Payouts.js.map +1 -1
- package/docs/accounts-v2-preview.md +132 -0
- package/docs/react-workflows.md +5 -2
- package/docs/settlement.md +158 -0
- package/package.json +3 -1
- package/src/client/apiVersion.ts +20 -0
- package/src/client/billing/checkout-idempotency.test.ts +82 -0
- package/src/client/billing/checkout.ts +6 -1
- package/src/client/billing/providerReads.test.ts +60 -0
- package/src/client/billing/providerReads.ts +30 -0
- package/src/client/billing/subscriptions.ts +1 -8
- package/src/client/connect/payoutSnapshot.test.ts +91 -0
- package/src/client/connect/payoutSnapshot.ts +130 -0
- package/src/client/connect/transfers.test.ts +15 -4
- package/src/client/connect/transfers.ts +13 -42
- package/src/client/core/account-idempotency.test.ts +78 -0
- package/src/client/core/accounts.ts +18 -25
- package/src/client/core/idempotency.test.ts +10 -0
- package/src/client/core/idempotency.ts +11 -0
- package/src/client/customer-preview-thin.test.ts +41 -0
- package/src/client/customer-preview-webhooks.test.ts +150 -0
- package/src/client/customer-preview.test.ts +185 -0
- package/src/client/index.ts +115 -119
- package/src/client/previewRoutes.ts +26 -0
- package/src/client/settlement/allocation.test.ts +98 -0
- package/src/client/settlement/allocation.ts +110 -0
- package/src/client/settlement/commissions.test.ts +103 -0
- package/src/client/settlement/commissions.ts +125 -0
- package/src/client/settlement/execution.test.ts +186 -0
- package/src/client/settlement/execution.ts +134 -0
- package/src/client/settlement/reconciliation.ts +119 -0
- package/src/client/settlement/settleSale.ts +59 -0
- package/src/client/settlement/verifiedSale.test.ts +139 -0
- package/src/client/settlement/verifiedSale.ts +159 -0
- package/src/client/stripe-version.test.ts +10 -4
- package/src/client/types/options.ts +3 -0
- package/src/client/utils/webhookEndpoints.ts +70 -15
- package/src/client/webhooks/asyncHooks.ts +38 -0
- package/src/client/webhooks/processors.test.ts +9 -9
- package/src/client/webhooks/v2.ts +14 -10
- package/src/component/_generated/api.ts +4 -0
- package/src/component/_generated/component.ts +100 -0
- package/src/component/lib/stripeFactory.ts +13 -5
- package/src/component/schema.ts +8 -0
- package/src/component/settlement/mutations.ts +119 -0
- package/src/component/settlement/queries.ts +38 -0
- package/src/component/settlement/schema.ts +45 -0
- package/src/component/settlement-claims.test.ts +77 -0
- package/src/react/components/EmbeddedDisputes.render.test.tsx +2 -2
- package/src/react/index.payment-element.test.ts +22 -37
- package/src/react/workflows/Checkout.test.tsx +30 -0
- package/src/react/workflows/Checkout.tsx +10 -3
- package/src/react/workflows/Payouts.test.tsx +33 -0
- package/src/react/workflows/Payouts.tsx +21 -15
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation } from "../_generated/server.js";
|
|
3
|
+
import { allocationFields, commissionFields, termValidator } from "./schema.js";
|
|
4
|
+
const doc = v.object({
|
|
5
|
+
...allocationFields,
|
|
6
|
+
_id: v.id("settlementAllocations"),
|
|
7
|
+
_creationTime: v.number(),
|
|
8
|
+
});
|
|
9
|
+
export const reserveSettlementAllocation = mutation({
|
|
10
|
+
args: allocationFields,
|
|
11
|
+
returns: doc,
|
|
12
|
+
handler: async (ctx, args) => {
|
|
13
|
+
const existing = await ctx.db
|
|
14
|
+
.query("settlementAllocations")
|
|
15
|
+
.withIndex("by_source_charge", (q) => q.eq("sourceChargeId", args.sourceChargeId))
|
|
16
|
+
.first();
|
|
17
|
+
if (existing) {
|
|
18
|
+
if (existing.currency !== args.currency ||
|
|
19
|
+
existing.paymentIntentId !== args.paymentIntentId ||
|
|
20
|
+
existing.sourceInvoiceId !== args.sourceInvoiceId)
|
|
21
|
+
throw new Error("Settlement source identity cannot change.");
|
|
22
|
+
return existing;
|
|
23
|
+
}
|
|
24
|
+
const adjustment = args.adjustmentAmount ?? 0;
|
|
25
|
+
const amounts = [
|
|
26
|
+
args.gross,
|
|
27
|
+
args.processingFee,
|
|
28
|
+
args.platformNet,
|
|
29
|
+
...args.transfers.map((t) => t.amount),
|
|
30
|
+
];
|
|
31
|
+
const keys = args.transfers.map((t) => `${t.destinationAccountId}:${t.role}`);
|
|
32
|
+
if (!Number.isSafeInteger(adjustment) ||
|
|
33
|
+
args.processingFee + args.platformNet + adjustment < 0 ||
|
|
34
|
+
amounts.some((n) => !Number.isSafeInteger(n) || n < 0) ||
|
|
35
|
+
args.gross <= 0 ||
|
|
36
|
+
!args.currency ||
|
|
37
|
+
!args.sourceChargeId ||
|
|
38
|
+
args.transfers.some((t) => !t.destinationAccountId) ||
|
|
39
|
+
new Set(keys).size !== keys.length ||
|
|
40
|
+
args.gross !==
|
|
41
|
+
args.processingFee +
|
|
42
|
+
args.platformNet +
|
|
43
|
+
adjustment +
|
|
44
|
+
args.transfers.reduce((sum, t) => sum + t.amount, 0))
|
|
45
|
+
throw new Error("Settlement allocation must reconcile in integer currency units with unique recipient legs.");
|
|
46
|
+
const id = await ctx.db.insert("settlementAllocations", args);
|
|
47
|
+
return (await ctx.db.get("settlementAllocations", id));
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
export const claimCommissionInvoice = mutation({
|
|
51
|
+
args: { ...commissionFields, invoiceId: v.string() },
|
|
52
|
+
returns: v.object({
|
|
53
|
+
eligible: v.boolean(),
|
|
54
|
+
term: termValidator,
|
|
55
|
+
firstPaidInvoiceId: v.string(),
|
|
56
|
+
claimKey: v.string(),
|
|
57
|
+
replay: v.boolean(),
|
|
58
|
+
}),
|
|
59
|
+
handler: async (ctx, args) => {
|
|
60
|
+
let stored = await ctx.db
|
|
61
|
+
.query("commissionTerms")
|
|
62
|
+
.withIndex("by_subscription", (q) => q.eq("subscriptionId", args.subscriptionId))
|
|
63
|
+
.first();
|
|
64
|
+
if (stored && stored.affiliateAccountId !== args.affiliateAccountId)
|
|
65
|
+
throw new Error("Subscription affiliate identity cannot change.");
|
|
66
|
+
if (!stored) {
|
|
67
|
+
const fields = {
|
|
68
|
+
subscriptionId: args.subscriptionId,
|
|
69
|
+
term: args.term,
|
|
70
|
+
affiliateAccountId: args.affiliateAccountId,
|
|
71
|
+
firstPaidInvoiceId: args.firstPaidInvoiceId,
|
|
72
|
+
};
|
|
73
|
+
const id = await ctx.db.insert("commissionTerms", fields);
|
|
74
|
+
stored = (await ctx.db.get("commissionTerms", id));
|
|
75
|
+
}
|
|
76
|
+
const existing = await ctx.db
|
|
77
|
+
.query("commissionDecisions")
|
|
78
|
+
.withIndex("by_subscription_invoice", (q) => q
|
|
79
|
+
.eq("subscriptionId", args.subscriptionId)
|
|
80
|
+
.eq("invoiceId", args.invoiceId))
|
|
81
|
+
.first();
|
|
82
|
+
const claimKey = existing?.claimKey ??
|
|
83
|
+
`commission:${args.subscriptionId}:${args.invoiceId}`;
|
|
84
|
+
const eligible = existing?.eligible ??
|
|
85
|
+
(!!stored.affiliateAccountId &&
|
|
86
|
+
(stored.term === "forever" ||
|
|
87
|
+
args.invoiceId === stored.firstPaidInvoiceId));
|
|
88
|
+
if (!existing)
|
|
89
|
+
await ctx.db.insert("commissionDecisions", {
|
|
90
|
+
subscriptionId: args.subscriptionId,
|
|
91
|
+
invoiceId: args.invoiceId,
|
|
92
|
+
eligible,
|
|
93
|
+
claimKey,
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
eligible,
|
|
97
|
+
term: stored.term,
|
|
98
|
+
firstPaidInvoiceId: stored.firstPaidInvoiceId,
|
|
99
|
+
claimKey,
|
|
100
|
+
replay: !!existing,
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=mutations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../../src/component/settlement/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAChF,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC;IACnB,GAAG,gBAAgB;IACnB,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,uBAAuB,CAAC;IAClC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;CAC1B,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,QAAQ,CAAC;IAClD,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,GAAG;IACZ,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,EAAE;aAC1B,KAAK,CAAC,uBAAuB,C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AI,CAAC,SAAS,KAAK,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC;QACrD,IAAI,CAAC,QAAQ;YACX,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,qBAAqB,EAAE;gBACzC,cAAc,EAAE,IAAI,CAAC,cAAc;gBACnC,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,QAAQ;gBACR,QAAQ;aACT,CAAC,CAAC;QACL,OAAO;YACL,QAAQ;YACR,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;YAC7C,QAAQ;YACR,MAAM,EAAE,CAAC,CAAC,QAAQ;SACnB,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const getSettlementAllocation: import("convex/server").RegisteredQuery<"public", {
|
|
2
|
+
sourceChargeId: string;
|
|
3
|
+
}, Promise<{
|
|
4
|
+
_creationTime: number;
|
|
5
|
+
_id: import("convex/values").GenericId<"settlementAllocations">;
|
|
6
|
+
adjustmentAmount?: number | undefined;
|
|
7
|
+
currency: string;
|
|
8
|
+
gross: number;
|
|
9
|
+
paymentId?: string | undefined;
|
|
10
|
+
paymentIntentId?: string | undefined;
|
|
11
|
+
platformNet: number;
|
|
12
|
+
processingFee: number;
|
|
13
|
+
sourceChargeId: string;
|
|
14
|
+
sourceInvoiceId?: string | undefined;
|
|
15
|
+
transfers: {
|
|
16
|
+
amount: number;
|
|
17
|
+
destinationAccountId: string;
|
|
18
|
+
role: "affiliate" | "other" | "store";
|
|
19
|
+
}[];
|
|
20
|
+
} | null>>;
|
|
21
|
+
export declare const getCommissionTerm: import("convex/server").RegisteredQuery<"public", {
|
|
22
|
+
subscriptionId: string;
|
|
23
|
+
}, Promise<{
|
|
24
|
+
subscriptionId: string;
|
|
25
|
+
term: "forever" | "one_time";
|
|
26
|
+
affiliateAccountId: string | undefined;
|
|
27
|
+
firstPaidInvoiceId: string;
|
|
28
|
+
} | null>>;
|
|
29
|
+
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/component/settlement/queries.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;UAUlC,CAAC;AACH,eAAO,MAAM,iBAAiB;;;;;;;UAkB5B,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { query } from "../_generated/server.js";
|
|
3
|
+
import { allocationFields, commissionFields } from "./schema.js";
|
|
4
|
+
const doc = v.object({
|
|
5
|
+
...allocationFields,
|
|
6
|
+
_id: v.id("settlementAllocations"),
|
|
7
|
+
_creationTime: v.number(),
|
|
8
|
+
});
|
|
9
|
+
export const getSettlementAllocation = query({
|
|
10
|
+
args: { sourceChargeId: v.string() },
|
|
11
|
+
returns: v.union(doc, v.null()),
|
|
12
|
+
handler: (ctx, args) => ctx.db
|
|
13
|
+
.query("settlementAllocations")
|
|
14
|
+
.withIndex("by_source_charge", (q) => q.eq("sourceChargeId", args.sourceChargeId))
|
|
15
|
+
.first(),
|
|
16
|
+
});
|
|
17
|
+
export const getCommissionTerm = query({
|
|
18
|
+
args: { subscriptionId: v.string() },
|
|
19
|
+
returns: v.union(v.object(commissionFields), v.null()),
|
|
20
|
+
handler: async (ctx, args) => {
|
|
21
|
+
const row = await ctx.db
|
|
22
|
+
.query("commissionTerms")
|
|
23
|
+
.withIndex("by_subscription", (q) => q.eq("subscriptionId", args.subscriptionId))
|
|
24
|
+
.first();
|
|
25
|
+
if (!row)
|
|
26
|
+
return null;
|
|
27
|
+
return {
|
|
28
|
+
subscriptionId: row.subscriptionId,
|
|
29
|
+
term: row.term,
|
|
30
|
+
affiliateAccountId: row.affiliateAccountId,
|
|
31
|
+
firstPaidInvoiceId: row.firstPaidInvoiceId,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/component/settlement/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACjE,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC;IACnB,GAAG,gBAAgB;IACnB,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,uBAAuB,CAAC;IAClC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;CAC1B,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,CAAC;IAC3C,IAAI,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;IACpC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/B,OAAO,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CACrB,GAAG,CAAC,EAAE;SACH,KAAK,CAAC,uBAAuB,CAAC;SAC9B,SAAS,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE,EAAE,CACnC,CAAC,CAAC,EAAE,CAAC,gBAAgB,EAAE,IAAI,CAAC,cAAc,CAAC,CAC5C;SACA,KAAK,EAAE;CACb,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;IACrC,IAAI,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;IACpC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACtD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE;aACrB,KAAK,CAAC,iBAAiB,CAAC;aACxB,SAAS,CAAC,iBAAiB,EAAE,CAAC,CAAC,EAAE,EAAE,CAClC,CAAC,CAAC,EAAE,CAAC,gBAAgB,EAAE,IAAI,CAAC,cAAc,CAAC,CAC5C;aACA,KAAK,EAAE,CAAC;QACX,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAC;QACtB,OAAO;YACL,cAAc,EAAE,GAAG,CAAC,cAAc;YAClC,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;YAC1C,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;SAC3C,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export declare const termValidator: import("convex/values").VUnion<"forever" | "one_time", [import("convex/values").VLiteral<"forever", "required">, import("convex/values").VLiteral<"one_time", "required">], "required", never>;
|
|
2
|
+
export declare const allocationFields: {
|
|
3
|
+
sourceChargeId: import("convex/values").VString<string, "required">;
|
|
4
|
+
paymentIntentId: import("convex/values").VString<string | undefined, "optional">;
|
|
5
|
+
sourceInvoiceId: import("convex/values").VString<string | undefined, "optional">;
|
|
6
|
+
gross: import("convex/values").VFloat64<number, "required">;
|
|
7
|
+
currency: import("convex/values").VString<string, "required">;
|
|
8
|
+
processingFee: import("convex/values").VFloat64<number, "required">;
|
|
9
|
+
platformNet: import("convex/values").VFloat64<number, "required">;
|
|
10
|
+
adjustmentAmount: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
11
|
+
paymentId: import("convex/values").VString<string | undefined, "optional">;
|
|
12
|
+
transfers: import("convex/values").VArray<{
|
|
13
|
+
amount: number;
|
|
14
|
+
destinationAccountId: string;
|
|
15
|
+
role: "affiliate" | "other" | "store";
|
|
16
|
+
}[], import("convex/values").VObject<{
|
|
17
|
+
amount: number;
|
|
18
|
+
destinationAccountId: string;
|
|
19
|
+
role: "affiliate" | "other" | "store";
|
|
20
|
+
}, {
|
|
21
|
+
destinationAccountId: import("convex/values").VString<string, "required">;
|
|
22
|
+
role: import("convex/values").VUnion<"affiliate" | "other" | "store", [import("convex/values").VLiteral<"store", "required">, import("convex/values").VLiteral<"affiliate", "required">, import("convex/values").VLiteral<"other", "required">], "required", never>;
|
|
23
|
+
amount: import("convex/values").VFloat64<number, "required">;
|
|
24
|
+
}, "required", "amount" | "destinationAccountId" | "role">, "required">;
|
|
25
|
+
};
|
|
26
|
+
export declare const allocationsTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
27
|
+
adjustmentAmount?: number | undefined;
|
|
28
|
+
currency: string;
|
|
29
|
+
gross: number;
|
|
30
|
+
paymentId?: string | undefined;
|
|
31
|
+
paymentIntentId?: string | undefined;
|
|
32
|
+
platformNet: number;
|
|
33
|
+
processingFee: number;
|
|
34
|
+
sourceChargeId: string;
|
|
35
|
+
sourceInvoiceId?: string | undefined;
|
|
36
|
+
transfers: {
|
|
37
|
+
amount: number;
|
|
38
|
+
destinationAccountId: string;
|
|
39
|
+
role: "affiliate" | "other" | "store";
|
|
40
|
+
}[];
|
|
41
|
+
}, {
|
|
42
|
+
sourceChargeId: import("convex/values").VString<string, "required">;
|
|
43
|
+
paymentIntentId: import("convex/values").VString<string | undefined, "optional">;
|
|
44
|
+
sourceInvoiceId: import("convex/values").VString<string | undefined, "optional">;
|
|
45
|
+
gross: import("convex/values").VFloat64<number, "required">;
|
|
46
|
+
currency: import("convex/values").VString<string, "required">;
|
|
47
|
+
processingFee: import("convex/values").VFloat64<number, "required">;
|
|
48
|
+
platformNet: import("convex/values").VFloat64<number, "required">;
|
|
49
|
+
adjustmentAmount: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
50
|
+
paymentId: import("convex/values").VString<string | undefined, "optional">;
|
|
51
|
+
transfers: import("convex/values").VArray<{
|
|
52
|
+
amount: number;
|
|
53
|
+
destinationAccountId: string;
|
|
54
|
+
role: "affiliate" | "other" | "store";
|
|
55
|
+
}[], import("convex/values").VObject<{
|
|
56
|
+
amount: number;
|
|
57
|
+
destinationAccountId: string;
|
|
58
|
+
role: "affiliate" | "other" | "store";
|
|
59
|
+
}, {
|
|
60
|
+
destinationAccountId: import("convex/values").VString<string, "required">;
|
|
61
|
+
role: import("convex/values").VUnion<"affiliate" | "other" | "store", [import("convex/values").VLiteral<"store", "required">, import("convex/values").VLiteral<"affiliate", "required">, import("convex/values").VLiteral<"other", "required">], "required", never>;
|
|
62
|
+
amount: import("convex/values").VFloat64<number, "required">;
|
|
63
|
+
}, "required", "amount" | "destinationAccountId" | "role">, "required">;
|
|
64
|
+
}, "required", "adjustmentAmount" | "currency" | "gross" | "paymentId" | "paymentIntentId" | "platformNet" | "processingFee" | "sourceChargeId" | "sourceInvoiceId" | "transfers">, {
|
|
65
|
+
by_source_charge: ["sourceChargeId", "_creationTime"];
|
|
66
|
+
}, {}, {}>;
|
|
67
|
+
export declare const commissionFields: {
|
|
68
|
+
subscriptionId: import("convex/values").VString<string, "required">;
|
|
69
|
+
term: import("convex/values").VUnion<"forever" | "one_time", [import("convex/values").VLiteral<"forever", "required">, import("convex/values").VLiteral<"one_time", "required">], "required", never>;
|
|
70
|
+
affiliateAccountId: import("convex/values").VString<string | undefined, "optional">;
|
|
71
|
+
firstPaidInvoiceId: import("convex/values").VString<string, "required">;
|
|
72
|
+
};
|
|
73
|
+
export declare const commissionTermsTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
74
|
+
affiliateAccountId?: string | undefined;
|
|
75
|
+
firstPaidInvoiceId: string;
|
|
76
|
+
subscriptionId: string;
|
|
77
|
+
term: "forever" | "one_time";
|
|
78
|
+
}, {
|
|
79
|
+
subscriptionId: import("convex/values").VString<string, "required">;
|
|
80
|
+
term: import("convex/values").VUnion<"forever" | "one_time", [import("convex/values").VLiteral<"forever", "required">, import("convex/values").VLiteral<"one_time", "required">], "required", never>;
|
|
81
|
+
affiliateAccountId: import("convex/values").VString<string | undefined, "optional">;
|
|
82
|
+
firstPaidInvoiceId: import("convex/values").VString<string, "required">;
|
|
83
|
+
}, "required", "affiliateAccountId" | "firstPaidInvoiceId" | "subscriptionId" | "term">, {
|
|
84
|
+
by_subscription: ["subscriptionId", "_creationTime"];
|
|
85
|
+
}, {}, {}>;
|
|
86
|
+
export declare const commissionDecisionsTable: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
87
|
+
claimKey: string;
|
|
88
|
+
eligible: boolean;
|
|
89
|
+
invoiceId: string;
|
|
90
|
+
subscriptionId: string;
|
|
91
|
+
}, {
|
|
92
|
+
subscriptionId: import("convex/values").VString<string, "required">;
|
|
93
|
+
invoiceId: import("convex/values").VString<string, "required">;
|
|
94
|
+
eligible: import("convex/values").VBoolean<boolean, "required">;
|
|
95
|
+
claimKey: import("convex/values").VString<string, "required">;
|
|
96
|
+
}, "required", "claimKey" | "eligible" | "invoiceId" | "subscriptionId">, {
|
|
97
|
+
by_subscription_invoice: ["subscriptionId", "invoiceId", "_creationTime"];
|
|
98
|
+
}, {}, {}>;
|
|
99
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/component/settlement/schema.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,gMAGzB,CAAC;AACF,eAAO,MAAM,gBAAgB;IAC3B,cAAc;IACd,eAAe;IACf,eAAe;IACf,KAAK;IACL,QAAQ;IACR,aAAa;IACb,WAAW;IACX,gBAAgB;IAChB,SAAS;IACT,SAAS;;;;;;;;;;;;;CAOV,CAAC;AACF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAG5B,CAAC;AACF,eAAO,MAAM,gBAAgB;IAC3B,cAAc;IACd,IAAI;IACJ,kBAAkB;IAClB,kBAAkB;CACnB,CAAC;AACF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;UAGhC,CAAC;AACF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;UAK+B,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { splitRecipientRoleValidator } from "../lib/fees.js";
|
|
4
|
+
export const termValidator = v.union(v.literal("forever"), v.literal("one_time"));
|
|
5
|
+
export const allocationFields = {
|
|
6
|
+
sourceChargeId: v.string(),
|
|
7
|
+
paymentIntentId: v.optional(v.string()),
|
|
8
|
+
sourceInvoiceId: v.optional(v.string()),
|
|
9
|
+
gross: v.number(),
|
|
10
|
+
currency: v.string(),
|
|
11
|
+
processingFee: v.number(),
|
|
12
|
+
platformNet: v.number(),
|
|
13
|
+
adjustmentAmount: v.optional(v.number()),
|
|
14
|
+
paymentId: v.optional(v.string()),
|
|
15
|
+
transfers: v.array(v.object({
|
|
16
|
+
destinationAccountId: v.string(),
|
|
17
|
+
role: splitRecipientRoleValidator,
|
|
18
|
+
amount: v.number(),
|
|
19
|
+
})),
|
|
20
|
+
};
|
|
21
|
+
export const allocationsTable = defineTable(allocationFields).index("by_source_charge", ["sourceChargeId"]);
|
|
22
|
+
export const commissionFields = {
|
|
23
|
+
subscriptionId: v.string(),
|
|
24
|
+
term: termValidator,
|
|
25
|
+
affiliateAccountId: v.optional(v.string()),
|
|
26
|
+
firstPaidInvoiceId: v.string(),
|
|
27
|
+
};
|
|
28
|
+
export const commissionTermsTable = defineTable(commissionFields).index("by_subscription", ["subscriptionId"]);
|
|
29
|
+
export const commissionDecisionsTable = defineTable({
|
|
30
|
+
subscriptionId: v.string(),
|
|
31
|
+
invoiceId: v.string(),
|
|
32
|
+
eligible: v.boolean(),
|
|
33
|
+
claimKey: v.string(),
|
|
34
|
+
}).index("by_subscription_invoice", ["subscriptionId", "invoiceId"]);
|
|
35
|
+
//# sourceMappingURL=schema.js.map
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AK,CACjE,kBAAkB,EAClB,CAAC,gBAAgB,CAAC,CACnB,CAAC;AACF,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;IAC1B,IAAI,EAAE,aAAa;IACnB,kBAAkB,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC1C,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE;CAC/B,CAAC;AACF,MAAM,CAAC,MAAM,oBAAoB,GAAG,WAAW,CAAC,gBAAgB,CAAC,CAAC,KAAK,CACrE,iBAAiB,EACjB,CAAC,gBAAgB,CAAC,CACnB,CAAC;AACF,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAW,CAAC;IAClD,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;IAC1B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;IACrB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;CACrB,CAAC,CAAC,KAAK,CAAC,yBAAyB,EAAE,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
2
|
import { type CheckoutFormOptions } from "./CheckoutForms.js";
|
|
3
3
|
export type CheckoutMode = "redirect" | "embedded" | "custom" | "form" | "payment-intent";
|
|
4
4
|
export type CheckoutSessionResult = {
|
|
@@ -27,6 +27,8 @@ type Common = CheckoutFormOptions & {
|
|
|
27
27
|
publishableKey: string;
|
|
28
28
|
/** Changes when the price, signed-in customer, or referral attribution changes. */
|
|
29
29
|
orderKey: string;
|
|
30
|
+
/** Optional durable logical-order identity, persisted by the host app. */
|
|
31
|
+
requestId?: string;
|
|
30
32
|
returnUrl: string;
|
|
31
33
|
onNavigate?: (url: string) => void;
|
|
32
34
|
children?: (state: CheckoutRenderProps) => ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkout.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Checkout.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Checkout.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Checkout.tsx"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAGjD,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAC5B,MAAM,MAAM,YAAY,GACtB,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAM,GAAG,gBAAgB,CAAC;AACjE,MAAM,MAAM,qBAAqB,GAAG;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AACF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;IAC9C,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,SAAS,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,IAAI,CAAC;CACjC,CAAC;AACF,KAAK,MAAM,GAAG,mBAAmB,GAAG;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,mFAAmF;IACnF,QAAQ,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,SAAS,CAAC;CACtD,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,MAAM,GAChC,CACI;IACE,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC;IAC9C,aAAa,EAAE,CACb,OAAO,EAAE,eAAe,KACrB,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACrC,GACD;IACE,IAAI,EAAE,gBAAgB,CAAC;IACvB,mBAAmB,EAAE,CAAC,OAAO,EAAE;QAC7B,SAAS,EAAE,MAAM,CAAC;KACnB,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAC;CACrC,CACJ,CAAC;AACJ,6HAA6H;AAC7H,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,+BAO5C"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
3
4
|
import { EmbeddedCheckout } from "../components/EmbeddedCheckout.js";
|
|
4
5
|
import { useWorkflowResource } from "./useWorkflowResource.js";
|
|
5
6
|
import { CheckoutElementsForm, PaymentIntentForm, CheckoutForm, } from "./CheckoutForms.js";
|
|
6
7
|
/** All checkout integrations share one unstyled lifecycle. Callbacks must authenticate and validate prices on the server. */
|
|
7
8
|
export function Checkout(props) {
|
|
8
|
-
return _jsx(CheckoutBody, { ...props }, `${props.orderKey}:${props.mode}`);
|
|
9
|
+
return (_jsx(CheckoutBody, { ...props }, `${props.orderKey}:${props.mode}:${props.requestId ?? ""}`));
|
|
9
10
|
}
|
|
10
11
|
function CheckoutBody(props) {
|
|
12
|
+
const [requestId] = useState(() => props.requestId ?? crypto.randomUUID());
|
|
11
13
|
const state = useWorkflowResource(async () => {
|
|
12
|
-
const requestId = crypto.randomUUID();
|
|
13
14
|
const result = props.mode === "payment-intent"
|
|
14
15
|
? await props.createPaymentIntent({ requestId })
|
|
15
16
|
: await props.createSession({ mode: props.mode, requestId });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkout.js","sourceRoot":"","sources":["../../../src/react/workflows/Checkout.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;
|
|
1
|
+
{"version":3,"file":"Checkout.js","sourceRoot":"","sources":["../../../src/react/workflows/Checkout.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,GAEb,MAAM,oBAAoB,CAAC;AAkD5B,6HAA6H;AAC7H,MAAM,UAAU,QAAQ,CAAC,KAAoB;IAC3C,OAAO,CACL,KAAC,YAAY,OAEP,KAAK,IADJ,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,SAAS,IAAI,EAAE,EAAE,CAE/D,CACH,CAAC;AACJ,CAAC;AACD,SAAS,YAAY,CAAC,KAAoB;IACxC,MAAM,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IAC3E,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAK,IAAI,EAAE;QAC3C,MAAM,MAAM,GACV,KAAK,CAAC,IAAI,KAAK,gBAAgB;YAC7B,CAAC,CAAC,MAAM,KAAK,CAAC,mBAAmB,CAAC,EAAE,S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EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;KACtE,CAAC;IACF,OAAO,4BAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,GAAI,CAAC;AAClE,CAAC"}
|
|
@@ -1,24 +1,9 @@
|
|
|
1
|
+
import type { RecipientPayoutSnapshot, RecipientPayoutRow } from "../../client/connect/payoutSnapshot.js";
|
|
1
2
|
import { type ReactNode } from "react";
|
|
2
3
|
import { type ConnectProps } from "./Connect.js";
|
|
3
4
|
import { type CollectionProps, type WorkflowColumn } from "./Collection.js";
|
|
4
|
-
export type PayoutRow =
|
|
5
|
-
|
|
6
|
-
amount: number;
|
|
7
|
-
currency: string;
|
|
8
|
-
status: string;
|
|
9
|
-
/** Unix milliseconds. */ arrivalDate: number | null;
|
|
10
|
-
created: number;
|
|
11
|
-
};
|
|
12
|
-
export type PayoutSnapshot = {
|
|
13
|
-
balances: {
|
|
14
|
-
currency: string;
|
|
15
|
-
available: number;
|
|
16
|
-
pending: number;
|
|
17
|
-
}[];
|
|
18
|
-
payouts: PayoutRow[];
|
|
19
|
-
upcoming: PayoutRow[];
|
|
20
|
-
nextCursor: string | null;
|
|
21
|
-
};
|
|
5
|
+
export type PayoutRow = RecipientPayoutRow;
|
|
6
|
+
export type PayoutSnapshot = Pick<RecipientPayoutSnapshot, "balances" | "payouts" | "upcoming" | "nextCursor"> & Partial<Pick<RecipientPayoutSnapshot, "status" | "reason" | "upcomingComplete">>;
|
|
22
7
|
export type PayoutsRenderProps = {
|
|
23
8
|
data: PayoutSnapshot | undefined;
|
|
24
9
|
error: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Payouts.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Payouts.tsx"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACj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EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IACnD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,SAAS,CAAC;CACrD,CAAC;AACF,MAAM,MAAM,YAAY,GACpB,oBAAoB,GACpB,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GAAG;IAAE,YAAY,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AAGrE,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,+BAM1C;AA+DD,MAAM,MAAM,gBAAgB,GAAG,IAAI,CACjC,SAAS,EACT,IAAI,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,aAAa,CACxD,CAAC;AACF,MAAM,MAAM,kBAAkB,CAC5B,GAAG,SAAS,gBAAgB,GAAG,gBAAgB,IAC7C,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG;IACrD,OAAO,CAAC,EAAE,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;CACjC,CAAC;AACF,wBAAgB,aAAa,CAAC,GAAG,SAAS,gBAAgB,EACxD,KAAK,EAAE,kBAAkB,CAAC,GAAG,CAAC,+BAyB/B"}
|
|
@@ -79,9 +79,9 @@ export function PayoutHistory(props) {
|
|
|
79
79
|
return (_jsx(Collection, { emptyLabel: "No payouts yet.", ...props, getKey: (row) => row.id, columns: props.columns ?? columns }));
|
|
80
80
|
}
|
|
81
81
|
function NativePayouts({ data, isLoading, isPending, error, nextPayout, previousPayouts, upcomingPayouts, refresh, loadMore, }) {
|
|
82
|
-
return (_jsxs("section", { "data-better-stripe": "payouts", "aria-busy": isPending, children: [_jsx("h2", { children: "Payouts" }), _jsx("button", { type: "button", disabled: isPending, onClick: refresh, children: isPending ? "Refreshing…" : "Refresh" }), error && _jsx("p", { role: "alert", children: error }), isLoading && !data && _jsx("p", { role: "status", children: "Loading payouts\u2026" }), data && (_jsxs(_Fragment, { children: [_jsxs("dl", { children: [data.balances.map((balance) => (_jsxs("div", { children: [_jsx("dt", { children: "Available" }), _jsx("dd", { children: formatPrice(balance.available, balance.currency) }), _jsx("dt", { children: "Pending" }), _jsx("dd", { children: formatPrice(balance.pending, balance.currency) })] }, balance.currency))), _jsx("dt", { children: "Next payout" }), _jsx("dd", { children: nextPayout
|
|
82
|
+
return (_jsxs("section", { "data-better-stripe": "payouts", "aria-busy": isPending, children: [_jsx("h2", { children: "Payouts" }), _jsx("button", { type: "button", disabled: isPending, onClick: refresh, children: isPending ? "Refreshing…" : "Refresh" }), error && _jsx("p", { role: "alert", children: error }), isLoading && !data && _jsx("p", { role: "status", children: "Loading payouts\u2026" }), data?.status === "not_ready" && (_jsx("p", { role: "alert", children: "Stripe account data is not available yet." })), data && data.status !== "not_ready" && (_jsxs(_Fragment, { children: [_jsxs("dl", { children: [data.balances.map((balance) => (_jsxs("div", { children: [_jsx("dt", { children: "Available" }), _jsx("dd", { children: formatPrice(balance.available, balance.currency) }), _jsx("dt", { children: "Pending" }), _jsx("dd", { children: formatPrice(balance.pending, balance.currency) })] }, balance.currency))), _jsx("dt", { children: "Next payout" }), _jsx("dd", { children: nextPayout
|
|
83
83
|
? `${formatPrice(nextPayout.amount, nextPayout.currency)} · ${date(nextPayout.arrivalDate)}`
|
|
84
|
-
: "Not scheduled" })] }), _jsx("h3", { children: "Upcoming payouts" }), _jsx(PayoutHistory, { rows: upcomingPayouts, emptyLabel: "No upcoming payouts scheduled." }), _jsx("h3", { children: "Previous payouts" }), _jsx(PayoutHistory, { rows: previousPayouts, emptyLabel: "No previous payouts yet." }), data.nextCursor && (_jsx("button", { type: "button", disabled: isPending, onClick: () => {
|
|
84
|
+
: "Not scheduled" })] }), _jsx("h3", { children: "Upcoming payouts" }), data.upcomingComplete === false && (_jsx("p", { children: "Upcoming payouts are a bounded preview. More may be scheduled." })), _jsx(PayoutHistory, { rows: upcomingPayouts, emptyLabel: "No upcoming payouts scheduled." }), _jsx("h3", { children: "Previous payouts" }), _jsx(PayoutHistory, { rows: previousPayouts, emptyLabel: "No previous payouts yet." }), data.nextCursor && (_jsx("button", { type: "button", disabled: isPending, onClick: () => {
|
|
85
85
|
void loadMore();
|
|
86
86
|
}, children: isPending ? "Loading…" : "Load more payouts" }))] }))] }));
|
|
87
87
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Payouts.js","sourceRoot":"","sources":["../../../src/react/workflows/Payouts.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;
|
|
1
|
+
{"version":3,"file":"Payouts.js","sourceRoot":"","sources":["../../../src/react/workflows/Payouts.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAKb,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,OAAO,EAAqB,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EACL,UAAU,GAGX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AA6BtD,MAAM,QAAQ,GAAG,CAAC,GAAc,EAAE,EAAE,CAClC,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,KAAK,YAAY,CAAC;AAC1D,MAAM,UAAU,OAAO,CAAC,KAAmB;IACzC,OAAO,KAAK,CAAC,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,CACzC,KAAC,OAAO,OAAK,KAAK,EAAE,SAAS,EAAC,SAAS,GAAG,CAC3C,CAAC,CAAC,CAAC,CACF,KAAC,WAAW,OAA0B,KAAK,IAAzB,KAAK,CAAC,QAAQ,CAAe,CAChD,CAAC;AACJ,CAAC;AACD,SAAS,WAAW,CAAC,EAAE,IAAI,EAAE,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AC,0BAA0B,GACrC,EACD,IAAI,CAAC,UAAU,IAAI,CAClB,iBACE,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,GAAG,EAAE;4BACZ,KAAK,QAAQ,EAAE,CAAC;wBAClB,CAAC,YAEA,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,mBAAmB,GACtC,CACV,IACA,CACJ,IACO,CACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Customer-only Accounts v2 preview
|
|
2
|
+
|
|
3
|
+
Connect platforms keep the default `2026-09-30.endive` API version. Non-Connect
|
|
4
|
+
merchants can explicitly opt into `2026-09-30.preview` for customer-configured
|
|
5
|
+
Accounts. The package does not enable Connect or onboard a merchant/recipient
|
|
6
|
+
when creating a buyer with `ensureCustomerAccount`.
|
|
7
|
+
|
|
8
|
+
## Enable the sandbox feature first
|
|
9
|
+
|
|
10
|
+
In the intended sandbox, the account owner must enable **Reusable payment
|
|
11
|
+
methods for Global Payouts** under **Account previews and features**. If the toggle
|
|
12
|
+
is unavailable, request access using Stripe's form. This also enables Stripe's
|
|
13
|
+
reusable payout credentials preview; it is not a Connect onboarding flow.
|
|
14
|
+
Changing an API version cannot enable the feature on the Stripe account.
|
|
15
|
+
|
|
16
|
+
Enabling the preview synchronizes existing Customers with customer-configured
|
|
17
|
+
Accounts and changes how Stripe-hosted integrations create customers. Review
|
|
18
|
+
Stripe's limitations and migration behavior before changing any live account.
|
|
19
|
+
See [Stripe's customer Account guide](https://docs.stripe.com/accounts-v2/use-accounts-as-customers).
|
|
20
|
+
|
|
21
|
+
## Configure one client and its webhook route
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
// convex/stripe.ts
|
|
25
|
+
import {
|
|
26
|
+
BetterStripe,
|
|
27
|
+
STRIPE_CUSTOMER_PREVIEW_API_VERSION,
|
|
28
|
+
} from "@fantastic.dev/better-stripe";
|
|
29
|
+
import { components } from "./_generated/api";
|
|
30
|
+
|
|
31
|
+
export const stripe = new BetterStripe(components.betterStripe, {
|
|
32
|
+
STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY,
|
|
33
|
+
stripeApiVersion: STRIPE_CUSTOMER_PREVIEW_API_VERSION,
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
// convex/http.ts
|
|
39
|
+
import { httpRouter } from "convex/server";
|
|
40
|
+
import { stripe } from "./stripe";
|
|
41
|
+
|
|
42
|
+
const http = httpRouter();
|
|
43
|
+
stripe.registerRoutes(http, {
|
|
44
|
+
webhookPath: "/stripe/webhook",
|
|
45
|
+
webhookSecret: process.env.STRIPE_WEBHOOK_SECRET,
|
|
46
|
+
webhookSecretV2: process.env.STRIPE_WEBHOOK_SECRET_V2,
|
|
47
|
+
// Preserve your existing `webhooks` handler references and retry policy here.
|
|
48
|
+
});
|
|
49
|
+
export default http;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The instance route inherits its client's key and version. Conflicting explicit
|
|
53
|
+
values fail at registration. The standalone `registerRoutes` function remains
|
|
54
|
+
available; when using it, pass `stripeApiVersion: stripe.stripeApiVersion` and the
|
|
55
|
+
same secret key explicitly. The client accepts only the supported GA and customer
|
|
56
|
+
preview versions; unsupported values fail with `INVALID_CONFIGURATION`.
|
|
57
|
+
|
|
58
|
+
All client operations use the selected version: account creation/configuration,
|
|
59
|
+
Checkout, subscriptions, portal sessions, refunds, authoritative reads, and the
|
|
60
|
+
provider calls made while handling webhooks. Component database writes remain
|
|
61
|
+
provider-version independent. SDK caches separate clients by key and version.
|
|
62
|
+
|
|
63
|
+
## Create a buyer and Checkout Session
|
|
64
|
+
|
|
65
|
+
Authenticate the caller and validate ownership/prices on the server. The client
|
|
66
|
+
is not an authorization boundary. Persist logical request identities in your host
|
|
67
|
+
app so retries keep the same provider keys and new purchases use distinct keys.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const buyer = await stripe.ensureCustomerAccount(ctx, {
|
|
71
|
+
userId: identity.subject,
|
|
72
|
+
email: verifiedEmail,
|
|
73
|
+
idempotencyKey: accountProvisioningKey,
|
|
74
|
+
});
|
|
75
|
+
const checkout = await stripe.createCheckoutSession(ctx, {
|
|
76
|
+
userId: identity.subject,
|
|
77
|
+
accountId: buyer.stripeAccountId,
|
|
78
|
+
stripePriceId: authorizedPriceId,
|
|
79
|
+
mode: "subscription",
|
|
80
|
+
uiMode: "redirect",
|
|
81
|
+
returnUrl: "https://example.com/receipt?session_id={CHECKOUT_SESSION_ID}",
|
|
82
|
+
idempotencyKey: orderKey,
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The buyer is an `acct_` object with the customer configuration. Checkout uses
|
|
87
|
+
`customer_account`, not a connected-account destination. No seller, recipient,
|
|
88
|
+
transfer, or application fee is added by this configuration.
|
|
89
|
+
|
|
90
|
+
After verifying buyer/order ownership, use `getCheckoutSessionFromStripe` to
|
|
91
|
+
check current payment status. Completion alone does not prove payment: fulfill
|
|
92
|
+
only when your payment policy accepts the authoritative status, and deduplicate
|
|
93
|
+
fulfillment by a durable order key. Subscription and coupon reads use the same
|
|
94
|
+
configured version. Cancellation/reactivation and refunds keep their existing
|
|
95
|
+
public API signatures and caller idempotency behavior.
|
|
96
|
+
|
|
97
|
+
## Match webhook payload versions and scope
|
|
98
|
+
|
|
99
|
+
Snapshot destinations created through this client pin `snapshot_api_version` to
|
|
100
|
+
the selected version. V1 webhook endpoints pin their `api_version`. Thin events
|
|
101
|
+
are unversioned; their related customer Account is fetched with the selected
|
|
102
|
+
request version and only customer/identity includes in customer-preview mode.
|
|
103
|
+
|
|
104
|
+
The preview's default thin subscription covers Account creation, customer
|
|
105
|
+
configuration changes, and identity changes, using Stripe's `@self` and
|
|
106
|
+
`@accounts` scopes. Subscription and invoice changes continue to use V1 snapshot
|
|
107
|
+
events. No merchant or recipient capability events are subscribed by default in
|
|
108
|
+
customer-preview mode. The GA defaults retain their existing event selection.
|
|
109
|
+
|
|
110
|
+
Stripe cannot update a destination's snapshot version or event scopes in place.
|
|
111
|
+
`setupEventDestination` refuses an incompatible existing destination rather than
|
|
112
|
+
silently reusing it. Create a replacement at a new webhook path, register the
|
|
113
|
+
matching route and signing secret, verify deliveries, then retire the old
|
|
114
|
+
endpoint. A low-level `createWebhookEndpoint` call retains its existing same-URL
|
|
115
|
+
secret-rotation behavior; do not use it as an implicit migration plan.
|
|
116
|
+
|
|
117
|
+
See [event destination creation](https://docs.stripe.com/api/v2/core/event-destinations/create)
|
|
118
|
+
and [update restrictions](https://docs.stripe.com/api/v2/core/event-destinations/update).
|
|
119
|
+
|
|
120
|
+
## Verification boundary
|
|
121
|
+
|
|
122
|
+
Package tests exercise serialized SDK request headers, customer-only account
|
|
123
|
+
configuration, idempotency keys, Checkout buyer binding, authoritative reads,
|
|
124
|
+
subscription cancellation/reactivation, portal and refund calls, webhook route
|
|
125
|
+
configuration, thin-event synchronization, and snapshot version/scope checks.
|
|
126
|
+
The GA version has regression coverage alongside the preview version.
|
|
127
|
+
|
|
128
|
+
A real non-Connect sandbox test additionally requires the owner-enabled preview
|
|
129
|
+
and sandbox credentials. A Connect sandbox, mocked transport, or successful
|
|
130
|
+
TypeScript compilation does not prove that separate eligibility requirement.
|
|
131
|
+
Do not report checkout, receipt, renewal, portal or refund acceptance as verified
|
|
132
|
+
for a non-Connect merchant until those flows run in its enabled sandbox.
|