@fantastic.dev/better-stripe 0.7.0 → 0.8.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 +23 -18
- package/README.md +122 -90
- package/dist/client/billing/checkout.d.ts +1 -1
- package/dist/client/billing/checkout.d.ts.map +1 -1
- package/dist/client/billing/checkout.js +7 -2
- package/dist/client/billing/checkout.js.map +1 -1
- package/dist/client/connect/paymentMethods.d.ts.map +1 -1
- package/dist/client/connect/paymentMethods.js.map +1 -1
- package/dist/client/connect/refundActor.d.ts.map +1 -1
- package/dist/client/connect/refundActor.js.map +1 -1
- package/dist/client/connect/refunds.d.ts.map +1 -1
- package/dist/client/connect/refunds.js.map +1 -1
- package/dist/client/connect/transfers.d.ts.map +1 -1
- package/dist/client/connect/transfers.js +15 -4
- package/dist/client/connect/transfers.js.map +1 -1
- package/dist/client/core/accountDefaults.d.ts +6 -0
- package/dist/client/core/accountDefaults.d.ts.map +1 -0
- package/dist/client/core/accountDefaults.js +15 -0
- package/dist/client/core/accountDefaults.js.map +1 -0
- package/dist/client/core/accounts.d.ts +1 -5
- package/dist/client/core/accounts.d.ts.map +1 -1
- package/dist/client/core/accounts.js +2 -14
- package/dist/client/core/accounts.js.map +1 -1
- package/dist/client/core/fees.d.ts.map +1 -1
- package/dist/client/core/fees.js +7 -2
- package/dist/client/core/fees.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/products/prices.d.ts.map +1 -1
- package/dist/client/products/prices.js.map +1 -1
- package/dist/client/products/products.d.ts.map +1 -1
- package/dist/client/products/products.js +3 -1
- package/dist/client/products/products.js.map +1 -1
- package/dist/client/utils/owner.d.ts.map +1 -1
- package/dist/client/utils/owner.js +3 -1
- package/dist/client/utils/owner.js.map +1 -1
- package/dist/client/utils/stripeDashboardUrl.d.ts.map +1 -1
- package/dist/client/utils/stripeDashboardUrl.js.map +1 -1
- package/dist/client/webhooks/helpers.d.ts +10 -0
- package/dist/client/webhooks/helpers.d.ts.map +1 -1
- package/dist/client/webhooks/helpers.js +18 -0
- package/dist/client/webhooks/helpers.js.map +1 -1
- package/dist/client/webhooks/processors.d.ts.map +1 -1
- package/dist/client/webhooks/processors.js +1 -19
- package/dist/client/webhooks/processors.js.map +1 -1
- package/dist/component/connect/mutations.d.ts.map +1 -1
- package/dist/component/connect/mutations.js +4 -33
- package/dist/component/connect/mutations.js.map +1 -1
- package/dist/component/connect/schema.d.ts.map +1 -1
- package/dist/component/connect/schema.js.map +1 -1
- package/dist/component/lib/paymentSeller.d.ts +3 -0
- package/dist/component/lib/paymentSeller.d.ts.map +1 -0
- package/dist/component/lib/paymentSeller.js +10 -0
- package/dist/component/lib/paymentSeller.js.map +1 -0
- package/dist/component/lib/reversals.d.ts +10 -0
- package/dist/component/lib/reversals.d.ts.map +1 -1
- package/dist/component/lib/reversals.js +17 -0
- package/dist/component/lib/reversals.js.map +1 -1
- package/dist/react/components/ConnectProvider.d.ts +1 -1
- package/dist/react/components/ConnectProvider.d.ts.map +1 -1
- package/dist/react/components/ConnectProvider.js +18 -4
- package/dist/react/components/ConnectProvider.js.map +1 -1
- package/dist/react/components/ConnectStatusBadge.d.ts.map +1 -1
- package/dist/react/components/ConnectStatusBadge.js.map +1 -1
- package/dist/react/components/EmbeddedDisputes.d.ts +1 -1
- package/dist/react/components/EmbeddedDisputes.d.ts.map +1 -1
- package/dist/react/components/EmbeddedDisputes.js +1 -1
- package/dist/react/components/EmbeddedDisputes.js.map +1 -1
- package/dist/react/components/SplitBreakdown.d.ts.map +1 -1
- package/dist/react/components/SplitBreakdown.js +12 -2
- package/dist/react/components/SplitBreakdown.js.map +1 -1
- package/dist/react/hooks/useCheckoutSession.d.ts.map +1 -1
- package/dist/react/hooks/useCheckoutSession.js.map +1 -1
- package/dist/react/hooks/useConfirmPayment.d.ts.map +1 -1
- package/dist/react/hooks/useConfirmPayment.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/workflows/Account.d.ts +67 -0
- package/dist/react/workflows/Account.d.ts.map +1 -0
- package/dist/react/workflows/Account.js +74 -0
- package/dist/react/workflows/Account.js.map +1 -0
- package/dist/react/workflows/Billing.d.ts +60 -0
- package/dist/react/workflows/Billing.d.ts.map +1 -0
- package/dist/react/workflows/Billing.js +84 -0
- package/dist/react/workflows/Billing.js.map +1 -0
- package/dist/react/workflows/BillingPlans.d.ts +45 -0
- package/dist/react/workflows/BillingPlans.d.ts.map +1 -0
- package/dist/react/workflows/BillingPlans.js +51 -0
- package/dist/react/workflows/BillingPlans.js.map +1 -0
- package/dist/react/workflows/Checkout.d.ts +46 -0
- package/dist/react/workflows/Checkout.d.ts.map +1 -0
- package/dist/react/workflows/Checkout.js +61 -0
- package/dist/react/workflows/Checkout.js.map +1 -0
- package/dist/react/workflows/CheckoutChooser.d.ts +20 -0
- package/dist/react/workflows/CheckoutChooser.d.ts.map +1 -0
- package/dist/react/workflows/CheckoutChooser.js +24 -0
- package/dist/react/workflows/CheckoutChooser.js.map +1 -0
- package/dist/react/workflows/CheckoutForms.d.ts +26 -0
- package/dist/react/workflows/CheckoutForms.d.ts.map +1 -0
- package/dist/react/workflows/CheckoutForms.js +126 -0
- package/dist/react/workflows/CheckoutForms.js.map +1 -0
- package/dist/react/workflows/ClipboardButton.d.ts +17 -0
- package/dist/react/workflows/ClipboardButton.d.ts.map +1 -0
- package/dist/react/workflows/ClipboardButton.js +35 -0
- package/dist/react/workflows/ClipboardButton.js.map +1 -0
- package/dist/react/workflows/Collection.d.ts +30 -0
- package/dist/react/workflows/Collection.d.ts.map +1 -0
- package/dist/react/workflows/Collection.js +25 -0
- package/dist/react/workflows/Collection.js.map +1 -0
- package/dist/react/workflows/Collections.d.ts +56 -0
- package/dist/react/workflows/Collections.d.ts.map +1 -0
- package/dist/react/workflows/Collections.js +111 -0
- package/dist/react/workflows/Collections.js.map +1 -0
- package/dist/react/workflows/Connect.d.ts +19 -0
- package/dist/react/workflows/Connect.d.ts.map +1 -0
- package/dist/react/workflows/Connect.js +43 -0
- package/dist/react/workflows/Connect.js.map +1 -0
- package/dist/react/workflows/Costs.d.ts +48 -0
- package/dist/react/workflows/Costs.d.ts.map +1 -0
- package/dist/react/workflows/Costs.js +66 -0
- package/dist/react/workflows/Costs.js.map +1 -0
- package/dist/react/workflows/Disputes.d.ts +36 -0
- package/dist/react/workflows/Disputes.d.ts.map +1 -0
- package/dist/react/workflows/Disputes.js +74 -0
- package/dist/react/workflows/Disputes.js.map +1 -0
- package/dist/react/workflows/Earnings.d.ts +42 -0
- package/dist/react/workflows/Earnings.d.ts.map +1 -0
- package/dist/react/workflows/Earnings.js +38 -0
- package/dist/react/workflows/Earnings.js.map +1 -0
- package/dist/react/workflows/Financials.d.ts +43 -0
- package/dist/react/workflows/Financials.d.ts.map +1 -0
- package/dist/react/workflows/Financials.js +57 -0
- package/dist/react/workflows/Financials.js.map +1 -0
- package/dist/react/workflows/IntegrationSwitch.d.ts +23 -0
- package/dist/react/workflows/IntegrationSwitch.d.ts.map +1 -0
- package/dist/react/workflows/IntegrationSwitch.js +31 -0
- package/dist/react/workflows/IntegrationSwitch.js.map +1 -0
- package/dist/react/workflows/Onboarding.d.ts +56 -0
- package/dist/react/workflows/Onboarding.d.ts.map +1 -0
- package/dist/react/workflows/Onboarding.js +86 -0
- package/dist/react/workflows/Onboarding.js.map +1 -0
- package/dist/react/workflows/Overview.d.ts +51 -0
- package/dist/react/workflows/Overview.d.ts.map +1 -0
- package/dist/react/workflows/Overview.js +63 -0
- package/dist/react/workflows/Overview.js.map +1 -0
- package/dist/react/workflows/PaymentMethods.d.ts +35 -0
- package/dist/react/workflows/PaymentMethods.d.ts.map +1 -0
- package/dist/react/workflows/PaymentMethods.js +63 -0
- package/dist/react/workflows/PaymentMethods.js.map +1 -0
- package/dist/react/workflows/PaymentReceipt.d.ts +20 -0
- package/dist/react/workflows/PaymentReceipt.d.ts.map +1 -0
- package/dist/react/workflows/PaymentReceipt.js +24 -0
- package/dist/react/workflows/PaymentReceipt.js.map +1 -0
- package/dist/react/workflows/Payouts.d.ts +47 -0
- package/dist/react/workflows/Payouts.d.ts.map +1 -0
- package/dist/react/workflows/Payouts.js +87 -0
- package/dist/react/workflows/Payouts.js.map +1 -0
- package/dist/react/workflows/Products.d.ts +92 -0
- package/dist/react/workflows/Products.d.ts.map +1 -0
- package/dist/react/workflows/Products.js +179 -0
- package/dist/react/workflows/Products.js.map +1 -0
- package/dist/react/workflows/ReferralLinks.d.ts +26 -0
- package/dist/react/workflows/ReferralLinks.d.ts.map +1 -0
- package/dist/react/workflows/ReferralLinks.js +30 -0
- package/dist/react/workflows/ReferralLinks.js.map +1 -0
- package/dist/react/workflows/Refunds.d.ts +72 -0
- package/dist/react/workflows/Refunds.d.ts.map +1 -0
- package/dist/react/workflows/Refunds.js +95 -0
- package/dist/react/workflows/Refunds.js.map +1 -0
- package/dist/react/workflows/Setup.d.ts +50 -0
- package/dist/react/workflows/Setup.d.ts.map +1 -0
- package/dist/react/workflows/Setup.js +59 -0
- package/dist/react/workflows/Setup.js.map +1 -0
- package/dist/react/workflows/Storefront.d.ts +53 -0
- package/dist/react/workflows/Storefront.d.ts.map +1 -0
- package/dist/react/workflows/Storefront.js +44 -0
- package/dist/react/workflows/Storefront.js.map +1 -0
- package/dist/react/workflows/SubscriptionOverview.d.ts +13 -0
- package/dist/react/workflows/SubscriptionOverview.d.ts.map +1 -0
- package/dist/react/workflows/SubscriptionOverview.js +26 -0
- package/dist/react/workflows/SubscriptionOverview.js.map +1 -0
- package/dist/react/workflows/Subscriptions.d.ts +92 -0
- package/dist/react/workflows/Subscriptions.d.ts.map +1 -0
- package/dist/react/workflows/Subscriptions.js +149 -0
- package/dist/react/workflows/Subscriptions.js.map +1 -0
- package/dist/react/workflows/Tasks.d.ts +40 -0
- package/dist/react/workflows/Tasks.d.ts.map +1 -0
- package/dist/react/workflows/Tasks.js +113 -0
- package/dist/react/workflows/Tasks.js.map +1 -0
- package/dist/react/workflows/checkout-options.d.ts +37 -0
- package/dist/react/workflows/checkout-options.d.ts.map +1 -0
- package/dist/react/workflows/checkout-options.js +43 -0
- package/dist/react/workflows/checkout-options.js.map +1 -0
- package/dist/react/workflows/current-subscription.d.ts +11 -0
- package/dist/react/workflows/current-subscription.d.ts.map +1 -0
- package/dist/react/workflows/current-subscription.js +14 -0
- package/dist/react/workflows/current-subscription.js.map +1 -0
- package/dist/react/workflows/filters.d.ts +17 -0
- package/dist/react/workflows/filters.d.ts.map +1 -0
- package/dist/react/workflows/filters.js +23 -0
- package/dist/react/workflows/filters.js.map +1 -0
- package/dist/react/workflows/index.d.ts +70 -0
- package/dist/react/workflows/index.d.ts.map +1 -0
- package/dist/react/workflows/index.js +38 -0
- package/dist/react/workflows/index.js.map +1 -0
- package/dist/react/workflows/useWorkflowAction.d.ts +11 -0
- package/dist/react/workflows/useWorkflowAction.d.ts.map +1 -0
- package/dist/react/workflows/useWorkflowAction.js +68 -0
- package/dist/react/workflows/useWorkflowAction.js.map +1 -0
- package/dist/react/workflows/useWorkflowResource.d.ts +9 -0
- package/dist/react/workflows/useWorkflowResource.d.ts.map +1 -0
- package/dist/react/workflows/useWorkflowResource.js +67 -0
- package/dist/react/workflows/useWorkflowResource.js.map +1 -0
- package/docs/react-workflows-audit.md +66 -0
- package/docs/react-workflows.md +231 -0
- package/package.json +19 -3
- package/src/client/billing/checkout-ui-modes.test.ts +49 -0
- package/src/client/billing/checkout.ts +8 -3
- package/src/client/billing/invoices.test.ts +12 -6
- package/src/client/connect/paymentMethods.test.ts +3 -1
- package/src/client/connect/paymentMethods.ts +4 -1
- package/src/client/connect/refundActor.ts +1 -2
- package/src/client/connect/refunds.test.ts +35 -10
- package/src/client/connect/refunds.ts +4 -1
- package/src/client/connect/transfers.test.ts +66 -12
- package/src/client/connect/transfers.ts +32 -8
- package/src/client/core/accountDefaults.ts +15 -0
- package/src/client/core/accounts.ts +14 -17
- package/src/client/core/config.test.ts +2 -1
- package/src/client/core/descriptors.test.ts +6 -4
- package/src/client/core/fees.test.ts +20 -28
- package/src/client/core/fees.ts +9 -2
- package/src/client/index.test.ts +22 -22
- package/src/client/index.ts +1 -1
- package/src/client/products/prices.test.ts +8 -2
- package/src/client/products/prices.ts +4 -1
- package/src/client/products/products.test.ts +61 -20
- package/src/client/products/products.ts +3 -1
- package/src/client/utils/data.test.ts +3 -1
- package/src/client/utils/owner.test.ts +4 -1
- package/src/client/utils/owner.ts +5 -1
- package/src/client/utils/stripeDashboardUrl.ts +1 -4
- package/src/client/webhooks/handler.test.ts +16 -19
- package/src/client/webhooks/helpers.test.ts +26 -13
- package/src/client/webhooks/helpers.ts +23 -0
- package/src/client/webhooks/hooks.test.ts +1 -2
- package/src/client/webhooks/processors.test.ts +18 -34
- package/src/client/webhooks/processors.ts +1 -23
- package/src/client/webhooks.test.ts +1 -2
- package/src/component/_generated/api.ts +2 -0
- package/src/component/connect/mutations.ts +5 -46
- package/src/component/connect/schema.ts +4 -3
- package/src/component/connect.test.ts +1 -5
- package/src/component/lib/paymentSeller.ts +15 -0
- package/src/component/lib/reversals.ts +30 -2
- package/src/component/subscription-scoping.test.ts +5 -1
- package/src/component/triggers.test.ts +7 -4
- package/src/react/components/BuyerBillingView.render.test.tsx +7 -2
- package/src/react/components/ConnectProvider.live.test.tsx +61 -0
- package/src/react/components/ConnectProvider.tsx +18 -4
- package/src/react/components/ConnectStatusBadge.tsx +1 -4
- package/src/react/components/DisputeDetail.render.test.tsx +5 -1
- package/src/react/components/EarningsSummary.render.test.tsx +2 -6
- package/src/react/components/EmbeddedDisputes.render.test.tsx +7 -5
- package/src/react/components/EmbeddedDisputes.tsx +4 -1
- package/src/react/components/EvidenceForm.render.test.tsx +2 -8
- package/src/react/components/SplitBreakdown.render.test.tsx +28 -5
- package/src/react/components/SplitBreakdown.tsx +12 -2
- package/src/react/hooks/useCheckoutSession.ts +1 -2
- package/src/react/hooks/useConfirmPayment.ts +1 -2
- package/src/react/hooks/useEarnings.test.ts +43 -8
- package/src/react/hooks/useStripeMode.test.ts +5 -8
- package/src/react/index.ts +3 -0
- package/src/react/workflows/Account.test.tsx +31 -0
- package/src/react/workflows/Account.tsx +183 -0
- package/src/react/workflows/Billing.test.tsx +45 -0
- package/src/react/workflows/Billing.tsx +213 -0
- package/src/react/workflows/BillingPlans.test.tsx +31 -0
- package/src/react/workflows/BillingPlans.tsx +130 -0
- package/src/react/workflows/Checkout.test.tsx +118 -0
- package/src/react/workflows/Checkout.tsx +135 -0
- package/src/react/workflows/CheckoutChooser.test.tsx +44 -0
- package/src/react/workflows/CheckoutChooser.tsx +77 -0
- package/src/react/workflows/CheckoutForm.test.tsx +66 -0
- package/src/react/workflows/CheckoutForms.test.tsx +123 -0
- package/src/react/workflows/CheckoutForms.tsx +247 -0
- package/src/react/workflows/ClipboardButton.test.tsx +34 -0
- package/src/react/workflows/ClipboardButton.tsx +67 -0
- package/src/react/workflows/Collection.tsx +76 -0
- package/src/react/workflows/Collections.test.tsx +86 -0
- package/src/react/workflows/Collections.tsx +213 -0
- package/src/react/workflows/Connect.test.tsx +50 -0
- package/src/react/workflows/Connect.tsx +107 -0
- package/src/react/workflows/Costs.test.tsx +41 -0
- package/src/react/workflows/Costs.tsx +133 -0
- package/src/react/workflows/Disputes.test.tsx +25 -0
- package/src/react/workflows/Disputes.tsx +164 -0
- package/src/react/workflows/Earnings.test.ts +19 -0
- package/src/react/workflows/Earnings.tsx +84 -0
- package/src/react/workflows/Financials.test.tsx +35 -0
- package/src/react/workflows/Financials.tsx +117 -0
- package/src/react/workflows/IntegrationSwitch.test.tsx +36 -0
- package/src/react/workflows/IntegrationSwitch.tsx +63 -0
- package/src/react/workflows/Onboarding.test.tsx +75 -0
- package/src/react/workflows/Onboarding.tsx +171 -0
- package/src/react/workflows/Overview.test.tsx +57 -0
- package/src/react/workflows/Overview.tsx +123 -0
- package/src/react/workflows/PaymentMethods.test.tsx +60 -0
- package/src/react/workflows/PaymentMethods.tsx +117 -0
- package/src/react/workflows/PaymentReceipt.test.tsx +24 -0
- package/src/react/workflows/PaymentReceipt.tsx +46 -0
- package/src/react/workflows/Payouts.test.tsx +82 -0
- package/src/react/workflows/Payouts.tsx +212 -0
- package/src/react/workflows/Products.test.tsx +90 -0
- package/src/react/workflows/Products.tsx +377 -0
- package/src/react/workflows/ReferralLinks.test.tsx +39 -0
- package/src/react/workflows/ReferralLinks.tsx +75 -0
- package/src/react/workflows/Refunds.test.tsx +75 -0
- package/src/react/workflows/Refunds.tsx +223 -0
- package/src/react/workflows/Setup.test.tsx +25 -0
- package/src/react/workflows/Setup.tsx +166 -0
- package/src/react/workflows/Storefront.test.tsx +82 -0
- package/src/react/workflows/Storefront.tsx +138 -0
- package/src/react/workflows/SubscriptionOverview.test.tsx +27 -0
- package/src/react/workflows/SubscriptionOverview.tsx +48 -0
- package/src/react/workflows/Subscriptions.test.tsx +61 -0
- package/src/react/workflows/Subscriptions.tsx +282 -0
- package/src/react/workflows/Tasks.test.tsx +23 -0
- package/src/react/workflows/Tasks.tsx +199 -0
- package/src/react/workflows/checkout-options.ts +42 -0
- package/src/react/workflows/current-subscription.test.ts +29 -0
- package/src/react/workflows/current-subscription.ts +25 -0
- package/src/react/workflows/filters.test.ts +12 -0
- package/src/react/workflows/filters.ts +22 -0
- package/src/react/workflows/index.ts +238 -0
- package/src/react/workflows/native-interactions.test.tsx +73 -0
- package/src/react/workflows/public-workflows.test.tsx +216 -0
- package/src/react/workflows/useWorkflowAction.test.tsx +54 -0
- package/src/react/workflows/useWorkflowAction.ts +75 -0
- package/src/react/workflows/useWorkflowResource.test.tsx +41 -0
- package/src/react/workflows/useWorkflowResource.ts +78 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
5
|
+
import { ReferralLinks } from "./ReferralLinks.js";
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
it("copies the complete attributed URL and reports clipboard failure", async () => {
|
|
8
|
+
const writeText = vi
|
|
9
|
+
.fn()
|
|
10
|
+
.mockResolvedValueOnce(undefined)
|
|
11
|
+
.mockRejectedValueOnce(new Error("Clipboard blocked"));
|
|
12
|
+
render(
|
|
13
|
+
<ReferralLinks
|
|
14
|
+
links={[
|
|
15
|
+
{
|
|
16
|
+
id: "store",
|
|
17
|
+
label: "Independent Store",
|
|
18
|
+
url: "https://app.test/stores?store=acct_one&ref=avery",
|
|
19
|
+
},
|
|
20
|
+
]}
|
|
21
|
+
writeText={writeText}
|
|
22
|
+
/>,
|
|
23
|
+
);
|
|
24
|
+
await userEvent.click(
|
|
25
|
+
screen.getByRole("button", {
|
|
26
|
+
name: "Copy referral link for Independent Store",
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
expect(writeText).toHaveBeenCalledWith(
|
|
30
|
+
"https://app.test/stores?store=acct_one&ref=avery",
|
|
31
|
+
);
|
|
32
|
+
expect(screen.getByRole("status").textContent).toContain("copied");
|
|
33
|
+
await userEvent.click(
|
|
34
|
+
screen.getByRole("button", {
|
|
35
|
+
name: "Copy referral link for Independent Store",
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
expect(screen.getByRole("alert").textContent).toContain("Clipboard blocked");
|
|
39
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { useWorkflowAction } from "./useWorkflowAction.js";
|
|
4
|
+
export type ReferralLink = { id: string; label: string; url: string };
|
|
5
|
+
export function useReferralLinks({
|
|
6
|
+
scopeKey = "referral-links",
|
|
7
|
+
writeText = (text: string) => navigator.clipboard.writeText(text),
|
|
8
|
+
}: { scopeKey?: string; writeText?: (text: string) => Promise<void> } = {}) {
|
|
9
|
+
const action = useWorkflowAction(async (url: string) => {
|
|
10
|
+
if (!url.trim()) throw new Error("A referral URL is required.");
|
|
11
|
+
await writeText(url);
|
|
12
|
+
return url;
|
|
13
|
+
}, scopeKey);
|
|
14
|
+
return {
|
|
15
|
+
copy: action.run,
|
|
16
|
+
copiedUrl: action.result,
|
|
17
|
+
error: action.error,
|
|
18
|
+
isPending: action.isPending,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export type ReferralLinksProps = {
|
|
22
|
+
links: ReferralLink[] | undefined;
|
|
23
|
+
scopeKey?: string;
|
|
24
|
+
writeText?: (text: string) => Promise<void>;
|
|
25
|
+
children?: (
|
|
26
|
+
state: ReturnType<typeof useReferralLinks> & {
|
|
27
|
+
links: ReferralLink[];
|
|
28
|
+
isLoading: boolean;
|
|
29
|
+
},
|
|
30
|
+
) => ReactNode;
|
|
31
|
+
};
|
|
32
|
+
export function ReferralLinks(props: ReferralLinksProps) {
|
|
33
|
+
const state = useReferralLinks(props);
|
|
34
|
+
if (props.children)
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
{props.children({
|
|
38
|
+
...state,
|
|
39
|
+
links: props.links ?? [],
|
|
40
|
+
isLoading: props.links === undefined,
|
|
41
|
+
})}
|
|
42
|
+
</>
|
|
43
|
+
);
|
|
44
|
+
return (
|
|
45
|
+
<section data-better-stripe="referral-links">
|
|
46
|
+
<h2>Referral links</h2>
|
|
47
|
+
{state.error && <p role="alert">{state.error}</p>}
|
|
48
|
+
{state.copiedUrl && <p role="status">Referral link copied</p>}
|
|
49
|
+
{props.links === undefined ? (
|
|
50
|
+
<p role="status">Loading referral links…</p>
|
|
51
|
+
) : !props.links.length ? (
|
|
52
|
+
<p>No referral links yet.</p>
|
|
53
|
+
) : (
|
|
54
|
+
<ul>
|
|
55
|
+
{props.links.map((link) => (
|
|
56
|
+
<li key={link.id}>
|
|
57
|
+
<a href={link.url}>{link.label}</a>
|
|
58
|
+
<p>{link.url}</p>
|
|
59
|
+
<button
|
|
60
|
+
type="button"
|
|
61
|
+
disabled={state.isPending}
|
|
62
|
+
aria-label={`Copy referral link for ${link.label}`}
|
|
63
|
+
onClick={() => {
|
|
64
|
+
void state.copy(link.url);
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
{state.isPending ? "Copying…" : "Copy link"}
|
|
68
|
+
</button>
|
|
69
|
+
</li>
|
|
70
|
+
))}
|
|
71
|
+
</ul>
|
|
72
|
+
)}
|
|
73
|
+
</section>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, cleanup, renderHook } from "@testing-library/react";
|
|
3
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
4
|
+
import { useRefunds } from "./Refunds.js";
|
|
5
|
+
afterEach(cleanup);
|
|
6
|
+
it("validates a partial amount before Stripe and preserves exact minor units", async () => {
|
|
7
|
+
const issueRefund = vi.fn().mockResolvedValue({ stripeRefundId: "re_test" });
|
|
8
|
+
const { result } = renderHook(() =>
|
|
9
|
+
useRefunds({
|
|
10
|
+
scopeKey: "seller",
|
|
11
|
+
issueRefund,
|
|
12
|
+
paymentIntentId: " pi_test ",
|
|
13
|
+
}),
|
|
14
|
+
);
|
|
15
|
+
await act(async () => {
|
|
16
|
+
await result.current.submitRefund("partial");
|
|
17
|
+
});
|
|
18
|
+
expect(issueRefund).not.toHaveBeenCalled();
|
|
19
|
+
expect(result.current.error).toContain("positive");
|
|
20
|
+
act(() => result.current.setRefundAmount("12.34"));
|
|
21
|
+
await act(async () => {
|
|
22
|
+
await result.current.submitRefund("partial");
|
|
23
|
+
});
|
|
24
|
+
expect(issueRefund).toHaveBeenCalledWith({
|
|
25
|
+
stripePaymentIntentId: "pi_test",
|
|
26
|
+
amountCents: 1234,
|
|
27
|
+
reason: "requested_by_customer",
|
|
28
|
+
});
|
|
29
|
+
expect(result.current.refundResult?.stripeRefundId).toBe("re_test");
|
|
30
|
+
});
|
|
31
|
+
it("rejects excess precision and resets fields for another account", async () => {
|
|
32
|
+
const issueRefund = vi.fn();
|
|
33
|
+
const { result, rerender } = renderHook(
|
|
34
|
+
({ scope }) =>
|
|
35
|
+
useRefunds({ scopeKey: scope, issueRefund, paymentIntentId: "pi_test" }),
|
|
36
|
+
{ initialProps: { scope: "one" } },
|
|
37
|
+
);
|
|
38
|
+
act(() => result.current.setRefundAmount("0.005"));
|
|
39
|
+
await act(async () => {
|
|
40
|
+
await result.current.submitRefund("partial");
|
|
41
|
+
});
|
|
42
|
+
expect(issueRefund).not.toHaveBeenCalled();
|
|
43
|
+
rerender({ scope: "two" });
|
|
44
|
+
expect(result.current.refundAmount).toBe("");
|
|
45
|
+
expect(result.current.refundResult).toBeNull();
|
|
46
|
+
});
|
|
47
|
+
it("keeps a pending refund labeled as a refund when a reversal is attempted", async () => {
|
|
48
|
+
let finish!: (value: { stripeRefundId: string }) => void;
|
|
49
|
+
const reverseTransfers = vi.fn();
|
|
50
|
+
const { result } = renderHook(() =>
|
|
51
|
+
useRefunds({
|
|
52
|
+
scopeKey: "seller",
|
|
53
|
+
paymentIntentId: "pi_one",
|
|
54
|
+
sourceChargeId: "ch_one",
|
|
55
|
+
issueRefund: () =>
|
|
56
|
+
new Promise((resolve) => {
|
|
57
|
+
finish = resolve;
|
|
58
|
+
}),
|
|
59
|
+
reverseTransfers,
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
let pending!: Promise<unknown>;
|
|
63
|
+
act(() => {
|
|
64
|
+
pending = result.current.submitRefund("full");
|
|
65
|
+
});
|
|
66
|
+
await act(async () => {
|
|
67
|
+
await result.current.submitReversal("full");
|
|
68
|
+
});
|
|
69
|
+
expect(result.current.busy).toBe("refund");
|
|
70
|
+
expect(reverseTransfers).not.toHaveBeenCalled();
|
|
71
|
+
await act(async () => {
|
|
72
|
+
finish({ stripeRefundId: "re_one" });
|
|
73
|
+
await pending;
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useId, type ReactNode } from "react";
|
|
3
|
+
import { useWorkflowAction } from "./useWorkflowAction.js";
|
|
4
|
+
import { Connect, type ConnectProps } from "./Connect.js";
|
|
5
|
+
export type RefundRequest = {
|
|
6
|
+
stripePaymentIntentId: string;
|
|
7
|
+
amountCents?: number;
|
|
8
|
+
reason: "requested_by_customer";
|
|
9
|
+
};
|
|
10
|
+
export type ReversalRequest = { sourceChargeId: string; amountCents?: number };
|
|
11
|
+
export type RefundResult = { stripeRefundId: string };
|
|
12
|
+
export type ReversalResult = {
|
|
13
|
+
reversals: { stripeTransferId: string; amount: number }[];
|
|
14
|
+
summary: { reversalCount: number; totalReversed: number };
|
|
15
|
+
};
|
|
16
|
+
export type RefundActionsProps = {
|
|
17
|
+
scopeKey: string;
|
|
18
|
+
paymentIntentId?: string;
|
|
19
|
+
sourceChargeId?: string;
|
|
20
|
+
issueRefund: (args: RefundRequest) => Promise<RefundResult>;
|
|
21
|
+
reverseTransfers?: (args: ReversalRequest) => Promise<ReversalResult>;
|
|
22
|
+
};
|
|
23
|
+
/** Currency input expressed in two decimal minor units. Rejects rounding and scientific notation. */
|
|
24
|
+
export function parseAmountCents(value: string): number | null {
|
|
25
|
+
if (!/^\d+(?:\.\d{1,2})?$/.test(value.trim())) return null;
|
|
26
|
+
const [whole, fraction = ""] = value.trim().split(".");
|
|
27
|
+
const amount = Number(whole) * 100 + Number(fraction.padEnd(2, "0"));
|
|
28
|
+
return Number.isSafeInteger(amount) && amount > 0 ? amount : null;
|
|
29
|
+
}
|
|
30
|
+
export function useRefunds(props: RefundActionsProps) {
|
|
31
|
+
const initial = {
|
|
32
|
+
scope: props.scopeKey,
|
|
33
|
+
paymentIntentId: props.paymentIntentId ?? "",
|
|
34
|
+
sourceChargeId: props.sourceChargeId ?? "",
|
|
35
|
+
refundAmount: "",
|
|
36
|
+
reversalAmount: "",
|
|
37
|
+
};
|
|
38
|
+
const [fields, setFields] = useState(initial);
|
|
39
|
+
if (fields.scope !== props.scopeKey) setFields(initial);
|
|
40
|
+
const [operationType, setOperationType] = useState<"refund" | "reversal">(
|
|
41
|
+
"refund",
|
|
42
|
+
);
|
|
43
|
+
const action = useWorkflowAction(
|
|
44
|
+
async (operation: {
|
|
45
|
+
type: "refund" | "reversal";
|
|
46
|
+
kind: "full" | "partial";
|
|
47
|
+
}) => {
|
|
48
|
+
setOperationType(operation.type);
|
|
49
|
+
const id = (
|
|
50
|
+
operation.type === "refund"
|
|
51
|
+
? fields.paymentIntentId
|
|
52
|
+
: fields.sourceChargeId
|
|
53
|
+
).trim();
|
|
54
|
+
if (!id)
|
|
55
|
+
throw new Error(
|
|
56
|
+
operation.type === "refund"
|
|
57
|
+
? "Enter a PaymentIntent id before issuing a refund."
|
|
58
|
+
: "Enter a source charge id before reversing transfers.",
|
|
59
|
+
);
|
|
60
|
+
const amount =
|
|
61
|
+
operation.kind === "partial"
|
|
62
|
+
? parseAmountCents(
|
|
63
|
+
operation.type === "refund"
|
|
64
|
+
? fields.refundAmount
|
|
65
|
+
: fields.reversalAmount,
|
|
66
|
+
)
|
|
67
|
+
: undefined;
|
|
68
|
+
if (amount === null)
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Enter a positive partial ${operation.type === "refund" ? "refund" : "reversal"} amount with at most two decimal places.`,
|
|
71
|
+
);
|
|
72
|
+
if (operation.type === "refund")
|
|
73
|
+
return {
|
|
74
|
+
type: "refund" as const,
|
|
75
|
+
value: await props.issueRefund({
|
|
76
|
+
stripePaymentIntentId: id,
|
|
77
|
+
amountCents: amount,
|
|
78
|
+
reason: "requested_by_customer",
|
|
79
|
+
}),
|
|
80
|
+
};
|
|
81
|
+
if (!props.reverseTransfers)
|
|
82
|
+
throw new Error("Transfer reversals are not configured.");
|
|
83
|
+
return {
|
|
84
|
+
type: "reversal" as const,
|
|
85
|
+
value: await props.reverseTransfers({
|
|
86
|
+
sourceChargeId: id,
|
|
87
|
+
amountCents: amount,
|
|
88
|
+
}),
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
props.scopeKey,
|
|
92
|
+
);
|
|
93
|
+
const set = (
|
|
94
|
+
name:
|
|
95
|
+
"paymentIntentId" | "sourceChargeId" | "refundAmount" | "reversalAmount",
|
|
96
|
+
value: string,
|
|
97
|
+
) => setFields((previous) => ({ ...previous, [name]: value }));
|
|
98
|
+
return {
|
|
99
|
+
...fields,
|
|
100
|
+
setPaymentIntentId: (value: string) => set("paymentIntentId", value),
|
|
101
|
+
setSourceChargeId: (value: string) => set("sourceChargeId", value),
|
|
102
|
+
setRefundAmount: (value: string) => set("refundAmount", value),
|
|
103
|
+
setReversalAmount: (value: string) => set("reversalAmount", value),
|
|
104
|
+
error: action.error,
|
|
105
|
+
isPending: action.isPending,
|
|
106
|
+
busy: action.isPending ? operationType : null,
|
|
107
|
+
refundResult: action.result?.type === "refund" ? action.result.value : null,
|
|
108
|
+
reversalResult:
|
|
109
|
+
action.result?.type === "reversal" ? action.result.value : null,
|
|
110
|
+
submitRefund: (kind: "full" | "partial") =>
|
|
111
|
+
action.run({ type: "refund", kind }),
|
|
112
|
+
submitReversal: (kind: "full" | "partial") =>
|
|
113
|
+
action.run({ type: "reversal", kind }),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export type RefundsRenderProps = ReturnType<typeof useRefunds>;
|
|
117
|
+
export type RefundsProps =
|
|
118
|
+
| (RefundActionsProps & {
|
|
119
|
+
presentation?: "headless";
|
|
120
|
+
children?: (state: RefundsRenderProps) => ReactNode;
|
|
121
|
+
})
|
|
122
|
+
| (Omit<ConnectProps, "component"> & { presentation: "embedded" });
|
|
123
|
+
export function Refunds(props: RefundsProps) {
|
|
124
|
+
return props.presentation === "embedded" ? (
|
|
125
|
+
<Connect {...props} component="refunds" />
|
|
126
|
+
) : (
|
|
127
|
+
<RefundsBody key={props.scopeKey} {...props} />
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
function RefundsBody(
|
|
131
|
+
props: RefundActionsProps & {
|
|
132
|
+
children?: (state: RefundsRenderProps) => ReactNode;
|
|
133
|
+
},
|
|
134
|
+
) {
|
|
135
|
+
const state = useRefunds(props);
|
|
136
|
+
const id = useId();
|
|
137
|
+
if (props.children) return <>{props.children(state)}</>;
|
|
138
|
+
return (
|
|
139
|
+
<section data-better-stripe="refunds" aria-busy={state.isPending}>
|
|
140
|
+
<h2>Refunds</h2>
|
|
141
|
+
{state.error && <p role="alert">{state.error}</p>}
|
|
142
|
+
<label htmlFor={`${id}-payment`}>PaymentIntent ID</label>
|
|
143
|
+
<input
|
|
144
|
+
id={`${id}-payment`}
|
|
145
|
+
value={state.paymentIntentId}
|
|
146
|
+
onChange={(event) => state.setPaymentIntentId(event.target.value)}
|
|
147
|
+
/>
|
|
148
|
+
<label htmlFor={`${id}-amount`}>Partial refund amount</label>
|
|
149
|
+
<input
|
|
150
|
+
id={`${id}-amount`}
|
|
151
|
+
type="number"
|
|
152
|
+
min="0.01"
|
|
153
|
+
step="0.01"
|
|
154
|
+
value={state.refundAmount}
|
|
155
|
+
onChange={(event) => state.setRefundAmount(event.target.value)}
|
|
156
|
+
/>
|
|
157
|
+
<button
|
|
158
|
+
type="button"
|
|
159
|
+
disabled={state.isPending}
|
|
160
|
+
onClick={() => {
|
|
161
|
+
void state.submitRefund("full");
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
{state.isPending ? "Processing…" : "Full refund"}
|
|
165
|
+
</button>
|
|
166
|
+
<button
|
|
167
|
+
type="button"
|
|
168
|
+
disabled={state.isPending}
|
|
169
|
+
onClick={() => {
|
|
170
|
+
void state.submitRefund("partial");
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
Partial refund
|
|
174
|
+
</button>
|
|
175
|
+
{state.refundResult && (
|
|
176
|
+
<p role="status">Refund created: {state.refundResult.stripeRefundId}</p>
|
|
177
|
+
)}
|
|
178
|
+
{props.reverseTransfers && (
|
|
179
|
+
<>
|
|
180
|
+
<h3>Transfer reversals</h3>
|
|
181
|
+
<label htmlFor={`${id}-charge`}>Source charge ID</label>
|
|
182
|
+
<input
|
|
183
|
+
id={`${id}-charge`}
|
|
184
|
+
value={state.sourceChargeId}
|
|
185
|
+
onChange={(event) => state.setSourceChargeId(event.target.value)}
|
|
186
|
+
/>
|
|
187
|
+
<label htmlFor={`${id}-reversal`}>Partial reversal amount</label>
|
|
188
|
+
<input
|
|
189
|
+
id={`${id}-reversal`}
|
|
190
|
+
type="number"
|
|
191
|
+
min="0.01"
|
|
192
|
+
step="0.01"
|
|
193
|
+
value={state.reversalAmount}
|
|
194
|
+
onChange={(event) => state.setReversalAmount(event.target.value)}
|
|
195
|
+
/>
|
|
196
|
+
<button
|
|
197
|
+
type="button"
|
|
198
|
+
disabled={state.isPending}
|
|
199
|
+
onClick={() => {
|
|
200
|
+
void state.submitReversal("full");
|
|
201
|
+
}}
|
|
202
|
+
>
|
|
203
|
+
Reverse all transfers
|
|
204
|
+
</button>
|
|
205
|
+
<button
|
|
206
|
+
type="button"
|
|
207
|
+
disabled={state.isPending}
|
|
208
|
+
onClick={() => {
|
|
209
|
+
void state.submitReversal("partial");
|
|
210
|
+
}}
|
|
211
|
+
>
|
|
212
|
+
Partial reversal
|
|
213
|
+
</button>
|
|
214
|
+
{state.reversalResult && (
|
|
215
|
+
<p role="status">
|
|
216
|
+
Reversed {state.reversalResult.summary.reversalCount} transfers.
|
|
217
|
+
</p>
|
|
218
|
+
)}
|
|
219
|
+
</>
|
|
220
|
+
)}
|
|
221
|
+
</section>
|
|
222
|
+
);
|
|
223
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, cleanup, renderHook, waitFor } from "@testing-library/react";
|
|
3
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
4
|
+
import { useWebhookSetup } from "./Setup.js";
|
|
5
|
+
afterEach(cleanup);
|
|
6
|
+
it("refreshes destination status after setup and keeps setup errors available for retry", async () => {
|
|
7
|
+
const load = vi
|
|
8
|
+
.fn()
|
|
9
|
+
.mockResolvedValueOnce({ configured: false })
|
|
10
|
+
.mockResolvedValueOnce({ configured: true });
|
|
11
|
+
const setup = vi.fn().mockResolvedValue({ id: "we_test" });
|
|
12
|
+
const { result } = renderHook(() =>
|
|
13
|
+
useWebhookSetup({ scopeKey: "site", load, setup }),
|
|
14
|
+
);
|
|
15
|
+
await waitFor(() =>
|
|
16
|
+
expect(result.current.status).toEqual({ configured: false }),
|
|
17
|
+
);
|
|
18
|
+
await act(async () => {
|
|
19
|
+
await result.current.configure();
|
|
20
|
+
});
|
|
21
|
+
await waitFor(() =>
|
|
22
|
+
expect(result.current.status).toEqual({ configured: true }),
|
|
23
|
+
);
|
|
24
|
+
expect(result.current.result).toEqual({ id: "we_test" });
|
|
25
|
+
});
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { useWorkflowAction } from "./useWorkflowAction.js";
|
|
4
|
+
import { useWorkflowResource } from "./useWorkflowResource.js";
|
|
5
|
+
export type WebhookSetupOptions<Status, Result> = {
|
|
6
|
+
scopeKey: string;
|
|
7
|
+
load: () => Promise<Status>;
|
|
8
|
+
setup: () => Promise<Result>;
|
|
9
|
+
};
|
|
10
|
+
export function useWebhookSetup<Status, Result>(
|
|
11
|
+
props: WebhookSetupOptions<Status, Result>,
|
|
12
|
+
) {
|
|
13
|
+
const status = useWorkflowResource(props.load, props.scopeKey);
|
|
14
|
+
const setup = useWorkflowAction(
|
|
15
|
+
async () => ({ value: await props.setup() }),
|
|
16
|
+
props.scopeKey,
|
|
17
|
+
);
|
|
18
|
+
return {
|
|
19
|
+
status: status.data,
|
|
20
|
+
isChecking: status.isLoading,
|
|
21
|
+
statusError: status.error,
|
|
22
|
+
checkStatus: status.refresh,
|
|
23
|
+
result: setup.result?.value,
|
|
24
|
+
isPending: setup.isPending,
|
|
25
|
+
error: setup.error,
|
|
26
|
+
configure: async () => {
|
|
27
|
+
if (await setup.run()) status.refresh();
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function WebhookSetup<Status, Result>(
|
|
32
|
+
props: WebhookSetupOptions<Status, Result> & {
|
|
33
|
+
renderStatus?: (status: Status) => ReactNode;
|
|
34
|
+
children?: (
|
|
35
|
+
state: ReturnType<typeof useWebhookSetup<Status, Result>>,
|
|
36
|
+
) => ReactNode;
|
|
37
|
+
},
|
|
38
|
+
) {
|
|
39
|
+
const state = useWebhookSetup(props);
|
|
40
|
+
if (props.children) return <>{props.children(state)}</>;
|
|
41
|
+
return (
|
|
42
|
+
<section data-better-stripe="webhook-setup">
|
|
43
|
+
<h2>Webhook destinations</h2>
|
|
44
|
+
{(state.error || state.statusError) && (
|
|
45
|
+
<p role="alert">{state.error || state.statusError}</p>
|
|
46
|
+
)}
|
|
47
|
+
{state.isChecking ? (
|
|
48
|
+
<p role="status">Checking destinations…</p>
|
|
49
|
+
) : state.status !== undefined && props.renderStatus ? (
|
|
50
|
+
props.renderStatus(state.status)
|
|
51
|
+
) : (
|
|
52
|
+
<p>Destination status loaded.</p>
|
|
53
|
+
)}
|
|
54
|
+
<button
|
|
55
|
+
type="button"
|
|
56
|
+
disabled={state.isPending || state.isChecking}
|
|
57
|
+
onClick={() => {
|
|
58
|
+
void state.configure();
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
{state.isPending ? "Configuring…" : "Configure webhooks"}
|
|
62
|
+
</button>
|
|
63
|
+
<button
|
|
64
|
+
type="button"
|
|
65
|
+
disabled={state.isChecking}
|
|
66
|
+
onClick={state.checkStatus}
|
|
67
|
+
>
|
|
68
|
+
Refresh status
|
|
69
|
+
</button>
|
|
70
|
+
</section>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
export type EnvironmentCheck = {
|
|
74
|
+
id: string;
|
|
75
|
+
label: string;
|
|
76
|
+
configured: boolean;
|
|
77
|
+
};
|
|
78
|
+
export function EnvironmentStatus({
|
|
79
|
+
checks,
|
|
80
|
+
isLoading = checks === undefined,
|
|
81
|
+
error,
|
|
82
|
+
children,
|
|
83
|
+
}: {
|
|
84
|
+
checks: EnvironmentCheck[] | undefined;
|
|
85
|
+
isLoading?: boolean;
|
|
86
|
+
error?: string | null;
|
|
87
|
+
children?: (state: {
|
|
88
|
+
checks: EnvironmentCheck[];
|
|
89
|
+
allConfigured: boolean;
|
|
90
|
+
isLoading: boolean;
|
|
91
|
+
error: string | null;
|
|
92
|
+
}) => ReactNode;
|
|
93
|
+
}) {
|
|
94
|
+
const state = {
|
|
95
|
+
checks: checks ?? [],
|
|
96
|
+
allConfigured:
|
|
97
|
+
!!checks?.length && checks.every((check) => check.configured),
|
|
98
|
+
isLoading,
|
|
99
|
+
error: error ?? null,
|
|
100
|
+
};
|
|
101
|
+
if (children) return <>{children(state)}</>;
|
|
102
|
+
return (
|
|
103
|
+
<section data-better-stripe="environment-status">
|
|
104
|
+
<h2>Environment</h2>
|
|
105
|
+
{error ? (
|
|
106
|
+
<p role="alert">{error}</p>
|
|
107
|
+
) : isLoading ? (
|
|
108
|
+
<p role="status">Checking configuration…</p>
|
|
109
|
+
) : !checks?.length ? (
|
|
110
|
+
<p>No environment checks configured.</p>
|
|
111
|
+
) : (
|
|
112
|
+
<ul>
|
|
113
|
+
{checks.map((check) => (
|
|
114
|
+
<li key={check.id}>
|
|
115
|
+
{check.label}: {check.configured ? "Set" : "Not set"}
|
|
116
|
+
</li>
|
|
117
|
+
))}
|
|
118
|
+
</ul>
|
|
119
|
+
)}
|
|
120
|
+
</section>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
export type FixtureProgressState = {
|
|
124
|
+
cursor: number;
|
|
125
|
+
total: number;
|
|
126
|
+
status: string;
|
|
127
|
+
error?: string;
|
|
128
|
+
};
|
|
129
|
+
export function FixtureProgress({
|
|
130
|
+
state,
|
|
131
|
+
children,
|
|
132
|
+
}: {
|
|
133
|
+
state: FixtureProgressState | null | undefined;
|
|
134
|
+
children?: (
|
|
135
|
+
state: FixtureProgressState & { progress: number; message: string },
|
|
136
|
+
) => ReactNode;
|
|
137
|
+
}) {
|
|
138
|
+
if (!state) return <p>No fixture run yet.</p>;
|
|
139
|
+
const result = {
|
|
140
|
+
...state,
|
|
141
|
+
progress:
|
|
142
|
+
state.total > 0
|
|
143
|
+
? Math.max(0, Math.min(1, state.cursor / state.total))
|
|
144
|
+
: 0,
|
|
145
|
+
message:
|
|
146
|
+
state.status === "running"
|
|
147
|
+
? "Fixtures are being created. Stripe events continue to update your data."
|
|
148
|
+
: state.status === "complete"
|
|
149
|
+
? "Fixtures are populated. Stripe statuses can continue updating through webhooks."
|
|
150
|
+
: "Population stopped. Resume to retry this step.",
|
|
151
|
+
};
|
|
152
|
+
if (children) return <>{children(result)}</>;
|
|
153
|
+
return (
|
|
154
|
+
<div data-better-stripe="fixture-progress">
|
|
155
|
+
<progress
|
|
156
|
+
aria-label="Sandbox fixture progress"
|
|
157
|
+
value={result.progress}
|
|
158
|
+
max={1}
|
|
159
|
+
/>
|
|
160
|
+
<p role="status">
|
|
161
|
+
{state.cursor} of {state.total} steps complete. {result.message}
|
|
162
|
+
</p>
|
|
163
|
+
{state.error && <p role="alert">{state.error}</p>}
|
|
164
|
+
</div>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
5
|
+
import { Storefront } from "./Storefront.js";
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
it("preserves product, store, and referral attribution when selecting a price", async () => {
|
|
8
|
+
const onSelectPrice = vi.fn();
|
|
9
|
+
render(
|
|
10
|
+
<Storefront
|
|
11
|
+
stores={[
|
|
12
|
+
{
|
|
13
|
+
accountId: "acct_one",
|
|
14
|
+
name: "Independent Store",
|
|
15
|
+
products: [
|
|
16
|
+
{
|
|
17
|
+
stripeProductId: "prod_one",
|
|
18
|
+
name: "Tee",
|
|
19
|
+
prices: [
|
|
20
|
+
{
|
|
21
|
+
stripePriceId: "price_one",
|
|
22
|
+
unitAmount: 2900,
|
|
23
|
+
currency: "usd",
|
|
24
|
+
type: "one_time",
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
]}
|
|
31
|
+
referralCode="avery"
|
|
32
|
+
onSelectPrice={onSelectPrice}
|
|
33
|
+
/>,
|
|
34
|
+
);
|
|
35
|
+
await userEvent.click(screen.getByRole("button", { name: "Buy Tee" }));
|
|
36
|
+
expect(onSelectPrice).toHaveBeenCalledWith(
|
|
37
|
+
expect.objectContaining({
|
|
38
|
+
store: expect.objectContaining({ accountId: "acct_one" }),
|
|
39
|
+
price: expect.objectContaining({ stripePriceId: "price_one" }),
|
|
40
|
+
referralCode: "avery",
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
it("does not offer inactive prices or purchases when the application disables buying", () => {
|
|
45
|
+
render(
|
|
46
|
+
<Storefront
|
|
47
|
+
canPurchase={false}
|
|
48
|
+
stores={[
|
|
49
|
+
{
|
|
50
|
+
accountId: "acct_one",
|
|
51
|
+
name: "Store",
|
|
52
|
+
products: [
|
|
53
|
+
{
|
|
54
|
+
stripeProductId: "prod_one",
|
|
55
|
+
name: "Tee",
|
|
56
|
+
prices: [
|
|
57
|
+
{
|
|
58
|
+
stripePriceId: "price_old",
|
|
59
|
+
active: false,
|
|
60
|
+
unitAmount: 100,
|
|
61
|
+
currency: "usd",
|
|
62
|
+
type: "one_time",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
stripePriceId: "price_one",
|
|
66
|
+
unitAmount: 2900,
|
|
67
|
+
currency: "usd",
|
|
68
|
+
type: "one_time",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
]}
|
|
75
|
+
/>,
|
|
76
|
+
);
|
|
77
|
+
expect(
|
|
78
|
+
(screen.getByRole("button", { name: "Buy Tee" }) as HTMLButtonElement)
|
|
79
|
+
.disabled,
|
|
80
|
+
).toBe(true);
|
|
81
|
+
expect(screen.getAllByRole("button")).toHaveLength(1);
|
|
82
|
+
});
|