@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,213 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import type { CollectionProps, WorkflowColumn } from "./Collection.js";
|
|
3
|
+
import { Collection } from "./Collection.js";
|
|
4
|
+
import { formatPrice } from "../lib/price-helpers.js";
|
|
5
|
+
export type ResourceCollectionProps<Row> = Omit<
|
|
6
|
+
CollectionProps<Row>,
|
|
7
|
+
"columns" | "getKey"
|
|
8
|
+
> & { columns?: WorkflowColumn<Row>[] };
|
|
9
|
+
export type SaleRow = {
|
|
10
|
+
_id?: string;
|
|
11
|
+
planId: string;
|
|
12
|
+
paymentIntentId: string;
|
|
13
|
+
chargeId?: string;
|
|
14
|
+
gross: number;
|
|
15
|
+
processingFee: number;
|
|
16
|
+
platformNet: number;
|
|
17
|
+
affiliateNet: number;
|
|
18
|
+
costRecoveryAmount?: number;
|
|
19
|
+
sellerNet: number;
|
|
20
|
+
currency: string;
|
|
21
|
+
status: string;
|
|
22
|
+
};
|
|
23
|
+
export function Sales(props: ResourceCollectionProps<SaleRow>) {
|
|
24
|
+
const columns: WorkflowColumn<SaleRow>[] = [
|
|
25
|
+
{ id: "planId", label: "Plan", cell: (row) => row.planId },
|
|
26
|
+
...(
|
|
27
|
+
[
|
|
28
|
+
["gross", "Sale"],
|
|
29
|
+
["processingFee", "Stripe processing"],
|
|
30
|
+
["platformNet", "Platform"],
|
|
31
|
+
["affiliateNet", "Affiliate"],
|
|
32
|
+
["costRecoveryAmount", "Cost recovery"],
|
|
33
|
+
["sellerNet", "Your earnings"],
|
|
34
|
+
] as const
|
|
35
|
+
).map(([field, label]) => ({
|
|
36
|
+
id: field,
|
|
37
|
+
label,
|
|
38
|
+
align: "end" as const,
|
|
39
|
+
cell: (row: SaleRow) => formatPrice(row[field] ?? 0, row.currency),
|
|
40
|
+
})),
|
|
41
|
+
{ id: "status", label: "Status", cell: (row) => row.status },
|
|
42
|
+
{ id: "payment", label: "Payment", cell: (row) => row.paymentIntentId },
|
|
43
|
+
];
|
|
44
|
+
return (
|
|
45
|
+
<Collection
|
|
46
|
+
emptyLabel="No sales yet."
|
|
47
|
+
{...props}
|
|
48
|
+
getKey={(row) => row._id ?? row.paymentIntentId}
|
|
49
|
+
columns={props.columns ?? columns}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
export type InvoiceRow = {
|
|
54
|
+
stripeInvoiceId: string;
|
|
55
|
+
amountPaid?: number;
|
|
56
|
+
amountDue?: number;
|
|
57
|
+
currency: string;
|
|
58
|
+
status: string;
|
|
59
|
+
hostedInvoiceUrl?: string;
|
|
60
|
+
};
|
|
61
|
+
export function Invoices(props: ResourceCollectionProps<InvoiceRow>) {
|
|
62
|
+
const columns: WorkflowColumn<InvoiceRow>[] = [
|
|
63
|
+
{ id: "id", label: "Invoice ID", cell: (row) => row.stripeInvoiceId },
|
|
64
|
+
{
|
|
65
|
+
id: "amount",
|
|
66
|
+
label: "Amount",
|
|
67
|
+
align: "end",
|
|
68
|
+
cell: (row) =>
|
|
69
|
+
formatPrice(row.amountPaid ?? row.amountDue ?? 0, row.currency),
|
|
70
|
+
},
|
|
71
|
+
{ id: "status", label: "Status", cell: (row) => row.status },
|
|
72
|
+
{
|
|
73
|
+
id: "invoice",
|
|
74
|
+
label: "Invoice",
|
|
75
|
+
cell: (row) =>
|
|
76
|
+
row.hostedInvoiceUrl ? (
|
|
77
|
+
<a
|
|
78
|
+
href={row.hostedInvoiceUrl}
|
|
79
|
+
target="_blank"
|
|
80
|
+
rel="noopener noreferrer"
|
|
81
|
+
>
|
|
82
|
+
View invoice
|
|
83
|
+
</a>
|
|
84
|
+
) : (
|
|
85
|
+
"Unavailable"
|
|
86
|
+
),
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
return (
|
|
90
|
+
<Collection
|
|
91
|
+
emptyLabel="No invoices yet."
|
|
92
|
+
{...props}
|
|
93
|
+
getKey={(row) => row.stripeInvoiceId}
|
|
94
|
+
columns={props.columns ?? columns}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
export type RefundRow = {
|
|
99
|
+
/** Unix milliseconds, matching Convex creation timestamps. */
|
|
100
|
+
_creationTime?: number;
|
|
101
|
+
stripeRefundId: string;
|
|
102
|
+
amount: number;
|
|
103
|
+
currency: string;
|
|
104
|
+
status: string;
|
|
105
|
+
reason?: string;
|
|
106
|
+
};
|
|
107
|
+
export function RefundHistory(props: ResourceCollectionProps<RefundRow>) {
|
|
108
|
+
const columns: WorkflowColumn<RefundRow>[] = [
|
|
109
|
+
{ id: "id", label: "Refund ID", cell: (row) => row.stripeRefundId },
|
|
110
|
+
{
|
|
111
|
+
id: "amount",
|
|
112
|
+
label: "Amount",
|
|
113
|
+
align: "end",
|
|
114
|
+
cell: (row) => formatPrice(row.amount, row.currency),
|
|
115
|
+
},
|
|
116
|
+
{ id: "status", label: "Status", cell: (row) => row.status },
|
|
117
|
+
{
|
|
118
|
+
id: "reason",
|
|
119
|
+
label: "Reason",
|
|
120
|
+
cell: (row) => row.reason ?? "Not supplied",
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: "created",
|
|
124
|
+
label: "Created",
|
|
125
|
+
cell: (row) =>
|
|
126
|
+
row._creationTime === undefined
|
|
127
|
+
? "Not supplied"
|
|
128
|
+
: new Date(row._creationTime).toLocaleString(),
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
return (
|
|
132
|
+
<Collection
|
|
133
|
+
emptyLabel="No refunds yet."
|
|
134
|
+
{...props}
|
|
135
|
+
getKey={(row) => row.stripeRefundId}
|
|
136
|
+
columns={props.columns ?? columns}
|
|
137
|
+
/>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
export type ReferredSaleRow = {
|
|
141
|
+
stripeTransferId: string;
|
|
142
|
+
sourceChargeId?: string;
|
|
143
|
+
storeName?: string | null;
|
|
144
|
+
amount: number;
|
|
145
|
+
currency?: string;
|
|
146
|
+
};
|
|
147
|
+
export function ReferredSales(props: ResourceCollectionProps<ReferredSaleRow>) {
|
|
148
|
+
const columns: WorkflowColumn<ReferredSaleRow>[] = [
|
|
149
|
+
{
|
|
150
|
+
id: "store",
|
|
151
|
+
label: "Store",
|
|
152
|
+
cell: (row) => row.storeName ?? "Store unavailable",
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
id: "payment",
|
|
156
|
+
label: "Payment",
|
|
157
|
+
cell: (row) => row.sourceChargeId ?? row.stripeTransferId,
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
id: "commission",
|
|
161
|
+
label: "Commission",
|
|
162
|
+
align: "end",
|
|
163
|
+
cell: (row) => formatPrice(row.amount, row.currency ?? "usd"),
|
|
164
|
+
},
|
|
165
|
+
];
|
|
166
|
+
return (
|
|
167
|
+
<Collection
|
|
168
|
+
emptyLabel="No referred sales yet."
|
|
169
|
+
{...props}
|
|
170
|
+
getKey={(row) => row.stripeTransferId}
|
|
171
|
+
columns={props.columns ?? columns}
|
|
172
|
+
/>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
export type WebhookEventRow = {
|
|
176
|
+
stripeEventId: string;
|
|
177
|
+
eventType: string;
|
|
178
|
+
status: string;
|
|
179
|
+
processedAt?: number;
|
|
180
|
+
lastError?: string;
|
|
181
|
+
livemode?: boolean;
|
|
182
|
+
};
|
|
183
|
+
export function WebhookEvents<Row extends WebhookEventRow>(
|
|
184
|
+
props: ResourceCollectionProps<Row>,
|
|
185
|
+
) {
|
|
186
|
+
const columns: WorkflowColumn<Row>[] = [
|
|
187
|
+
{ id: "type", label: "Type", cell: (row) => row.eventType },
|
|
188
|
+
{ id: "status", label: "Status", cell: (row) => row.status },
|
|
189
|
+
{ id: "id", label: "Event ID", cell: (row) => row.stripeEventId },
|
|
190
|
+
{ id: "error", label: "Error", cell: (row) => row.lastError ?? "None" },
|
|
191
|
+
{
|
|
192
|
+
id: "processed",
|
|
193
|
+
label: "Processed",
|
|
194
|
+
cell: (row) =>
|
|
195
|
+
row.processedAt === undefined
|
|
196
|
+
? "Not supplied"
|
|
197
|
+
: new Date(row.processedAt).toLocaleString(),
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
id: "mode",
|
|
201
|
+
label: "Mode",
|
|
202
|
+
cell: (row) => (row.livemode ? "Live" : "Test"),
|
|
203
|
+
},
|
|
204
|
+
];
|
|
205
|
+
return (
|
|
206
|
+
<Collection
|
|
207
|
+
emptyLabel="No webhook events yet."
|
|
208
|
+
{...props}
|
|
209
|
+
getKey={(row) => row.stripeEventId}
|
|
210
|
+
columns={props.columns ?? columns}
|
|
211
|
+
/>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 type { ReactNode } from "react";
|
|
6
|
+
vi.mock("../components/ConnectProvider.js", () => ({
|
|
7
|
+
ConnectProvider: ({ children }: { children: ReactNode }) => children,
|
|
8
|
+
}));
|
|
9
|
+
vi.mock("@stripe/react-connect-js", () => {
|
|
10
|
+
const Widget = ({
|
|
11
|
+
onLoadError,
|
|
12
|
+
}: {
|
|
13
|
+
onLoadError: (event: { error: { message: string } }) => void;
|
|
14
|
+
}) => (
|
|
15
|
+
<button
|
|
16
|
+
onClick={() =>
|
|
17
|
+
onLoadError({ error: { message: "Account not eligible" } })
|
|
18
|
+
}
|
|
19
|
+
>
|
|
20
|
+
Stripe widget
|
|
21
|
+
</button>
|
|
22
|
+
);
|
|
23
|
+
return {
|
|
24
|
+
ConnectAccountManagement: Widget,
|
|
25
|
+
ConnectAccountOnboarding: Widget,
|
|
26
|
+
ConnectBalances: Widget,
|
|
27
|
+
ConnectDisputesList: Widget,
|
|
28
|
+
ConnectNotificationBanner: Widget,
|
|
29
|
+
ConnectPayments: Widget,
|
|
30
|
+
ConnectPayouts: Widget,
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
import { Connect } from "./Connect.js";
|
|
34
|
+
afterEach(cleanup);
|
|
35
|
+
it("exposes Stripe widget errors and remounts only on retry", async () => {
|
|
36
|
+
render(
|
|
37
|
+
<Connect
|
|
38
|
+
component="payouts"
|
|
39
|
+
scopeKey="acct_test"
|
|
40
|
+
publishableKey="pk_test_example"
|
|
41
|
+
fetchClientSecret={async () => "secret"}
|
|
42
|
+
/>,
|
|
43
|
+
);
|
|
44
|
+
await userEvent.click(screen.getByRole("button", { name: "Stripe widget" }));
|
|
45
|
+
expect(screen.getByRole("alert").textContent).toContain(
|
|
46
|
+
"Account not eligible",
|
|
47
|
+
);
|
|
48
|
+
await userEvent.click(screen.getByRole("button", { name: "Retry" }));
|
|
49
|
+
expect(screen.getByRole("button", { name: "Stripe widget" })).toBeTruthy();
|
|
50
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, type ReactNode } from "react";
|
|
3
|
+
import {
|
|
4
|
+
ConnectAccountManagement,
|
|
5
|
+
ConnectAccountOnboarding,
|
|
6
|
+
ConnectBalances,
|
|
7
|
+
ConnectDisputesList,
|
|
8
|
+
ConnectNotificationBanner,
|
|
9
|
+
ConnectPayments,
|
|
10
|
+
ConnectPayouts,
|
|
11
|
+
} from "@stripe/react-connect-js";
|
|
12
|
+
import {
|
|
13
|
+
ConnectProvider,
|
|
14
|
+
type ConnectProviderProps,
|
|
15
|
+
} from "../components/ConnectProvider.js";
|
|
16
|
+
export type ConnectComponent =
|
|
17
|
+
| "account"
|
|
18
|
+
| "onboarding"
|
|
19
|
+
| "payments"
|
|
20
|
+
| "refunds"
|
|
21
|
+
| "disputes"
|
|
22
|
+
| "balances"
|
|
23
|
+
| "payouts"
|
|
24
|
+
| "notifications";
|
|
25
|
+
export type ConnectRenderProps = {
|
|
26
|
+
content: ReactNode;
|
|
27
|
+
error: string | null;
|
|
28
|
+
retry: () => void;
|
|
29
|
+
completed: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type ConnectProps = Omit<ConnectProviderProps, "children"> & {
|
|
32
|
+
component: ConnectComponent;
|
|
33
|
+
/** Remounts the Stripe instance when the authenticated account changes. The server must authorize it independently. */
|
|
34
|
+
scopeKey: string;
|
|
35
|
+
onExit?: () => void;
|
|
36
|
+
children?: (state: ConnectRenderProps) => ReactNode;
|
|
37
|
+
};
|
|
38
|
+
const widgets = {
|
|
39
|
+
account: ConnectAccountManagement,
|
|
40
|
+
onboarding: ConnectAccountOnboarding,
|
|
41
|
+
payments: ConnectPayments,
|
|
42
|
+
refunds: ConnectPayments,
|
|
43
|
+
disputes: ConnectDisputesList,
|
|
44
|
+
balances: ConnectBalances,
|
|
45
|
+
payouts: ConnectPayouts,
|
|
46
|
+
notifications: ConnectNotificationBanner,
|
|
47
|
+
};
|
|
48
|
+
/** Unstyled, account-scoped Connect component with session refresh, error recovery, appearance, and locale. */
|
|
49
|
+
export function Connect(props: ConnectProps) {
|
|
50
|
+
return (
|
|
51
|
+
<ConnectBody key={`${props.scopeKey}:${props.component}`} {...props} />
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
function ConnectBody({
|
|
55
|
+
component,
|
|
56
|
+
publishableKey,
|
|
57
|
+
fetchClientSecret,
|
|
58
|
+
appearance,
|
|
59
|
+
locale,
|
|
60
|
+
onExit,
|
|
61
|
+
children,
|
|
62
|
+
}: ConnectProps) {
|
|
63
|
+
const [attempt, setAttempt] = useState(0);
|
|
64
|
+
const [error, setError] = useState<string | null>(null);
|
|
65
|
+
const [completed, setCompleted] = useState(false);
|
|
66
|
+
const Widget = widgets[component];
|
|
67
|
+
const retry = () => {
|
|
68
|
+
setError(null);
|
|
69
|
+
setAttempt((value) => value + 1);
|
|
70
|
+
};
|
|
71
|
+
const content = error ? (
|
|
72
|
+
<div role="alert">
|
|
73
|
+
<p>{error}</p>
|
|
74
|
+
<button type="button" onClick={retry}>
|
|
75
|
+
Retry
|
|
76
|
+
</button>
|
|
77
|
+
</div>
|
|
78
|
+
) : (
|
|
79
|
+
<ConnectProvider
|
|
80
|
+
key={attempt}
|
|
81
|
+
publishableKey={publishableKey}
|
|
82
|
+
appearance={appearance}
|
|
83
|
+
locale={locale}
|
|
84
|
+
fetchClientSecret={async () => {
|
|
85
|
+
try {
|
|
86
|
+
return await fetchClientSecret();
|
|
87
|
+
} catch (error) {
|
|
88
|
+
setError(error instanceof Error ? error.message : String(error));
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
<Widget
|
|
94
|
+
onLoadError={({ error }) =>
|
|
95
|
+
setError(error.message ?? "Stripe could not load this component.")
|
|
96
|
+
}
|
|
97
|
+
onExit={() => {
|
|
98
|
+
setCompleted(true);
|
|
99
|
+
onExit?.();
|
|
100
|
+
}}
|
|
101
|
+
/>
|
|
102
|
+
</ConnectProvider>
|
|
103
|
+
);
|
|
104
|
+
return (
|
|
105
|
+
<>{children ? children({ content, error, retry, completed }) : content}</>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
3
|
+
import { afterEach, expect, it } from "vitest";
|
|
4
|
+
import { CostRecovery, ChargebackLedger } from "./Costs.js";
|
|
5
|
+
afterEach(cleanup);
|
|
6
|
+
it("displays the authoritative cost balances without inventing a recovery policy", () => {
|
|
7
|
+
render(
|
|
8
|
+
<CostRecovery
|
|
9
|
+
rows={[
|
|
10
|
+
{
|
|
11
|
+
paymentIntentId: "pi_cost",
|
|
12
|
+
amountDue: 1000,
|
|
13
|
+
collectedAmount: 400,
|
|
14
|
+
invoicedAmount: 300,
|
|
15
|
+
outstanding: 300,
|
|
16
|
+
currency: "usd",
|
|
17
|
+
},
|
|
18
|
+
]}
|
|
19
|
+
/>,
|
|
20
|
+
);
|
|
21
|
+
expect(screen.getByText("$10.00")).toBeTruthy();
|
|
22
|
+
expect(screen.getByText("$4.00")).toBeTruthy();
|
|
23
|
+
expect(screen.getAllByText("$3.00")).toHaveLength(2);
|
|
24
|
+
});
|
|
25
|
+
it("renders chargeback economics and explicitly handles missing charge links", () => {
|
|
26
|
+
const { rerender } = render(<ChargebackLedger chargeback={null} />);
|
|
27
|
+
expect(screen.getByText(/No linked charge/)).toBeTruthy();
|
|
28
|
+
rerender(
|
|
29
|
+
<ChargebackLedger
|
|
30
|
+
chargeback={{
|
|
31
|
+
dispute: { stripeChargeId: "ch_one", currency: "usd", status: "lost" },
|
|
32
|
+
gross: 10000,
|
|
33
|
+
reversed: 2000,
|
|
34
|
+
net: 8000,
|
|
35
|
+
transfers: [],
|
|
36
|
+
}}
|
|
37
|
+
/>,
|
|
38
|
+
);
|
|
39
|
+
expect(screen.getByText("$80.00")).toBeTruthy();
|
|
40
|
+
expect(screen.getByText("No transfer rows found.")).toBeTruthy();
|
|
41
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { Collection, type WorkflowColumn } from "./Collection.js";
|
|
4
|
+
import type { ResourceCollectionProps } from "./Collections.js";
|
|
5
|
+
import { formatPrice } from "../lib/price-helpers.js";
|
|
6
|
+
export type CostRecoveryRow = {
|
|
7
|
+
_id?: string;
|
|
8
|
+
id?: string;
|
|
9
|
+
paymentIntentId: string;
|
|
10
|
+
amountDue: number;
|
|
11
|
+
collectedAmount: number;
|
|
12
|
+
invoicedAmount: number;
|
|
13
|
+
outstanding: number;
|
|
14
|
+
currency: string;
|
|
15
|
+
};
|
|
16
|
+
export function CostRecovery(props: ResourceCollectionProps<CostRecoveryRow>) {
|
|
17
|
+
const columns: WorkflowColumn<CostRecoveryRow>[] = [
|
|
18
|
+
{ id: "payment", label: "Payment", cell: (row) => row.paymentIntentId },
|
|
19
|
+
...(
|
|
20
|
+
[
|
|
21
|
+
["amountDue", "Total cost"],
|
|
22
|
+
["collectedAmount", "Deducted from earnings"],
|
|
23
|
+
["invoicedAmount", "Added to invoice"],
|
|
24
|
+
["outstanding", "Outstanding"],
|
|
25
|
+
] as const
|
|
26
|
+
).map(([field, label]) => ({
|
|
27
|
+
id: field,
|
|
28
|
+
label,
|
|
29
|
+
align: "end" as const,
|
|
30
|
+
cell: (row: CostRecoveryRow) => formatPrice(row[field], row.currency),
|
|
31
|
+
})),
|
|
32
|
+
];
|
|
33
|
+
return (
|
|
34
|
+
<Collection
|
|
35
|
+
emptyLabel="No costs yet."
|
|
36
|
+
loadingLabel="Loading costs…"
|
|
37
|
+
{...props}
|
|
38
|
+
columns={props.columns ?? columns}
|
|
39
|
+
getKey={(row) => row._id ?? row.id ?? row.paymentIntentId}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
export type ChargebackTransfer = {
|
|
44
|
+
stripeTransferId: string;
|
|
45
|
+
destinationAccountId: string;
|
|
46
|
+
amount: number;
|
|
47
|
+
currency: string;
|
|
48
|
+
role?: string;
|
|
49
|
+
reversedAmount?: number;
|
|
50
|
+
reversalStatus?: string;
|
|
51
|
+
};
|
|
52
|
+
export type ChargebackSummary = {
|
|
53
|
+
dispute: { stripeChargeId?: string; currency: string; status: string };
|
|
54
|
+
transfers: ChargebackTransfer[];
|
|
55
|
+
gross: number;
|
|
56
|
+
reversed: number;
|
|
57
|
+
net: number;
|
|
58
|
+
};
|
|
59
|
+
export type ChargebackLedgerRenderProps = {
|
|
60
|
+
data: ChargebackSummary | null | undefined;
|
|
61
|
+
isLoading: boolean;
|
|
62
|
+
isEmpty: boolean;
|
|
63
|
+
grossLabel: string;
|
|
64
|
+
reversedLabel: string;
|
|
65
|
+
netLabel: string;
|
|
66
|
+
columns: WorkflowColumn<ChargebackTransfer>[];
|
|
67
|
+
};
|
|
68
|
+
export function ChargebackLedger({
|
|
69
|
+
chargeback,
|
|
70
|
+
children,
|
|
71
|
+
}: {
|
|
72
|
+
chargeback: ChargebackSummary | null | undefined;
|
|
73
|
+
children?: (state: ChargebackLedgerRenderProps) => ReactNode;
|
|
74
|
+
}) {
|
|
75
|
+
const currency = chargeback?.dispute.currency ?? "usd";
|
|
76
|
+
const columns: WorkflowColumn<ChargebackTransfer>[] = [
|
|
77
|
+
{ id: "transfer", label: "Transfer", cell: (row) => row.stripeTransferId },
|
|
78
|
+
{
|
|
79
|
+
id: "account",
|
|
80
|
+
label: "Recipient",
|
|
81
|
+
cell: (row) => row.destinationAccountId,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: "amount",
|
|
85
|
+
label: "Amount",
|
|
86
|
+
align: "end",
|
|
87
|
+
cell: (row) => formatPrice(row.amount, row.currency),
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
id: "reversed",
|
|
91
|
+
label: "Reversed",
|
|
92
|
+
align: "end",
|
|
93
|
+
cell: (row) => formatPrice(row.reversedAmount ?? 0, row.currency),
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "status",
|
|
97
|
+
label: "Status",
|
|
98
|
+
cell: (row) => row.reversalStatus ?? "Not reversed",
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
const state: ChargebackLedgerRenderProps = {
|
|
102
|
+
data: chargeback,
|
|
103
|
+
isLoading: chargeback === undefined,
|
|
104
|
+
isEmpty: chargeback === null || !chargeback?.dispute.stripeChargeId,
|
|
105
|
+
grossLabel: formatPrice(chargeback?.gross ?? 0, currency),
|
|
106
|
+
reversedLabel: formatPrice(-(chargeback?.reversed ?? 0), currency),
|
|
107
|
+
netLabel: formatPrice(chargeback?.net ?? 0, currency),
|
|
108
|
+
columns,
|
|
109
|
+
};
|
|
110
|
+
if (children) return <>{children(state)}</>;
|
|
111
|
+
if (state.isLoading)
|
|
112
|
+
return <p role="status">Loading chargeback transfers…</p>;
|
|
113
|
+
if (state.isEmpty) return <p>No linked charge is available yet.</p>;
|
|
114
|
+
return (
|
|
115
|
+
<section data-better-stripe="chargeback-ledger">
|
|
116
|
+
<h3>Chargeback transfers</h3>
|
|
117
|
+
<dl>
|
|
118
|
+
<dt>Original transfers</dt>
|
|
119
|
+
<dd>{state.grossLabel}</dd>
|
|
120
|
+
<dt>Funds pulled back</dt>
|
|
121
|
+
<dd>{state.reversedLabel}</dd>
|
|
122
|
+
<dt>Recipient net</dt>
|
|
123
|
+
<dd>{state.netLabel}</dd>
|
|
124
|
+
</dl>
|
|
125
|
+
<Collection
|
|
126
|
+
rows={chargeback!.transfers}
|
|
127
|
+
columns={columns}
|
|
128
|
+
getKey={(row) => row.stripeTransferId}
|
|
129
|
+
emptyLabel="No transfer rows found."
|
|
130
|
+
/>
|
|
131
|
+
</section>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import {
|
|
3
|
+
act,
|
|
4
|
+
cleanup,
|
|
5
|
+
renderHook,
|
|
6
|
+
render,
|
|
7
|
+
screen,
|
|
8
|
+
fireEvent,
|
|
9
|
+
} from "@testing-library/react";
|
|
10
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
11
|
+
import { Disputes, useDisputeResponse } from "./Disputes.js";
|
|
12
|
+
afterEach(cleanup);
|
|
13
|
+
it("requires explicit confirmation and clears it when selecting another dispute", async () => {
|
|
14
|
+
const acceptDispute = vi.fn().mockResolvedValue(null);
|
|
15
|
+
const { result } = renderHook(() =>
|
|
16
|
+
useDisputeResponse({ scopeKey: "seller", acceptDispute }),
|
|
17
|
+
);
|
|
18
|
+
act(() => result.current.setSelectedId("dp_one"));
|
|
19
|
+
await act(async () => {
|
|
20
|
+
await result.current.accept();
|
|
21
|
+
});
|
|
22
|
+
expect(acceptDispute).not.toHaveBeenCalled();
|
|
23
|
+
act(() => result.current.requestAccept());
|
|
24
|
+
act(() => result.current.setSelectedId("dp_two"));
|
|
25
|
+
expect(result.current.acceptStatus).toBe("idle");
|
|
26
|
+
act(() => result.current.requestAccept());
|
|
27
|
+
await act(async () => {
|
|
28
|
+
await result.current.accept();
|
|
29
|
+
});
|
|
30
|
+
expect(acceptDispute).toHaveBeenCalledWith("dp_two");
|
|
31
|
+
expect(result.current.acceptStatus).toBe("accepted");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it.each(["won", "lost", "under_review"] as const)(
|
|
35
|
+
"keeps %s disputes read-only",
|
|
36
|
+
(status) => {
|
|
37
|
+
const detail = {
|
|
38
|
+
_id: "doc",
|
|
39
|
+
_creationTime: 0,
|
|
40
|
+
stripeDisputeId: "dp_closed",
|
|
41
|
+
amount: 1000,
|
|
42
|
+
currency: "usd",
|
|
43
|
+
status,
|
|
44
|
+
reason: "product_not_received",
|
|
45
|
+
isChargeRefundable: false,
|
|
46
|
+
countdown: { daysRemaining: 9, isOverdue: false },
|
|
47
|
+
};
|
|
48
|
+
render(
|
|
49
|
+
<Disputes
|
|
50
|
+
scopeKey="seller"
|
|
51
|
+
disputes={[detail]}
|
|
52
|
+
detail={detail}
|
|
53
|
+
acceptDispute={vi.fn()}
|
|
54
|
+
onUpdateEvidence={vi.fn()}
|
|
55
|
+
/>,
|
|
56
|
+
);
|
|
57
|
+
fireEvent.click(screen.getByRole("button", { name: /dp_closed/ }));
|
|
58
|
+
expect(screen.queryByRole("button", { name: "Accept dispute" })).toBeNull();
|
|
59
|
+
expect(
|
|
60
|
+
screen.queryByRole("button", { name: "Submit evidence" }),
|
|
61
|
+
).toBeNull();
|
|
62
|
+
expect(screen.queryByText("Evidence due in 9 days")).toBeNull();
|
|
63
|
+
},
|
|
64
|
+
);
|