@fantastic.dev/better-stripe 0.32.0 → 0.34.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 +14 -0
- package/README.md +36 -1
- package/dist/client/billing/checkoutPages.d.ts +26 -0
- package/dist/client/billing/checkoutPages.d.ts.map +1 -0
- package/dist/client/billing/checkoutPages.js +111 -0
- package/dist/client/billing/checkoutPages.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +36 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +18 -0
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +36 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +18 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/refundContext.d.ts +6 -0
- package/dist/client/connect/refundContext.d.ts.map +1 -0
- package/dist/client/connect/refundContext.js +109 -0
- package/dist/client/connect/refundContext.js.map +1 -0
- package/dist/client/connect/refundContextHistory.d.ts +20 -0
- package/dist/client/connect/refundContextHistory.d.ts.map +1 -0
- package/dist/client/connect/refundContextHistory.js +55 -0
- package/dist/client/connect/refundContextHistory.js.map +1 -0
- package/dist/client/connect/refundContextTypes.d.ts +39 -0
- package/dist/client/connect/refundContextTypes.d.ts.map +1 -0
- package/dist/client/connect/refundContextTypes.js +15 -0
- package/dist/client/connect/refundContextTypes.js.map +1 -0
- package/dist/client/connect/refundTarget.d.ts +14 -0
- package/dist/client/connect/refundTarget.d.ts.map +1 -0
- package/dist/client/connect/refundTarget.js +17 -0
- package/dist/client/connect/refundTarget.js.map +1 -0
- package/dist/client/connect/refunds.d.ts +17 -1
- package/dist/client/connect/refunds.d.ts.map +1 -1
- package/dist/client/connect/refunds.js +7 -17
- package/dist/client/connect/refunds.js.map +1 -1
- package/dist/client/core/accountClosures.d.ts +15 -0
- package/dist/client/core/accountClosures.d.ts.map +1 -0
- package/dist/client/core/accountClosures.js +10 -0
- package/dist/client/core/accountClosures.js.map +1 -0
- package/dist/client/core/accounts.d.ts.map +1 -1
- package/dist/client/core/accounts.js +15 -23
- package/dist/client/core/accounts.js.map +1 -1
- package/dist/client/core/personalAccountMapping.d.ts +8 -0
- package/dist/client/core/personalAccountMapping.d.ts.map +1 -0
- package/dist/client/core/personalAccountMapping.js +11 -0
- package/dist/client/core/personalAccountMapping.js.map +1 -0
- package/dist/client/index.d.ts +57 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +13 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/invoiceReads.d.ts +7 -1
- package/dist/client/invoiceReads.d.ts.map +1 -1
- package/dist/client/invoiceReads.js +11 -1
- package/dist/client/invoiceReads.js.map +1 -1
- package/dist/client/publicTypes.d.ts +5 -0
- package/dist/client/publicTypes.d.ts.map +1 -0
- package/dist/client/publicTypes.js +2 -0
- package/dist/client/publicTypes.js.map +1 -0
- package/dist/component/_generated/component.d.ts +88 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/accountClosure/helpers.d.ts +18 -0
- package/dist/component/accountClosure/helpers.d.ts.map +1 -0
- package/dist/component/accountClosure/helpers.js +18 -0
- package/dist/component/accountClosure/helpers.js.map +1 -0
- package/dist/component/accountClosure/mutations.d.ts +20 -0
- package/dist/component/accountClosure/mutations.d.ts.map +1 -0
- package/dist/component/accountClosure/mutations.js +55 -0
- package/dist/component/accountClosure/mutations.js.map +1 -0
- package/dist/component/accountClosure/queries.d.ts +34 -0
- package/dist/component/accountClosure/queries.d.ts.map +1 -0
- package/dist/component/accountClosure/queries.js +36 -0
- package/dist/component/accountClosure/queries.js.map +1 -0
- package/dist/component/accountClosure/schema.d.ts +46 -0
- package/dist/component/accountClosure/schema.d.ts.map +1 -0
- package/dist/component/accountClosure/schema.js +20 -0
- package/dist/component/accountClosure/schema.js.map +1 -0
- package/dist/component/core/mutations.d.ts.map +1 -1
- package/dist/component/core/mutations.js +5 -0
- package/dist/component/core/mutations.js.map +1 -1
- package/dist/component/core/personalAccountMapping.d.ts +95 -0
- package/dist/component/core/personalAccountMapping.d.ts.map +1 -0
- package/dist/component/core/personalAccountMapping.js +54 -0
- package/dist/component/core/personalAccountMapping.js.map +1 -0
- package/dist/component/core/queries.d.ts +27 -0
- package/dist/component/core/queries.d.ts.map +1 -1
- package/dist/component/core/queries.js +7 -0
- package/dist/component/core/queries.js.map +1 -1
- package/dist/component/earnings/triggers.d.ts +42 -0
- package/dist/component/earnings/triggers.d.ts.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/schema.d.ts +18 -0
- package/dist/component/schema.js +2 -0
- package/dist/component/schema.js.map +1 -1
- package/docs/checkout-session-pages.md +71 -0
- package/docs/personal-account-mapping.md +54 -0
- package/docs/read-contracts.md +28 -0
- package/docs/refund-context.md +84 -0
- package/package.json +5 -2
- package/src/client/billing/checkoutPages.test.ts +251 -0
- package/src/client/billing/checkoutPages.ts +135 -0
- package/src/client/connect/refundContext.ts +140 -0
- package/src/client/connect/refundContextHistory.ts +84 -0
- package/src/client/connect/refundContextTypes.ts +56 -0
- package/src/client/connect/refundTarget.ts +39 -0
- package/src/client/connect/refunds.test.ts +72 -0
- package/src/client/connect/refunds.ts +8 -22
- package/src/client/core/account-close-orchestration.test.ts +131 -0
- package/src/client/core/account-closure.test.ts +317 -0
- package/src/client/core/accountClosures.ts +37 -0
- package/src/client/core/accounts.test.ts +0 -111
- package/src/client/core/accounts.ts +24 -29
- package/src/client/core/personal-account-mapping.test.ts +71 -0
- package/src/client/core/personalAccountMapping.ts +23 -0
- package/src/client/index.ts +45 -33
- package/src/client/invoiceReads.ts +17 -1
- package/src/client/publicTypes.ts +35 -0
- package/src/client/refund-context-shapes.test.ts +127 -0
- package/src/client/refund-context.test.ts +404 -0
- package/src/component/_generated/api.ts +8 -0
- package/src/component/_generated/component.ts +126 -0
- package/src/component/accountClosure/helpers.ts +21 -0
- package/src/component/accountClosure/mutations.ts +56 -0
- package/src/component/accountClosure/queries.ts +43 -0
- package/src/component/accountClosure/schema.ts +20 -0
- package/src/component/core/mutations.ts +3 -0
- package/src/component/core/personal-account-mapping.test.ts +173 -0
- package/src/component/core/personalAccountMapping.ts +81 -0
- package/src/component/core/queries.ts +11 -0
- package/src/component/schema.ts +2 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// @vitest-environment edge-runtime
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
import schema from "../../component/schema.js";
|
|
5
|
+
import { BetterStripe } from "../index.js";
|
|
6
|
+
import type { RunCtx } from "../helpers.js";
|
|
7
|
+
import { components, initConvexTest } from "../setup.test.js";
|
|
8
|
+
|
|
9
|
+
const modules = import.meta.glob("../../component/**/*.ts");
|
|
10
|
+
function fixture() {
|
|
11
|
+
const t = initConvexTest();
|
|
12
|
+
t.registerComponent("betterStripe", schema, modules);
|
|
13
|
+
const ctx = { runQuery: t.query, runMutation: t.mutation } as RunCtx;
|
|
14
|
+
const client = new BetterStripe(components.betterStripe, {});
|
|
15
|
+
return { t, ctx, client };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("public personal account mapping", () => {
|
|
19
|
+
it("returns real component proof without a Stripe secret or provider read", async () => {
|
|
20
|
+
const f = fixture();
|
|
21
|
+
await f.client.upsertAccount(f.ctx, {
|
|
22
|
+
stripeAccountId: "acct_original",
|
|
23
|
+
userId: "user_original",
|
|
24
|
+
});
|
|
25
|
+
expect(
|
|
26
|
+
await f.client.getPersonalAccountMapping(f.ctx, {
|
|
27
|
+
userId: "user_original",
|
|
28
|
+
}),
|
|
29
|
+
).toMatchObject({
|
|
30
|
+
status: "unique",
|
|
31
|
+
account: { stripeAccountId: "acct_original", userId: "user_original" },
|
|
32
|
+
});
|
|
33
|
+
await f.client.upsertAccount(f.ctx, {
|
|
34
|
+
stripeAccountId: "acct_replacement",
|
|
35
|
+
userId: "user_original",
|
|
36
|
+
});
|
|
37
|
+
expect(
|
|
38
|
+
await f.client.getPersonalAccountMapping(f.ctx, {
|
|
39
|
+
userId: "user_original",
|
|
40
|
+
}),
|
|
41
|
+
).toEqual({ status: "unavailable", reason: "ambiguous" });
|
|
42
|
+
expect(
|
|
43
|
+
(await f.client.getAccountByUserId(f.ctx, { userId: "user_original" }))
|
|
44
|
+
?.stripeAccountId,
|
|
45
|
+
).toBe("acct_original");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it.each([
|
|
49
|
+
undefined,
|
|
50
|
+
null,
|
|
51
|
+
{},
|
|
52
|
+
{ userId: "" },
|
|
53
|
+
{ userId: " a" },
|
|
54
|
+
{ userId: 123 },
|
|
55
|
+
{ userId: "x".repeat(257) },
|
|
56
|
+
{ userId: "user_original", stripeAccountId: "acct_browser" },
|
|
57
|
+
])(
|
|
58
|
+
"rejects malformed options %j before component lookup",
|
|
59
|
+
async (options) => {
|
|
60
|
+
const f = fixture();
|
|
61
|
+
const runQuery = vi.fn();
|
|
62
|
+
const ctx = { runQuery } as RunCtx;
|
|
63
|
+
const read = f.client.getPersonalAccountMapping.bind(f.client) as (
|
|
64
|
+
ctx: RunCtx,
|
|
65
|
+
opts: unknown,
|
|
66
|
+
) => Promise<unknown>;
|
|
67
|
+
await expect(read(ctx, options)).rejects.toThrow();
|
|
68
|
+
expect(runQuery).not.toHaveBeenCalled();
|
|
69
|
+
},
|
|
70
|
+
);
|
|
71
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import { assertPersonalAccountUserId } from "../../component/core/personalAccountMapping.js";
|
|
4
|
+
import type { PersonalAccountMapping } from "../../component/core/personalAccountMapping.js";
|
|
5
|
+
import type { Component, RunCtx } from "../helpers.js";
|
|
6
|
+
import { componentRef } from "../webhooks/helpers.js";
|
|
7
|
+
|
|
8
|
+
export type { PersonalAccountMapping } from "../../component/core/personalAccountMapping.js";
|
|
9
|
+
const optionsSchema = z.object({ userId: z.string() }).strict();
|
|
10
|
+
|
|
11
|
+
/** Mapping evidence only. Authenticate the host actor before passing its server-owned identity. */
|
|
12
|
+
export async function getPersonalAccountMapping(
|
|
13
|
+
component: Component,
|
|
14
|
+
ctx: RunCtx,
|
|
15
|
+
input: { userId: string },
|
|
16
|
+
): Promise<PersonalAccountMapping> {
|
|
17
|
+
const opts = optionsSchema.parse(input);
|
|
18
|
+
assertPersonalAccountUserId(opts.userId);
|
|
19
|
+
return ctx.runQuery(
|
|
20
|
+
componentRef(component, "core/queries/getPersonalAccountMapping"),
|
|
21
|
+
opts,
|
|
22
|
+
);
|
|
23
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import * as personalAccountMappingImpl from "./core/personalAccountMapping.js";
|
|
2
|
+
export type * from "./publicTypes.js";
|
|
3
|
+
import * as accountClosuresImpl from "./core/accountClosures.js";
|
|
4
|
+
import type { PaginationOptions } from "convex/server";
|
|
1
5
|
import { reconcilePayoutAndTrigger } from "./webhooks/payoutReconciliation.js";
|
|
2
6
|
import { AffiliateRecoveryClient } from "./affiliateRecovery.js";
|
|
3
7
|
export * from "./affiliateRecovery.js";
|
|
@@ -63,6 +67,10 @@ export type {
|
|
|
63
67
|
InvoicePageOptions,
|
|
64
68
|
ProviderInvoicePage,
|
|
65
69
|
} from "./billing/invoicePages.js";
|
|
70
|
+
export type {
|
|
71
|
+
CheckoutSessionPageOptions,
|
|
72
|
+
ProviderCheckoutSessionPage,
|
|
73
|
+
} from "./billing/checkoutPages.js";
|
|
66
74
|
export type { CreateAccountOptions } from "./core/accounts.js";
|
|
67
75
|
import { buildAsyncHookRoutes } from "./webhooks/asyncHooks.js";
|
|
68
76
|
import * as saleContextImpl from "./settlement/verifiedSale.js";
|
|
@@ -121,6 +129,11 @@ export {
|
|
|
121
129
|
disputeEvidenceCountdown,
|
|
122
130
|
} from "./connect/disputes.js";
|
|
123
131
|
export type { RefundActor } from "./connect/refunds.js";
|
|
132
|
+
export type {
|
|
133
|
+
RefundContextOptions,
|
|
134
|
+
RefundContext,
|
|
135
|
+
RefundContextUnavailableReason,
|
|
136
|
+
} from "./connect/refundContextTypes.js";
|
|
124
137
|
import type { RefundActor } from "./connect/refunds.js";
|
|
125
138
|
export type { AccountBalance } from "./connect/payouts.js";
|
|
126
139
|
export type { WedgedReversalClaim } from "./connect/transfers.js";
|
|
@@ -181,43 +194,10 @@ export type {
|
|
|
181
194
|
BetterStripeWebhookEvent,
|
|
182
195
|
} from "./utils/webhookEndpoints.js";
|
|
183
196
|
// Re-export types for consumers
|
|
184
|
-
export type {
|
|
185
|
-
BetterStripeOptions,
|
|
186
|
-
FeeOverride,
|
|
187
|
-
FeeTier,
|
|
188
|
-
PlatformFeeConfig,
|
|
189
|
-
RegisterRoutesConfig,
|
|
190
|
-
} from "./types.js";
|
|
191
197
|
export type {
|
|
192
198
|
StripeDashboardResourceType,
|
|
193
199
|
StripeMode,
|
|
194
200
|
} from "./utils/stripeDashboardUrl.js";
|
|
195
|
-
export type {
|
|
196
|
-
AccountLinkWithStatus,
|
|
197
|
-
AsyncHookCtx,
|
|
198
|
-
AsyncHooks,
|
|
199
|
-
PaymentMethodCard,
|
|
200
|
-
PaymentMethodLike,
|
|
201
|
-
StripeComponentAccount,
|
|
202
|
-
StripeComponentCheckoutSession,
|
|
203
|
-
StripeComponentDispute,
|
|
204
|
-
StripeComponentInvoice,
|
|
205
|
-
StripeComponentPayment,
|
|
206
|
-
StripeComponentPayout,
|
|
207
|
-
StripeComponentPrice,
|
|
208
|
-
StripeComponentProduct,
|
|
209
|
-
StripeComponentRefund,
|
|
210
|
-
StripeComponentSubscription,
|
|
211
|
-
StripeCountrySpecs,
|
|
212
|
-
StripeEventHandler,
|
|
213
|
-
StripeEventHandlers,
|
|
214
|
-
StripeV2Account,
|
|
215
|
-
StripeWebhookEvent,
|
|
216
|
-
SyncTriggerCtx,
|
|
217
|
-
SyncTriggers,
|
|
218
|
-
V2ThinEvent,
|
|
219
|
-
WebhookActionCtx,
|
|
220
|
-
} from "./types.js";
|
|
221
201
|
export type BetterStripeComponent = ComponentApi;
|
|
222
202
|
|
|
223
203
|
// BETTER STRIPE CLIENT
|
|
@@ -359,6 +339,38 @@ export class BetterStripe extends InvoiceReadClient {
|
|
|
359
339
|
return accountsImpl.getAccountByUserId(this.component, ctx, opts);
|
|
360
340
|
}
|
|
361
341
|
|
|
342
|
+
/** Unambiguous personal mapping only; host authentication and provider usability remain separate. */
|
|
343
|
+
getPersonalAccountMapping(ctx: RunCtx, opts: { userId: string }) {
|
|
344
|
+
return personalAccountMappingImpl.getPersonalAccountMapping(
|
|
345
|
+
this.component,
|
|
346
|
+
ctx,
|
|
347
|
+
opts,
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Authenticate the host actor before consulting closed-account provenance. */
|
|
352
|
+
async getClosedAccountByStripeId(
|
|
353
|
+
ctx: RunCtx,
|
|
354
|
+
opts: { stripeAccountId: string },
|
|
355
|
+
) {
|
|
356
|
+
return accountClosuresImpl.getClosedAccountByStripeId(
|
|
357
|
+
this.component,
|
|
358
|
+
ctx,
|
|
359
|
+
opts,
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
async listClosedAccountsByUserId(
|
|
364
|
+
ctx: RunCtx,
|
|
365
|
+
opts: { userId: string; paginationOpts: PaginationOptions },
|
|
366
|
+
) {
|
|
367
|
+
return accountClosuresImpl.listClosedAccountsByUserId(
|
|
368
|
+
this.component,
|
|
369
|
+
ctx,
|
|
370
|
+
opts,
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
362
374
|
async getAccountByOrgId(
|
|
363
375
|
ctx: RunCtx,
|
|
364
376
|
opts: { orgId: string },
|
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import type Stripe from "stripe";
|
|
2
2
|
import { ReadContractClient } from "./readContracts.js";
|
|
3
3
|
import type { RunCtx } from "./helpers.js";
|
|
4
|
+
import { getRefundContext } from "./connect/refundContext.js";
|
|
5
|
+
import type { RefundContextOptions } from "./connect/refundContextTypes.js";
|
|
4
6
|
import * as invoicePages from "./billing/invoicePages.js";
|
|
5
7
|
import * as invoicePaymentPages from "./billing/invoicePaymentPages.js";
|
|
8
|
+
import * as checkoutPages from "./billing/checkoutPages.js";
|
|
6
9
|
|
|
7
|
-
/** Provider
|
|
10
|
+
/** Provider billing history readers inherited by BetterStripe; hosts authorize their caller. */
|
|
8
11
|
export abstract class InvoiceReadClient extends ReadContractClient {
|
|
9
12
|
protected abstract stripe(): Stripe;
|
|
10
13
|
|
|
14
|
+
/** Required-actor observation only; the host authorizes community scope and revalidates creation. */
|
|
15
|
+
async getRefundContext(ctx: RunCtx, opts: RefundContextOptions) {
|
|
16
|
+
return getRefundContext(this.stripe(), this.component, ctx, opts);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Buyer-scoped discovery, not an atomic snapshot or a claim of complete purchase coverage. */
|
|
20
|
+
async getCheckoutSessionPageFromStripe(
|
|
21
|
+
_ctx: RunCtx,
|
|
22
|
+
opts: checkoutPages.CheckoutSessionPageOptions,
|
|
23
|
+
) {
|
|
24
|
+
return checkoutPages.getCheckoutSessionPageFromStripe(this.stripe(), opts);
|
|
25
|
+
}
|
|
26
|
+
|
|
11
27
|
/** Provider page only; the host authorizes scope and verifies historical completeness. */
|
|
12
28
|
async getInvoicePageFromStripe(
|
|
13
29
|
_ctx: RunCtx,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type { StripeAccountClosure } from "./core/accountClosures.js";
|
|
2
|
+
export type {
|
|
3
|
+
BetterStripeOptions,
|
|
4
|
+
FeeOverride,
|
|
5
|
+
FeeTier,
|
|
6
|
+
PlatformFeeConfig,
|
|
7
|
+
RegisterRoutesConfig,
|
|
8
|
+
} from "./types.js";
|
|
9
|
+
export type {
|
|
10
|
+
AccountLinkWithStatus,
|
|
11
|
+
AsyncHookCtx,
|
|
12
|
+
AsyncHooks,
|
|
13
|
+
PaymentMethodCard,
|
|
14
|
+
PaymentMethodLike,
|
|
15
|
+
StripeComponentAccount,
|
|
16
|
+
StripeComponentCheckoutSession,
|
|
17
|
+
StripeComponentDispute,
|
|
18
|
+
StripeComponentInvoice,
|
|
19
|
+
StripeComponentPayment,
|
|
20
|
+
StripeComponentPayout,
|
|
21
|
+
StripeComponentPrice,
|
|
22
|
+
StripeComponentProduct,
|
|
23
|
+
StripeComponentRefund,
|
|
24
|
+
StripeComponentSubscription,
|
|
25
|
+
StripeCountrySpecs,
|
|
26
|
+
StripeEventHandler,
|
|
27
|
+
StripeEventHandlers,
|
|
28
|
+
StripeV2Account,
|
|
29
|
+
StripeWebhookEvent,
|
|
30
|
+
SyncTriggerCtx,
|
|
31
|
+
SyncTriggers,
|
|
32
|
+
V2ThinEvent,
|
|
33
|
+
WebhookActionCtx,
|
|
34
|
+
} from "./types.js";
|
|
35
|
+
export type { PersonalAccountMapping } from "./core/personalAccountMapping.js";
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type Stripe from "stripe";
|
|
2
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
refundContextFixture as fixture,
|
|
5
|
+
refund,
|
|
6
|
+
page,
|
|
7
|
+
expectUnavailable,
|
|
8
|
+
} from "../../tests/fixtures/refund-context.js";
|
|
9
|
+
afterEach(() => vi.restoreAllMocks());
|
|
10
|
+
|
|
11
|
+
it.each([{ object: "payment_method" }, { object: undefined }])(
|
|
12
|
+
"holds malformed PI discriminator %j before charge lookup",
|
|
13
|
+
async (fields) => {
|
|
14
|
+
const f = fixture();
|
|
15
|
+
f.intentRead.mockResolvedValue({
|
|
16
|
+
...f.payment,
|
|
17
|
+
...fields,
|
|
18
|
+
} as Stripe.Response<Stripe.PaymentIntent>);
|
|
19
|
+
expectUnavailable(await f.read());
|
|
20
|
+
expect(f.chargeRead).not.toHaveBeenCalled();
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
it.each([
|
|
25
|
+
{ object: "payment_intent" },
|
|
26
|
+
{ object: undefined },
|
|
27
|
+
{ status: "failed" },
|
|
28
|
+
{ status: undefined },
|
|
29
|
+
{ paid: "true" },
|
|
30
|
+
{ captured: "false" },
|
|
31
|
+
{ disputed: undefined },
|
|
32
|
+
{ disputed: null },
|
|
33
|
+
{ refunded: undefined },
|
|
34
|
+
{ refunded: "false" },
|
|
35
|
+
])("holds malformed charge flags and discriminator %j", async (fields) => {
|
|
36
|
+
const f = fixture();
|
|
37
|
+
f.chargeRead.mockResolvedValue({
|
|
38
|
+
...f.charge,
|
|
39
|
+
...fields,
|
|
40
|
+
} as Stripe.Response<Stripe.Charge>);
|
|
41
|
+
expectUnavailable(await f.read());
|
|
42
|
+
expect(f.refundRead).not.toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it.each([
|
|
46
|
+
undefined,
|
|
47
|
+
{},
|
|
48
|
+
{ id: "cus_same" },
|
|
49
|
+
{ id: "acct_wrong", object: "customer" },
|
|
50
|
+
{ id: "cus_valid", object: "account" },
|
|
51
|
+
])(
|
|
52
|
+
"does not equate malformed legacy customer references %j",
|
|
53
|
+
async (customer) => {
|
|
54
|
+
const f = fixture();
|
|
55
|
+
f.intentRead.mockResolvedValue({
|
|
56
|
+
...f.payment,
|
|
57
|
+
customer,
|
|
58
|
+
} as Stripe.Response<Stripe.PaymentIntent>);
|
|
59
|
+
f.chargeRead.mockResolvedValue({
|
|
60
|
+
...f.charge,
|
|
61
|
+
customer,
|
|
62
|
+
} as Stripe.Response<Stripe.Charge>);
|
|
63
|
+
expectUnavailable(await f.read());
|
|
64
|
+
expect(f.refundRead).not.toHaveBeenCalled();
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
it("accepts canonical nullable or expanded legacy customer correlation without inventing a Charge buyer field", async () => {
|
|
69
|
+
const f = fixture();
|
|
70
|
+
f.intentRead.mockResolvedValue({ ...f.payment, customer: "cus_legacy" });
|
|
71
|
+
f.chargeRead.mockResolvedValue({
|
|
72
|
+
...f.charge,
|
|
73
|
+
customer: { id: "cus_legacy", object: "customer" } as Stripe.Customer,
|
|
74
|
+
});
|
|
75
|
+
expect(await f.read()).toMatchObject({
|
|
76
|
+
status: "ready",
|
|
77
|
+
remainingRefundableAmount: 1000,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it.each(["charge", undefined])(
|
|
82
|
+
"holds a malformed refund object %s",
|
|
83
|
+
async (object) => {
|
|
84
|
+
const f = fixture();
|
|
85
|
+
f.refundRead.mockResolvedValue(
|
|
86
|
+
page([
|
|
87
|
+
{
|
|
88
|
+
...refund("re_bad", 0, "failed"),
|
|
89
|
+
object,
|
|
90
|
+
} as unknown as Stripe.Refund,
|
|
91
|
+
]),
|
|
92
|
+
);
|
|
93
|
+
expectUnavailable(await f.read());
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
it.each([
|
|
98
|
+
{ refunded: false, amount: 1000 },
|
|
99
|
+
{ refunded: true, amount: 200 },
|
|
100
|
+
])(
|
|
101
|
+
"holds contradictory full-refund lifecycle flags %j",
|
|
102
|
+
async ({ refunded, amount }) => {
|
|
103
|
+
const f = fixture();
|
|
104
|
+
f.chargeRead.mockResolvedValue({
|
|
105
|
+
...f.charge,
|
|
106
|
+
amount_refunded: amount,
|
|
107
|
+
refunded,
|
|
108
|
+
});
|
|
109
|
+
f.refundRead.mockResolvedValue(page([refund("re_returned", amount)]));
|
|
110
|
+
expectUnavailable(await f.read());
|
|
111
|
+
},
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
it.each([false, true])(
|
|
115
|
+
"holds a zero capture instead of a ready free-payment observation (refunded=%s)",
|
|
116
|
+
async (refunded) => {
|
|
117
|
+
const f = fixture();
|
|
118
|
+
f.intentRead.mockResolvedValue({ ...f.payment, amount_received: 0 });
|
|
119
|
+
f.chargeRead.mockResolvedValue({
|
|
120
|
+
...f.charge,
|
|
121
|
+
amount_captured: 0,
|
|
122
|
+
refunded,
|
|
123
|
+
});
|
|
124
|
+
expectUnavailable(await f.read());
|
|
125
|
+
expect(f.refundRead).not.toHaveBeenCalled();
|
|
126
|
+
},
|
|
127
|
+
);
|