@fantastic.dev/better-stripe 0.7.0 → 0.8.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 +29 -18
- package/README.md +123 -91
- 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/disputes.d.ts +1 -1
- package/dist/client/connect/disputes.d.ts.map +1 -1
- package/dist/client/connect/disputes.js +12 -6
- package/dist/client/connect/disputes.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/DisputeDetail.d.ts +4 -1
- package/dist/react/components/DisputeDetail.d.ts.map +1 -1
- package/dist/react/components/DisputeDetail.js +12 -6
- package/dist/react/components/DisputeDetail.js.map +1 -1
- package/dist/react/components/DisputesList.d.ts.map +1 -1
- package/dist/react/components/DisputesList.js +2 -1
- package/dist/react/components/DisputesList.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 +2 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +3 -1
- 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 +48 -0
- package/dist/react/workflows/Payouts.d.ts.map +1 -0
- package/dist/react/workflows/Payouts.js +88 -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 +88 -0
- package/docs/react-workflows.md +234 -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/disputes.test.ts +15 -0
- package/src/client/connect/disputes.ts +13 -7
- 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/DisputeDetail.tsx +14 -5
- package/src/react/components/DisputesList.render.test.tsx +21 -0
- package/src/react/components/DisputesList.tsx +2 -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 +3 -10
- 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 +7 -1
- 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 +64 -0
- package/src/react/workflows/Disputes.tsx +173 -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 +112 -0
- package/src/react/workflows/Payouts.tsx +215 -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,247 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useId,
|
|
4
|
+
useMemo,
|
|
5
|
+
useState,
|
|
6
|
+
type FormEvent,
|
|
7
|
+
type ReactNode,
|
|
8
|
+
} from "react";
|
|
9
|
+
import { loadStripe, type Appearance } from "@stripe/stripe-js";
|
|
10
|
+
import {
|
|
11
|
+
PaymentElement as IntentElement,
|
|
12
|
+
useElements,
|
|
13
|
+
useStripe,
|
|
14
|
+
} from "@stripe/react-stripe-js";
|
|
15
|
+
import {
|
|
16
|
+
PaymentElement,
|
|
17
|
+
useCheckout,
|
|
18
|
+
CheckoutFormProvider,
|
|
19
|
+
CheckoutForm as StripeCheckoutForm,
|
|
20
|
+
useCheckoutForm,
|
|
21
|
+
} from "@stripe/react-stripe-js/checkout";
|
|
22
|
+
import { CheckoutSessionProvider } from "../components/CheckoutSessionProvider.js";
|
|
23
|
+
import { StripeProvider } from "../components/StripeProvider.js";
|
|
24
|
+
import { useWorkflowAction } from "./useWorkflowAction.js";
|
|
25
|
+
export type CheckoutFormState = {
|
|
26
|
+
email: string;
|
|
27
|
+
setEmail: (email: string) => void;
|
|
28
|
+
emailInputId: string;
|
|
29
|
+
isPending: boolean;
|
|
30
|
+
error: string | null;
|
|
31
|
+
paymentElement: ReactNode;
|
|
32
|
+
submit: (event: FormEvent<HTMLFormElement>) => void;
|
|
33
|
+
};
|
|
34
|
+
export type CheckoutFormOptions = {
|
|
35
|
+
email?: string;
|
|
36
|
+
appearance?: Appearance;
|
|
37
|
+
renderForm?: (state: CheckoutFormState) => ReactNode;
|
|
38
|
+
};
|
|
39
|
+
export type CheckoutFormProps = CheckoutFormOptions & {
|
|
40
|
+
publishableKey: string;
|
|
41
|
+
clientSecret: string;
|
|
42
|
+
returnUrl: string;
|
|
43
|
+
onNavigate: (url: string) => void;
|
|
44
|
+
};
|
|
45
|
+
function NativeForm({
|
|
46
|
+
email,
|
|
47
|
+
setEmail,
|
|
48
|
+
emailInputId,
|
|
49
|
+
paymentElement,
|
|
50
|
+
submit,
|
|
51
|
+
isPending,
|
|
52
|
+
error,
|
|
53
|
+
}: CheckoutFormState) {
|
|
54
|
+
return (
|
|
55
|
+
<form
|
|
56
|
+
onSubmit={submit}
|
|
57
|
+
data-better-stripe="checkout-form"
|
|
58
|
+
aria-busy={isPending}
|
|
59
|
+
>
|
|
60
|
+
<label htmlFor={emailInputId}>Email for your receipt</label>
|
|
61
|
+
<input
|
|
62
|
+
id={emailInputId}
|
|
63
|
+
type="email"
|
|
64
|
+
name="email"
|
|
65
|
+
required
|
|
66
|
+
autoComplete="email"
|
|
67
|
+
value={email}
|
|
68
|
+
onChange={(event) => setEmail(event.target.value)}
|
|
69
|
+
/>
|
|
70
|
+
{paymentElement}
|
|
71
|
+
{error && <p role="alert">{error}</p>}
|
|
72
|
+
<button type="submit" disabled={isPending}>
|
|
73
|
+
{isPending ? "Processing…" : "Pay"}
|
|
74
|
+
</button>
|
|
75
|
+
</form>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
export function CheckoutElementsForm(props: CheckoutFormProps) {
|
|
79
|
+
return (
|
|
80
|
+
<CheckoutSessionProvider
|
|
81
|
+
publishableKey={props.publishableKey}
|
|
82
|
+
clientSecret={props.clientSecret}
|
|
83
|
+
appearance={props.appearance}
|
|
84
|
+
>
|
|
85
|
+
<SessionForm {...props} />
|
|
86
|
+
</CheckoutSessionProvider>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
function SessionForm({
|
|
90
|
+
email: initialEmail = "",
|
|
91
|
+
returnUrl,
|
|
92
|
+
onNavigate,
|
|
93
|
+
renderForm,
|
|
94
|
+
}: CheckoutFormProps) {
|
|
95
|
+
const checkout = useCheckout();
|
|
96
|
+
const [email, setEmail] = useState(initialEmail);
|
|
97
|
+
const emailInputId = useId();
|
|
98
|
+
const action = useWorkflowAction(async () => {
|
|
99
|
+
if (checkout.type !== "success") throw new Error("Checkout is not ready.");
|
|
100
|
+
const updated = await checkout.checkout.updateEmail(email);
|
|
101
|
+
if (updated.type === "error") throw new Error(updated.error.message);
|
|
102
|
+
const confirmed = await checkout.checkout.confirm();
|
|
103
|
+
if (confirmed.type === "error") throw new Error(confirmed.error.message);
|
|
104
|
+
onNavigate(
|
|
105
|
+
returnUrl.replace("{CHECKOUT_SESSION_ID}", checkout.checkout.id),
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
if (checkout.type === "loading")
|
|
109
|
+
return <p role="status">Loading checkout…</p>;
|
|
110
|
+
if (checkout.type === "error")
|
|
111
|
+
return <p role="alert">{checkout.error.message}</p>;
|
|
112
|
+
const state: CheckoutFormState = {
|
|
113
|
+
email,
|
|
114
|
+
setEmail,
|
|
115
|
+
emailInputId,
|
|
116
|
+
paymentElement: <PaymentElement />,
|
|
117
|
+
error: action.error,
|
|
118
|
+
isPending: action.isPending,
|
|
119
|
+
submit: (event) => {
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
void action.run();
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
return <>{renderForm ? renderForm(state) : <NativeForm {...state} />}</>;
|
|
125
|
+
}
|
|
126
|
+
export function PaymentIntentForm(props: CheckoutFormProps) {
|
|
127
|
+
return (
|
|
128
|
+
<StripeProvider
|
|
129
|
+
publishableKey={props.publishableKey}
|
|
130
|
+
elementsOptions={{
|
|
131
|
+
clientSecret: props.clientSecret,
|
|
132
|
+
...(props.appearance ? { appearance: props.appearance } : {}),
|
|
133
|
+
}}
|
|
134
|
+
>
|
|
135
|
+
<IntentForm {...props} />
|
|
136
|
+
</StripeProvider>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
function IntentForm({
|
|
140
|
+
email: initialEmail = "",
|
|
141
|
+
returnUrl,
|
|
142
|
+
onNavigate,
|
|
143
|
+
renderForm,
|
|
144
|
+
}: CheckoutFormProps) {
|
|
145
|
+
const stripe = useStripe();
|
|
146
|
+
const elements = useElements();
|
|
147
|
+
const emailInputId = useId();
|
|
148
|
+
const [email, setEmail] = useState(initialEmail);
|
|
149
|
+
const action = useWorkflowAction(async () => {
|
|
150
|
+
if (!stripe || !elements)
|
|
151
|
+
throw new Error("Payment details are still loading.");
|
|
152
|
+
const validation = await elements.submit();
|
|
153
|
+
if (validation.error)
|
|
154
|
+
throw new Error(
|
|
155
|
+
validation.error.message ?? "Check your payment details.",
|
|
156
|
+
);
|
|
157
|
+
const result = await stripe.confirmPayment({
|
|
158
|
+
elements,
|
|
159
|
+
confirmParams: {
|
|
160
|
+
return_url: returnUrl,
|
|
161
|
+
payment_method_data: { billing_details: { email } },
|
|
162
|
+
},
|
|
163
|
+
redirect: "if_required",
|
|
164
|
+
});
|
|
165
|
+
if (result.error)
|
|
166
|
+
throw new Error(result.error.message ?? "Payment failed.");
|
|
167
|
+
if (result.paymentIntent) {
|
|
168
|
+
const url = new URL(returnUrl, window.location.origin);
|
|
169
|
+
url.searchParams.set("payment_intent", result.paymentIntent.id);
|
|
170
|
+
onNavigate(url.toString());
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const state: CheckoutFormState = {
|
|
174
|
+
email,
|
|
175
|
+
setEmail,
|
|
176
|
+
emailInputId,
|
|
177
|
+
paymentElement: <IntentElement />,
|
|
178
|
+
error: action.error,
|
|
179
|
+
isPending: action.isPending || !stripe || !elements,
|
|
180
|
+
submit: (event) => {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
void action.run();
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
return <>{renderForm ? renderForm(state) : <NativeForm {...state} />}</>;
|
|
186
|
+
}
|
|
187
|
+
export function CheckoutForm(props: CheckoutFormProps) {
|
|
188
|
+
const stripe = useMemo(
|
|
189
|
+
() => loadStripe(props.publishableKey),
|
|
190
|
+
[props.publishableKey],
|
|
191
|
+
);
|
|
192
|
+
return (
|
|
193
|
+
<CheckoutFormProvider
|
|
194
|
+
stripe={stripe}
|
|
195
|
+
options={{
|
|
196
|
+
clientSecret: props.clientSecret,
|
|
197
|
+
...(props.appearance
|
|
198
|
+
? { elementsOptions: { appearance: props.appearance } }
|
|
199
|
+
: {}),
|
|
200
|
+
}}
|
|
201
|
+
>
|
|
202
|
+
<CompactForm {...props} />
|
|
203
|
+
</CheckoutFormProvider>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
function CompactForm({ returnUrl, onNavigate }: CheckoutFormProps) {
|
|
207
|
+
const checkout = useCheckoutForm();
|
|
208
|
+
const [loadError, setLoadError] = useState<string | null>(null);
|
|
209
|
+
const action = useWorkflowAction(
|
|
210
|
+
async (
|
|
211
|
+
event: Parameters<
|
|
212
|
+
NonNullable<
|
|
213
|
+
React.ComponentProps<typeof StripeCheckoutForm>["onConfirm"]
|
|
214
|
+
>
|
|
215
|
+
>[0],
|
|
216
|
+
) => {
|
|
217
|
+
if (checkout.type !== "success")
|
|
218
|
+
throw new Error("Checkout is not ready.");
|
|
219
|
+
const result = await checkout.checkout.confirm({
|
|
220
|
+
formConfirmEvent: event,
|
|
221
|
+
});
|
|
222
|
+
if (result.type === "error") throw new Error(result.error.message);
|
|
223
|
+
onNavigate(
|
|
224
|
+
returnUrl.replace("{CHECKOUT_SESSION_ID}", checkout.checkout.id),
|
|
225
|
+
);
|
|
226
|
+
},
|
|
227
|
+
);
|
|
228
|
+
if (checkout.type === "loading")
|
|
229
|
+
return <p role="status">Loading embedded form…</p>;
|
|
230
|
+
if (checkout.type === "error")
|
|
231
|
+
return <p role="alert">{checkout.error.message}</p>;
|
|
232
|
+
return (
|
|
233
|
+
<div data-better-stripe="checkout-form" aria-busy={action.isPending}>
|
|
234
|
+
<StripeCheckoutForm
|
|
235
|
+
onLoadError={({ error }) =>
|
|
236
|
+
setLoadError(error.message ?? "Could not load checkout.")
|
|
237
|
+
}
|
|
238
|
+
onConfirm={async (event) => {
|
|
239
|
+
await action.run(event);
|
|
240
|
+
}}
|
|
241
|
+
/>
|
|
242
|
+
{(loadError || action.error) && (
|
|
243
|
+
<p role="alert">{loadError || action.error}</p>
|
|
244
|
+
)}
|
|
245
|
+
</div>
|
|
246
|
+
);
|
|
247
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import {
|
|
3
|
+
act,
|
|
4
|
+
cleanup,
|
|
5
|
+
fireEvent,
|
|
6
|
+
render,
|
|
7
|
+
screen,
|
|
8
|
+
} from "@testing-library/react";
|
|
9
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
10
|
+
import { ClipboardButton } from "./ClipboardButton.js";
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
cleanup();
|
|
13
|
+
vi.useRealTimers();
|
|
14
|
+
});
|
|
15
|
+
it("copies on demand, restores its label, and catches denied clipboard access", async () => {
|
|
16
|
+
vi.useFakeTimers();
|
|
17
|
+
const writeText = vi
|
|
18
|
+
.fn()
|
|
19
|
+
.mockResolvedValueOnce(undefined)
|
|
20
|
+
.mockRejectedValueOnce(new Error("Clipboard denied"));
|
|
21
|
+
render(<ClipboardButton text="pnpm check:all" writeText={writeText} />);
|
|
22
|
+
await act(async () => {
|
|
23
|
+
fireEvent.click(screen.getByRole("button", { name: "Copy" }));
|
|
24
|
+
});
|
|
25
|
+
expect(writeText).toHaveBeenCalledWith("pnpm check:all");
|
|
26
|
+
expect(screen.getByText("Copied!")).toBeTruthy();
|
|
27
|
+
act(() => {
|
|
28
|
+
vi.advanceTimersByTime(2000);
|
|
29
|
+
});
|
|
30
|
+
await act(async () => {
|
|
31
|
+
fireEvent.click(screen.getByRole("button", { name: "Copy" }));
|
|
32
|
+
});
|
|
33
|
+
expect(screen.getByRole("alert").textContent).toContain("Clipboard denied");
|
|
34
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef, type ReactNode } from "react";
|
|
3
|
+
import { useWorkflowAction } from "./useWorkflowAction.js";
|
|
4
|
+
export type ClipboardButtonProps = {
|
|
5
|
+
text: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
copiedLabel?: string;
|
|
8
|
+
resetAfterMs?: number;
|
|
9
|
+
writeText?: (text: string) => Promise<void>;
|
|
10
|
+
children?: (state: {
|
|
11
|
+
copy: () => Promise<void>;
|
|
12
|
+
copied: boolean;
|
|
13
|
+
isPending: boolean;
|
|
14
|
+
error: string | null;
|
|
15
|
+
label: string;
|
|
16
|
+
}) => ReactNode;
|
|
17
|
+
};
|
|
18
|
+
export function ClipboardButton({
|
|
19
|
+
text,
|
|
20
|
+
label = "Copy",
|
|
21
|
+
copiedLabel = "Copied!",
|
|
22
|
+
resetAfterMs = 2000,
|
|
23
|
+
writeText = (text) => navigator.clipboard.writeText(text),
|
|
24
|
+
children,
|
|
25
|
+
}: ClipboardButtonProps) {
|
|
26
|
+
const action = useWorkflowAction(async () => {
|
|
27
|
+
await writeText(text);
|
|
28
|
+
return text;
|
|
29
|
+
});
|
|
30
|
+
const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
31
|
+
useEffect(
|
|
32
|
+
() => () => {
|
|
33
|
+
clearTimeout(timer.current);
|
|
34
|
+
},
|
|
35
|
+
[],
|
|
36
|
+
);
|
|
37
|
+
const copied = action.result === text;
|
|
38
|
+
const copy = async () => {
|
|
39
|
+
const result = await action.run();
|
|
40
|
+
if (result !== undefined) {
|
|
41
|
+
clearTimeout(timer.current);
|
|
42
|
+
timer.current = setTimeout(action.reset, resetAfterMs);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const state = {
|
|
46
|
+
copy,
|
|
47
|
+
copied,
|
|
48
|
+
isPending: action.isPending,
|
|
49
|
+
error: action.error,
|
|
50
|
+
label: copied ? copiedLabel : label,
|
|
51
|
+
};
|
|
52
|
+
if (children) return <>{children(state)}</>;
|
|
53
|
+
return (
|
|
54
|
+
<span data-better-stripe="clipboard">
|
|
55
|
+
<button
|
|
56
|
+
type="button"
|
|
57
|
+
disabled={state.isPending}
|
|
58
|
+
onClick={() => {
|
|
59
|
+
void copy();
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
{state.label}
|
|
63
|
+
</button>
|
|
64
|
+
{state.error && <span role="alert">{state.error}</span>}
|
|
65
|
+
</span>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import type { Key, ReactNode } from "react";
|
|
3
|
+
export type WorkflowColumn<Row> = {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
align?: "start" | "end";
|
|
7
|
+
cell: (row: Row) => ReactNode;
|
|
8
|
+
};
|
|
9
|
+
export type CollectionRenderProps<Row> = {
|
|
10
|
+
rows: Row[];
|
|
11
|
+
columns: WorkflowColumn<Row>[];
|
|
12
|
+
getKey: (row: Row) => Key;
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
isEmpty: boolean;
|
|
15
|
+
error: string | null;
|
|
16
|
+
emptyLabel: string;
|
|
17
|
+
loadingLabel: string;
|
|
18
|
+
};
|
|
19
|
+
export type CollectionProps<Row> = {
|
|
20
|
+
rows: Row[] | null | undefined;
|
|
21
|
+
columns: WorkflowColumn<Row>[];
|
|
22
|
+
getKey: (row: Row) => Key;
|
|
23
|
+
isLoading?: boolean;
|
|
24
|
+
error?: string | null;
|
|
25
|
+
emptyLabel?: string;
|
|
26
|
+
loadingLabel?: string;
|
|
27
|
+
children?: (state: CollectionRenderProps<Row>) => ReactNode;
|
|
28
|
+
};
|
|
29
|
+
/** Accessible native table by default. Render props let the application supply its design-system elements. */
|
|
30
|
+
export function Collection<Row>({
|
|
31
|
+
rows,
|
|
32
|
+
columns,
|
|
33
|
+
getKey,
|
|
34
|
+
isLoading = rows === undefined,
|
|
35
|
+
error = null,
|
|
36
|
+
emptyLabel = "No records yet.",
|
|
37
|
+
loadingLabel = "Loading…",
|
|
38
|
+
children,
|
|
39
|
+
}: CollectionProps<Row>) {
|
|
40
|
+
const state: CollectionRenderProps<Row> = {
|
|
41
|
+
rows: rows ?? [],
|
|
42
|
+
columns,
|
|
43
|
+
getKey,
|
|
44
|
+
isLoading,
|
|
45
|
+
isEmpty: !isLoading && !rows?.length,
|
|
46
|
+
error,
|
|
47
|
+
emptyLabel,
|
|
48
|
+
loadingLabel,
|
|
49
|
+
};
|
|
50
|
+
if (children) return <>{children(state)}</>;
|
|
51
|
+
if (error) return <p role="alert">{error}</p>;
|
|
52
|
+
if (isLoading) return <p role="status">{loadingLabel}</p>;
|
|
53
|
+
if (state.isEmpty) return <p>{emptyLabel}</p>;
|
|
54
|
+
return (
|
|
55
|
+
<table data-better-stripe="collection">
|
|
56
|
+
<thead>
|
|
57
|
+
<tr>
|
|
58
|
+
{columns.map((column) => (
|
|
59
|
+
<th key={column.id} scope="col">
|
|
60
|
+
{column.label}
|
|
61
|
+
</th>
|
|
62
|
+
))}
|
|
63
|
+
</tr>
|
|
64
|
+
</thead>
|
|
65
|
+
<tbody>
|
|
66
|
+
{state.rows.map((row) => (
|
|
67
|
+
<tr key={getKey(row)}>
|
|
68
|
+
{columns.map((column) => (
|
|
69
|
+
<td key={column.id}>{column.cell(row)}</td>
|
|
70
|
+
))}
|
|
71
|
+
</tr>
|
|
72
|
+
))}
|
|
73
|
+
</tbody>
|
|
74
|
+
</table>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
3
|
+
import { afterEach, expect, it } from "vitest";
|
|
4
|
+
import {
|
|
5
|
+
Sales,
|
|
6
|
+
Invoices,
|
|
7
|
+
RefundHistory,
|
|
8
|
+
ReferredSales,
|
|
9
|
+
} from "./Collections.js";
|
|
10
|
+
afterEach(cleanup);
|
|
11
|
+
it("renders sale economics in minor units without recomputing the platform's fee policy", () => {
|
|
12
|
+
render(
|
|
13
|
+
<Sales
|
|
14
|
+
rows={[
|
|
15
|
+
{
|
|
16
|
+
paymentIntentId: "pi_sale",
|
|
17
|
+
planId: "custom",
|
|
18
|
+
gross: 10000,
|
|
19
|
+
processingFee: 320,
|
|
20
|
+
platformNet: 580,
|
|
21
|
+
affiliateNet: 1820,
|
|
22
|
+
costRecoveryAmount: 100,
|
|
23
|
+
sellerNet: 7180,
|
|
24
|
+
currency: "usd",
|
|
25
|
+
status: "settled",
|
|
26
|
+
},
|
|
27
|
+
]}
|
|
28
|
+
/>,
|
|
29
|
+
);
|
|
30
|
+
expect(screen.getByText("$100.00")).toBeTruthy();
|
|
31
|
+
expect(screen.getByText("$71.80")).toBeTruthy();
|
|
32
|
+
expect(screen.getByText("pi_sale")).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
it("renders invoice links and explicit loading/empty states", () => {
|
|
35
|
+
const { rerender } = render(<Invoices rows={undefined} />);
|
|
36
|
+
expect(screen.getByRole("status").textContent).toContain("Loading");
|
|
37
|
+
rerender(<Invoices rows={[]} />);
|
|
38
|
+
expect(screen.getByText("No invoices yet.")).toBeTruthy();
|
|
39
|
+
rerender(
|
|
40
|
+
<Invoices
|
|
41
|
+
rows={[
|
|
42
|
+
{
|
|
43
|
+
stripeInvoiceId: "in_test",
|
|
44
|
+
status: "paid",
|
|
45
|
+
amountPaid: 1200,
|
|
46
|
+
currency: "usd",
|
|
47
|
+
hostedInvoiceUrl: "https://invoice.stripe.com/test",
|
|
48
|
+
},
|
|
49
|
+
]}
|
|
50
|
+
/>,
|
|
51
|
+
);
|
|
52
|
+
expect(
|
|
53
|
+
screen.getByRole("link", { name: "View invoice" }).getAttribute("href"),
|
|
54
|
+
).toBe("https://invoice.stripe.com/test");
|
|
55
|
+
});
|
|
56
|
+
it("preserves store attribution in referred sales and refund statuses in history", () => {
|
|
57
|
+
const { unmount } = render(
|
|
58
|
+
<ReferredSales
|
|
59
|
+
rows={[
|
|
60
|
+
{
|
|
61
|
+
stripeTransferId: "tr_test",
|
|
62
|
+
storeName: "Independent Store",
|
|
63
|
+
amount: 900,
|
|
64
|
+
currency: "usd",
|
|
65
|
+
},
|
|
66
|
+
]}
|
|
67
|
+
/>,
|
|
68
|
+
);
|
|
69
|
+
expect(screen.getByText("Independent Store")).toBeTruthy();
|
|
70
|
+
unmount();
|
|
71
|
+
render(
|
|
72
|
+
<RefundHistory
|
|
73
|
+
rows={[
|
|
74
|
+
{
|
|
75
|
+
stripeRefundId: "re_test",
|
|
76
|
+
amount: 1000,
|
|
77
|
+
currency: "usd",
|
|
78
|
+
status: "failed",
|
|
79
|
+
_creationTime: Date.UTC(2026, 9, 13),
|
|
80
|
+
},
|
|
81
|
+
]}
|
|
82
|
+
/>,
|
|
83
|
+
);
|
|
84
|
+
expect(screen.getByText("failed")).toBeTruthy();
|
|
85
|
+
expect(screen.getByRole("columnheader", { name: "Created" })).toBeTruthy();
|
|
86
|
+
});
|