@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,112 @@
|
|
|
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 { Payouts } from "./Payouts.js";
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
const row = (id: string, status = "paid") => ({
|
|
8
|
+
id,
|
|
9
|
+
status,
|
|
10
|
+
amount: 5000,
|
|
11
|
+
currency: "usd",
|
|
12
|
+
arrivalDate: 1800000000000,
|
|
13
|
+
created: 1799990000000,
|
|
14
|
+
});
|
|
15
|
+
it("shows balances, the actual next payout/date, and merges paginated history without duplicates", async () => {
|
|
16
|
+
const first = row("po_first");
|
|
17
|
+
const next = row("po_next", "pending");
|
|
18
|
+
const load = vi
|
|
19
|
+
.fn()
|
|
20
|
+
.mockResolvedValueOnce({
|
|
21
|
+
balances: [{ currency: "usd", available: 12000, pending: 2000 }],
|
|
22
|
+
upcoming: [next],
|
|
23
|
+
payouts: [next, first],
|
|
24
|
+
nextCursor: "po_first",
|
|
25
|
+
})
|
|
26
|
+
.mockResolvedValueOnce({
|
|
27
|
+
balances: [],
|
|
28
|
+
upcoming: [next],
|
|
29
|
+
payouts: [first, row("po_older")],
|
|
30
|
+
nextCursor: null,
|
|
31
|
+
});
|
|
32
|
+
render(<Payouts scopeKey="acct_one" load={load} />);
|
|
33
|
+
await screen.findByText("$120.00");
|
|
34
|
+
expect(screen.getByText("$20.00")).toBeTruthy();
|
|
35
|
+
expect(screen.getByText("po_next")).toBeTruthy();
|
|
36
|
+
await userEvent.click(
|
|
37
|
+
screen.getByRole("button", { name: "Load more payouts" }),
|
|
38
|
+
);
|
|
39
|
+
await screen.findByText("po_older");
|
|
40
|
+
expect(screen.getAllByText("po_first")).toHaveLength(1);
|
|
41
|
+
expect(screen.getByText("$120.00")).toBeTruthy();
|
|
42
|
+
expect(load).toHaveBeenLastCalledWith("po_first");
|
|
43
|
+
});
|
|
44
|
+
it("shows a load error with a working retry", async () => {
|
|
45
|
+
const load = vi
|
|
46
|
+
.fn()
|
|
47
|
+
.mockRejectedValueOnce(new Error("No balance access"))
|
|
48
|
+
.mockResolvedValueOnce({
|
|
49
|
+
balances: [],
|
|
50
|
+
upcoming: [],
|
|
51
|
+
payouts: [],
|
|
52
|
+
nextCursor: null,
|
|
53
|
+
});
|
|
54
|
+
render(<Payouts scopeKey="acct_one" load={load} />);
|
|
55
|
+
expect((await screen.findByRole("alert")).textContent).toContain(
|
|
56
|
+
"No balance access",
|
|
57
|
+
);
|
|
58
|
+
await userEvent.click(screen.getByRole("button", { name: "Refresh" }));
|
|
59
|
+
await screen.findByText("No previous payouts yet.");
|
|
60
|
+
});
|
|
61
|
+
it("exports payout history with explicit empty/loading states and date formatting", async () => {
|
|
62
|
+
const { PayoutHistory } = await import("./Payouts.js");
|
|
63
|
+
const { rerender } = render(<PayoutHistory rows={undefined} />);
|
|
64
|
+
expect(screen.getByRole("status")).toBeTruthy();
|
|
65
|
+
rerender(<PayoutHistory rows={[]} />);
|
|
66
|
+
expect(screen.getByText("No payouts yet.")).toBeTruthy();
|
|
67
|
+
rerender(
|
|
68
|
+
<PayoutHistory
|
|
69
|
+
rows={[
|
|
70
|
+
{
|
|
71
|
+
id: "po_history",
|
|
72
|
+
amount: 900,
|
|
73
|
+
currency: "usd",
|
|
74
|
+
status: "paid",
|
|
75
|
+
arrivalDate: null,
|
|
76
|
+
},
|
|
77
|
+
]}
|
|
78
|
+
/>,
|
|
79
|
+
);
|
|
80
|
+
expect(screen.getByText("po_history")).toBeTruthy();
|
|
81
|
+
expect(screen.getByText("Not supplied by Stripe")).toBeTruthy();
|
|
82
|
+
});
|
|
83
|
+
it("keeps completed payouts out of upcoming and sorts the remaining arrivals", async () => {
|
|
84
|
+
const pending = {
|
|
85
|
+
...row("po_pending", "pending"),
|
|
86
|
+
arrivalDate: 1900000000000,
|
|
87
|
+
};
|
|
88
|
+
const transit = {
|
|
89
|
+
...row("po_transit", "in_transit"),
|
|
90
|
+
arrivalDate: 1800000000000,
|
|
91
|
+
};
|
|
92
|
+
const paid = row("po_paid");
|
|
93
|
+
const failed = row("po_failed", "failed");
|
|
94
|
+
const load = async () => ({
|
|
95
|
+
balances: [],
|
|
96
|
+
upcoming: [paid, pending, failed, transit],
|
|
97
|
+
payouts: [paid, pending, failed, transit],
|
|
98
|
+
nextCursor: null,
|
|
99
|
+
});
|
|
100
|
+
const { container } = render(<Payouts scopeKey="seller" load={load} />);
|
|
101
|
+
await screen.findByText("po_pending");
|
|
102
|
+
const headings = Array.from(container.querySelectorAll("h3"));
|
|
103
|
+
const upcomingTable = headings.find(
|
|
104
|
+
(node) => node.textContent === "Upcoming payouts",
|
|
105
|
+
)!.nextElementSibling!;
|
|
106
|
+
expect(upcomingTable.textContent).not.toContain("po_paid");
|
|
107
|
+
expect(upcomingTable.textContent).not.toContain("po_failed");
|
|
108
|
+
expect(upcomingTable.textContent!.indexOf("po_transit")).toBeLessThan(
|
|
109
|
+
upcomingTable.textContent!.indexOf("po_pending"),
|
|
110
|
+
);
|
|
111
|
+
expect(screen.getAllByText("po_paid")).toHaveLength(1);
|
|
112
|
+
});
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, type ReactNode } from "react";
|
|
3
|
+
import { Connect, type ConnectProps } from "./Connect.js";
|
|
4
|
+
import { useWorkflowAction } from "./useWorkflowAction.js";
|
|
5
|
+
import { useWorkflowResource } from "./useWorkflowResource.js";
|
|
6
|
+
import {
|
|
7
|
+
Collection,
|
|
8
|
+
type CollectionProps,
|
|
9
|
+
type WorkflowColumn,
|
|
10
|
+
} from "./Collection.js";
|
|
11
|
+
import { formatPrice } from "../lib/price-helpers.js";
|
|
12
|
+
export type PayoutRow = {
|
|
13
|
+
id: string;
|
|
14
|
+
amount: number;
|
|
15
|
+
currency: string;
|
|
16
|
+
status: string;
|
|
17
|
+
/** Unix milliseconds. */ arrivalDate: number | null;
|
|
18
|
+
created: number;
|
|
19
|
+
};
|
|
20
|
+
export type PayoutSnapshot = {
|
|
21
|
+
balances: { currency: string; available: number; pending: number }[];
|
|
22
|
+
payouts: PayoutRow[];
|
|
23
|
+
upcoming: PayoutRow[];
|
|
24
|
+
nextCursor: string | null;
|
|
25
|
+
};
|
|
26
|
+
export type PayoutsRenderProps = {
|
|
27
|
+
data: PayoutSnapshot | undefined;
|
|
28
|
+
error: string | null;
|
|
29
|
+
isLoading: boolean;
|
|
30
|
+
isPending: boolean;
|
|
31
|
+
nextPayout: PayoutRow | undefined;
|
|
32
|
+
previousPayouts: PayoutRow[];
|
|
33
|
+
upcomingPayouts: PayoutRow[];
|
|
34
|
+
refresh: () => void;
|
|
35
|
+
loadMore: () => Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
export type HeadlessPayoutsProps = {
|
|
38
|
+
presentation?: "headless";
|
|
39
|
+
scopeKey: string;
|
|
40
|
+
load: (cursor?: string) => Promise<PayoutSnapshot>;
|
|
41
|
+
children?: (state: PayoutsRenderProps) => ReactNode;
|
|
42
|
+
};
|
|
43
|
+
export type PayoutsProps =
|
|
44
|
+
| HeadlessPayoutsProps
|
|
45
|
+
| (Omit<ConnectProps, "component"> & { presentation: "embedded" });
|
|
46
|
+
const upcoming = (row: PayoutRow) =>
|
|
47
|
+
row.status === "pending" || row.status === "in_transit";
|
|
48
|
+
export function Payouts(props: PayoutsProps) {
|
|
49
|
+
return props.presentation === "embedded" ? (
|
|
50
|
+
<Connect {...props} component="payouts" />
|
|
51
|
+
) : (
|
|
52
|
+
<PayoutsBody key={props.scopeKey} {...props} />
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
function PayoutsBody({ load, scopeKey, children }: HeadlessPayoutsProps) {
|
|
56
|
+
const resource = useWorkflowResource(() => load(), scopeKey);
|
|
57
|
+
const more = useWorkflowAction(
|
|
58
|
+
(cursor: string) => load(cursor),
|
|
59
|
+
`${scopeKey}:${resource.revision}`,
|
|
60
|
+
);
|
|
61
|
+
const [pages, setPages] = useState<{
|
|
62
|
+
base: PayoutSnapshot | undefined;
|
|
63
|
+
rows: PayoutRow[];
|
|
64
|
+
cursor: string | null | undefined;
|
|
65
|
+
}>({ base: undefined, rows: [], cursor: undefined });
|
|
66
|
+
if (pages.base !== resource.data)
|
|
67
|
+
setPages({ base: resource.data, rows: [], cursor: undefined });
|
|
68
|
+
const base = resource.data;
|
|
69
|
+
const nextCursor =
|
|
70
|
+
pages.cursor === undefined ? (base?.nextCursor ?? null) : pages.cursor;
|
|
71
|
+
const data = base
|
|
72
|
+
? {
|
|
73
|
+
...base,
|
|
74
|
+
nextCursor,
|
|
75
|
+
payouts: [
|
|
76
|
+
...new Map(
|
|
77
|
+
[...base.payouts, ...pages.rows].map((row) => [row.id, row]),
|
|
78
|
+
).values(),
|
|
79
|
+
],
|
|
80
|
+
}
|
|
81
|
+
: undefined;
|
|
82
|
+
const loadMore = async () => {
|
|
83
|
+
if (!nextCursor || resource.isLoading) return;
|
|
84
|
+
const next = await more.run(nextCursor);
|
|
85
|
+
if (next)
|
|
86
|
+
setPages((previous) => ({
|
|
87
|
+
...previous,
|
|
88
|
+
rows: [...previous.rows, ...next.payouts],
|
|
89
|
+
cursor: next.nextCursor,
|
|
90
|
+
}));
|
|
91
|
+
};
|
|
92
|
+
const sortedUpcoming =
|
|
93
|
+
data?.upcoming
|
|
94
|
+
.filter(upcoming)
|
|
95
|
+
.slice()
|
|
96
|
+
.sort(
|
|
97
|
+
(a, b) => (a.arrivalDate ?? Infinity) - (b.arrivalDate ?? Infinity),
|
|
98
|
+
) ?? [];
|
|
99
|
+
const state: PayoutsRenderProps = {
|
|
100
|
+
data,
|
|
101
|
+
isLoading: resource.isLoading,
|
|
102
|
+
isPending: resource.isLoading || more.isPending,
|
|
103
|
+
error: resource.error ?? more.error,
|
|
104
|
+
nextPayout: sortedUpcoming[0],
|
|
105
|
+
upcomingPayouts: sortedUpcoming,
|
|
106
|
+
previousPayouts: data?.payouts.filter((row) => !upcoming(row)) ?? [],
|
|
107
|
+
refresh: resource.refresh,
|
|
108
|
+
loadMore,
|
|
109
|
+
};
|
|
110
|
+
return <>{children ? children(state) : <NativePayouts {...state} />}</>;
|
|
111
|
+
}
|
|
112
|
+
function date(value: number | null) {
|
|
113
|
+
return value === null
|
|
114
|
+
? "Not supplied by Stripe"
|
|
115
|
+
: new Date(value).toLocaleDateString(undefined, { timeZone: "UTC" });
|
|
116
|
+
}
|
|
117
|
+
export type PayoutHistoryRow = Pick<
|
|
118
|
+
PayoutRow,
|
|
119
|
+
"id" | "amount" | "currency" | "status" | "arrivalDate"
|
|
120
|
+
>;
|
|
121
|
+
export type PayoutHistoryProps<
|
|
122
|
+
Row extends PayoutHistoryRow = PayoutHistoryRow,
|
|
123
|
+
> = Omit<CollectionProps<Row>, "columns" | "getKey"> & {
|
|
124
|
+
columns?: WorkflowColumn<Row>[];
|
|
125
|
+
};
|
|
126
|
+
export function PayoutHistory<Row extends PayoutHistoryRow>(
|
|
127
|
+
props: PayoutHistoryProps<Row>,
|
|
128
|
+
) {
|
|
129
|
+
const columns: WorkflowColumn<Row>[] = [
|
|
130
|
+
{ id: "id", label: "Payout ID", cell: (row) => row.id },
|
|
131
|
+
{
|
|
132
|
+
id: "amount",
|
|
133
|
+
label: "Amount",
|
|
134
|
+
align: "end",
|
|
135
|
+
cell: (row) => formatPrice(row.amount, row.currency),
|
|
136
|
+
},
|
|
137
|
+
{ id: "status", label: "Status", cell: (row) => row.status },
|
|
138
|
+
{
|
|
139
|
+
id: "arrival",
|
|
140
|
+
label: "Arrival date",
|
|
141
|
+
cell: (row) => date(row.arrivalDate),
|
|
142
|
+
},
|
|
143
|
+
];
|
|
144
|
+
return (
|
|
145
|
+
<Collection
|
|
146
|
+
emptyLabel="No payouts yet."
|
|
147
|
+
{...props}
|
|
148
|
+
getKey={(row) => row.id}
|
|
149
|
+
columns={props.columns ?? columns}
|
|
150
|
+
/>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
function NativePayouts({
|
|
154
|
+
data,
|
|
155
|
+
isLoading,
|
|
156
|
+
isPending,
|
|
157
|
+
error,
|
|
158
|
+
nextPayout,
|
|
159
|
+
previousPayouts,
|
|
160
|
+
upcomingPayouts,
|
|
161
|
+
refresh,
|
|
162
|
+
loadMore,
|
|
163
|
+
}: PayoutsRenderProps) {
|
|
164
|
+
return (
|
|
165
|
+
<section data-better-stripe="payouts" aria-busy={isPending}>
|
|
166
|
+
<h2>Payouts</h2>
|
|
167
|
+
<button type="button" disabled={isPending} onClick={refresh}>
|
|
168
|
+
{isPending ? "Refreshing…" : "Refresh"}
|
|
169
|
+
</button>
|
|
170
|
+
{error && <p role="alert">{error}</p>}
|
|
171
|
+
{isLoading && !data && <p role="status">Loading payouts…</p>}
|
|
172
|
+
{data && (
|
|
173
|
+
<>
|
|
174
|
+
<dl>
|
|
175
|
+
{data.balances.map((balance) => (
|
|
176
|
+
<div key={balance.currency}>
|
|
177
|
+
<dt>Available</dt>
|
|
178
|
+
<dd>{formatPrice(balance.available, balance.currency)}</dd>
|
|
179
|
+
<dt>Pending</dt>
|
|
180
|
+
<dd>{formatPrice(balance.pending, balance.currency)}</dd>
|
|
181
|
+
</div>
|
|
182
|
+
))}
|
|
183
|
+
<dt>Next payout</dt>
|
|
184
|
+
<dd>
|
|
185
|
+
{nextPayout
|
|
186
|
+
? `${formatPrice(nextPayout.amount, nextPayout.currency)} · ${date(nextPayout.arrivalDate)}`
|
|
187
|
+
: "Not scheduled"}
|
|
188
|
+
</dd>
|
|
189
|
+
</dl>
|
|
190
|
+
<h3>Upcoming payouts</h3>
|
|
191
|
+
<PayoutHistory
|
|
192
|
+
rows={upcomingPayouts}
|
|
193
|
+
emptyLabel="No upcoming payouts scheduled."
|
|
194
|
+
/>
|
|
195
|
+
<h3>Previous payouts</h3>
|
|
196
|
+
<PayoutHistory
|
|
197
|
+
rows={previousPayouts}
|
|
198
|
+
emptyLabel="No previous payouts yet."
|
|
199
|
+
/>
|
|
200
|
+
{data.nextCursor && (
|
|
201
|
+
<button
|
|
202
|
+
type="button"
|
|
203
|
+
disabled={isPending}
|
|
204
|
+
onClick={() => {
|
|
205
|
+
void loadMore();
|
|
206
|
+
}}
|
|
207
|
+
>
|
|
208
|
+
{isPending ? "Loading…" : "Load more payouts"}
|
|
209
|
+
</button>
|
|
210
|
+
)}
|
|
211
|
+
</>
|
|
212
|
+
)}
|
|
213
|
+
</section>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, cleanup, renderHook } from "@testing-library/react";
|
|
3
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
4
|
+
import { useProductManager } from "./Products.js";
|
|
5
|
+
afterEach(cleanup);
|
|
6
|
+
it("validates product names and price minor units before mutation", async () => {
|
|
7
|
+
const createProduct = vi.fn().mockResolvedValue("prod_test");
|
|
8
|
+
const createPrice = vi.fn().mockResolvedValue("price_test");
|
|
9
|
+
const { result } = renderHook(() =>
|
|
10
|
+
useProductManager({ scopeKey: "seller", createProduct, createPrice }),
|
|
11
|
+
);
|
|
12
|
+
await act(async () => {
|
|
13
|
+
await result.current.handleCreateProduct();
|
|
14
|
+
});
|
|
15
|
+
expect(createProduct).not.toHaveBeenCalled();
|
|
16
|
+
act(() =>
|
|
17
|
+
result.current.setNewProduct({
|
|
18
|
+
name: " Classic Tee ",
|
|
19
|
+
description: "Cotton",
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
await act(async () => {
|
|
23
|
+
await result.current.handleCreateProduct();
|
|
24
|
+
});
|
|
25
|
+
expect(createProduct).toHaveBeenCalledWith({
|
|
26
|
+
name: "Classic Tee",
|
|
27
|
+
description: "Cotton",
|
|
28
|
+
});
|
|
29
|
+
act(() =>
|
|
30
|
+
result.current.setNewPrice({
|
|
31
|
+
amount: "12.50",
|
|
32
|
+
currency: "usd",
|
|
33
|
+
interval: "one_time",
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
await act(async () => {
|
|
37
|
+
await result.current.handleAddPrice("prod_test");
|
|
38
|
+
});
|
|
39
|
+
expect(createPrice).not.toHaveBeenCalled();
|
|
40
|
+
act(() =>
|
|
41
|
+
result.current.setNewPrice({
|
|
42
|
+
amount: "2900",
|
|
43
|
+
currency: "usd",
|
|
44
|
+
interval: "one_time",
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
await act(async () => {
|
|
48
|
+
await result.current.handleAddPrice("prod_test");
|
|
49
|
+
});
|
|
50
|
+
expect(createPrice).toHaveBeenCalledWith({
|
|
51
|
+
stripeProductId: "prod_test",
|
|
52
|
+
unitAmount: 2900,
|
|
53
|
+
currency: "usd",
|
|
54
|
+
type: "one_time",
|
|
55
|
+
interval: undefined,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("keeps the active product operation when a second operation is attempted", async () => {
|
|
60
|
+
let finish!: () => void;
|
|
61
|
+
const deactivateProduct = vi.fn(
|
|
62
|
+
() =>
|
|
63
|
+
new Promise<void>((resolve) => {
|
|
64
|
+
finish = resolve;
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
67
|
+
const deactivatePrice = vi.fn();
|
|
68
|
+
const { result } = renderHook(() =>
|
|
69
|
+
useProductManager({
|
|
70
|
+
scopeKey: "seller",
|
|
71
|
+
createProduct: async () => null,
|
|
72
|
+
createPrice: async () => null,
|
|
73
|
+
deactivateProduct,
|
|
74
|
+
deactivatePrice,
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
let pending!: Promise<unknown>;
|
|
78
|
+
act(() => {
|
|
79
|
+
pending = result.current.handleDeactivate("prod_one");
|
|
80
|
+
});
|
|
81
|
+
await act(async () => {
|
|
82
|
+
await result.current.handleDeactivatePrice("price_one");
|
|
83
|
+
});
|
|
84
|
+
expect(result.current.deactivatingId).toBe("prod_one");
|
|
85
|
+
expect(deactivatePrice).not.toHaveBeenCalled();
|
|
86
|
+
await act(async () => {
|
|
87
|
+
finish();
|
|
88
|
+
await pending;
|
|
89
|
+
});
|
|
90
|
+
});
|