@fantastic.dev/better-stripe 0.48.1 → 0.50.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 +34 -0
- package/README.md +1 -1
- package/dist/client/billing/invoicePaymentPages.d.ts +2 -5
- package/dist/client/billing/invoicePaymentPages.d.ts.map +1 -1
- package/dist/client/billing/invoicePaymentPages.js +2 -58
- package/dist/client/billing/invoicePaymentPages.js.map +1 -1
- package/dist/client/billing/invoicePaymentRead.d.ts +17 -0
- package/dist/client/billing/invoicePaymentRead.d.ts.map +1 -0
- package/dist/client/billing/invoicePaymentRead.js +25 -0
- package/dist/client/billing/invoicePaymentRead.js.map +1 -0
- package/dist/client/billing/invoicePaymentShared.d.ts +22 -0
- package/dist/client/billing/invoicePaymentShared.d.ts.map +1 -0
- package/dist/client/billing/invoicePaymentShared.js +62 -0
- package/dist/client/billing/invoicePaymentShared.js.map +1 -0
- package/dist/client/billing/setup-intent-read.d.ts +22 -0
- package/dist/client/billing/setup-intent-read.d.ts.map +1 -0
- package/dist/client/billing/setup-intent-read.js +63 -0
- package/dist/client/billing/setup-intent-read.js.map +1 -0
- package/dist/client/billing/subscription-payment-method.d.ts +28 -0
- package/dist/client/billing/subscription-payment-method.d.ts.map +1 -0
- package/dist/client/billing/subscription-payment-method.js +101 -0
- package/dist/client/billing/subscription-payment-method.js.map +1 -0
- package/dist/client/index.d.ts +9 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +10 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/invoiceReads.d.ts +3 -0
- package/dist/client/invoiceReads.d.ts.map +1 -1
- package/dist/client/invoiceReads.js +5 -0
- package/dist/client/invoiceReads.js.map +1 -1
- package/dist/component/_generated/component.d.ts +1 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/connect/queries.d.ts +1 -0
- package/dist/component/connect/queries.d.ts.map +1 -1
- package/dist/component/connect/queries.js +10 -4
- package/dist/component/connect/queries.js.map +1 -1
- package/dist/component/refundHistory/queries.d.ts +1 -1
- package/docs/invoice-payment-pages.md +62 -0
- package/docs/react-workflows.md +9 -0
- package/docs/read-contracts.md +45 -0
- package/docs/setup-intent-recovery.md +27 -0
- package/docs/subscription-payment-methods.md +121 -0
- package/package.json +4 -2
- package/src/client/billing/invoicePaymentPages.ts +9 -74
- package/src/client/billing/invoicePaymentRead.test.ts +233 -0
- package/src/client/billing/invoicePaymentRead.ts +44 -0
- package/src/client/billing/invoicePaymentReadTransport.test.ts +101 -0
- package/src/client/billing/invoicePaymentShared.ts +84 -0
- package/src/client/billing/setup-intent-read.test.ts +284 -0
- package/src/client/billing/setup-intent-read.ts +97 -0
- package/src/client/billing/subscription-payment-method.test.ts +460 -0
- package/src/client/billing/subscription-payment-method.ts +177 -0
- package/src/client/index.ts +39 -0
- package/src/client/invoiceReads.ts +9 -0
- package/src/component/_generated/component.ts +1 -1
- package/src/component/connect/payment-unique.test.ts +195 -0
- package/src/component/connect/queries.ts +9 -4
|
@@ -3,6 +3,7 @@ import { ReadContractClient } from "./readContracts.js";
|
|
|
3
3
|
import type { RunCtx } from "./helpers.js";
|
|
4
4
|
import { getRefundContext } from "./connect/refundContext.js";
|
|
5
5
|
import type { RefundContextOptions } from "./connect/refundContextTypes.js";
|
|
6
|
+
import * as invoicePaymentRead from "./billing/invoicePaymentRead.js";
|
|
6
7
|
import * as invoicePages from "./billing/invoicePages.js";
|
|
7
8
|
import * as invoicePaymentPages from "./billing/invoicePaymentPages.js";
|
|
8
9
|
import * as checkoutPages from "./billing/checkoutPages.js";
|
|
@@ -42,4 +43,12 @@ export abstract class InvoiceReadClient extends ReadContractClient {
|
|
|
42
43
|
opts,
|
|
43
44
|
);
|
|
44
45
|
}
|
|
46
|
+
|
|
47
|
+
/** Exact original reference read; host authorization and post-read checks remain required. */
|
|
48
|
+
async getInvoicePaymentFromStripe(
|
|
49
|
+
_ctx: RunCtx,
|
|
50
|
+
opts: invoicePaymentRead.InvoicePaymentReadOptions,
|
|
51
|
+
) {
|
|
52
|
+
return invoicePaymentRead.getInvoicePaymentFromStripe(this.stripe(), opts);
|
|
53
|
+
}
|
|
45
54
|
}
|
|
@@ -2974,7 +2974,7 @@ export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
|
2974
2974
|
getPaymentByStripeId: FunctionReference<
|
|
2975
2975
|
"query",
|
|
2976
2976
|
"internal",
|
|
2977
|
-
{ stripePaymentIntentId: string },
|
|
2977
|
+
{ requireUnique?: boolean; stripePaymentIntentId: string },
|
|
2978
2978
|
{
|
|
2979
2979
|
_creationTime: number;
|
|
2980
2980
|
_id: string;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// @vitest-environment edge-runtime
|
|
2
|
+
import { convexTest } from "convex-test";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import { api } from "../_generated/api.js";
|
|
5
|
+
import { schema, modules } from "../../test.js";
|
|
6
|
+
|
|
7
|
+
async function fixture() {
|
|
8
|
+
const t = convexTest(schema, modules);
|
|
9
|
+
const paymentId = await t.run((ctx) =>
|
|
10
|
+
ctx.db.insert("payments", {
|
|
11
|
+
stripePaymentIntentId: "pi_original_history",
|
|
12
|
+
userId: "original_buyer",
|
|
13
|
+
accountId: "acct_original_buyer",
|
|
14
|
+
destinationAccountId: "acct_original_merchant",
|
|
15
|
+
chargeType: "destination",
|
|
16
|
+
amount: 123,
|
|
17
|
+
currency: "usd",
|
|
18
|
+
status: "succeeded",
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
return { t, paymentId };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
it("retains the existing unique-row and legacy duplicate first-row positives", async () => {
|
|
25
|
+
const f = await fixture();
|
|
26
|
+
const args = { stripePaymentIntentId: "pi_original_history" };
|
|
27
|
+
const original = await f.t.query(
|
|
28
|
+
api.connect.queries.getPaymentByStripeId,
|
|
29
|
+
args,
|
|
30
|
+
);
|
|
31
|
+
expect(original).toMatchObject({
|
|
32
|
+
_id: f.paymentId,
|
|
33
|
+
userId: "original_buyer",
|
|
34
|
+
});
|
|
35
|
+
await f.t.run(async (ctx) => {
|
|
36
|
+
if (!original) throw new Error("Missing actual original payment");
|
|
37
|
+
const { _id: _id, _creationTime: _creationTime, ...fields } = original;
|
|
38
|
+
await ctx.db.insert("payments", {
|
|
39
|
+
...fields,
|
|
40
|
+
userId: "foreign_buyer",
|
|
41
|
+
accountId: "acct_foreign_buyer",
|
|
42
|
+
destinationAccountId: "acct_foreign_merchant",
|
|
43
|
+
currency: "eur",
|
|
44
|
+
status: "failed",
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
expect(
|
|
48
|
+
await f.t.query(api.connect.queries.getPaymentByStripeId, args),
|
|
49
|
+
).toEqual(original);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("returns null for globally ambiguous exact PI when uniqueness is explicitly required", async () => {
|
|
53
|
+
const f = await fixture();
|
|
54
|
+
await f.t.run((ctx) =>
|
|
55
|
+
ctx.db.insert("payments", {
|
|
56
|
+
stripePaymentIntentId: "pi_original_history",
|
|
57
|
+
userId: "foreign_buyer",
|
|
58
|
+
orgId: "foreign_org",
|
|
59
|
+
accountId: "acct_foreign_buyer",
|
|
60
|
+
destinationAccountId: "acct_foreign_merchant",
|
|
61
|
+
chargeType: "destination",
|
|
62
|
+
amount: 123,
|
|
63
|
+
currency: "eur",
|
|
64
|
+
status: "failed",
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
67
|
+
const args = {
|
|
68
|
+
stripePaymentIntentId: "pi_original_history",
|
|
69
|
+
requireUnique: true,
|
|
70
|
+
};
|
|
71
|
+
await expect(
|
|
72
|
+
f.t.query(api.connect.queries.getPaymentByStripeId, args),
|
|
73
|
+
).resolves.toBeNull();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("returns null for a missing exact PI when uniqueness is required", async () => {
|
|
77
|
+
const f = await fixture();
|
|
78
|
+
const args = { stripePaymentIntentId: "pi_missing", requireUnique: true };
|
|
79
|
+
expect(
|
|
80
|
+
await f.t.query(api.connect.queries.getPaymentByStripeId, args),
|
|
81
|
+
).toBeNull();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("returns the unchanged sole original document without filtering failed state or currency", async () => {
|
|
85
|
+
const f = await fixture();
|
|
86
|
+
await f.t.run((ctx) =>
|
|
87
|
+
ctx.db.patch("payments", f.paymentId, {
|
|
88
|
+
currency: "jpy",
|
|
89
|
+
status: "failed",
|
|
90
|
+
amount: 123,
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
const args = {
|
|
94
|
+
stripePaymentIntentId: "pi_original_history",
|
|
95
|
+
requireUnique: true,
|
|
96
|
+
};
|
|
97
|
+
const stored = await f.t.run((ctx) => ctx.db.get("payments", f.paymentId));
|
|
98
|
+
expect(
|
|
99
|
+
await f.t.query(api.connect.queries.getPaymentByStripeId, args),
|
|
100
|
+
).toEqual(stored);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("preserves explicit false first-row behavior on duplicate original PIs", async () => {
|
|
104
|
+
const f = await fixture();
|
|
105
|
+
await f.t.run((ctx) =>
|
|
106
|
+
ctx.db.insert("payments", {
|
|
107
|
+
stripePaymentIntentId: "pi_original_history",
|
|
108
|
+
userId: "foreign_buyer",
|
|
109
|
+
amount: 1,
|
|
110
|
+
currency: "eur",
|
|
111
|
+
status: "failed",
|
|
112
|
+
}),
|
|
113
|
+
);
|
|
114
|
+
const args = {
|
|
115
|
+
stripePaymentIntentId: "pi_original_history",
|
|
116
|
+
requireUnique: false,
|
|
117
|
+
};
|
|
118
|
+
expect(
|
|
119
|
+
await f.t.query(api.connect.queries.getPaymentByStripeId, args),
|
|
120
|
+
).toMatchObject({ _id: f.paymentId });
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it.each([
|
|
124
|
+
{ userId: "foreign_buyer" },
|
|
125
|
+
{ orgId: "foreign_org" },
|
|
126
|
+
{ accountId: "acct_replacement" },
|
|
127
|
+
{ destinationAccountId: "acct_foreign_merchant" },
|
|
128
|
+
{ currency: "eur" },
|
|
129
|
+
{ status: "failed" },
|
|
130
|
+
] as const)(
|
|
131
|
+
"holds global duplicate PI before qualification of %j",
|
|
132
|
+
async (changed) => {
|
|
133
|
+
const f = await fixture();
|
|
134
|
+
await f.t.run(async (ctx) => {
|
|
135
|
+
const original = await ctx.db.get("payments", f.paymentId);
|
|
136
|
+
if (!original) throw new Error("Missing original");
|
|
137
|
+
const { _id: _id, _creationTime: _creationTime, ...fields } = original;
|
|
138
|
+
await ctx.db.insert("payments", { ...fields, ...changed });
|
|
139
|
+
});
|
|
140
|
+
const args = {
|
|
141
|
+
stripePaymentIntentId: "pi_original_history",
|
|
142
|
+
requireUnique: true,
|
|
143
|
+
};
|
|
144
|
+
expect(
|
|
145
|
+
await f.t.query(api.connect.queries.getPaymentByStripeId, args),
|
|
146
|
+
).toBeNull();
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
it("does not depend on whether a matching or foreign duplicate was inserted first", async () => {
|
|
151
|
+
const f = await fixture();
|
|
152
|
+
await f.t.run(async (ctx) => {
|
|
153
|
+
await ctx.db.insert("payments", {
|
|
154
|
+
stripePaymentIntentId: "pi_foreign_first",
|
|
155
|
+
userId: "foreign_buyer",
|
|
156
|
+
amount: 1,
|
|
157
|
+
currency: "eur",
|
|
158
|
+
status: "failed",
|
|
159
|
+
});
|
|
160
|
+
await ctx.db.insert("payments", {
|
|
161
|
+
stripePaymentIntentId: "pi_foreign_first",
|
|
162
|
+
userId: "original_buyer",
|
|
163
|
+
amount: 123,
|
|
164
|
+
currency: "usd",
|
|
165
|
+
status: "succeeded",
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
const args = {
|
|
169
|
+
stripePaymentIntentId: "pi_foreign_first",
|
|
170
|
+
requireUnique: true,
|
|
171
|
+
};
|
|
172
|
+
expect(
|
|
173
|
+
await f.t.query(api.connect.queries.getPaymentByStripeId, args),
|
|
174
|
+
).toBeNull();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("does not confuse unrelated PIs with ambiguity of the exact requested key", async () => {
|
|
178
|
+
const f = await fixture();
|
|
179
|
+
await f.t.run((ctx) =>
|
|
180
|
+
ctx.db.insert("payments", {
|
|
181
|
+
stripePaymentIntentId: "pi_unrelated_original",
|
|
182
|
+
userId: "original_buyer",
|
|
183
|
+
amount: 123,
|
|
184
|
+
currency: "usd",
|
|
185
|
+
status: "succeeded",
|
|
186
|
+
}),
|
|
187
|
+
);
|
|
188
|
+
const args = {
|
|
189
|
+
stripePaymentIntentId: "pi_original_history",
|
|
190
|
+
requireUnique: true,
|
|
191
|
+
};
|
|
192
|
+
expect(
|
|
193
|
+
await f.t.query(api.connect.queries.getPaymentByStripeId, args),
|
|
194
|
+
).toMatchObject({ _id: f.paymentId });
|
|
195
|
+
});
|
|
@@ -30,15 +30,20 @@ import {
|
|
|
30
30
|
// PAYMENT QUERIES
|
|
31
31
|
|
|
32
32
|
export const getPaymentByStripeId = query({
|
|
33
|
-
args: {
|
|
33
|
+
args: {
|
|
34
|
+
stripePaymentIntentId: v.string(),
|
|
35
|
+
requireUnique: v.optional(v.boolean()),
|
|
36
|
+
},
|
|
34
37
|
returns: v.union(paymentDocValidator, v.null()),
|
|
35
38
|
handler: async (ctx, args) => {
|
|
36
|
-
|
|
39
|
+
const rows = ctx.db
|
|
37
40
|
.query("payments")
|
|
38
41
|
.withIndex("by_stripe_payment_intent_id", (q) =>
|
|
39
42
|
q.eq("stripePaymentIntentId", args.stripePaymentIntentId),
|
|
40
|
-
)
|
|
41
|
-
|
|
43
|
+
);
|
|
44
|
+
if (!args.requireUnique) return await rows.first();
|
|
45
|
+
const matches = await rows.take(2);
|
|
46
|
+
return matches.length === 1 ? matches[0]! : null;
|
|
42
47
|
},
|
|
43
48
|
});
|
|
44
49
|
|