@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,95 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useId } from "react";
|
|
4
|
+
import { useWorkflowAction } from "./useWorkflowAction.js";
|
|
5
|
+
import { Connect } from "./Connect.js";
|
|
6
|
+
/** Currency input expressed in two decimal minor units. Rejects rounding and scientific notation. */
|
|
7
|
+
export function parseAmountCents(value) {
|
|
8
|
+
if (!/^\d+(?:\.\d{1,2})?$/.test(value.trim()))
|
|
9
|
+
return null;
|
|
10
|
+
const [whole, fraction = ""] = value.trim().split(".");
|
|
11
|
+
const amount = Number(whole) * 100 + Number(fraction.padEnd(2, "0"));
|
|
12
|
+
return Number.isSafeInteger(amount) && amount > 0 ? amount : null;
|
|
13
|
+
}
|
|
14
|
+
export function useRefunds(props) {
|
|
15
|
+
const initial = {
|
|
16
|
+
scope: props.scopeKey,
|
|
17
|
+
paymentIntentId: props.paymentIntentId ?? "",
|
|
18
|
+
sourceChargeId: props.sourceChargeId ?? "",
|
|
19
|
+
refundAmount: "",
|
|
20
|
+
reversalAmount: "",
|
|
21
|
+
};
|
|
22
|
+
const [fields, setFields] = useState(initial);
|
|
23
|
+
if (fields.scope !== props.scopeKey)
|
|
24
|
+
setFields(initial);
|
|
25
|
+
const [operationType, setOperationType] = useState("refund");
|
|
26
|
+
const action = useWorkflowAction(async (operation) => {
|
|
27
|
+
setOperationType(operation.type);
|
|
28
|
+
const id = (operation.type === "refund"
|
|
29
|
+
? fields.paymentIntentId
|
|
30
|
+
: fields.sourceChargeId).trim();
|
|
31
|
+
if (!id)
|
|
32
|
+
throw new Error(operation.type === "refund"
|
|
33
|
+
? "Enter a PaymentIntent id before issuing a refund."
|
|
34
|
+
: "Enter a source charge id before reversing transfers.");
|
|
35
|
+
const amount = operation.kind === "partial"
|
|
36
|
+
? parseAmountCents(operation.type === "refund"
|
|
37
|
+
? fields.refundAmount
|
|
38
|
+
: fields.reversalAmount)
|
|
39
|
+
: undefined;
|
|
40
|
+
if (amount === null)
|
|
41
|
+
throw new Error(`Enter a positive partial ${operation.type === "refund" ? "refund" : "reversal"} amount with at most two decimal places.`);
|
|
42
|
+
if (operation.type === "refund")
|
|
43
|
+
return {
|
|
44
|
+
type: "refund",
|
|
45
|
+
value: await props.issueRefund({
|
|
46
|
+
stripePaymentIntentId: id,
|
|
47
|
+
amountCents: amount,
|
|
48
|
+
reason: "requested_by_customer",
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
if (!props.reverseTransfers)
|
|
52
|
+
throw new Error("Transfer reversals are not configured.");
|
|
53
|
+
return {
|
|
54
|
+
type: "reversal",
|
|
55
|
+
value: await props.reverseTransfers({
|
|
56
|
+
sourceChargeId: id,
|
|
57
|
+
amountCents: amount,
|
|
58
|
+
}),
|
|
59
|
+
};
|
|
60
|
+
}, props.scopeKey);
|
|
61
|
+
const set = (name, value) => setFields((previous) => ({ ...previous, [name]: value }));
|
|
62
|
+
return {
|
|
63
|
+
...fields,
|
|
64
|
+
setPaymentIntentId: (value) => set("paymentIntentId", value),
|
|
65
|
+
setSourceChargeId: (value) => set("sourceChargeId", value),
|
|
66
|
+
setRefundAmount: (value) => set("refundAmount", value),
|
|
67
|
+
setReversalAmount: (value) => set("reversalAmount", value),
|
|
68
|
+
error: action.error,
|
|
69
|
+
isPending: action.isPending,
|
|
70
|
+
busy: action.isPending ? operationType : null,
|
|
71
|
+
refundResult: action.result?.type === "refund" ? action.result.value : null,
|
|
72
|
+
reversalResult: action.result?.type === "reversal" ? action.result.value : null,
|
|
73
|
+
submitRefund: (kind) => action.run({ type: "refund", kind }),
|
|
74
|
+
submitReversal: (kind) => action.run({ type: "reversal", kind }),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function Refunds(props) {
|
|
78
|
+
return props.presentation === "embedded" ? (_jsx(Connect, { ...props, component: "refunds" })) : (_jsx(RefundsBody, { ...props }, props.scopeKey));
|
|
79
|
+
}
|
|
80
|
+
function RefundsBody(props) {
|
|
81
|
+
const state = useRefunds(props);
|
|
82
|
+
const id = useId();
|
|
83
|
+
if (props.children)
|
|
84
|
+
return _jsx(_Fragment, { children: props.children(state) });
|
|
85
|
+
return (_jsxs("section", { "data-better-stripe": "refunds", "aria-busy": state.isPending, children: [_jsx("h2", { children: "Refunds" }), state.error && _jsx("p", { role: "alert", children: state.error }), _jsx("label", { htmlFor: `${id}-payment`, children: "PaymentIntent ID" }), _jsx("input", { id: `${id}-payment`, value: state.paymentIntentId, onChange: (event) => state.setPaymentIntentId(event.target.value) }), _jsx("label", { htmlFor: `${id}-amount`, children: "Partial refund amount" }), _jsx("input", { id: `${id}-amount`, type: "number", min: "0.01", step: "0.01", value: state.refundAmount, onChange: (event) => state.setRefundAmount(event.target.value) }), _jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
|
|
86
|
+
void state.submitRefund("full");
|
|
87
|
+
}, children: state.isPending ? "Processing…" : "Full refund" }), _jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
|
|
88
|
+
void state.submitRefund("partial");
|
|
89
|
+
}, children: "Partial refund" }), state.refundResult && (_jsxs("p", { role: "status", children: ["Refund created: ", state.refundResult.stripeRefundId] })), props.reverseTransfers && (_jsxs(_Fragment, { children: [_jsx("h3", { children: "Transfer reversals" }), _jsx("label", { htmlFor: `${id}-charge`, children: "Source charge ID" }), _jsx("input", { id: `${id}-charge`, value: state.sourceChargeId, onChange: (event) => state.setSourceChargeId(event.target.value) }), _jsx("label", { htmlFor: `${id}-reversal`, children: "Partial reversal amount" }), _jsx("input", { id: `${id}-reversal`, type: "number", min: "0.01", step: "0.01", value: state.reversalAmount, onChange: (event) => state.setReversalAmount(event.target.value) }), _jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
|
|
90
|
+
void state.submitReversal("full");
|
|
91
|
+
}, children: "Reverse all transfers" }), _jsx("button", { type: "button", disabled: state.isPending, onClick: () => {
|
|
92
|
+
void state.submitReversal("partial");
|
|
93
|
+
}, children: "Partial reversal" }), state.reversalResult && (_jsxs("p", { role: "status", children: ["Reversed ", state.reversalResult.summary.reversalCount, " transfers."] }))] }))] }));
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=Ref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ACb,GAAG,EAAC,MAAM,EACV,IAAI,EAAC,MAAM,EACX,KAAK,EAAE,KAAK,CAAC,cAAc,EAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAChE,EACF,iBACE,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,OAAO,EAAE,GAAG,EAAE;4BACZ,KAAK,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;wBACpC,CAAC,sCAGM,EACT,iBACE,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,OAAO,EAAE,GAAG,EAAE;4BACZ,KAAK,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;wBACvC,CAAC,iCAGM,EACR,KAAK,CAAC,cAAc,IAAI,CACvB,aAAG,IAAI,EAAC,QAAQ,0BACJ,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,aAAa,mBAClD,CACL,IACA,CACJ,IACO,CACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export type WebhookSetupOptions<Status, Result> = {
|
|
3
|
+
scopeKey: string;
|
|
4
|
+
load: () => Promise<Status>;
|
|
5
|
+
setup: () => Promise<Result>;
|
|
6
|
+
};
|
|
7
|
+
export declare function useWebhookSetup<Status, Result>(props: WebhookSetupOptions<Status, Result>): {
|
|
8
|
+
status: Status | undefined;
|
|
9
|
+
isChecking: boolean;
|
|
10
|
+
statusError: string | null;
|
|
11
|
+
checkStatus: () => void;
|
|
12
|
+
result: Awaited<Result> | undefined;
|
|
13
|
+
isPending: boolean;
|
|
14
|
+
error: string | null;
|
|
15
|
+
configure: () => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
export declare function WebhookSetup<Status, Result>(props: WebhookSetupOptions<Status, Result> & {
|
|
18
|
+
renderStatus?: (status: Status) => ReactNode;
|
|
19
|
+
children?: (state: ReturnType<typeof useWebhookSetup<Status, Result>>) => ReactNode;
|
|
20
|
+
}): import("react").JSX.Element;
|
|
21
|
+
export type EnvironmentCheck = {
|
|
22
|
+
id: string;
|
|
23
|
+
label: string;
|
|
24
|
+
configured: boolean;
|
|
25
|
+
};
|
|
26
|
+
export declare function EnvironmentStatus({ checks, isLoading, error, children, }: {
|
|
27
|
+
checks: EnvironmentCheck[] | undefined;
|
|
28
|
+
isLoading?: boolean;
|
|
29
|
+
error?: string | null;
|
|
30
|
+
children?: (state: {
|
|
31
|
+
checks: EnvironmentCheck[];
|
|
32
|
+
allConfigured: boolean;
|
|
33
|
+
isLoading: boolean;
|
|
34
|
+
error: string | null;
|
|
35
|
+
}) => ReactNode;
|
|
36
|
+
}): import("react").JSX.Element;
|
|
37
|
+
export type FixtureProgressState = {
|
|
38
|
+
cursor: number;
|
|
39
|
+
total: number;
|
|
40
|
+
status: string;
|
|
41
|
+
error?: string;
|
|
42
|
+
};
|
|
43
|
+
export declare function FixtureProgress({ state, children, }: {
|
|
44
|
+
state: FixtureProgressState | null | undefined;
|
|
45
|
+
children?: (state: FixtureProgressState & {
|
|
46
|
+
progress: number;
|
|
47
|
+
message: string;
|
|
48
|
+
}) => ReactNode;
|
|
49
|
+
}): import("react").JSX.Element;
|
|
50
|
+
//# sourceMappingURL=Setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Setup.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Setup.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,MAAM,MAAM,mBAAmB,CAAC,MAAM,EAAE,MAAM,IAAI;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5B,KAAK,EAAE,MAAM,OAAO,CAAC,MAAM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,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AACF,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,oBAAoB,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/C,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,oBAAoB,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAChE,SAAS,CAAC;CAChB,+BA6BA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useWorkflowAction } from "./useWorkflowAction.js";
|
|
4
|
+
import { useWorkflowResource } from "./useWorkflowResource.js";
|
|
5
|
+
export function useWebhookSetup(props) {
|
|
6
|
+
const status = useWorkflowResource(props.load, props.scopeKey);
|
|
7
|
+
const setup = useWorkflowAction(async () => ({ value: await props.setup() }), props.scopeKey);
|
|
8
|
+
return {
|
|
9
|
+
status: status.data,
|
|
10
|
+
isChecking: status.isLoading,
|
|
11
|
+
statusError: status.error,
|
|
12
|
+
checkStatus: status.refresh,
|
|
13
|
+
result: setup.result?.value,
|
|
14
|
+
isPending: setup.isPending,
|
|
15
|
+
error: setup.error,
|
|
16
|
+
configure: async () => {
|
|
17
|
+
if (await setup.run())
|
|
18
|
+
status.refresh();
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function WebhookSetup(props) {
|
|
23
|
+
const state = useWebhookSetup(props);
|
|
24
|
+
if (props.children)
|
|
25
|
+
return _jsx(_Fragment, { children: props.children(state) });
|
|
26
|
+
return (_jsxs("section", { "data-better-stripe": "webhook-setup", children: [_jsx("h2", { children: "Webhook destinations" }), (state.error || state.statusError) && (_jsx("p", { role: "alert", children: state.error || state.statusError })), state.isChecking ? (_jsx("p", { role: "status", children: "Checking destinations\u2026" })) : state.status !== undefined && props.renderStatus ? (props.renderStatus(state.status)) : (_jsx("p", { children: "Destination status loaded." })), _jsx("button", { type: "button", disabled: state.isPending || state.isChecking, onClick: () => {
|
|
27
|
+
void state.configure();
|
|
28
|
+
}, children: state.isPending ? "Configuring…" : "Configure webhooks" }), _jsx("button", { type: "button", disabled: state.isChecking, onClick: state.checkStatus, children: "Refresh status" })] }));
|
|
29
|
+
}
|
|
30
|
+
export function EnvironmentStatus({ checks, isLoading = checks === undefined, error, children, }) {
|
|
31
|
+
const state = {
|
|
32
|
+
checks: checks ?? [],
|
|
33
|
+
allConfigured: !!checks?.length && checks.every((check) => check.configured),
|
|
34
|
+
isLoading,
|
|
35
|
+
error: error ?? null,
|
|
36
|
+
};
|
|
37
|
+
if (children)
|
|
38
|
+
return _jsx(_Fragment, { children: children(state) });
|
|
39
|
+
return (_jsxs("section", { "data-better-stripe": "environment-status", children: [_jsx("h2", { children: "Environment" }), error ? (_jsx("p", { role: "alert", children: error })) : isLoading ? (_jsx("p", { role: "status", children: "Checking configuration\u2026" })) : !checks?.length ? (_jsx("p", { children: "No environment checks configured." })) : (_jsx("ul", { children: checks.map((check) => (_jsxs("li", { children: [check.label, ": ", check.configured ? "Set" : "Not set"] }, check.id))) }))] }));
|
|
40
|
+
}
|
|
41
|
+
export function FixtureProgress({ state, children, }) {
|
|
42
|
+
if (!state)
|
|
43
|
+
return _jsx("p", { children: "No fixture run yet." });
|
|
44
|
+
const result = {
|
|
45
|
+
...state,
|
|
46
|
+
progress: state.total > 0
|
|
47
|
+
? Math.max(0, Math.min(1, state.cursor / state.total))
|
|
48
|
+
: 0,
|
|
49
|
+
message: state.status === "running"
|
|
50
|
+
? "Fixtures are being created. Stripe events continue to update your data."
|
|
51
|
+
: state.status === "complete"
|
|
52
|
+
? "Fixtures are populated. Stripe statuses can continue updating through webhooks."
|
|
53
|
+
: "Population stopped. Resume to retry this step.",
|
|
54
|
+
};
|
|
55
|
+
if (children)
|
|
56
|
+
return _jsx(_Fragment, { children: children(result) });
|
|
57
|
+
return (_jsxs("div", { "data-better-stripe": "fixture-progress", children: [_jsx("progress", { "aria-label": "Sandbox fixture progress", value: result.progress, max: 1 }), _jsxs("p", { role: "status", children: [state.cursor, " of ", state.total, " steps complete. ", result.message] }), state.error && _jsx("p", { role: "alert", children: state.error })] }));
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=Setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Setup.js","sourceRoot":"","sources":["../../../src/react/workflows/Setup.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAM/D,MAAM,UAAU,eAAe,CAC7B,KAA0C;IAE1C,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,iBAAiB,CAC7B,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,EAC5C,KAAK,CAAC,QAAQ,CACf,CAAC;IACF,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,IAAI;QACnB,UAAU,EAAE,MAAM,CAAC,SAAS;QAC5B,WAAW,EAAE,MAAM,CAAC,KAAK;QACzB,WAAW,EAAE,MAAM,CAAC,OAAO;QAC3B,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK;QAC3B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,SAAS,EAAE,KAAK,IAAI,EAAE;YACpB,IAAI,MAAM,KAAK,CAAC,GAAG,EAAE;gBAAE,MAAM,CAAC,OAAO,EAAE,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC;AACD,MAAM,U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SAAS;YACxB,CAAC,CAAC,yEAAyE;YAC3E,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,UAAU;gBAC3B,CAAC,CAAC,iFAAiF;gBACnF,CAAC,CAAC,gDAAgD;KACzD,CAAC;IACF,IAAI,QAAQ;QAAE,OAAO,4BAAG,QAAQ,CAAC,MAAM,CAAC,GAAI,CAAC;IAC7C,OAAO,CACL,qCAAwB,kBAAkB,aACxC,iCACa,0BAA0B,EACrC,KAAK,EAAE,MAAM,CAAC,QAAQ,EACtB,GAAG,EAAE,CAAC,GACN,EACF,aAAG,IAAI,EAAC,QAAQ,aACb,KAAK,CAAC,MAAM,UAAM,KAAK,CAAC,KAAK,uBAAmB,MAAM,CAAC,OAAO,IAC7D,EACH,KAAK,CAAC,KAAK,IAAI,YAAG,IAAI,EAAC,OAAO,YAAE,KAAK,CAAC,KAAK,GAAK,IAC7C,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export type StorefrontPrice = {
|
|
3
|
+
stripePriceId: string;
|
|
4
|
+
unitAmount: number;
|
|
5
|
+
currency: string;
|
|
6
|
+
type: string;
|
|
7
|
+
interval?: string | null;
|
|
8
|
+
intervalCount?: number | null;
|
|
9
|
+
active?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type StorefrontProduct = {
|
|
12
|
+
stripeProductId: string;
|
|
13
|
+
name: string;
|
|
14
|
+
description?: string | null;
|
|
15
|
+
active?: boolean;
|
|
16
|
+
prices: StorefrontPrice[];
|
|
17
|
+
};
|
|
18
|
+
export type StorefrontStore = {
|
|
19
|
+
accountId: string;
|
|
20
|
+
name: string;
|
|
21
|
+
products: StorefrontProduct[];
|
|
22
|
+
};
|
|
23
|
+
export type StorefrontSelection = {
|
|
24
|
+
store: StorefrontStore;
|
|
25
|
+
product: StorefrontProduct;
|
|
26
|
+
price: StorefrontPrice;
|
|
27
|
+
referralCode?: string;
|
|
28
|
+
};
|
|
29
|
+
export type StorefrontCard = StorefrontSelection & {
|
|
30
|
+
formattedPrice: string;
|
|
31
|
+
purchaseLabel: string;
|
|
32
|
+
accessibilityLabel: string;
|
|
33
|
+
checkoutUrl?: string;
|
|
34
|
+
purchase: () => void;
|
|
35
|
+
};
|
|
36
|
+
export type StorefrontRenderProps = {
|
|
37
|
+
stores: StorefrontStore[];
|
|
38
|
+
cards: StorefrontCard[];
|
|
39
|
+
isLoading: boolean;
|
|
40
|
+
isEmpty: boolean;
|
|
41
|
+
canPurchase: boolean;
|
|
42
|
+
};
|
|
43
|
+
export type StorefrontProps = {
|
|
44
|
+
stores: StorefrontStore[] | undefined;
|
|
45
|
+
storeId?: string;
|
|
46
|
+
referralCode?: string;
|
|
47
|
+
canPurchase?: boolean;
|
|
48
|
+
getCheckoutUrl?: (selection: StorefrontSelection) => string;
|
|
49
|
+
onSelectPrice?: (selection: StorefrontSelection) => void;
|
|
50
|
+
children?: (state: StorefrontRenderProps) => ReactNode;
|
|
51
|
+
};
|
|
52
|
+
export declare function Storefront({ stores, storeId, referralCode, canPurchase, getCheckoutUrl, onSelectPrice, children, }: StorefrontProps): import("react").JSX.Element;
|
|
53
|
+
//# sourceMappingURL=Storefront.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storefront.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Storefront.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;A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aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,mBAAmB,KAAK,IAAI,CAAC;IACzD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,SAAS,CAAC;CACxD,CAAC;AACF,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,OAAO,EACP,YAAY,EACZ,WAAkB,EAClB,cAAc,EACd,aAAa,EACb,QAAQ,GACT,EAAE,eAAe,+BA4EjB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { formatPriceWithInterval } from "../lib/price-helpers.js";
|
|
4
|
+
export function Storefront({ stores, storeId, referralCode, canPurchase = true, getCheckoutUrl, onSelectPrice, children, }) {
|
|
5
|
+
const visible = stores?.filter((store) => !storeId || store.accountId === storeId) ?? [];
|
|
6
|
+
const cards = visible.flatMap((store) => store.products
|
|
7
|
+
.filter((product) => product.active !== false)
|
|
8
|
+
.flatMap((product) => product.prices
|
|
9
|
+
.filter((price) => price.active !== false)
|
|
10
|
+
.map((price) => {
|
|
11
|
+
const selection = { store, product, price, referralCode };
|
|
12
|
+
return {
|
|
13
|
+
...selection,
|
|
14
|
+
formattedPrice: formatPriceWithInterval({
|
|
15
|
+
...price,
|
|
16
|
+
active: true,
|
|
17
|
+
}),
|
|
18
|
+
purchaseLabel: price.type === "recurring" ? "Subscribe" : "Buy now",
|
|
19
|
+
accessibilityLabel: `${price.type === "recurring" ? "Subscribe to" : "Buy"} ${product.name}`,
|
|
20
|
+
checkoutUrl: getCheckoutUrl?.(selection),
|
|
21
|
+
purchase: () => {
|
|
22
|
+
if (canPurchase)
|
|
23
|
+
onSelectPrice?.(selection);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
})));
|
|
27
|
+
const state = {
|
|
28
|
+
stores: visible,
|
|
29
|
+
cards,
|
|
30
|
+
isLoading: stores === undefined,
|
|
31
|
+
isEmpty: stores !== undefined && !visible.length,
|
|
32
|
+
canPurchase,
|
|
33
|
+
};
|
|
34
|
+
if (children)
|
|
35
|
+
return _jsx(_Fragment, { children: children(state) });
|
|
36
|
+
if (state.isLoading)
|
|
37
|
+
return _jsx("p", { role: "status", children: "Loading stores\u2026" });
|
|
38
|
+
if (state.isEmpty)
|
|
39
|
+
return _jsx("p", { children: "No stores available yet." });
|
|
40
|
+
return (_jsx("div", { "data-better-stripe": "storefront", children: visible.map((store) => (_jsxs("section", { children: [_jsx("h2", { children: store.name }), !cards.some((card) => card.store.accountId === store.accountId) && (_jsx("p", { children: "No products available yet." })), cards
|
|
41
|
+
.filter((card) => card.store.accountId === store.accountId)
|
|
42
|
+
.map((card) => (_jsxs("article", { children: [_jsx("h3", { children: card.product.name }), _jsx("p", { children: card.product.description }), _jsx("p", { children: card.formattedPrice }), card.checkoutUrl && canPurchase ? (_jsx("a", { href: card.checkoutUrl, "aria-label": card.accessibilityLabel, children: card.purchaseLabel })) : (_jsx("button", { type: "button", disabled: !canPurchase || !onSelectPrice, "aria-label": card.accessibilityLabel, onClick: card.purchase, children: card.purchaseLabel }))] }, card.price.stripePriceId)))] }, store.accountId))) }));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=Storefront.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storefront.js","sourceRoot":"","sources":["../../../src/react/workflows/Storefront.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAmDlE,MAAM,UAAU,UAAU,CAAC,EACzB,MAAM,EACN,OAAO,EACP,YAAY,EACZ,WAAW,GAAG,IAAI,EAClB,cAAc,EACd,aAAa,EACb,QAAQ,GACQ;IAChB,MAAM,OAAO,GACX,MAAM,EAAE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,IAAI,KAAK,CAAC,SAAS,KAAK,OAA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S,CA+BnB,CACX,CAAC,GACE,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { SubscriptionRow } from "./Subscriptions.js";
|
|
3
|
+
export type SubscriptionOverviewState<Row> = {
|
|
4
|
+
subscription: Row | null;
|
|
5
|
+
isLoading: boolean;
|
|
6
|
+
isEmpty: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type SubscriptionOverviewProps<Row extends SubscriptionRow = SubscriptionRow> = {
|
|
9
|
+
subscriptions: Row[] | undefined;
|
|
10
|
+
children?: (state: SubscriptionOverviewState<Row>) => ReactNode;
|
|
11
|
+
};
|
|
12
|
+
export declare function SubscriptionOverview<Row extends SubscriptionRow>({ subscriptions, children, }: SubscriptionOverviewProps<Row>): import("react").JSX.Element;
|
|
13
|
+
//# sourceMappingURL=SubscriptionOverview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionOverview.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/SubscriptionOverview.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,MAAM,MAAM,yBAAyB,CAAC,GAAG,IAAI;IAC3C,YAAY,EAAE,GAAG,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AACF,MAAM,MAAM,yBAAyB,CACnC,GAAG,SAAS,eAAe,GAAG,eAAe,IAC3C;IACF,aAAa,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;IACjC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,yBAAyB,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC;CACjE,CAAC;AACF,wBAAgB,oBAAoB,CAAC,GAAG,SAAS,eAAe,EAAE,EAChE,aAAa,EACb,QAAQ,GACT,EAAE,yBAAyB,CAAC,GAAG,CAAC,+BA4BhC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { currentSubscriptionFrom } from "./current-subscription.js";
|
|
4
|
+
import { SubscriptionCard } from "../components/SubscriptionCard.js";
|
|
5
|
+
export function SubscriptionOverview({ subscriptions, children, }) {
|
|
6
|
+
const subscription = currentSubscriptionFrom((subscriptions ?? []).map((row) => ({
|
|
7
|
+
...row,
|
|
8
|
+
cancelAtPeriodEnd: row.cancelAtPeriodEnd ?? false,
|
|
9
|
+
})));
|
|
10
|
+
const state = {
|
|
11
|
+
subscription,
|
|
12
|
+
isLoading: subscriptions === undefined,
|
|
13
|
+
isEmpty: subscriptions !== undefined && !subscription,
|
|
14
|
+
};
|
|
15
|
+
if (children)
|
|
16
|
+
return _jsx(_Fragment, { children: children(state) });
|
|
17
|
+
if (state.isLoading)
|
|
18
|
+
return _jsx("p", { role: "status", children: "Loading subscription\u2026" });
|
|
19
|
+
if (!subscription)
|
|
20
|
+
return _jsx("p", { children: "No subscription yet." });
|
|
21
|
+
return (_jsxs("section", { "data-better-stripe": "subscription-overview", children: [_jsx("h2", { children: "Your subscription" }), _jsx("p", { children: subscription.stripeSubscriptionId }), _jsx(SubscriptionCard, { subscription: {
|
|
22
|
+
...subscription,
|
|
23
|
+
isTrialing: subscription.isTrialing ?? subscription.status === "trialing",
|
|
24
|
+
} })] }));
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=SubscriptionOverview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionOverview.js","sourceRoot":"","sources":["../../../src/react/workflows/SubscriptionOverview.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAYrE,MAAM,UAAU,oBAAoB,CAA8B,EAChE,aAAa,EACb,QAAQ,GACuB;IAC/B,MAAM,YAAY,GAAG,uBAAuB,CAC1C,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAClC,GAAG,GAAG;QACN,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,IAAI,KAAK;KAClD,CAAC,CAAC,CACJ,CAAC;IACF,MAAM,KAAK,GAAG;QACZ,YAAY;QACZ,SAAS,EAAE,aAAa,KAAK,SAAS;QACtC,OAAO,EAAE,aAAa,KAAK,SAAS,IAAI,CAAC,YAAY;KACtD,CAAC;IACF,IAAI,QAAQ;QAAE,OAAO,4BAAG,QAAQ,CAAC,KAAK,CAAC,GAAI,CAAC;IAC5C,IAAI,KAAK,CAAC,SAAS;QAAE,OAAO,YAAG,IAAI,EAAC,QAAQ,2CAA0B,CAAC;IACvE,IAAI,CAAC,YAAY;QAAE,OAAO,+CAA2B,CAAC;IACtD,OAAO,CACL,yCAA4B,uBAAuB,aACjD,6CAA0B,EAC1B,sBAAI,YAAY,CAAC,oBAAoB,GAAK,EAC1C,KAAC,gBAAgB,IACf,YAAY,EAAE;oBACZ,GAAG,YAAY;oBACf,UAAU,EACR,YAAY,CAAC,UAAU,IAAI,YAAY,CAAC,MAAM,KAAK,UAAU;iBAChE,GACD,IACM,CACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type CollectionProps, type WorkflowColumn } from "./Collection.js";
|
|
3
|
+
export type SubscriptionRow = {
|
|
4
|
+
stripeSubscriptionId: string;
|
|
5
|
+
status: string;
|
|
6
|
+
isTrialing?: boolean;
|
|
7
|
+
cancelAtPeriodEnd?: boolean;
|
|
8
|
+
isCollectionPaused?: boolean;
|
|
9
|
+
currentPeriodEnd?: string | null;
|
|
10
|
+
trialEnd?: string | null;
|
|
11
|
+
quantity?: number;
|
|
12
|
+
userId?: string;
|
|
13
|
+
};
|
|
14
|
+
export type SubscriptionActionType = "pause" | "resume" | "reactivate" | "cancel" | "price" | "quantity" | "trial" | "endTrial";
|
|
15
|
+
export type SubscriptionCommand = {
|
|
16
|
+
type: SubscriptionActionType;
|
|
17
|
+
stripeSubscriptionId: string;
|
|
18
|
+
stripePriceId?: string;
|
|
19
|
+
quantity?: number;
|
|
20
|
+
trialEnd?: string;
|
|
21
|
+
};
|
|
22
|
+
export type SubscriptionManagerOptions = {
|
|
23
|
+
scopeKey: string;
|
|
24
|
+
subscription: SubscriptionRow | null | undefined;
|
|
25
|
+
onAction: (command: SubscriptionCommand) => Promise<unknown>;
|
|
26
|
+
};
|
|
27
|
+
export declare function useSubscriptionManager(props: SubscriptionManagerOptions): {
|
|
28
|
+
scope: string;
|
|
29
|
+
quantity: string;
|
|
30
|
+
selectedPriceId: string;
|
|
31
|
+
trialEnd: string;
|
|
32
|
+
setQuantity: (quantity: string) => void;
|
|
33
|
+
setSelectedPriceId: (selectedPriceId: string) => void;
|
|
34
|
+
setTrialEnd: (trialEnd: string) => void;
|
|
35
|
+
pendingAction: string | null;
|
|
36
|
+
isPending: boolean;
|
|
37
|
+
message: string | null;
|
|
38
|
+
error: string | null;
|
|
39
|
+
canPause: boolean;
|
|
40
|
+
canResume: boolean;
|
|
41
|
+
canReactivate: boolean;
|
|
42
|
+
run: (type: SubscriptionActionType) => Promise<string | undefined>;
|
|
43
|
+
};
|
|
44
|
+
export type SubscriptionManagerProps = SubscriptionManagerOptions & {
|
|
45
|
+
children?: (state: ReturnType<typeof useSubscriptionManager>) => ReactNode;
|
|
46
|
+
};
|
|
47
|
+
export declare function SubscriptionManager(props: SubscriptionManagerProps): import("react").JSX.Element;
|
|
48
|
+
export declare const SUBSCRIPTION_FILTERS: readonly [{
|
|
49
|
+
readonly label: "All";
|
|
50
|
+
readonly value: "all";
|
|
51
|
+
}, {
|
|
52
|
+
readonly label: "Active";
|
|
53
|
+
readonly value: "active";
|
|
54
|
+
}, {
|
|
55
|
+
readonly label: "Trialing";
|
|
56
|
+
readonly value: "trialing";
|
|
57
|
+
}, {
|
|
58
|
+
readonly label: "Past Due";
|
|
59
|
+
readonly value: "past_due";
|
|
60
|
+
}, {
|
|
61
|
+
readonly label: "Canceled";
|
|
62
|
+
readonly value: "canceled";
|
|
63
|
+
}];
|
|
64
|
+
export declare function useSubscriptionFilter<T extends {
|
|
65
|
+
status: string;
|
|
66
|
+
}>(subscriptions: T[] | undefined): {
|
|
67
|
+
filter: string;
|
|
68
|
+
setFilter: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
69
|
+
filtered: T[];
|
|
70
|
+
countByStatus: (status: string) => number;
|
|
71
|
+
tabs: readonly [{
|
|
72
|
+
readonly label: "All";
|
|
73
|
+
readonly value: "all";
|
|
74
|
+
}, {
|
|
75
|
+
readonly label: "Active";
|
|
76
|
+
readonly value: "active";
|
|
77
|
+
}, {
|
|
78
|
+
readonly label: "Trialing";
|
|
79
|
+
readonly value: "trialing";
|
|
80
|
+
}, {
|
|
81
|
+
readonly label: "Past Due";
|
|
82
|
+
readonly value: "past_due";
|
|
83
|
+
}, {
|
|
84
|
+
readonly label: "Canceled";
|
|
85
|
+
readonly value: "canceled";
|
|
86
|
+
}];
|
|
87
|
+
};
|
|
88
|
+
export type SubscriptionsProps<Row extends SubscriptionRow = SubscriptionRow> = Omit<CollectionProps<Row>, "getKey" | "columns"> & {
|
|
89
|
+
columns?: WorkflowColumn<Row>[];
|
|
90
|
+
};
|
|
91
|
+
export declare function Subscriptions<Row extends SubscriptionRow>(props: SubscriptionsProps<Row>): import("react").JSX.Element;
|
|
92
|
+
//# sourceMappingURL=Subscriptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Subscriptions.d.ts","sourceRoot":"","sources":["../../../src/react/workflows/Subscriptions.tsx"],"names":[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