@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,377 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useId, useState, type ReactNode } from "react";
|
|
3
|
+
import { useWorkflowAction } from "./useWorkflowAction.js";
|
|
4
|
+
import { PriceCard, type PriceCardPrice } from "../components/PriceCard.js";
|
|
5
|
+
export type ProductInput = { name: string; description?: string };
|
|
6
|
+
export type PriceInput = {
|
|
7
|
+
stripeProductId: string;
|
|
8
|
+
unitAmount: number;
|
|
9
|
+
currency: string;
|
|
10
|
+
type: "one_time" | "recurring";
|
|
11
|
+
interval?: "month" | "year" | "week" | "day";
|
|
12
|
+
};
|
|
13
|
+
export type ProductActions = {
|
|
14
|
+
scopeKey: string;
|
|
15
|
+
createProduct: (args: ProductInput) => Promise<unknown>;
|
|
16
|
+
createPrice: (args: PriceInput) => Promise<unknown>;
|
|
17
|
+
updateProduct?: (
|
|
18
|
+
args: ProductInput & { stripeProductId: string },
|
|
19
|
+
) => Promise<unknown>;
|
|
20
|
+
deactivateProduct?: (args: { stripeProductId: string }) => Promise<unknown>;
|
|
21
|
+
deactivatePrice?: (args: { stripePriceId: string }) => Promise<unknown>;
|
|
22
|
+
};
|
|
23
|
+
export type ProductEdit = {
|
|
24
|
+
stripeProductId: string;
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
};
|
|
28
|
+
export function useProductManager(props: ProductActions) {
|
|
29
|
+
const initial = {
|
|
30
|
+
scope: props.scopeKey,
|
|
31
|
+
expandedProduct: null as string | null,
|
|
32
|
+
showCreateDialog: false,
|
|
33
|
+
showAddPriceFor: null as string | null,
|
|
34
|
+
newProduct: { name: "", description: "" },
|
|
35
|
+
newPrice: { amount: "", currency: "usd", interval: "month" },
|
|
36
|
+
editingProduct: null as ProductEdit | null,
|
|
37
|
+
};
|
|
38
|
+
const [fields, setFields] = useState(initial);
|
|
39
|
+
if (fields.scope !== props.scopeKey) setFields(initial);
|
|
40
|
+
type Command = {
|
|
41
|
+
type: "create" | "price" | "edit" | "archiveProduct" | "archivePrice";
|
|
42
|
+
id?: string;
|
|
43
|
+
};
|
|
44
|
+
const [command, setCommand] = useState<Command | null>(null);
|
|
45
|
+
const action = useWorkflowAction(async (command: Command) => {
|
|
46
|
+
setCommand(command);
|
|
47
|
+
switch (command.type) {
|
|
48
|
+
case "create": {
|
|
49
|
+
if (!fields.newProduct.name.trim())
|
|
50
|
+
throw new Error("Enter a product name.");
|
|
51
|
+
await props.createProduct({
|
|
52
|
+
name: fields.newProduct.name.trim(),
|
|
53
|
+
description: fields.newProduct.description.trim() || undefined,
|
|
54
|
+
});
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case "price": {
|
|
58
|
+
const unitAmount = Number(fields.newPrice.amount);
|
|
59
|
+
if (
|
|
60
|
+
!/^\d+$/.test(fields.newPrice.amount) ||
|
|
61
|
+
!Number.isSafeInteger(unitAmount) ||
|
|
62
|
+
unitAmount <= 0
|
|
63
|
+
)
|
|
64
|
+
throw new Error("Enter a positive integer price in minor units.");
|
|
65
|
+
if (!/^[a-zA-Z]{3}$/.test(fields.newPrice.currency))
|
|
66
|
+
throw new Error("Enter a three-letter currency code.");
|
|
67
|
+
const interval = fields.newPrice.interval;
|
|
68
|
+
if (!["one_time", "month", "year", "week", "day"].includes(interval))
|
|
69
|
+
throw new Error("Choose a supported price interval.");
|
|
70
|
+
await props.createPrice({
|
|
71
|
+
stripeProductId: command.id!,
|
|
72
|
+
unitAmount,
|
|
73
|
+
currency: fields.newPrice.currency.toLowerCase(),
|
|
74
|
+
type: interval === "one_time" ? "one_time" : "recurring",
|
|
75
|
+
interval:
|
|
76
|
+
interval === "one_time"
|
|
77
|
+
? undefined
|
|
78
|
+
: (interval as PriceInput["interval"]),
|
|
79
|
+
});
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case "edit": {
|
|
83
|
+
if (!props.updateProduct || !fields.editingProduct)
|
|
84
|
+
throw new Error("Product editing is not configured.");
|
|
85
|
+
if (!fields.editingProduct.name.trim())
|
|
86
|
+
throw new Error("Enter a product name.");
|
|
87
|
+
await props.updateProduct({
|
|
88
|
+
stripeProductId: fields.editingProduct.stripeProductId,
|
|
89
|
+
name: fields.editingProduct.name.trim(),
|
|
90
|
+
description: fields.editingProduct.description.trim() || undefined,
|
|
91
|
+
});
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case "archiveProduct":
|
|
95
|
+
if (!props.deactivateProduct)
|
|
96
|
+
throw new Error("Product archiving is not configured.");
|
|
97
|
+
else await props.deactivateProduct({ stripeProductId: command.id! });
|
|
98
|
+
break;
|
|
99
|
+
case "archivePrice":
|
|
100
|
+
if (!props.deactivatePrice)
|
|
101
|
+
throw new Error("Price archiving is not configured.");
|
|
102
|
+
else await props.deactivatePrice({ stripePriceId: command.id! });
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}, props.scopeKey);
|
|
107
|
+
const run = action.run;
|
|
108
|
+
const set = <K extends keyof typeof initial>(
|
|
109
|
+
key: K,
|
|
110
|
+
value: (typeof initial)[K],
|
|
111
|
+
) => setFields((previous) => ({ ...previous, [key]: value }));
|
|
112
|
+
return {
|
|
113
|
+
...fields,
|
|
114
|
+
error: action.error,
|
|
115
|
+
clearError: action.reset,
|
|
116
|
+
isPending: action.isPending,
|
|
117
|
+
isCreatingProduct: action.isPending && command?.type === "create",
|
|
118
|
+
isCreatingPrice: action.isPending && command?.type === "price",
|
|
119
|
+
isSavingEdit: action.isPending && command?.type === "edit",
|
|
120
|
+
deactivatingId:
|
|
121
|
+
action.isPending && command?.type === "archiveProduct"
|
|
122
|
+
? command.id
|
|
123
|
+
: null,
|
|
124
|
+
deactivatingPriceId:
|
|
125
|
+
action.isPending && command?.type === "archivePrice" ? command.id : null,
|
|
126
|
+
setExpandedProduct: (value: string | null) => set("expandedProduct", value),
|
|
127
|
+
setShowCreateDialog: (value: boolean) => set("showCreateDialog", value),
|
|
128
|
+
setShowAddPriceFor: (value: string | null) => set("showAddPriceFor", value),
|
|
129
|
+
setNewProduct: (value: typeof initial.newProduct) =>
|
|
130
|
+
set("newProduct", value),
|
|
131
|
+
setNewPrice: (value: typeof initial.newPrice) => set("newPrice", value),
|
|
132
|
+
setEditingProduct: (value: ProductEdit | null) =>
|
|
133
|
+
set("editingProduct", value),
|
|
134
|
+
handleCreateProduct: async () => {
|
|
135
|
+
if (await run({ type: "create" }))
|
|
136
|
+
setFields((previous) => ({
|
|
137
|
+
...previous,
|
|
138
|
+
newProduct: initial.newProduct,
|
|
139
|
+
showCreateDialog: false,
|
|
140
|
+
}));
|
|
141
|
+
},
|
|
142
|
+
handleAddPrice: async (id: string) => {
|
|
143
|
+
if (await run({ type: "price", id }))
|
|
144
|
+
setFields((previous) => ({
|
|
145
|
+
...previous,
|
|
146
|
+
newPrice: initial.newPrice,
|
|
147
|
+
showAddPriceFor: null,
|
|
148
|
+
}));
|
|
149
|
+
},
|
|
150
|
+
handleSaveEdit: async () => {
|
|
151
|
+
if (await run({ type: "edit" })) set("editingProduct", null);
|
|
152
|
+
},
|
|
153
|
+
handleDeactivate: (id: string) => run({ type: "archiveProduct", id }),
|
|
154
|
+
handleDeactivatePrice: (id: string) => run({ type: "archivePrice", id }),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export type CatalogProduct = {
|
|
158
|
+
stripeProductId: string;
|
|
159
|
+
name: string;
|
|
160
|
+
description?: string;
|
|
161
|
+
active: boolean;
|
|
162
|
+
prices: PriceCardPrice[];
|
|
163
|
+
};
|
|
164
|
+
export type ProductsRenderProps = ReturnType<typeof useProductManager> & {
|
|
165
|
+
products: CatalogProduct[];
|
|
166
|
+
isLoading: boolean;
|
|
167
|
+
};
|
|
168
|
+
export type ProductsProps = ProductActions & {
|
|
169
|
+
products: CatalogProduct[] | undefined;
|
|
170
|
+
children?: (state: ProductsRenderProps) => ReactNode;
|
|
171
|
+
};
|
|
172
|
+
/** Complete catalog creation/editing/archiving controller, with optional custom rendering. Amount inputs use minor units. */
|
|
173
|
+
export function Products(props: ProductsProps) {
|
|
174
|
+
return <ProductsBody key={props.scopeKey} {...props} />;
|
|
175
|
+
}
|
|
176
|
+
function ProductsBody(props: ProductsProps) {
|
|
177
|
+
const state = useProductManager(props);
|
|
178
|
+
const id = useId();
|
|
179
|
+
const result = {
|
|
180
|
+
...state,
|
|
181
|
+
products: props.products ?? [],
|
|
182
|
+
isLoading: props.products === undefined,
|
|
183
|
+
};
|
|
184
|
+
if (props.children) return <>{props.children(result)}</>;
|
|
185
|
+
return (
|
|
186
|
+
<section data-better-stripe="products" aria-busy={state.isPending}>
|
|
187
|
+
<h2>Products</h2>
|
|
188
|
+
{state.error && <p role="alert">{state.error}</p>}
|
|
189
|
+
<form
|
|
190
|
+
onSubmit={(event) => {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
void state.handleCreateProduct();
|
|
193
|
+
}}
|
|
194
|
+
>
|
|
195
|
+
<label htmlFor={`${id}-name`}>Product name</label>
|
|
196
|
+
<input
|
|
197
|
+
id={`${id}-name`}
|
|
198
|
+
required
|
|
199
|
+
value={state.newProduct.name}
|
|
200
|
+
onChange={(event) =>
|
|
201
|
+
state.setNewProduct({
|
|
202
|
+
...state.newProduct,
|
|
203
|
+
name: event.target.value,
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
/>
|
|
207
|
+
<label htmlFor={`${id}-description`}>Description</label>
|
|
208
|
+
<input
|
|
209
|
+
id={`${id}-description`}
|
|
210
|
+
value={state.newProduct.description}
|
|
211
|
+
onChange={(event) =>
|
|
212
|
+
state.setNewProduct({
|
|
213
|
+
...state.newProduct,
|
|
214
|
+
description: event.target.value,
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
/>
|
|
218
|
+
<button type="submit" disabled={state.isPending}>
|
|
219
|
+
{state.isCreatingProduct ? "Creating…" : "Create product"}
|
|
220
|
+
</button>
|
|
221
|
+
</form>
|
|
222
|
+
{result.isLoading ? (
|
|
223
|
+
<p role="status">Loading products…</p>
|
|
224
|
+
) : !result.products.length ? (
|
|
225
|
+
<p>No products yet.</p>
|
|
226
|
+
) : (
|
|
227
|
+
result.products.map((product) => (
|
|
228
|
+
<article key={product.stripeProductId}>
|
|
229
|
+
<h3>{product.name}</h3>
|
|
230
|
+
<p>{product.description}</p>
|
|
231
|
+
{product.prices.map((price) => (
|
|
232
|
+
<div key={price.stripePriceId}>
|
|
233
|
+
<PriceCard price={price}>
|
|
234
|
+
{({ formattedPrice }) => <p>{formattedPrice}</p>}
|
|
235
|
+
</PriceCard>
|
|
236
|
+
{props.deactivatePrice && price.active && (
|
|
237
|
+
<button
|
|
238
|
+
type="button"
|
|
239
|
+
disabled={state.isPending}
|
|
240
|
+
onClick={() => {
|
|
241
|
+
void state.handleDeactivatePrice(price.stripePriceId);
|
|
242
|
+
}}
|
|
243
|
+
>
|
|
244
|
+
Archive price
|
|
245
|
+
</button>
|
|
246
|
+
)}
|
|
247
|
+
</div>
|
|
248
|
+
))}
|
|
249
|
+
<button
|
|
250
|
+
type="button"
|
|
251
|
+
disabled={state.isPending}
|
|
252
|
+
onClick={() => state.setShowAddPriceFor(product.stripeProductId)}
|
|
253
|
+
>
|
|
254
|
+
Add price
|
|
255
|
+
</button>
|
|
256
|
+
{props.updateProduct && (
|
|
257
|
+
<button
|
|
258
|
+
type="button"
|
|
259
|
+
onClick={() =>
|
|
260
|
+
state.setEditingProduct({
|
|
261
|
+
stripeProductId: product.stripeProductId,
|
|
262
|
+
name: product.name,
|
|
263
|
+
description: product.description ?? "",
|
|
264
|
+
})
|
|
265
|
+
}
|
|
266
|
+
>
|
|
267
|
+
Edit product
|
|
268
|
+
</button>
|
|
269
|
+
)}
|
|
270
|
+
{props.deactivateProduct && (
|
|
271
|
+
<button
|
|
272
|
+
type="button"
|
|
273
|
+
disabled={state.isPending}
|
|
274
|
+
onClick={() => {
|
|
275
|
+
void state.handleDeactivate(product.stripeProductId);
|
|
276
|
+
}}
|
|
277
|
+
>
|
|
278
|
+
Archive product
|
|
279
|
+
</button>
|
|
280
|
+
)}
|
|
281
|
+
</article>
|
|
282
|
+
))
|
|
283
|
+
)}
|
|
284
|
+
{state.showAddPriceFor && (
|
|
285
|
+
<form
|
|
286
|
+
onSubmit={(event) => {
|
|
287
|
+
event.preventDefault();
|
|
288
|
+
void state.handleAddPrice(state.showAddPriceFor!);
|
|
289
|
+
}}
|
|
290
|
+
>
|
|
291
|
+
<label htmlFor={`${id}-amount`}>Price in minor units</label>
|
|
292
|
+
<input
|
|
293
|
+
id={`${id}-amount`}
|
|
294
|
+
type="number"
|
|
295
|
+
required
|
|
296
|
+
min="1"
|
|
297
|
+
step="1"
|
|
298
|
+
value={state.newPrice.amount}
|
|
299
|
+
onChange={(event) =>
|
|
300
|
+
state.setNewPrice({
|
|
301
|
+
...state.newPrice,
|
|
302
|
+
amount: event.target.value,
|
|
303
|
+
})
|
|
304
|
+
}
|
|
305
|
+
/>
|
|
306
|
+
<label htmlFor={`${id}-currency`}>Currency</label>
|
|
307
|
+
<input
|
|
308
|
+
id={`${id}-currency`}
|
|
309
|
+
required
|
|
310
|
+
minLength={3}
|
|
311
|
+
maxLength={3}
|
|
312
|
+
value={state.newPrice.currency}
|
|
313
|
+
onChange={(event) =>
|
|
314
|
+
state.setNewPrice({
|
|
315
|
+
...state.newPrice,
|
|
316
|
+
currency: event.target.value,
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
/>
|
|
320
|
+
<label htmlFor={`${id}-interval`}>Interval</label>
|
|
321
|
+
<select
|
|
322
|
+
id={`${id}-interval`}
|
|
323
|
+
value={state.newPrice.interval}
|
|
324
|
+
onChange={(event) =>
|
|
325
|
+
state.setNewPrice({
|
|
326
|
+
...state.newPrice,
|
|
327
|
+
interval: event.target.value,
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
>
|
|
331
|
+
{["one_time", "month", "year", "week", "day"].map((value) => (
|
|
332
|
+
<option key={value}>{value}</option>
|
|
333
|
+
))}
|
|
334
|
+
</select>
|
|
335
|
+
<button type="submit" disabled={state.isPending}>
|
|
336
|
+
{state.isCreatingPrice ? "Creating…" : "Create price"}
|
|
337
|
+
</button>
|
|
338
|
+
</form>
|
|
339
|
+
)}
|
|
340
|
+
{state.editingProduct && (
|
|
341
|
+
<form
|
|
342
|
+
onSubmit={(event) => {
|
|
343
|
+
event.preventDefault();
|
|
344
|
+
void state.handleSaveEdit();
|
|
345
|
+
}}
|
|
346
|
+
>
|
|
347
|
+
<label htmlFor={`${id}-edit-name`}>Product name</label>
|
|
348
|
+
<input
|
|
349
|
+
id={`${id}-edit-name`}
|
|
350
|
+
required
|
|
351
|
+
value={state.editingProduct.name}
|
|
352
|
+
onChange={(event) =>
|
|
353
|
+
state.setEditingProduct({
|
|
354
|
+
...state.editingProduct!,
|
|
355
|
+
name: event.target.value,
|
|
356
|
+
})
|
|
357
|
+
}
|
|
358
|
+
/>
|
|
359
|
+
<label htmlFor={`${id}-edit-description`}>Description</label>
|
|
360
|
+
<input
|
|
361
|
+
id={`${id}-edit-description`}
|
|
362
|
+
value={state.editingProduct.description}
|
|
363
|
+
onChange={(event) =>
|
|
364
|
+
state.setEditingProduct({
|
|
365
|
+
...state.editingProduct!,
|
|
366
|
+
description: event.target.value,
|
|
367
|
+
})
|
|
368
|
+
}
|
|
369
|
+
/>
|
|
370
|
+
<button type="submit" disabled={state.isPending}>
|
|
371
|
+
{state.isSavingEdit ? "Saving…" : "Save product"}
|
|
372
|
+
</button>
|
|
373
|
+
</form>
|
|
374
|
+
)}
|
|
375
|
+
</section>
|
|
376
|
+
);
|
|
377
|
+
}
|
|
@@ -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
|
+
});
|