@fantastic.dev/better-stripe 0.4.0-bootstrap.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 +318 -0
- package/README.md +1117 -0
- package/dist/client/billing/checkout.d.ts +75 -0
- package/dist/client/billing/checkout.d.ts.map +1 -0
- package/dist/client/billing/checkout.js +260 -0
- package/dist/client/billing/checkout.js.map +1 -0
- package/dist/client/billing/invoices.d.ts +37 -0
- package/dist/client/billing/invoices.d.ts.map +1 -0
- package/dist/client/billing/invoices.js +29 -0
- package/dist/client/billing/invoices.js.map +1 -0
- package/dist/client/billing/subscriptions.d.ts +179 -0
- package/dist/client/billing/subscriptions.d.ts.map +1 -0
- package/dist/client/billing/subscriptions.js +346 -0
- package/dist/client/billing/subscriptions.js.map +1 -0
- package/dist/client/connect/disputes.d.ts +112 -0
- package/dist/client/connect/disputes.d.ts.map +1 -0
- package/dist/client/connect/disputes.js +186 -0
- package/dist/client/connect/disputes.js.map +1 -0
- package/dist/client/connect/paymentMethodUtils.d.ts +17 -0
- package/dist/client/connect/paymentMethodUtils.d.ts.map +1 -0
- package/dist/client/connect/paymentMethodUtils.js +24 -0
- package/dist/client/connect/paymentMethodUtils.js.map +1 -0
- package/dist/client/connect/paymentMethods.d.ts +23 -0
- package/dist/client/connect/paymentMethods.d.ts.map +1 -0
- package/dist/client/connect/paymentMethods.js +27 -0
- package/dist/client/connect/paymentMethods.js.map +1 -0
- package/dist/client/connect/payouts.d.ts +47 -0
- package/dist/client/connect/payouts.d.ts.map +1 -0
- package/dist/client/connect/payouts.js +52 -0
- package/dist/client/connect/payouts.js.map +1 -0
- package/dist/client/connect/refundActor.d.ts +50 -0
- package/dist/client/connect/refundActor.d.ts.map +1 -0
- package/dist/client/connect/refundActor.js +17 -0
- package/dist/client/connect/refundActor.js.map +1 -0
- package/dist/client/connect/refunds.d.ts +75 -0
- package/dist/client/connect/refunds.d.ts.map +1 -0
- package/dist/client/connect/refunds.js +141 -0
- package/dist/client/connect/refunds.js.map +1 -0
- package/dist/client/connect/transfers.d.ts +189 -0
- package/dist/client/connect/transfers.d.ts.map +1 -0
- package/dist/client/connect/transfers.js +347 -0
- package/dist/client/connect/transfers.js.map +1 -0
- package/dist/client/constants.d.ts +15 -0
- package/dist/client/constants.d.ts.map +1 -0
- package/dist/client/constants.js +14 -0
- package/dist/client/constants.js.map +1 -0
- package/dist/client/core/accountLinks.d.ts +68 -0
- package/dist/client/core/accountLinks.d.ts.map +1 -0
- package/dist/client/core/accountLinks.js +131 -0
- package/dist/client/core/accountLinks.js.map +1 -0
- package/dist/client/core/accountStatus.d.ts +12 -0
- package/dist/client/core/accountStatus.d.ts.map +1 -0
- package/dist/client/core/accountStatus.js +56 -0
- package/dist/client/core/accountStatus.js.map +1 -0
- package/dist/client/core/accounts.d.ts +181 -0
- package/dist/client/core/accounts.d.ts.map +1 -0
- package/dist/client/core/accounts.js +359 -0
- package/dist/client/core/accounts.js.map +1 -0
- package/dist/client/core/config.d.ts +5 -0
- package/dist/client/core/config.d.ts.map +1 -0
- package/dist/client/core/config.js +11 -0
- package/dist/client/core/config.js.map +1 -0
- package/dist/client/core/descriptors.d.ts +24 -0
- package/dist/client/core/descriptors.d.ts.map +1 -0
- package/dist/client/core/descriptors.js +43 -0
- package/dist/client/core/descriptors.js.map +1 -0
- package/dist/client/core/fees.d.ts +83 -0
- package/dist/client/core/fees.d.ts.map +1 -0
- package/dist/client/core/fees.js +178 -0
- package/dist/client/core/fees.js.map +1 -0
- package/dist/client/errors.d.ts +20 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/errors.js +31 -0
- package/dist/client/errors.js.map +1 -0
- package/dist/client/helpers.d.ts +20 -0
- package/dist/client/helpers.d.ts.map +1 -0
- package/dist/client/helpers.js +46 -0
- package/dist/client/helpers.js.map +1 -0
- package/dist/client/index.d.ts +880 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +791 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/products/prices.d.ts +61 -0
- package/dist/client/products/prices.d.ts.map +1 -0
- package/dist/client/products/prices.js +92 -0
- package/dist/client/products/prices.js.map +1 -0
- package/dist/client/products/products.d.ts +65 -0
- package/dist/client/products/products.d.ts.map +1 -0
- package/dist/client/products/products.js +186 -0
- package/dist/client/products/products.js.map +1 -0
- package/dist/client/stripe-types.d.ts +44 -0
- package/dist/client/stripe-types.d.ts.map +1 -0
- package/dist/client/stripe-types.js +2 -0
- package/dist/client/stripe-types.js.map +1 -0
- package/dist/client/types/documents.d.ts +195 -0
- package/dist/client/types/documents.d.ts.map +1 -0
- package/dist/client/types/documents.js +2 -0
- package/dist/client/types/documents.js.map +1 -0
- package/dist/client/types/events.d.ts +43 -0
- package/dist/client/types/events.d.ts.map +1 -0
- package/dist/client/types/events.js +2 -0
- package/dist/client/types/events.js.map +1 -0
- package/dist/client/types/index.d.ts +5 -0
- package/dist/client/types/index.d.ts.map +1 -0
- package/dist/client/types/index.js +2 -0
- package/dist/client/types/index.js.map +1 -0
- package/dist/client/types/options.d.ts +79 -0
- package/dist/client/types/options.d.ts.map +1 -0
- package/dist/client/types/options.js +2 -0
- package/dist/client/types/options.js.map +1 -0
- package/dist/client/types/triggers.d.ts +101 -0
- package/dist/client/types/triggers.d.ts.map +1 -0
- package/dist/client/types/triggers.js +2 -0
- package/dist/client/types/triggers.js.map +1 -0
- package/dist/client/types.d.ts +2 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +2 -0
- package/dist/client/types.js.map +1 -0
- package/dist/client/utils/data.d.ts +10 -0
- package/dist/client/utils/data.d.ts.map +1 -0
- package/dist/client/utils/data.js +13 -0
- package/dist/client/utils/data.js.map +1 -0
- package/dist/client/utils/owner.d.ts +22 -0
- package/dist/client/utils/owner.d.ts.map +1 -0
- package/dist/client/utils/owner.js +20 -0
- package/dist/client/utils/owner.js.map +1 -0
- package/dist/client/utils/stripeDashboardUrl.d.ts +12 -0
- package/dist/client/utils/stripeDashboardUrl.d.ts.map +1 -0
- package/dist/client/utils/stripeDashboardUrl.js +39 -0
- package/dist/client/utils/stripeDashboardUrl.js.map +1 -0
- package/dist/client/utils/webhookEndpoints.d.ts +83 -0
- package/dist/client/utils/webhookEndpoints.d.ts.map +1 -0
- package/dist/client/utils/webhookEndpoints.js +185 -0
- package/dist/client/utils/webhookEndpoints.js.map +1 -0
- package/dist/client/webhooks/handler.d.ts +4 -0
- package/dist/client/webhooks/handler.d.ts.map +1 -0
- package/dist/client/webhooks/handler.js +170 -0
- package/dist/client/webhooks/handler.js.map +1 -0
- package/dist/client/webhooks/helpers.d.ts +56 -0
- package/dist/client/webhooks/helpers.d.ts.map +1 -0
- package/dist/client/webhooks/helpers.js +229 -0
- package/dist/client/webhooks/helpers.js.map +1 -0
- package/dist/client/webhooks/hooks.d.ts +11 -0
- package/dist/client/webhooks/hooks.d.ts.map +1 -0
- package/dist/client/webhooks/hooks.js +134 -0
- package/dist/client/webhooks/hooks.js.map +1 -0
- package/dist/client/webhooks/index.d.ts +23 -0
- package/dist/client/webhooks/index.d.ts.map +1 -0
- package/dist/client/webhooks/index.js +35 -0
- package/dist/client/webhooks/index.js.map +1 -0
- package/dist/client/webhooks/processors.d.ts +4 -0
- package/dist/client/webhooks/processors.d.ts.map +1 -0
- package/dist/client/webhooks/processors.js +932 -0
- package/dist/client/webhooks/processors.js.map +1 -0
- package/dist/client/webhooks/v2.d.ts +11 -0
- package/dist/client/webhooks/v2.d.ts.map +1 -0
- package/dist/client/webhooks/v2.js +94 -0
- package/dist/client/webhooks/v2.js.map +1 -0
- package/dist/client/webhooks.d.ts +2 -0
- package/dist/client/webhooks.d.ts.map +1 -0
- package/dist/client/webhooks.js +4 -0
- package/dist/client/webhooks.js.map +1 -0
- package/dist/component/_generated/component.d.ts +1262 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +129 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +79 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/billing/mutations.d.ts +86 -0
- package/dist/component/billing/mutations.d.ts.map +1 -0
- package/dist/component/billing/mutations.js +131 -0
- package/dist/component/billing/mutations.js.map +1 -0
- package/dist/component/billing/queries.d.ts +425 -0
- package/dist/component/billing/queries.d.ts.map +1 -0
- package/dist/component/billing/queries.js +304 -0
- package/dist/component/billing/queries.js.map +1 -0
- package/dist/component/billing/schema.d.ts +228 -0
- package/dist/component/billing/schema.d.ts.map +1 -0
- package/dist/component/billing/schema.js +33 -0
- package/dist/component/billing/schema.js.map +1 -0
- package/dist/component/billing/validators.d.ts +364 -0
- package/dist/component/billing/validators.d.ts.map +1 -0
- package/dist/component/billing/validators.js +98 -0
- package/dist/component/billing/validators.js.map +1 -0
- package/dist/component/connect/mutations.d.ts +182 -0
- package/dist/component/connect/mutations.d.ts.map +1 -0
- package/dist/component/connect/mutations.js +480 -0
- package/dist/component/connect/mutations.js.map +1 -0
- package/dist/component/connect/queries.d.ts +347 -0
- package/dist/component/connect/queries.d.ts.map +1 -0
- package/dist/component/connect/queries.js +449 -0
- package/dist/component/connect/queries.js.map +1 -0
- package/dist/component/connect/schema.d.ts +258 -0
- package/dist/component/connect/schema.d.ts.map +1 -0
- package/dist/component/connect/schema.js +70 -0
- package/dist/component/connect/schema.js.map +1 -0
- package/dist/component/connect/validators.d.ts +468 -0
- package/dist/component/connect/validators.d.ts.map +1 -0
- package/dist/component/connect/validators.js +250 -0
- package/dist/component/connect/validators.js.map +1 -0
- package/dist/component/convex.config.d.ts +5 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +17 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/core/mutations.d.ts +52 -0
- package/dist/component/core/mutations.d.ts.map +1 -0
- package/dist/component/core/mutations.js +153 -0
- package/dist/component/core/mutations.js.map +1 -0
- package/dist/component/core/queries.d.ts +95 -0
- package/dist/component/core/queries.d.ts.map +1 -0
- package/dist/component/core/queries.js +86 -0
- package/dist/component/core/queries.js.map +1 -0
- package/dist/component/core/schema.d.ts +41 -0
- package/dist/component/core/schema.d.ts.map +1 -0
- package/dist/component/core/schema.js +12 -0
- package/dist/component/core/schema.js.map +1 -0
- package/dist/component/core/validators.d.ts +65 -0
- package/dist/component/core/validators.d.ts.map +1 -0
- package/dist/component/core/validators.js +35 -0
- package/dist/component/core/validators.js.map +1 -0
- package/dist/component/lib/fees.d.ts +74 -0
- package/dist/component/lib/fees.d.ts.map +1 -0
- package/dist/component/lib/fees.js +51 -0
- package/dist/component/lib/fees.js.map +1 -0
- package/dist/component/lib/idempotency.d.ts +9 -0
- package/dist/component/lib/idempotency.d.ts.map +1 -0
- package/dist/component/lib/idempotency.js +18 -0
- package/dist/component/lib/idempotency.js.map +1 -0
- package/dist/component/lib/reversals.d.ts +48 -0
- package/dist/component/lib/reversals.d.ts.map +1 -0
- package/dist/component/lib/reversals.js +79 -0
- package/dist/component/lib/reversals.js.map +1 -0
- package/dist/component/lib/stripeFactory.d.ts +7 -0
- package/dist/component/lib/stripeFactory.d.ts.map +1 -0
- package/dist/component/lib/stripeFactory.js +28 -0
- package/dist/component/lib/stripeFactory.js.map +1 -0
- package/dist/component/products/mutations.d.ts +22 -0
- package/dist/component/products/mutations.d.ts.map +1 -0
- package/dist/component/products/mutations.js +63 -0
- package/dist/component/products/mutations.js.map +1 -0
- package/dist/component/products/queries.d.ts +109 -0
- package/dist/component/products/queries.d.ts.map +1 -0
- package/dist/component/products/queries.js +122 -0
- package/dist/component/products/queries.js.map +1 -0
- package/dist/component/products/schema.d.ts +58 -0
- package/dist/component/products/schema.d.ts.map +1 -0
- package/dist/component/products/schema.js +20 -0
- package/dist/component/products/schema.js.map +1 -0
- package/dist/component/products/validators.d.ts +86 -0
- package/dist/component/products/validators.d.ts.map +1 -0
- package/dist/component/products/validators.js +47 -0
- package/dist/component/products/validators.js.map +1 -0
- package/dist/component/schema.d.ts +555 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +28 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/webhooks/mutations.d.ts +30 -0
- package/dist/component/webhooks/mutations.d.ts.map +1 -0
- package/dist/component/webhooks/mutations.js +124 -0
- package/dist/component/webhooks/mutations.js.map +1 -0
- package/dist/component/webhooks/queries.d.ts +35 -0
- package/dist/component/webhooks/queries.d.ts.map +1 -0
- package/dist/component/webhooks/queries.js +41 -0
- package/dist/component/webhooks/queries.js.map +1 -0
- package/dist/component/webhooks/schema.d.ts +22 -0
- package/dist/component/webhooks/schema.d.ts.map +1 -0
- package/dist/component/webhooks/schema.js +9 -0
- package/dist/component/webhooks/schema.js.map +1 -0
- package/dist/component/webhooks/validators.d.ts +37 -0
- package/dist/component/webhooks/validators.d.ts.map +1 -0
- package/dist/component/webhooks/validators.js +22 -0
- package/dist/component/webhooks/validators.js.map +1 -0
- package/dist/react/components/AccountCloseButton.d.ts +42 -0
- package/dist/react/components/AccountCloseButton.d.ts.map +1 -0
- package/dist/react/components/AccountCloseButton.js +33 -0
- package/dist/react/components/AccountCloseButton.js.map +1 -0
- package/dist/react/components/AccountCloseCard.d.ts +31 -0
- package/dist/react/components/AccountCloseCard.d.ts.map +1 -0
- package/dist/react/components/AccountCloseCard.js +22 -0
- package/dist/react/components/AccountCloseCard.js.map +1 -0
- package/dist/react/components/AccountCreateButton.d.ts +37 -0
- package/dist/react/components/AccountCreateButton.d.ts.map +1 -0
- package/dist/react/components/AccountCreateButton.js +30 -0
- package/dist/react/components/AccountCreateButton.js.map +1 -0
- package/dist/react/components/AccountCreateCard.d.ts +48 -0
- package/dist/react/components/AccountCreateCard.d.ts.map +1 -0
- package/dist/react/components/AccountCreateCard.js +29 -0
- package/dist/react/components/AccountCreateCard.js.map +1 -0
- package/dist/react/components/AccountLoginButton.d.ts +31 -0
- package/dist/react/components/AccountLoginButton.d.ts.map +1 -0
- package/dist/react/components/AccountLoginButton.js +31 -0
- package/dist/react/components/AccountLoginButton.js.map +1 -0
- package/dist/react/components/AccountLoginCard.d.ts +33 -0
- package/dist/react/components/AccountLoginCard.d.ts.map +1 -0
- package/dist/react/components/AccountLoginCard.js +19 -0
- package/dist/react/components/AccountLoginCard.js.map +1 -0
- package/dist/react/components/AccountOnboardingButton.d.ts +37 -0
- package/dist/react/components/AccountOnboardingButton.d.ts.map +1 -0
- package/dist/react/components/AccountOnboardingButton.js +30 -0
- package/dist/react/components/AccountOnboardingButton.js.map +1 -0
- package/dist/react/components/AccountOnboardingCard.d.ts +56 -0
- package/dist/react/components/AccountOnboardingCard.d.ts.map +1 -0
- package/dist/react/components/AccountOnboardingCard.js +36 -0
- package/dist/react/components/AccountOnboardingCard.js.map +1 -0
- package/dist/react/components/AddCardForm.d.ts +18 -0
- package/dist/react/components/AddCardForm.d.ts.map +1 -0
- package/dist/react/components/AddCardForm.js +49 -0
- package/dist/react/components/AddCardForm.js.map +1 -0
- package/dist/react/components/BillingPortalLink.d.ts +23 -0
- package/dist/react/components/BillingPortalLink.d.ts.map +1 -0
- package/dist/react/components/BillingPortalLink.js +55 -0
- package/dist/react/components/BillingPortalLink.js.map +1 -0
- package/dist/react/components/BuyerBillingView.d.ts +80 -0
- package/dist/react/components/BuyerBillingView.d.ts.map +1 -0
- package/dist/react/components/BuyerBillingView.js +44 -0
- package/dist/react/components/BuyerBillingView.js.map +1 -0
- package/dist/react/components/CheckoutSessionProvider.d.ts +34 -0
- package/dist/react/components/CheckoutSessionProvider.d.ts.map +1 -0
- package/dist/react/components/CheckoutSessionProvider.js +38 -0
- package/dist/react/components/CheckoutSessionProvider.js.map +1 -0
- package/dist/react/components/CheckoutSessionProviderWithKey.d.ts +36 -0
- package/dist/react/components/CheckoutSessionProviderWithKey.d.ts.map +1 -0
- package/dist/react/components/CheckoutSessionProviderWithKey.js +36 -0
- package/dist/react/components/CheckoutSessionProviderWithKey.js.map +1 -0
- package/dist/react/components/CheckoutStatus.d.ts +25 -0
- package/dist/react/components/CheckoutStatus.d.ts.map +1 -0
- package/dist/react/components/CheckoutStatus.js +22 -0
- package/dist/react/components/CheckoutStatus.js.map +1 -0
- package/dist/react/components/ConnectProvider.d.ts +29 -0
- package/dist/react/components/ConnectProvider.d.ts.map +1 -0
- package/dist/react/components/ConnectProvider.js +25 -0
- package/dist/react/components/ConnectProvider.js.map +1 -0
- package/dist/react/components/ConnectRequirements.d.ts +55 -0
- package/dist/react/components/ConnectRequirements.d.ts.map +1 -0
- package/dist/react/components/ConnectRequirements.js +58 -0
- package/dist/react/components/ConnectRequirements.js.map +1 -0
- package/dist/react/components/ConnectStatusBadge.d.ts +26 -0
- package/dist/react/components/ConnectStatusBadge.d.ts.map +1 -0
- package/dist/react/components/ConnectStatusBadge.js +20 -0
- package/dist/react/components/ConnectStatusBadge.js.map +1 -0
- package/dist/react/components/DeletePaymentMethodDialog.d.ts +25 -0
- package/dist/react/components/DeletePaymentMethodDialog.d.ts.map +1 -0
- package/dist/react/components/DeletePaymentMethodDialog.js +16 -0
- package/dist/react/components/DeletePaymentMethodDialog.js.map +1 -0
- package/dist/react/components/DisputeDetail.d.ts +42 -0
- package/dist/react/components/DisputeDetail.d.ts.map +1 -0
- package/dist/react/components/DisputeDetail.js +34 -0
- package/dist/react/components/DisputeDetail.js.map +1 -0
- package/dist/react/components/DisputesList.d.ts +42 -0
- package/dist/react/components/DisputesList.d.ts.map +1 -0
- package/dist/react/components/DisputesList.js +47 -0
- package/dist/react/components/DisputesList.js.map +1 -0
- package/dist/react/components/EarningsSummary.d.ts +53 -0
- package/dist/react/components/EarningsSummary.d.ts.map +1 -0
- package/dist/react/components/EarningsSummary.js +37 -0
- package/dist/react/components/EarningsSummary.js.map +1 -0
- package/dist/react/components/EmbeddedCheckout.d.ts +18 -0
- package/dist/react/components/EmbeddedCheckout.d.ts.map +1 -0
- package/dist/react/components/EmbeddedCheckout.js +17 -0
- package/dist/react/components/EmbeddedCheckout.js.map +1 -0
- package/dist/react/components/EmbeddedDisputes.d.ts +21 -0
- package/dist/react/components/EmbeddedDisputes.d.ts.map +1 -0
- package/dist/react/components/EmbeddedDisputes.js +17 -0
- package/dist/react/components/EmbeddedDisputes.js.map +1 -0
- package/dist/react/components/EvidenceForm.d.ts +63 -0
- package/dist/react/components/EvidenceForm.d.ts.map +1 -0
- package/dist/react/components/EvidenceForm.js +79 -0
- package/dist/react/components/EvidenceForm.js.map +1 -0
- package/dist/react/components/IntervalSelector.d.ts +20 -0
- package/dist/react/components/IntervalSelector.d.ts.map +1 -0
- package/dist/react/components/IntervalSelector.js +15 -0
- package/dist/react/components/IntervalSelector.js.map +1 -0
- package/dist/react/components/PaymentMethodActions.d.ts +27 -0
- package/dist/react/components/PaymentMethodActions.d.ts.map +1 -0
- package/dist/react/components/PaymentMethodActions.js +23 -0
- package/dist/react/components/PaymentMethodActions.js.map +1 -0
- package/dist/react/components/PaymentMethodsList.d.ts +32 -0
- package/dist/react/components/PaymentMethodsList.d.ts.map +1 -0
- package/dist/react/components/PaymentMethodsList.js +18 -0
- package/dist/react/components/PaymentMethodsList.js.map +1 -0
- package/dist/react/components/PayoutSchedule.d.ts +55 -0
- package/dist/react/components/PayoutSchedule.d.ts.map +1 -0
- package/dist/react/components/PayoutSchedule.js +51 -0
- package/dist/react/components/PayoutSchedule.js.map +1 -0
- package/dist/react/components/PriceBadge.d.ts +19 -0
- package/dist/react/components/PriceBadge.d.ts.map +1 -0
- package/dist/react/components/PriceBadge.js +25 -0
- package/dist/react/components/PriceBadge.js.map +1 -0
- package/dist/react/components/PriceCard.d.ts +34 -0
- package/dist/react/components/PriceCard.d.ts.map +1 -0
- package/dist/react/components/PriceCard.js +20 -0
- package/dist/react/components/PriceCard.js.map +1 -0
- package/dist/react/components/PricePicker.d.ts +28 -0
- package/dist/react/components/PricePicker.d.ts.map +1 -0
- package/dist/react/components/PricePicker.js +32 -0
- package/dist/react/components/PricePicker.js.map +1 -0
- package/dist/react/components/SplitBreakdown.d.ts +45 -0
- package/dist/react/components/SplitBreakdown.d.ts.map +1 -0
- package/dist/react/components/SplitBreakdown.js +48 -0
- package/dist/react/components/SplitBreakdown.js.map +1 -0
- package/dist/react/components/StripeProvider.d.ts +30 -0
- package/dist/react/components/StripeProvider.d.ts.map +1 -0
- package/dist/react/components/StripeProvider.js +38 -0
- package/dist/react/components/StripeProvider.js.map +1 -0
- package/dist/react/components/StripeProviderWithKey.d.ts +33 -0
- package/dist/react/components/StripeProviderWithKey.d.ts.map +1 -0
- package/dist/react/components/StripeProviderWithKey.js +44 -0
- package/dist/react/components/StripeProviderWithKey.js.map +1 -0
- package/dist/react/components/SubscriptionActions.d.ts +31 -0
- package/dist/react/components/SubscriptionActions.d.ts.map +1 -0
- package/dist/react/components/SubscriptionActions.js +30 -0
- package/dist/react/components/SubscriptionActions.js.map +1 -0
- package/dist/react/components/SubscriptionCard.d.ts +41 -0
- package/dist/react/components/SubscriptionCard.d.ts.map +1 -0
- package/dist/react/components/SubscriptionCard.js +18 -0
- package/dist/react/components/SubscriptionCard.js.map +1 -0
- package/dist/react/components/SubscriptionLineItems.d.ts +23 -0
- package/dist/react/components/SubscriptionLineItems.d.ts.map +1 -0
- package/dist/react/components/SubscriptionLineItems.js +20 -0
- package/dist/react/components/SubscriptionLineItems.js.map +1 -0
- package/dist/react/components/TrialAlert.d.ts +19 -0
- package/dist/react/components/TrialAlert.d.ts.map +1 -0
- package/dist/react/components/TrialAlert.js +16 -0
- package/dist/react/components/TrialAlert.js.map +1 -0
- package/dist/react/hooks/useAccount.d.ts +14 -0
- package/dist/react/hooks/useAccount.d.ts.map +1 -0
- package/dist/react/hooks/useAccount.js +18 -0
- package/dist/react/hooks/useAccount.js.map +1 -0
- package/dist/react/hooks/useAccountOnboarding.d.ts +15 -0
- package/dist/react/hooks/useAccountOnboarding.d.ts.map +1 -0
- package/dist/react/hooks/useAccountOnboarding.js +19 -0
- package/dist/react/hooks/useAccountOnboarding.js.map +1 -0
- package/dist/react/hooks/useCheckout.d.ts +14 -0
- package/dist/react/hooks/useCheckout.d.ts.map +1 -0
- package/dist/react/hooks/useCheckout.js +18 -0
- package/dist/react/hooks/useCheckout.js.map +1 -0
- package/dist/react/hooks/useCheckoutSession.d.ts +62 -0
- package/dist/react/hooks/useCheckoutSession.d.ts.map +1 -0
- package/dist/react/hooks/useCheckoutSession.js +68 -0
- package/dist/react/hooks/useCheckoutSession.js.map +1 -0
- package/dist/react/hooks/useConfirmPayment.d.ts +38 -0
- package/dist/react/hooks/useConfirmPayment.d.ts.map +1 -0
- package/dist/react/hooks/useConfirmPayment.js +91 -0
- package/dist/react/hooks/useConfirmPayment.js.map +1 -0
- package/dist/react/hooks/useDisputeWithCountdown.d.ts +25 -0
- package/dist/react/hooks/useDisputeWithCountdown.d.ts.map +1 -0
- package/dist/react/hooks/useDisputeWithCountdown.js +19 -0
- package/dist/react/hooks/useDisputeWithCountdown.js.map +1 -0
- package/dist/react/hooks/useDisputes.d.ts +14 -0
- package/dist/react/hooks/useDisputes.d.ts.map +1 -0
- package/dist/react/hooks/useDisputes.js +15 -0
- package/dist/react/hooks/useDisputes.js.map +1 -0
- package/dist/react/hooks/useEarnings.d.ts +92 -0
- package/dist/react/hooks/useEarnings.d.ts.map +1 -0
- package/dist/react/hooks/useEarnings.js +35 -0
- package/dist/react/hooks/useEarnings.js.map +1 -0
- package/dist/react/hooks/useInvoices.d.ts +11 -0
- package/dist/react/hooks/useInvoices.d.ts.map +1 -0
- package/dist/react/hooks/useInvoices.js +11 -0
- package/dist/react/hooks/useInvoices.js.map +1 -0
- package/dist/react/hooks/usePaymentMethodActions.d.ts +74 -0
- package/dist/react/hooks/usePaymentMethodActions.d.ts.map +1 -0
- package/dist/react/hooks/usePaymentMethodActions.js +156 -0
- package/dist/react/hooks/usePaymentMethodActions.js.map +1 -0
- package/dist/react/hooks/usePaymentMethods.d.ts +23 -0
- package/dist/react/hooks/usePaymentMethods.d.ts.map +1 -0
- package/dist/react/hooks/usePaymentMethods.js +18 -0
- package/dist/react/hooks/usePaymentMethods.js.map +1 -0
- package/dist/react/hooks/usePrices.d.ts +12 -0
- package/dist/react/hooks/usePrices.d.ts.map +1 -0
- package/dist/react/hooks/usePrices.js +16 -0
- package/dist/react/hooks/usePrices.js.map +1 -0
- package/dist/react/hooks/useProducts.d.ts +10 -0
- package/dist/react/hooks/useProducts.d.ts.map +1 -0
- package/dist/react/hooks/useProducts.js +11 -0
- package/dist/react/hooks/useProducts.js.map +1 -0
- package/dist/react/hooks/useSplitBreakdown.d.ts +58 -0
- package/dist/react/hooks/useSplitBreakdown.d.ts.map +1 -0
- package/dist/react/hooks/useSplitBreakdown.js +59 -0
- package/dist/react/hooks/useSplitBreakdown.js.map +1 -0
- package/dist/react/hooks/useStripeConfig.d.ts +14 -0
- package/dist/react/hooks/useStripeConfig.d.ts.map +1 -0
- package/dist/react/hooks/useStripeConfig.js +21 -0
- package/dist/react/hooks/useStripeConfig.js.map +1 -0
- package/dist/react/hooks/useStripeMode.d.ts +3 -0
- package/dist/react/hooks/useStripeMode.d.ts.map +1 -0
- package/dist/react/hooks/useStripeMode.js +6 -0
- package/dist/react/hooks/useStripeMode.js.map +1 -0
- package/dist/react/hooks/useStripePublishableKey.d.ts +2 -0
- package/dist/react/hooks/useStripePublishableKey.d.ts.map +1 -0
- package/dist/react/hooks/useStripePublishableKey.js +6 -0
- package/dist/react/hooks/useStripePublishableKey.js.map +1 -0
- package/dist/react/hooks/useSubscription.d.ts +17 -0
- package/dist/react/hooks/useSubscription.d.ts.map +1 -0
- package/dist/react/hooks/useSubscription.js +30 -0
- package/dist/react/hooks/useSubscription.js.map +1 -0
- package/dist/react/hooks/useSubscriptions.d.ts +11 -0
- package/dist/react/hooks/useSubscriptions.d.ts.map +1 -0
- package/dist/react/hooks/useSubscriptions.js +13 -0
- package/dist/react/hooks/useSubscriptions.js.map +1 -0
- package/dist/react/index.d.ts +108 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +87 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/lib/connect-requirement-keys.d.ts +14 -0
- package/dist/react/lib/connect-requirement-keys.d.ts.map +1 -0
- package/dist/react/lib/connect-requirement-keys.js +57 -0
- package/dist/react/lib/connect-requirement-keys.js.map +1 -0
- package/dist/react/lib/price-helpers.d.ts +31 -0
- package/dist/react/lib/price-helpers.d.ts.map +1 -0
- package/dist/react/lib/price-helpers.js +46 -0
- package/dist/react/lib/price-helpers.js.map +1 -0
- package/dist/react/lib/stripe-element-styles.d.ts +91 -0
- package/dist/react/lib/stripe-element-styles.d.ts.map +1 -0
- package/dist/react/lib/stripe-element-styles.js +131 -0
- package/dist/react/lib/stripe-element-styles.js.map +1 -0
- package/dist/react/lib/subscription-helpers.d.ts +33 -0
- package/dist/react/lib/subscription-helpers.d.ts.map +1 -0
- package/dist/react/lib/subscription-helpers.js +47 -0
- package/dist/react/lib/subscription-helpers.js.map +1 -0
- package/dist/react/types.d.ts +20 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react/types.js +2 -0
- package/dist/react/types.js.map +1 -0
- package/dist/testing/assert-test-env.d.ts +6 -0
- package/dist/testing/assert-test-env.d.ts.map +1 -0
- package/dist/testing/assert-test-env.js +15 -0
- package/dist/testing/assert-test-env.js.map +1 -0
- package/dist/testing/fixtures.d.ts +38 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +54 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mock-webhooks.d.ts +19 -0
- package/dist/testing/mock-webhooks.d.ts.map +1 -0
- package/dist/testing/mock-webhooks.js +81 -0
- package/dist/testing/mock-webhooks.js.map +1 -0
- package/package.json +131 -0
- package/src/client/billing/checkout.test.ts +1234 -0
- package/src/client/billing/checkout.ts +416 -0
- package/src/client/billing/invoices.test.ts +237 -0
- package/src/client/billing/invoices.ts +93 -0
- package/src/client/billing/subscriptions.test.ts +987 -0
- package/src/client/billing/subscriptions.ts +604 -0
- package/src/client/component-api-types.test.ts +137 -0
- package/src/client/connect/disputes.test.ts +487 -0
- package/src/client/connect/disputes.ts +302 -0
- package/src/client/connect/paymentMethodUtils.test.ts +83 -0
- package/src/client/connect/paymentMethodUtils.ts +28 -0
- package/src/client/connect/paymentMethods.test.ts +66 -0
- package/src/client/connect/paymentMethods.ts +55 -0
- package/src/client/connect/payouts.test.ts +132 -0
- package/src/client/connect/payouts.ts +105 -0
- package/src/client/connect/refundActor.test.ts +121 -0
- package/src/client/connect/refundActor.ts +60 -0
- package/src/client/connect/refunds.test.ts +341 -0
- package/src/client/connect/refunds.ts +256 -0
- package/src/client/connect/transfers.test.ts +492 -0
- package/src/client/connect/transfers.ts +572 -0
- package/src/client/constants.ts +15 -0
- package/src/client/core/accountLinks.test.ts +378 -0
- package/src/client/core/accountLinks.ts +211 -0
- package/src/client/core/accountStatus.test.ts +102 -0
- package/src/client/core/accountStatus.ts +91 -0
- package/src/client/core/accounts.test.ts +1496 -0
- package/src/client/core/accounts.ts +667 -0
- package/src/client/core/config.test.ts +68 -0
- package/src/client/core/config.ts +27 -0
- package/src/client/core/descriptors.test.ts +68 -0
- package/src/client/core/descriptors.ts +46 -0
- package/src/client/core/fees.test.ts +377 -0
- package/src/client/core/fees.ts +268 -0
- package/src/client/errors.test.ts +66 -0
- package/src/client/errors.ts +70 -0
- package/src/client/helpers.test.ts +74 -0
- package/src/client/helpers.ts +94 -0
- package/src/client/index.test.ts +1848 -0
- package/src/client/index.ts +1872 -0
- package/src/client/products/prices.test.ts +345 -0
- package/src/client/products/prices.ts +194 -0
- package/src/client/products/products.test.ts +476 -0
- package/src/client/products/products.ts +335 -0
- package/src/client/setup.test.ts +47 -0
- package/src/client/stripe-types.ts +108 -0
- package/src/client/types/documents.ts +245 -0
- package/src/client/types/events.ts +72 -0
- package/src/client/types/index.ts +43 -0
- package/src/client/types/options.ts +103 -0
- package/src/client/types/triggers.ts +293 -0
- package/src/client/types.ts +35 -0
- package/src/client/utils/data.test.ts +59 -0
- package/src/client/utils/data.ts +22 -0
- package/src/client/utils/owner.test.ts +35 -0
- package/src/client/utils/owner.ts +27 -0
- package/src/client/utils/stripeDashboardUrl.test.ts +71 -0
- package/src/client/utils/stripeDashboardUrl.ts +71 -0
- package/src/client/utils/webhookEndpoints.test.ts +454 -0
- package/src/client/utils/webhookEndpoints.ts +271 -0
- package/src/client/webhook-handlers.test.ts +603 -0
- package/src/client/webhooks/handler.test.ts +604 -0
- package/src/client/webhooks/handler.ts +256 -0
- package/src/client/webhooks/helpers.test.ts +330 -0
- package/src/client/webhooks/helpers.ts +277 -0
- package/src/client/webhooks/hooks.test.ts +111 -0
- package/src/client/webhooks/hooks.ts +177 -0
- package/src/client/webhooks/index.ts +51 -0
- package/src/client/webhooks/processors.test.ts +2392 -0
- package/src/client/webhooks/processors.ts +1166 -0
- package/src/client/webhooks/v2.test.ts +396 -0
- package/src/client/webhooks/v2.ts +124 -0
- package/src/client/webhooks.test.ts +1689 -0
- package/src/client/webhooks.ts +3 -0
- package/src/component/_generated/api.ts +86 -0
- package/src/component/_generated/component.ts +1758 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +164 -0
- package/src/component/billing/mutations.ts +155 -0
- package/src/component/billing/queries.ts +378 -0
- package/src/component/billing/schema.ts +40 -0
- package/src/component/billing/validators.ts +137 -0
- package/src/component/config-queries.test.ts +47 -0
- package/src/component/connect/mutations.ts +624 -0
- package/src/component/connect/queries.ts +537 -0
- package/src/component/connect/schema.ts +90 -0
- package/src/component/connect/validators.ts +333 -0
- package/src/component/connect.test.ts +721 -0
- package/src/component/convex.config.ts +17 -0
- package/src/component/core/mutations.ts +182 -0
- package/src/component/core/queries.ts +100 -0
- package/src/component/core/schema.ts +13 -0
- package/src/component/core/validators.ts +55 -0
- package/src/component/earnings-totals.test.ts +196 -0
- package/src/component/fee-routing.test.ts +124 -0
- package/src/component/lib/fees.ts +64 -0
- package/src/component/lib/idempotency.test.ts +37 -0
- package/src/component/lib/idempotency.ts +20 -0
- package/src/component/lib/reversals.ts +113 -0
- package/src/component/lib/stripeFactory.ts +30 -0
- package/src/component/products/mutations.ts +73 -0
- package/src/component/products/queries.ts +149 -0
- package/src/component/products/schema.ts +22 -0
- package/src/component/products/validators.ts +63 -0
- package/src/component/public.test.ts +1858 -0
- package/src/component/reversal-races.test.ts +920 -0
- package/src/component/schema.ts +45 -0
- package/src/component/subscription-scoping.test.ts +118 -0
- package/src/component/transfers.test.ts +402 -0
- package/src/component/triggers.test.ts +359 -0
- package/src/component/webhooks/mutations.ts +151 -0
- package/src/component/webhooks/queries.ts +44 -0
- package/src/component/webhooks/schema.ts +10 -0
- package/src/component/webhooks/validators.ts +30 -0
- package/src/react/components/AccountCloseButton.tsx +91 -0
- package/src/react/components/AccountCloseCard.tsx +84 -0
- package/src/react/components/AccountCreateButton.tsx +83 -0
- package/src/react/components/AccountCreateCard.tsx +123 -0
- package/src/react/components/AccountLoginButton.tsx +69 -0
- package/src/react/components/AccountLoginCard.tsx +99 -0
- package/src/react/components/AccountOnboardingButton.tsx +83 -0
- package/src/react/components/AccountOnboardingCard.test.ts +27 -0
- package/src/react/components/AccountOnboardingCard.tsx +152 -0
- package/src/react/components/AddCardForm.tsx +80 -0
- package/src/react/components/BillingPortalLink.tsx +93 -0
- package/src/react/components/BuyerBillingView.render.test.tsx +207 -0
- package/src/react/components/BuyerBillingView.tsx +193 -0
- package/src/react/components/CheckoutSessionProvider.tsx +70 -0
- package/src/react/components/CheckoutSessionProviderWithKey.tsx +99 -0
- package/src/react/components/CheckoutStatus.tsx +71 -0
- package/src/react/components/ConnectProvider.tsx +58 -0
- package/src/react/components/ConnectRequirements.tsx +159 -0
- package/src/react/components/ConnectStatusBadge.tsx +60 -0
- package/src/react/components/DeletePaymentMethodDialog.tsx +61 -0
- package/src/react/components/DisputeDetail.render.test.tsx +143 -0
- package/src/react/components/DisputeDetail.tsx +111 -0
- package/src/react/components/DisputesList.render.test.tsx +244 -0
- package/src/react/components/DisputesList.tsx +120 -0
- package/src/react/components/EarningsSummary.render.test.tsx +153 -0
- package/src/react/components/EarningsSummary.tsx +131 -0
- package/src/react/components/EmbeddedCheckout.test.ts +25 -0
- package/src/react/components/EmbeddedCheckout.tsx +54 -0
- package/src/react/components/EmbeddedDisputes.render.test.tsx +142 -0
- package/src/react/components/EmbeddedDisputes.tsx +38 -0
- package/src/react/components/EvidenceForm.render.test.tsx +215 -0
- package/src/react/components/EvidenceForm.tsx +176 -0
- package/src/react/components/IntervalSelector.tsx +58 -0
- package/src/react/components/PaymentMethodActions.tsx +68 -0
- package/src/react/components/PaymentMethodsList.tsx +81 -0
- package/src/react/components/PayoutSchedule.render.test.tsx +178 -0
- package/src/react/components/PayoutSchedule.tsx +148 -0
- package/src/react/components/PriceBadge.render.test.tsx +134 -0
- package/src/react/components/PriceBadge.tsx +49 -0
- package/src/react/components/PriceCard.render.test.tsx +135 -0
- package/src/react/components/PriceCard.tsx +83 -0
- package/src/react/components/PricePicker.tsx +95 -0
- package/src/react/components/SplitBreakdown.render.test.tsx +168 -0
- package/src/react/components/SplitBreakdown.tsx +121 -0
- package/src/react/components/StripeProvider.test.ts +45 -0
- package/src/react/components/StripeProvider.tsx +80 -0
- package/src/react/components/StripeProviderWithKey.tsx +95 -0
- package/src/react/components/SubscriptionActions.tsx +79 -0
- package/src/react/components/SubscriptionCard.tsx +92 -0
- package/src/react/components/SubscriptionLineItems.tsx +62 -0
- package/src/react/components/TrialAlert.render.test.tsx +132 -0
- package/src/react/components/TrialAlert.tsx +44 -0
- package/src/react/hooks/skipSentinel.test.ts +85 -0
- package/src/react/hooks/useAccount.ts +28 -0
- package/src/react/hooks/useAccountOnboarding.test.ts +75 -0
- package/src/react/hooks/useAccountOnboarding.ts +35 -0
- package/src/react/hooks/useCheckout.ts +33 -0
- package/src/react/hooks/useCheckoutSession.ts +110 -0
- package/src/react/hooks/useConfirmPayment.ts +117 -0
- package/src/react/hooks/useDisputeWithCountdown.test.ts +90 -0
- package/src/react/hooks/useDisputeWithCountdown.ts +48 -0
- package/src/react/hooks/useDisputes.test.ts +75 -0
- package/src/react/hooks/useDisputes.ts +28 -0
- package/src/react/hooks/useEarnings.test.ts +159 -0
- package/src/react/hooks/useEarnings.ts +132 -0
- package/src/react/hooks/useInvoices.test.ts +79 -0
- package/src/react/hooks/useInvoices.ts +25 -0
- package/src/react/hooks/usePaymentMethodActions.ts +206 -0
- package/src/react/hooks/usePaymentMethods.ts +44 -0
- package/src/react/hooks/usePrices.ts +26 -0
- package/src/react/hooks/useProducts.test.ts +75 -0
- package/src/react/hooks/useProducts.ts +24 -0
- package/src/react/hooks/useSplitBreakdown.test.ts +151 -0
- package/src/react/hooks/useSplitBreakdown.ts +118 -0
- package/src/react/hooks/useStripeConfig.ts +31 -0
- package/src/react/hooks/useStripeMode.test.ts +49 -0
- package/src/react/hooks/useStripeMode.ts +9 -0
- package/src/react/hooks/useStripePublishableKey.test.ts +35 -0
- package/src/react/hooks/useStripePublishableKey.ts +9 -0
- package/src/react/hooks/useSubscription.ts +52 -0
- package/src/react/hooks/useSubscriptions.ts +33 -0
- package/src/react/index.payment-element.test.ts +41 -0
- package/src/react/index.test.ts +167 -0
- package/src/react/index.ts +279 -0
- package/src/react/lib/connect-requirement-keys.test.ts +73 -0
- package/src/react/lib/connect-requirement-keys.ts +66 -0
- package/src/react/lib/price-helpers.test.ts +199 -0
- package/src/react/lib/price-helpers.ts +68 -0
- package/src/react/lib/stripe-element-styles.test.ts +94 -0
- package/src/react/lib/stripe-element-styles.ts +178 -0
- package/src/react/lib/subscription-helpers.test.ts +127 -0
- package/src/react/lib/subscription-helpers.ts +64 -0
- package/src/react/types.ts +32 -0
- package/src/test.ts +5 -0
- package/src/testing/assert-test-env.test.ts +33 -0
- package/src/testing/assert-test-env.ts +20 -0
- package/src/testing/fixtures.ts +95 -0
- package/src/testing/index.ts +13 -0
- package/src/testing/mock-webhooks.test.ts +97 -0
- package/src/testing/mock-webhooks.ts +101 -0
- package/src/vite-env.d.ts +4 -0
|
@@ -0,0 +1,1496 @@
|
|
|
1
|
+
// @vitest-environment edge-runtime
|
|
2
|
+
/**
|
|
3
|
+
* Tests for the core Account methods. These functions span three boundaries:
|
|
4
|
+
* the Stripe V2 Accounts SDK (`stripe.v2.core.accounts.*` plus `accountLinks`),
|
|
5
|
+
* the component query/mutation layer (resolved via `componentRef`), and the
|
|
6
|
+
* `deriveAccountStatus` helper. The headline targets are the multi-step
|
|
7
|
+
* orchestrators — `createAccount`, `createAccountWithOnboarding` (with its
|
|
8
|
+
* rollback path), `getOrCreateAccount`, `closeAccount` (DB-vs-Stripe fallback),
|
|
9
|
+
* `listStripeAccounts`, and `syncAllAccounts` (SDK auto-pagination via
|
|
10
|
+
* `for await` + per-record error accumulation). We assert the exact params handed to each boundary, the
|
|
11
|
+
* shapes returned, every branch, and the error/rollback paths.
|
|
12
|
+
*
|
|
13
|
+
* Most of the suite mocks `ctx`/the component entirely (fast, boundary-focused
|
|
14
|
+
* unit tests). The `addRecipientConfiguration` idempotency test (BTS-78) is
|
|
15
|
+
* the exception: it runs against a REAL `convex-test` store — see the
|
|
16
|
+
* "addRecipientConfiguration (real convex-test store)" describe block below —
|
|
17
|
+
* because a genuine double-write/overwrite conflict needs a real row to
|
|
18
|
+
* conflict against; a fully-mocked `runMutation` can never fail that way.
|
|
19
|
+
*/
|
|
20
|
+
import { describe, expect, it, vi } from "vitest";
|
|
21
|
+
|
|
22
|
+
import type { Component, RunCtx } from "../helpers.js";
|
|
23
|
+
import { components, initConvexTest } from "../setup.test.js";
|
|
24
|
+
import schema from "../../component/schema.js";
|
|
25
|
+
import {
|
|
26
|
+
DEFAULT_ACCOUNT_CONFIGURATION,
|
|
27
|
+
DEFAULT_ACCOUNT_DEFAULTS,
|
|
28
|
+
DEFAULT_CUSTOMER_CONFIGURATION,
|
|
29
|
+
addCustomerConfiguration,
|
|
30
|
+
addRecipientConfiguration,
|
|
31
|
+
ensureCustomerAccount,
|
|
32
|
+
closeAccount,
|
|
33
|
+
createAccount,
|
|
34
|
+
createAccountWithOnboarding,
|
|
35
|
+
getAccount,
|
|
36
|
+
getAccountByOrgId,
|
|
37
|
+
getAccountByStripeId,
|
|
38
|
+
getAccountByUserId,
|
|
39
|
+
getAccountOnboardingStatus,
|
|
40
|
+
getOrCreateAccount,
|
|
41
|
+
getV2Account,
|
|
42
|
+
listStripeAccounts,
|
|
43
|
+
restartAccountOnboarding,
|
|
44
|
+
setAccountStatementDescriptor,
|
|
45
|
+
syncAllAccounts,
|
|
46
|
+
updateAccount,
|
|
47
|
+
updateV2Account,
|
|
48
|
+
upsertAccount,
|
|
49
|
+
} from "./accounts.js";
|
|
50
|
+
|
|
51
|
+
const TO_REF = Symbol.for("toReferencePath");
|
|
52
|
+
|
|
53
|
+
/** A fake component whose nested refs carry the Symbol the resolver looks up. */
|
|
54
|
+
function makeComponent(): Component {
|
|
55
|
+
const ref = (path: string) => ({ [TO_REF]: `betterStripe/${path}` });
|
|
56
|
+
return {
|
|
57
|
+
core: {
|
|
58
|
+
queries: {
|
|
59
|
+
getAccount: ref("core/queries/getAccount"),
|
|
60
|
+
getAccountByStripeId: ref("core/queries/getAccountByStripeId"),
|
|
61
|
+
getAccountByUserId: ref("core/queries/getAccountByUserId"),
|
|
62
|
+
getAccountByOrgId: ref("core/queries/getAccountByOrgId"),
|
|
63
|
+
getAccountOnboardingStatus: ref(
|
|
64
|
+
"core/queries/getAccountOnboardingStatus",
|
|
65
|
+
),
|
|
66
|
+
},
|
|
67
|
+
mutations: {
|
|
68
|
+
upsertAccount: ref("core/mutations/upsertAccount"),
|
|
69
|
+
deleteAccountByStripeId: ref("core/mutations/deleteAccountByStripeId"),
|
|
70
|
+
setStatementDescriptor: ref("core/mutations/setStatementDescriptor"),
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
} as unknown as Component;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The reference object the resolver returns for a given path. */
|
|
77
|
+
function refFor(path: string) {
|
|
78
|
+
return { [TO_REF]: `betterStripe/${path}` };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Build a mock Stripe instance exposing only the slice these helpers touch. */
|
|
82
|
+
function makeStripe() {
|
|
83
|
+
return {
|
|
84
|
+
v2: {
|
|
85
|
+
core: {
|
|
86
|
+
accounts: {
|
|
87
|
+
create: vi.fn(),
|
|
88
|
+
update: vi.fn(),
|
|
89
|
+
retrieve: vi.fn(),
|
|
90
|
+
list: vi.fn(),
|
|
91
|
+
close: vi.fn(),
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
accountLinks: { create: vi.fn() },
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
type MockStripe = ReturnType<typeof makeStripe>;
|
|
100
|
+
const asStripe = (s: MockStripe) =>
|
|
101
|
+
s as unknown as Parameters<typeof createAccount>[0];
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Real V2 list responses (`stripe.v2.core.accounts.list(...)`) are an
|
|
105
|
+
* `AsyncIterableIterator` that follows `next_page_url` internally — they do
|
|
106
|
+
* NOT resolve to a plain `{ data, has_more }` object a caller can inspect.
|
|
107
|
+
* This mirrors that shape so `for await` consumes it the same way it would
|
|
108
|
+
* consume the real SDK response.
|
|
109
|
+
*/
|
|
110
|
+
function asyncIterable<T>(items: T[]) {
|
|
111
|
+
return {
|
|
112
|
+
async *[Symbol.asyncIterator]() {
|
|
113
|
+
for (const item of items) yield item;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// =============================================================================
|
|
119
|
+
// Real convex-test store helpers (BTS-78) — used only by the
|
|
120
|
+
// "addRecipientConfiguration (real convex-test store)" suite below. Registers
|
|
121
|
+
// the component as an actual CHILD COMPONENT named "betterStripe" (mirroring
|
|
122
|
+
// how an installing app wires it up in production, via
|
|
123
|
+
// `app.use(betterStripe, ...)`), so `components.betterStripe.*` — the same
|
|
124
|
+
// typed proxy `setup.test.ts` exports — resolves to REAL function references
|
|
125
|
+
// that `t.query`/`t.mutation` execute against a genuine in-memory backend,
|
|
126
|
+
// rather than a `vi.fn()`. (A flat `convexTest(componentSchema, componentModules)`
|
|
127
|
+
// with the component's own generated `api` doesn't work here: `componentRef`
|
|
128
|
+
// resolves via the childComponent `toReferencePath` symbol that only
|
|
129
|
+
// `componentsGeneric()`-based refs like `components.betterStripe.*` carry.)
|
|
130
|
+
// =============================================================================
|
|
131
|
+
const componentModules = import.meta.glob(
|
|
132
|
+
"../../component/**/*.{ts,js,tsx,jsx}",
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
/** A real convex-test instance with the component registered as child "betterStripe". */
|
|
136
|
+
function makeRealConvexTest() {
|
|
137
|
+
const t = initConvexTest();
|
|
138
|
+
t.registerComponent("betterStripe", schema, componentModules);
|
|
139
|
+
return t;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A `RunCtx` backed by a real convex-test instance. */
|
|
143
|
+
function makeRealCtx(t: ReturnType<typeof makeRealConvexTest>): RunCtx {
|
|
144
|
+
return {
|
|
145
|
+
runQuery: (ref: any, args: any) => t.query(ref, args),
|
|
146
|
+
runMutation: (ref: any, args: any) => t.mutation(ref, args),
|
|
147
|
+
} as unknown as RunCtx;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const realComponent = components.betterStripe as unknown as Component;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* `runInComponent` (read/write the mock backend scoped to a registered child
|
|
154
|
+
* component) isn't part of convex-test's public `.d.ts` surface, only its
|
|
155
|
+
* runtime API — narrow the cast to just this one method instead of reaching
|
|
156
|
+
* for `any` on the whole test handle.
|
|
157
|
+
*/
|
|
158
|
+
type RunInComponent = (
|
|
159
|
+
componentPath: string,
|
|
160
|
+
handler: (ctx: {
|
|
161
|
+
db: {
|
|
162
|
+
query: (table: "accounts") => {
|
|
163
|
+
collect: () => Promise<
|
|
164
|
+
Array<{ stripeAccountId: string; userId: string }>
|
|
165
|
+
>;
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
}) => Promise<Array<{ stripeAccountId: string; userId: string }>>,
|
|
169
|
+
) => Promise<Array<{ stripeAccountId: string; userId: string }>>;
|
|
170
|
+
|
|
171
|
+
describe("createAccount", () => {
|
|
172
|
+
it("creates the V2 account, upserts it, and returns the stored internal id", async () => {
|
|
173
|
+
const stripe = makeStripe();
|
|
174
|
+
stripe.v2.core.accounts.create.mockResolvedValue({ id: "acct_1" });
|
|
175
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
176
|
+
const runQuery = vi.fn().mockResolvedValue({ _id: "internal_1" });
|
|
177
|
+
const ctx = { runMutation, runQuery } as unknown as RunCtx;
|
|
178
|
+
|
|
179
|
+
const result = await createAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
180
|
+
userId: "user_1",
|
|
181
|
+
email: "a@b.com",
|
|
182
|
+
name: "Acme",
|
|
183
|
+
country: "US",
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
expect(result).toEqual({
|
|
187
|
+
accountId: "internal_1",
|
|
188
|
+
stripeAccountId: "acct_1",
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Stripe create params: contact_email + metadata (userId injected), identity from country
|
|
192
|
+
expect(stripe.v2.core.accounts.create).toHaveBeenCalledWith({
|
|
193
|
+
contact_email: "a@b.com",
|
|
194
|
+
metadata: { userId: "user_1" },
|
|
195
|
+
identity: { country: "US" },
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Upsert mutation carries the derived metadata and pending defaults
|
|
199
|
+
expect(runMutation).toHaveBeenCalledWith(
|
|
200
|
+
refFor("core/mutations/upsertAccount"),
|
|
201
|
+
{
|
|
202
|
+
stripeAccountId: "acct_1",
|
|
203
|
+
userId: "user_1",
|
|
204
|
+
orgId: undefined,
|
|
205
|
+
email: "a@b.com",
|
|
206
|
+
name: "Acme",
|
|
207
|
+
country: "US",
|
|
208
|
+
appliedConfigurations: [],
|
|
209
|
+
onboardingStatus: "pending",
|
|
210
|
+
metadata: { userId: "user_1" },
|
|
211
|
+
},
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
// Read-back query keyed by the new Stripe id
|
|
215
|
+
expect(runQuery).toHaveBeenCalledWith(
|
|
216
|
+
refFor("core/queries/getAccountByStripeId"),
|
|
217
|
+
{ stripeAccountId: "acct_1" },
|
|
218
|
+
);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("merges orgId and caller metadata, and omits identity when no country", async () => {
|
|
222
|
+
const stripe = makeStripe();
|
|
223
|
+
stripe.v2.core.accounts.create.mockResolvedValue({ id: "acct_2" });
|
|
224
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
225
|
+
const runQuery = vi.fn().mockResolvedValue({ _id: "internal_2" });
|
|
226
|
+
const ctx = { runMutation, runQuery } as unknown as RunCtx;
|
|
227
|
+
|
|
228
|
+
await createAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
229
|
+
userId: "user_2",
|
|
230
|
+
orgId: "org_2",
|
|
231
|
+
metadata: { plan: "pro" },
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const createArg = stripe.v2.core.accounts.create.mock.calls[0][0];
|
|
235
|
+
expect(createArg).toEqual({
|
|
236
|
+
contact_email: undefined,
|
|
237
|
+
metadata: { plan: "pro", userId: "user_2", orgId: "org_2" },
|
|
238
|
+
});
|
|
239
|
+
// no country → no identity key at all
|
|
240
|
+
expect("identity" in createArg).toBe(false);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("returns null accountId when the stored row cannot be read back", async () => {
|
|
244
|
+
const stripe = makeStripe();
|
|
245
|
+
stripe.v2.core.accounts.create.mockResolvedValue({ id: "acct_3" });
|
|
246
|
+
const ctx = {
|
|
247
|
+
runMutation: vi.fn().mockResolvedValue(undefined),
|
|
248
|
+
runQuery: vi.fn().mockResolvedValue(null),
|
|
249
|
+
} as unknown as RunCtx;
|
|
250
|
+
|
|
251
|
+
const result = await createAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
252
|
+
userId: "user_3",
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
expect(result).toEqual({ accountId: null, stripeAccountId: "acct_3" });
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("throws when ctx has no runMutation", async () => {
|
|
259
|
+
const stripe = makeStripe();
|
|
260
|
+
stripe.v2.core.accounts.create.mockResolvedValue({ id: "acct_4" });
|
|
261
|
+
const ctx = { runQuery: vi.fn() } as unknown as RunCtx;
|
|
262
|
+
|
|
263
|
+
await expect(
|
|
264
|
+
createAccount(asStripe(stripe), makeComponent(), ctx, { userId: "u" }),
|
|
265
|
+
).rejects.toThrow(/requires a Convex ctx with runMutation/);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe("createAccountWithOnboarding", () => {
|
|
270
|
+
function happyCtx() {
|
|
271
|
+
return {
|
|
272
|
+
runMutation: vi.fn().mockResolvedValue(undefined),
|
|
273
|
+
runQuery: vi.fn().mockResolvedValue({ _id: "internal_x" }),
|
|
274
|
+
} as unknown as RunCtx & { runMutation: ReturnType<typeof vi.fn> };
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
it("applies default configuration, re-fetches applied configs, and returns the onboarding url", async () => {
|
|
278
|
+
const stripe = makeStripe();
|
|
279
|
+
stripe.v2.core.accounts.create.mockResolvedValue({ id: "acct_ob" });
|
|
280
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
281
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({
|
|
282
|
+
applied_configurations: ["merchant"],
|
|
283
|
+
});
|
|
284
|
+
stripe.accountLinks.create.mockResolvedValue({ url: "https://onboard" });
|
|
285
|
+
const ctx = happyCtx();
|
|
286
|
+
|
|
287
|
+
const result = await createAccountWithOnboarding(
|
|
288
|
+
asStripe(stripe),
|
|
289
|
+
makeComponent(),
|
|
290
|
+
ctx,
|
|
291
|
+
{
|
|
292
|
+
userId: "user_ob",
|
|
293
|
+
country: "US",
|
|
294
|
+
refreshUrl: "https://refresh",
|
|
295
|
+
returnUrl: "https://return",
|
|
296
|
+
},
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
expect(result).toEqual({
|
|
300
|
+
stripeAccountId: "acct_ob",
|
|
301
|
+
onboardingUrl: "https://onboard",
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// defaults applied + dashboard defaults to "express"
|
|
305
|
+
expect(stripe.v2.core.accounts.update).toHaveBeenCalledWith("acct_ob", {
|
|
306
|
+
configuration: DEFAULT_ACCOUNT_CONFIGURATION,
|
|
307
|
+
dashboard: "express",
|
|
308
|
+
defaults: DEFAULT_ACCOUNT_DEFAULTS,
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// second upsert records the applied configs + in_progress status
|
|
312
|
+
const secondUpsert = (
|
|
313
|
+
ctx.runMutation as ReturnType<typeof vi.fn>
|
|
314
|
+
).mock.calls.find(
|
|
315
|
+
(c) =>
|
|
316
|
+
c[1].onboardingStatus === "in_progress" &&
|
|
317
|
+
c[1].stripeAccountId === "acct_ob",
|
|
318
|
+
);
|
|
319
|
+
expect(secondUpsert?.[1]).toEqual({
|
|
320
|
+
stripeAccountId: "acct_ob",
|
|
321
|
+
userId: "user_ob",
|
|
322
|
+
appliedConfigurations: ["merchant"],
|
|
323
|
+
onboardingStatus: "in_progress",
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// account link built with the right type + urls
|
|
327
|
+
expect(stripe.accountLinks.create).toHaveBeenCalledWith({
|
|
328
|
+
account: "acct_ob",
|
|
329
|
+
refresh_url: "https://refresh",
|
|
330
|
+
return_url: "https://return",
|
|
331
|
+
type: "account_onboarding",
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it("honours caller-provided configuration, defaults, and dashboard", async () => {
|
|
336
|
+
const stripe = makeStripe();
|
|
337
|
+
stripe.v2.core.accounts.create.mockResolvedValue({ id: "acct_cfg" });
|
|
338
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
339
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({});
|
|
340
|
+
stripe.accountLinks.create.mockResolvedValue({ url: "https://onboard" });
|
|
341
|
+
const ctx = happyCtx();
|
|
342
|
+
|
|
343
|
+
await createAccountWithOnboarding(asStripe(stripe), makeComponent(), ctx, {
|
|
344
|
+
userId: "user_cfg",
|
|
345
|
+
country: "GB",
|
|
346
|
+
refreshUrl: "https://refresh",
|
|
347
|
+
returnUrl: "https://return",
|
|
348
|
+
accountConfiguration: { recipient: {} },
|
|
349
|
+
accountDefaults: { locales: ["en"] },
|
|
350
|
+
dashboard: "none",
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
expect(stripe.v2.core.accounts.update).toHaveBeenCalledWith("acct_cfg", {
|
|
354
|
+
configuration: { recipient: {} },
|
|
355
|
+
dashboard: "none",
|
|
356
|
+
defaults: { locales: ["en"] },
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("defaults applied_configurations to [] when Stripe omits them", async () => {
|
|
361
|
+
const stripe = makeStripe();
|
|
362
|
+
stripe.v2.core.accounts.create.mockResolvedValue({ id: "acct_empty" });
|
|
363
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
364
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({}); // no applied_configurations
|
|
365
|
+
stripe.accountLinks.create.mockResolvedValue({ url: "https://onboard" });
|
|
366
|
+
const ctx = happyCtx();
|
|
367
|
+
|
|
368
|
+
await createAccountWithOnboarding(asStripe(stripe), makeComponent(), ctx, {
|
|
369
|
+
userId: "user_empty",
|
|
370
|
+
country: "US",
|
|
371
|
+
refreshUrl: "https://refresh",
|
|
372
|
+
returnUrl: "https://return",
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
const inProgress = (
|
|
376
|
+
ctx.runMutation as ReturnType<typeof vi.fn>
|
|
377
|
+
).mock.calls.find((c) => c[1].onboardingStatus === "in_progress");
|
|
378
|
+
expect(inProgress?.[1].appliedConfigurations).toEqual([]);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it("rolls back the Convex account and throws ACCOUNT_CREATE_FAILED when config update fails", async () => {
|
|
382
|
+
const stripe = makeStripe();
|
|
383
|
+
stripe.v2.core.accounts.create.mockResolvedValue({ id: "acct_fail" });
|
|
384
|
+
stripe.v2.core.accounts.update.mockRejectedValue(new Error("config boom"));
|
|
385
|
+
const ctx = happyCtx();
|
|
386
|
+
|
|
387
|
+
await expect(
|
|
388
|
+
createAccountWithOnboarding(asStripe(stripe), makeComponent(), ctx, {
|
|
389
|
+
userId: "user_fail",
|
|
390
|
+
country: "US",
|
|
391
|
+
refreshUrl: "https://refresh",
|
|
392
|
+
returnUrl: "https://return",
|
|
393
|
+
}),
|
|
394
|
+
).rejects.toMatchObject({ data: { code: "ACCOUNT_CREATE_FAILED" } });
|
|
395
|
+
|
|
396
|
+
// rollback deletes the half-created account
|
|
397
|
+
expect(ctx.runMutation).toHaveBeenCalledWith(
|
|
398
|
+
refFor("core/mutations/deleteAccountByStripeId"),
|
|
399
|
+
{ stripeAccountId: "acct_fail" },
|
|
400
|
+
);
|
|
401
|
+
// never reached the account-link creation
|
|
402
|
+
expect(stripe.accountLinks.create).not.toHaveBeenCalled();
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it("still throws ACCOUNT_CREATE_FAILED even if the rollback delete also fails", async () => {
|
|
406
|
+
const stripe = makeStripe();
|
|
407
|
+
stripe.v2.core.accounts.create.mockResolvedValue({ id: "acct_fail2" });
|
|
408
|
+
stripe.v2.core.accounts.update.mockRejectedValue(new Error("config boom"));
|
|
409
|
+
const runMutation = vi
|
|
410
|
+
.fn()
|
|
411
|
+
.mockResolvedValueOnce(undefined) // initial upsert in createAccount
|
|
412
|
+
.mockRejectedValueOnce(new Error("delete boom")); // rollback delete fails
|
|
413
|
+
const ctx = {
|
|
414
|
+
runMutation,
|
|
415
|
+
runQuery: vi.fn().mockResolvedValue({ _id: "internal_x" }),
|
|
416
|
+
} as unknown as RunCtx;
|
|
417
|
+
|
|
418
|
+
await expect(
|
|
419
|
+
createAccountWithOnboarding(asStripe(stripe), makeComponent(), ctx, {
|
|
420
|
+
userId: "user_fail2",
|
|
421
|
+
country: "US",
|
|
422
|
+
refreshUrl: "https://refresh",
|
|
423
|
+
returnUrl: "https://return",
|
|
424
|
+
}),
|
|
425
|
+
).rejects.toMatchObject({ data: { code: "ACCOUNT_CREATE_FAILED" } });
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
describe("getOrCreateAccount", () => {
|
|
430
|
+
it("returns an existing account looked up by orgId without creating", async () => {
|
|
431
|
+
const stripe = makeStripe();
|
|
432
|
+
const runQuery = vi.fn().mockResolvedValue({
|
|
433
|
+
_id: "internal_e",
|
|
434
|
+
stripeAccountId: "acct_existing",
|
|
435
|
+
});
|
|
436
|
+
const ctx = { runQuery, runMutation: vi.fn() } as unknown as RunCtx;
|
|
437
|
+
|
|
438
|
+
const result = await getOrCreateAccount(
|
|
439
|
+
asStripe(stripe),
|
|
440
|
+
makeComponent(),
|
|
441
|
+
ctx,
|
|
442
|
+
{ userId: "user_e", orgId: "org_e" },
|
|
443
|
+
);
|
|
444
|
+
|
|
445
|
+
expect(result).toEqual({
|
|
446
|
+
accountId: "internal_e",
|
|
447
|
+
stripeAccountId: "acct_existing",
|
|
448
|
+
isNew: false,
|
|
449
|
+
});
|
|
450
|
+
// orgId branch → getAccountByOrgId
|
|
451
|
+
expect(runQuery).toHaveBeenCalledWith(
|
|
452
|
+
refFor("core/queries/getAccountByOrgId"),
|
|
453
|
+
{ orgId: "org_e" },
|
|
454
|
+
);
|
|
455
|
+
expect(stripe.v2.core.accounts.create).not.toHaveBeenCalled();
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it("looks up by userId when no orgId is supplied", async () => {
|
|
459
|
+
const stripe = makeStripe();
|
|
460
|
+
const runQuery = vi.fn().mockResolvedValue({
|
|
461
|
+
_id: "internal_u",
|
|
462
|
+
stripeAccountId: "acct_u",
|
|
463
|
+
});
|
|
464
|
+
const ctx = { runQuery, runMutation: vi.fn() } as unknown as RunCtx;
|
|
465
|
+
|
|
466
|
+
await getOrCreateAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
467
|
+
userId: "user_u",
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
expect(runQuery).toHaveBeenCalledWith(
|
|
471
|
+
refFor("core/queries/getAccountByUserId"),
|
|
472
|
+
{ userId: "user_u" },
|
|
473
|
+
);
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it("creates a new account and flags isNew when none exists", async () => {
|
|
477
|
+
const stripe = makeStripe();
|
|
478
|
+
stripe.v2.core.accounts.create.mockResolvedValue({ id: "acct_new" });
|
|
479
|
+
// first query = existence check (null), second = read-back in createAccount
|
|
480
|
+
const runQuery = vi
|
|
481
|
+
.fn()
|
|
482
|
+
.mockResolvedValueOnce(null)
|
|
483
|
+
.mockResolvedValueOnce({ _id: "internal_new" });
|
|
484
|
+
const ctx = {
|
|
485
|
+
runQuery,
|
|
486
|
+
runMutation: vi.fn().mockResolvedValue(undefined),
|
|
487
|
+
} as unknown as RunCtx;
|
|
488
|
+
|
|
489
|
+
const result = await getOrCreateAccount(
|
|
490
|
+
asStripe(stripe),
|
|
491
|
+
makeComponent(),
|
|
492
|
+
ctx,
|
|
493
|
+
{ userId: "user_new" },
|
|
494
|
+
);
|
|
495
|
+
|
|
496
|
+
expect(result).toEqual({
|
|
497
|
+
accountId: "internal_new",
|
|
498
|
+
stripeAccountId: "acct_new",
|
|
499
|
+
isNew: true,
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
describe("read delegators", () => {
|
|
505
|
+
it("getAccount queries getAccount with the opts", async () => {
|
|
506
|
+
const runQuery = vi.fn().mockResolvedValue({ _id: "a" });
|
|
507
|
+
const ctx = { runQuery } as unknown as RunCtx;
|
|
508
|
+
const result = await getAccount(makeComponent(), ctx, { accountId: "a" });
|
|
509
|
+
expect(result).toEqual({ _id: "a" });
|
|
510
|
+
expect(runQuery).toHaveBeenCalledWith(refFor("core/queries/getAccount"), {
|
|
511
|
+
accountId: "a",
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
it("getAccountByUserId queries getAccountByUserId", async () => {
|
|
516
|
+
const runQuery = vi.fn().mockResolvedValue(null);
|
|
517
|
+
const ctx = { runQuery } as unknown as RunCtx;
|
|
518
|
+
const result = await getAccountByUserId(makeComponent(), ctx, {
|
|
519
|
+
userId: "u",
|
|
520
|
+
});
|
|
521
|
+
expect(result).toBeNull();
|
|
522
|
+
expect(runQuery).toHaveBeenCalledWith(
|
|
523
|
+
refFor("core/queries/getAccountByUserId"),
|
|
524
|
+
{ userId: "u" },
|
|
525
|
+
);
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
it("getAccountByOrgId queries getAccountByOrgId", async () => {
|
|
529
|
+
const runQuery = vi.fn().mockResolvedValue({ _id: "o" });
|
|
530
|
+
const ctx = { runQuery } as unknown as RunCtx;
|
|
531
|
+
await getAccountByOrgId(makeComponent(), ctx, { orgId: "o" });
|
|
532
|
+
expect(runQuery).toHaveBeenCalledWith(
|
|
533
|
+
refFor("core/queries/getAccountByOrgId"),
|
|
534
|
+
{ orgId: "o" },
|
|
535
|
+
);
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it("getAccountByStripeId queries getAccountByStripeId", async () => {
|
|
539
|
+
const runQuery = vi.fn().mockResolvedValue({ _id: "s" });
|
|
540
|
+
const ctx = { runQuery } as unknown as RunCtx;
|
|
541
|
+
await getAccountByStripeId(makeComponent(), ctx, {
|
|
542
|
+
stripeAccountId: "acct_x",
|
|
543
|
+
});
|
|
544
|
+
expect(runQuery).toHaveBeenCalledWith(
|
|
545
|
+
refFor("core/queries/getAccountByStripeId"),
|
|
546
|
+
{ stripeAccountId: "acct_x" },
|
|
547
|
+
);
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("getAccountOnboardingStatus queries getAccountOnboardingStatus", async () => {
|
|
551
|
+
const runQuery = vi.fn().mockResolvedValue({ onboardingStatus: "pending" });
|
|
552
|
+
const ctx = { runQuery } as unknown as RunCtx;
|
|
553
|
+
const result = await getAccountOnboardingStatus(makeComponent(), ctx, {
|
|
554
|
+
accountId: "a",
|
|
555
|
+
});
|
|
556
|
+
expect(result).toEqual({ onboardingStatus: "pending" });
|
|
557
|
+
expect(runQuery).toHaveBeenCalledWith(
|
|
558
|
+
refFor("core/queries/getAccountOnboardingStatus"),
|
|
559
|
+
{ accountId: "a" },
|
|
560
|
+
);
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
describe("upsertAccount", () => {
|
|
565
|
+
it("runs the upsert mutation with the raw opts and returns null", async () => {
|
|
566
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
567
|
+
const ctx = { runMutation } as unknown as RunCtx;
|
|
568
|
+
const opts = {
|
|
569
|
+
stripeAccountId: "acct_up",
|
|
570
|
+
userId: "user_up",
|
|
571
|
+
onboardingStatus: "complete" as const,
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
const result = await upsertAccount(makeComponent(), ctx, opts);
|
|
575
|
+
|
|
576
|
+
expect(result).toBeNull();
|
|
577
|
+
expect(runMutation).toHaveBeenCalledWith(
|
|
578
|
+
refFor("core/mutations/upsertAccount"),
|
|
579
|
+
opts,
|
|
580
|
+
);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
it("throws when ctx has no runMutation", async () => {
|
|
584
|
+
const ctx = {} as unknown as RunCtx;
|
|
585
|
+
await expect(
|
|
586
|
+
upsertAccount(makeComponent(), ctx, {
|
|
587
|
+
stripeAccountId: "acct_up",
|
|
588
|
+
userId: "user_up",
|
|
589
|
+
}),
|
|
590
|
+
).rejects.toThrow(/requires a Convex ctx with runMutation/);
|
|
591
|
+
});
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
describe("updateAccount", () => {
|
|
595
|
+
it("sends only the provided fields and returns success", async () => {
|
|
596
|
+
const stripe = makeStripe();
|
|
597
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
598
|
+
const ctx = {} as RunCtx;
|
|
599
|
+
|
|
600
|
+
const result = await updateAccount(asStripe(stripe), ctx, {
|
|
601
|
+
stripeAccountId: "acct_u1",
|
|
602
|
+
email: "new@b.com",
|
|
603
|
+
metadata: { tier: "gold" },
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
expect(result).toEqual({ success: true });
|
|
607
|
+
expect(stripe.v2.core.accounts.update).toHaveBeenCalledWith("acct_u1", {
|
|
608
|
+
contact_email: "new@b.com",
|
|
609
|
+
metadata: { tier: "gold" },
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it("sends an empty update when neither email nor metadata is provided", async () => {
|
|
614
|
+
const stripe = makeStripe();
|
|
615
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
616
|
+
const ctx = {} as RunCtx;
|
|
617
|
+
|
|
618
|
+
await updateAccount(asStripe(stripe), ctx, { stripeAccountId: "acct_u2" });
|
|
619
|
+
|
|
620
|
+
expect(stripe.v2.core.accounts.update).toHaveBeenCalledWith("acct_u2", {});
|
|
621
|
+
});
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
describe("getV2Account / updateV2Account", () => {
|
|
625
|
+
it("getV2Account retrieves with the include array", async () => {
|
|
626
|
+
const stripe = makeStripe();
|
|
627
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({ id: "acct_g" });
|
|
628
|
+
const result = await getV2Account(asStripe(stripe), {} as RunCtx, {
|
|
629
|
+
stripeAccountId: "acct_g",
|
|
630
|
+
include: ["identity"] as never,
|
|
631
|
+
});
|
|
632
|
+
expect(result).toEqual({ id: "acct_g" });
|
|
633
|
+
expect(stripe.v2.core.accounts.retrieve).toHaveBeenCalledWith("acct_g", {
|
|
634
|
+
include: ["identity"],
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
it("updateV2Account passes through the raw update params", async () => {
|
|
639
|
+
const stripe = makeStripe();
|
|
640
|
+
stripe.v2.core.accounts.update.mockResolvedValue({ id: "acct_uv" });
|
|
641
|
+
const updateParams = { contact_email: "x@y.com" } as never;
|
|
642
|
+
const result = await updateV2Account(asStripe(stripe), {} as RunCtx, {
|
|
643
|
+
stripeAccountId: "acct_uv",
|
|
644
|
+
updateParams,
|
|
645
|
+
});
|
|
646
|
+
expect(result).toEqual({ id: "acct_uv" });
|
|
647
|
+
expect(stripe.v2.core.accounts.update).toHaveBeenCalledWith(
|
|
648
|
+
"acct_uv",
|
|
649
|
+
updateParams,
|
|
650
|
+
);
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
describe("addRecipientConfiguration", () => {
|
|
655
|
+
it("requests the recipient configuration and returns success", async () => {
|
|
656
|
+
const stripe = makeStripe();
|
|
657
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
658
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({
|
|
659
|
+
applied_configurations: ["recipient"],
|
|
660
|
+
});
|
|
661
|
+
const runQuery = vi.fn().mockResolvedValue({ userId: "user_1" });
|
|
662
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
663
|
+
const ctx = { runQuery, runMutation } as unknown as RunCtx;
|
|
664
|
+
|
|
665
|
+
const result = await addRecipientConfiguration(
|
|
666
|
+
asStripe(stripe),
|
|
667
|
+
makeComponent(),
|
|
668
|
+
ctx,
|
|
669
|
+
{ stripeAccountId: "acct_r" },
|
|
670
|
+
);
|
|
671
|
+
expect(result).toEqual({
|
|
672
|
+
success: true,
|
|
673
|
+
appliedConfigurations: ["recipient"],
|
|
674
|
+
});
|
|
675
|
+
// V2 (API 2026-05-27.dahlia) requires the `capabilities` wrapper and an
|
|
676
|
+
// explicit `requested: true`; the bare `recipient.stripe_balance` shape is
|
|
677
|
+
// rejected with "Unknown field" (confirmed against the Stripe sandbox).
|
|
678
|
+
expect(stripe.v2.core.accounts.update).toHaveBeenCalledWith("acct_r", {
|
|
679
|
+
configuration: {
|
|
680
|
+
recipient: {
|
|
681
|
+
capabilities: {
|
|
682
|
+
stripe_balance: { stripe_transfers: { requested: true } },
|
|
683
|
+
},
|
|
684
|
+
},
|
|
685
|
+
},
|
|
686
|
+
});
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
it("records the Stripe-reported applied configurations on the component account", async () => {
|
|
690
|
+
const stripe = makeStripe();
|
|
691
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
692
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({
|
|
693
|
+
applied_configurations: ["recipient"],
|
|
694
|
+
});
|
|
695
|
+
const runQuery = vi.fn().mockResolvedValue({ userId: "user_1" });
|
|
696
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
697
|
+
const ctx = { runQuery, runMutation } as unknown as RunCtx;
|
|
698
|
+
|
|
699
|
+
await addRecipientConfiguration(asStripe(stripe), makeComponent(), ctx, {
|
|
700
|
+
stripeAccountId: "acct_r",
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
// Read-back keyed by the Stripe id to recover the owning userId
|
|
704
|
+
expect(runQuery).toHaveBeenCalledWith(
|
|
705
|
+
refFor("core/queries/getAccountByStripeId"),
|
|
706
|
+
{ stripeAccountId: "acct_r" },
|
|
707
|
+
);
|
|
708
|
+
// Applied configs come from the re-fetched Stripe account (source of truth)
|
|
709
|
+
expect(runMutation).toHaveBeenCalledWith(
|
|
710
|
+
refFor("core/mutations/upsertAccount"),
|
|
711
|
+
{
|
|
712
|
+
stripeAccountId: "acct_r",
|
|
713
|
+
userId: "user_1",
|
|
714
|
+
appliedConfigurations: ["recipient"],
|
|
715
|
+
},
|
|
716
|
+
);
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
it("throws ACCOUNT_NOT_FOUND and never touches Stripe when the account is not in the component DB", async () => {
|
|
720
|
+
const stripe = makeStripe();
|
|
721
|
+
const runQuery = vi.fn().mockResolvedValue(null);
|
|
722
|
+
const runMutation = vi.fn();
|
|
723
|
+
const ctx = { runQuery, runMutation } as unknown as RunCtx;
|
|
724
|
+
|
|
725
|
+
await expect(
|
|
726
|
+
addRecipientConfiguration(asStripe(stripe), makeComponent(), ctx, {
|
|
727
|
+
stripeAccountId: "acct_missing",
|
|
728
|
+
}),
|
|
729
|
+
).rejects.toMatchObject({ data: { code: "ACCOUNT_NOT_FOUND" } });
|
|
730
|
+
|
|
731
|
+
expect(stripe.v2.core.accounts.update).not.toHaveBeenCalled();
|
|
732
|
+
expect(runMutation).not.toHaveBeenCalled();
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
it("surfaces the error and never calls upsertAccount when update() succeeds but the re-fetch retrieve() throws (BTS-78)", async () => {
|
|
736
|
+
// Partial-failure path: Stripe IS mutated (update() resolves), but the
|
|
737
|
+
// re-fetch that reads back applied_configurations fails. The component
|
|
738
|
+
// row must NOT be silently left stale — the error must propagate and
|
|
739
|
+
// upsertAccount must never fire, so a caller can't mistake this for
|
|
740
|
+
// success and no stale/absent row masks the real Stripe state.
|
|
741
|
+
const stripe = makeStripe();
|
|
742
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
743
|
+
stripe.v2.core.accounts.retrieve.mockRejectedValue(
|
|
744
|
+
new Error("Stripe retrieve failed: connection reset"),
|
|
745
|
+
);
|
|
746
|
+
const runQuery = vi.fn().mockResolvedValue({ userId: "user_1" });
|
|
747
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
748
|
+
const ctx = { runQuery, runMutation } as unknown as RunCtx;
|
|
749
|
+
|
|
750
|
+
await expect(
|
|
751
|
+
addRecipientConfiguration(asStripe(stripe), makeComponent(), ctx, {
|
|
752
|
+
stripeAccountId: "acct_r",
|
|
753
|
+
}),
|
|
754
|
+
).rejects.toThrow(/connection reset/);
|
|
755
|
+
|
|
756
|
+
// Stripe was mutated...
|
|
757
|
+
expect(stripe.v2.core.accounts.update).toHaveBeenCalledTimes(1);
|
|
758
|
+
// ...but the component row was never touched — no silent stale write.
|
|
759
|
+
expect(runMutation).not.toHaveBeenCalled();
|
|
760
|
+
});
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
describe("addRecipientConfiguration (real convex-test store, BTS-78)", () => {
|
|
764
|
+
it("persists exactly one account row reflecting the applied configuration — a real double-write/overwrite conflict would fail this", async () => {
|
|
765
|
+
const t = makeRealConvexTest();
|
|
766
|
+
const ctx = makeRealCtx(t);
|
|
767
|
+
|
|
768
|
+
// Seed the pre-existing component row addRecipientConfiguration requires.
|
|
769
|
+
await t.mutation(components.betterStripe.core.mutations.upsertAccount, {
|
|
770
|
+
stripeAccountId: "acct_r",
|
|
771
|
+
userId: "user_1",
|
|
772
|
+
appliedConfigurations: [],
|
|
773
|
+
onboardingStatus: "pending",
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
const stripe = makeStripe();
|
|
777
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
778
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({
|
|
779
|
+
applied_configurations: ["recipient"],
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
const result = await addRecipientConfiguration(
|
|
783
|
+
asStripe(stripe),
|
|
784
|
+
realComponent,
|
|
785
|
+
ctx,
|
|
786
|
+
{ stripeAccountId: "acct_r" },
|
|
787
|
+
);
|
|
788
|
+
expect(result).toEqual({
|
|
789
|
+
success: true,
|
|
790
|
+
appliedConfigurations: ["recipient"],
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
// The REAL persisted row (not a mock return value) reflects the applied
|
|
794
|
+
// configuration and preserves the owning userId.
|
|
795
|
+
const stored = await t.query(
|
|
796
|
+
components.betterStripe.core.queries.getAccountByStripeId,
|
|
797
|
+
{
|
|
798
|
+
stripeAccountId: "acct_r",
|
|
799
|
+
},
|
|
800
|
+
);
|
|
801
|
+
expect(stored?.appliedConfigurations).toEqual(["recipient"]);
|
|
802
|
+
expect(stored?.userId).toBe("user_1");
|
|
803
|
+
|
|
804
|
+
// A subsequent full sync re-derives the same account from Stripe's list
|
|
805
|
+
// endpoint and must PATCH the same row, not create a duplicate — the
|
|
806
|
+
// double-sync regression this test guards against would show up here as
|
|
807
|
+
// more than one row for the same stripeAccountId.
|
|
808
|
+
stripe.v2.core.accounts.list.mockReturnValue(
|
|
809
|
+
asyncIterable([
|
|
810
|
+
{
|
|
811
|
+
id: "acct_r",
|
|
812
|
+
configuration: { recipient: {} },
|
|
813
|
+
metadata: { userId: "user_1" },
|
|
814
|
+
},
|
|
815
|
+
]),
|
|
816
|
+
);
|
|
817
|
+
|
|
818
|
+
await syncAllAccounts(asStripe(stripe), realComponent, ctx);
|
|
819
|
+
|
|
820
|
+
const allRows = await (
|
|
821
|
+
t as unknown as { runInComponent: RunInComponent }
|
|
822
|
+
).runInComponent("betterStripe", async (dbCtx) =>
|
|
823
|
+
dbCtx.db.query("accounts").collect(),
|
|
824
|
+
);
|
|
825
|
+
expect(allRows).toHaveLength(1);
|
|
826
|
+
expect(allRows[0]?.stripeAccountId).toBe("acct_r");
|
|
827
|
+
expect(allRows[0]?.userId).toBe("user_1");
|
|
828
|
+
});
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
describe("listStripeAccounts", () => {
|
|
832
|
+
it("collects every account the SDK's auto-pagination iterator yields", async () => {
|
|
833
|
+
const stripe = makeStripe();
|
|
834
|
+
stripe.v2.core.accounts.list.mockReturnValue(
|
|
835
|
+
asyncIterable([{ id: "acct_a" }, { id: "acct_b" }, { id: "acct_c" }]),
|
|
836
|
+
);
|
|
837
|
+
|
|
838
|
+
const result = await listStripeAccounts(asStripe(stripe), {} as RunCtx);
|
|
839
|
+
|
|
840
|
+
expect(result.map((a) => a.id)).toEqual(["acct_a", "acct_b", "acct_c"]);
|
|
841
|
+
expect(stripe.v2.core.accounts.list.mock.calls[0][0]).toEqual({
|
|
842
|
+
limit: 100,
|
|
843
|
+
});
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
it("honours an explicit limit", async () => {
|
|
847
|
+
const stripe = makeStripe();
|
|
848
|
+
stripe.v2.core.accounts.list.mockReturnValue(asyncIterable([]));
|
|
849
|
+
|
|
850
|
+
const result = await listStripeAccounts(asStripe(stripe), {} as RunCtx, {
|
|
851
|
+
limit: 5,
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
expect(result).toEqual([]);
|
|
855
|
+
expect(stripe.v2.core.accounts.list).toHaveBeenCalledTimes(1);
|
|
856
|
+
expect(stripe.v2.core.accounts.list.mock.calls[0][0]).toEqual({ limit: 5 });
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
it("returns accounts beyond a single page (BTS-109 regression)", async () => {
|
|
860
|
+
// Real V2 list responses never populate `has_more` — a manual
|
|
861
|
+
// has_more/starting_after loop reads it as `undefined` and silently
|
|
862
|
+
// stops after page 1. The SDK's own async iterator (driven by
|
|
863
|
+
// `next_page_url`, not exposed here) is what actually walks every page,
|
|
864
|
+
// so draining a result set far larger than one page's `limit` proves
|
|
865
|
+
// the fix relies on that iterator rather than a `has_more` flag.
|
|
866
|
+
const stripe = makeStripe();
|
|
867
|
+
const manyAccounts = Array.from({ length: 250 }, (_, i) => ({
|
|
868
|
+
id: `acct_${i}`,
|
|
869
|
+
}));
|
|
870
|
+
stripe.v2.core.accounts.list.mockReturnValue(asyncIterable(manyAccounts));
|
|
871
|
+
|
|
872
|
+
const result = await listStripeAccounts(asStripe(stripe), {} as RunCtx);
|
|
873
|
+
|
|
874
|
+
expect(result).toHaveLength(250);
|
|
875
|
+
expect(result.map((a) => a.id)).toEqual(manyAccounts.map((a) => a.id));
|
|
876
|
+
});
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
describe("closeAccount / restartAccountOnboarding", () => {
|
|
880
|
+
it("uses stored appliedConfigurations from the DB and deletes after Stripe close", async () => {
|
|
881
|
+
const stripe = makeStripe();
|
|
882
|
+
stripe.v2.core.accounts.close.mockResolvedValue({});
|
|
883
|
+
const runQuery = vi.fn().mockResolvedValue({
|
|
884
|
+
appliedConfigurations: ["merchant", "recipient"],
|
|
885
|
+
});
|
|
886
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
887
|
+
const ctx = { runQuery, runMutation } as unknown as RunCtx;
|
|
888
|
+
|
|
889
|
+
const result = await closeAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
890
|
+
stripeAccountId: "acct_close",
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
expect(result).toEqual({ closed: true });
|
|
894
|
+
// never falls back to Stripe retrieve when DB has configs
|
|
895
|
+
expect(stripe.v2.core.accounts.retrieve).not.toHaveBeenCalled();
|
|
896
|
+
expect(stripe.v2.core.accounts.close).toHaveBeenCalledWith("acct_close", {
|
|
897
|
+
applied_configurations: ["merchant", "recipient"],
|
|
898
|
+
});
|
|
899
|
+
expect(runMutation).toHaveBeenCalledWith(
|
|
900
|
+
refFor("core/mutations/deleteAccountByStripeId"),
|
|
901
|
+
{ stripeAccountId: "acct_close" },
|
|
902
|
+
);
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
it("falls back to Stripe retrieve when the DB has no applied configs", async () => {
|
|
906
|
+
const stripe = makeStripe();
|
|
907
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({
|
|
908
|
+
applied_configurations: ["merchant"],
|
|
909
|
+
});
|
|
910
|
+
stripe.v2.core.accounts.close.mockResolvedValue({});
|
|
911
|
+
const ctx = {
|
|
912
|
+
runQuery: vi.fn().mockResolvedValue(null), // no DB row
|
|
913
|
+
runMutation: vi.fn().mockResolvedValue(undefined),
|
|
914
|
+
} as unknown as RunCtx;
|
|
915
|
+
|
|
916
|
+
await closeAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
917
|
+
stripeAccountId: "acct_fb",
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
expect(stripe.v2.core.accounts.retrieve).toHaveBeenCalledWith("acct_fb");
|
|
921
|
+
expect(stripe.v2.core.accounts.close).toHaveBeenCalledWith("acct_fb", {
|
|
922
|
+
applied_configurations: ["merchant"],
|
|
923
|
+
});
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
it("closes with an empty config list when the Stripe retrieve fallback throws", async () => {
|
|
927
|
+
const stripe = makeStripe();
|
|
928
|
+
stripe.v2.core.accounts.retrieve.mockRejectedValue(
|
|
929
|
+
new Error("no such account"),
|
|
930
|
+
);
|
|
931
|
+
stripe.v2.core.accounts.close.mockResolvedValue({});
|
|
932
|
+
const ctx = {
|
|
933
|
+
runQuery: vi.fn().mockResolvedValue(null),
|
|
934
|
+
runMutation: vi.fn().mockResolvedValue(undefined),
|
|
935
|
+
} as unknown as RunCtx;
|
|
936
|
+
|
|
937
|
+
await closeAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
938
|
+
stripeAccountId: "acct_missing",
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
expect(stripe.v2.core.accounts.close).toHaveBeenCalledWith("acct_missing", {
|
|
942
|
+
applied_configurations: [],
|
|
943
|
+
});
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
it("does not delete from the DB if the Stripe close fails", async () => {
|
|
947
|
+
const stripe = makeStripe();
|
|
948
|
+
stripe.v2.core.accounts.close.mockRejectedValue(new Error("close boom"));
|
|
949
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
950
|
+
const ctx = {
|
|
951
|
+
runQuery: vi
|
|
952
|
+
.fn()
|
|
953
|
+
.mockResolvedValue({ appliedConfigurations: ["merchant"] }),
|
|
954
|
+
runMutation,
|
|
955
|
+
} as unknown as RunCtx;
|
|
956
|
+
|
|
957
|
+
await expect(
|
|
958
|
+
closeAccount(asStripe(stripe), makeComponent(), ctx, {
|
|
959
|
+
stripeAccountId: "acct_err",
|
|
960
|
+
}),
|
|
961
|
+
).rejects.toThrow(/close boom/);
|
|
962
|
+
|
|
963
|
+
expect(runMutation).not.toHaveBeenCalled();
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
it("restartAccountOnboarding delegates to closeAccount", async () => {
|
|
967
|
+
const stripe = makeStripe();
|
|
968
|
+
stripe.v2.core.accounts.close.mockResolvedValue({});
|
|
969
|
+
const ctx = {
|
|
970
|
+
runQuery: vi.fn().mockResolvedValue({ appliedConfigurations: [] }),
|
|
971
|
+
runMutation: vi.fn().mockResolvedValue(undefined),
|
|
972
|
+
} as unknown as RunCtx;
|
|
973
|
+
|
|
974
|
+
const result = await restartAccountOnboarding(
|
|
975
|
+
asStripe(stripe),
|
|
976
|
+
makeComponent(),
|
|
977
|
+
ctx,
|
|
978
|
+
{ stripeAccountId: "acct_restart" },
|
|
979
|
+
);
|
|
980
|
+
|
|
981
|
+
expect(result).toEqual({ closed: true });
|
|
982
|
+
expect(stripe.v2.core.accounts.close).toHaveBeenCalledWith("acct_restart", {
|
|
983
|
+
applied_configurations: [],
|
|
984
|
+
});
|
|
985
|
+
});
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
describe("syncAllAccounts", () => {
|
|
989
|
+
it("maps a business V2 account into an upsert and counts it synced", async () => {
|
|
990
|
+
const stripe = makeStripe();
|
|
991
|
+
stripe.v2.core.accounts.list.mockReturnValue(
|
|
992
|
+
asyncIterable([
|
|
993
|
+
{
|
|
994
|
+
id: "acct_biz",
|
|
995
|
+
contact_email: "biz@co.com",
|
|
996
|
+
metadata: { userId: "u_biz", orgId: "o_biz" },
|
|
997
|
+
identity: {
|
|
998
|
+
country: "US",
|
|
999
|
+
business_details: { registered_name: "Big Co" },
|
|
1000
|
+
},
|
|
1001
|
+
configuration: { merchant: { applied: true } },
|
|
1002
|
+
requirements: { entries: [] },
|
|
1003
|
+
},
|
|
1004
|
+
]),
|
|
1005
|
+
);
|
|
1006
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
1007
|
+
const ctx = { runMutation, runQuery: vi.fn() } as unknown as RunCtx;
|
|
1008
|
+
|
|
1009
|
+
const result = await syncAllAccounts(
|
|
1010
|
+
asStripe(stripe),
|
|
1011
|
+
makeComponent(),
|
|
1012
|
+
ctx,
|
|
1013
|
+
);
|
|
1014
|
+
|
|
1015
|
+
expect(result).toEqual({ synced: 1, errors: [], errorCount: 0 });
|
|
1016
|
+
|
|
1017
|
+
const upsertArg = runMutation.mock.calls[0][1];
|
|
1018
|
+
expect(upsertArg).toMatchObject({
|
|
1019
|
+
stripeAccountId: "acct_biz",
|
|
1020
|
+
userId: "u_biz",
|
|
1021
|
+
orgId: "o_biz",
|
|
1022
|
+
email: "biz@co.com",
|
|
1023
|
+
name: "Big Co",
|
|
1024
|
+
country: "US",
|
|
1025
|
+
onboardingStatus: "complete",
|
|
1026
|
+
missingRequirements: [],
|
|
1027
|
+
metadata: { userId: "u_biz", orgId: "o_biz" },
|
|
1028
|
+
});
|
|
1029
|
+
// list called with limit 20
|
|
1030
|
+
expect(stripe.v2.core.accounts.list.mock.calls[0][0]).toEqual({
|
|
1031
|
+
limit: 20,
|
|
1032
|
+
});
|
|
1033
|
+
});
|
|
1034
|
+
|
|
1035
|
+
it("derives an individual name, falls back to contact email, and accepts snake_case ids", async () => {
|
|
1036
|
+
const stripe = makeStripe();
|
|
1037
|
+
stripe.v2.core.accounts.list.mockReturnValue(
|
|
1038
|
+
asyncIterable([
|
|
1039
|
+
{
|
|
1040
|
+
id: "acct_ind",
|
|
1041
|
+
metadata: { user_id: "u_snake", org_id: "o_snake" },
|
|
1042
|
+
identity: {
|
|
1043
|
+
country: "CA",
|
|
1044
|
+
individual: {
|
|
1045
|
+
given_name: "Jane",
|
|
1046
|
+
surname: "Doe",
|
|
1047
|
+
email: "jane@x.com",
|
|
1048
|
+
},
|
|
1049
|
+
},
|
|
1050
|
+
},
|
|
1051
|
+
]),
|
|
1052
|
+
);
|
|
1053
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
1054
|
+
const ctx = { runMutation, runQuery: vi.fn() } as unknown as RunCtx;
|
|
1055
|
+
|
|
1056
|
+
await syncAllAccounts(asStripe(stripe), makeComponent(), ctx);
|
|
1057
|
+
|
|
1058
|
+
const upsertArg = runMutation.mock.calls[0][1];
|
|
1059
|
+
expect(upsertArg).toMatchObject({
|
|
1060
|
+
userId: "u_snake",
|
|
1061
|
+
orgId: "o_snake",
|
|
1062
|
+
email: "jane@x.com", // individual.email fallback (no contact_email)
|
|
1063
|
+
name: "Jane Doe", // given_name + surname
|
|
1064
|
+
country: "CA",
|
|
1065
|
+
});
|
|
1066
|
+
});
|
|
1067
|
+
|
|
1068
|
+
it("falls back to the account id as userId when metadata has none", async () => {
|
|
1069
|
+
const stripe = makeStripe();
|
|
1070
|
+
stripe.v2.core.accounts.list.mockReturnValue(
|
|
1071
|
+
asyncIterable([{ id: "acct_noid" }]),
|
|
1072
|
+
);
|
|
1073
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
1074
|
+
const ctx = { runMutation, runQuery: vi.fn() } as unknown as RunCtx;
|
|
1075
|
+
|
|
1076
|
+
await syncAllAccounts(asStripe(stripe), makeComponent(), ctx);
|
|
1077
|
+
|
|
1078
|
+
const upsertArg = runMutation.mock.calls[0][1];
|
|
1079
|
+
expect(upsertArg.userId).toBe("acct_noid");
|
|
1080
|
+
expect(upsertArg.orgId).toBeUndefined();
|
|
1081
|
+
expect(upsertArg.email).toBeUndefined();
|
|
1082
|
+
expect(upsertArg.name).toBeUndefined();
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
it("accumulates a per-account error instead of aborting the sync", async () => {
|
|
1086
|
+
const stripe = makeStripe();
|
|
1087
|
+
stripe.v2.core.accounts.list.mockReturnValue(
|
|
1088
|
+
asyncIterable([
|
|
1089
|
+
{ id: "acct_ok", metadata: { userId: "ok" } },
|
|
1090
|
+
{ id: "acct_bad", metadata: { userId: "bad" } },
|
|
1091
|
+
]),
|
|
1092
|
+
);
|
|
1093
|
+
const runMutation = vi
|
|
1094
|
+
.fn()
|
|
1095
|
+
.mockResolvedValueOnce(undefined) // acct_ok
|
|
1096
|
+
.mockRejectedValueOnce(new Error("db down")); // acct_bad
|
|
1097
|
+
const ctx = { runMutation, runQuery: vi.fn() } as unknown as RunCtx;
|
|
1098
|
+
|
|
1099
|
+
const result = await syncAllAccounts(
|
|
1100
|
+
asStripe(stripe),
|
|
1101
|
+
makeComponent(),
|
|
1102
|
+
ctx,
|
|
1103
|
+
);
|
|
1104
|
+
|
|
1105
|
+
expect(result.synced).toBe(1);
|
|
1106
|
+
expect(result.errorCount).toBe(1);
|
|
1107
|
+
expect(result.errors[0]).toContain("acct_bad");
|
|
1108
|
+
expect(result.errors[0]).toContain("db down");
|
|
1109
|
+
});
|
|
1110
|
+
|
|
1111
|
+
it("stringifies a non-Error thrown value as 'Unknown error'", async () => {
|
|
1112
|
+
const stripe = makeStripe();
|
|
1113
|
+
stripe.v2.core.accounts.list.mockReturnValue(
|
|
1114
|
+
asyncIterable([{ id: "acct_weird", metadata: { userId: "u" } }]),
|
|
1115
|
+
);
|
|
1116
|
+
const runMutation = vi.fn().mockRejectedValueOnce("not-an-error-object");
|
|
1117
|
+
const ctx = { runMutation, runQuery: vi.fn() } as unknown as RunCtx;
|
|
1118
|
+
|
|
1119
|
+
const result = await syncAllAccounts(
|
|
1120
|
+
asStripe(stripe),
|
|
1121
|
+
makeComponent(),
|
|
1122
|
+
ctx,
|
|
1123
|
+
);
|
|
1124
|
+
|
|
1125
|
+
expect(result.errorCount).toBe(1);
|
|
1126
|
+
expect(result.errors[0]).toBe("Account acct_weird: Unknown error");
|
|
1127
|
+
});
|
|
1128
|
+
|
|
1129
|
+
it("leaves name undefined for an individual with no given_name or surname", async () => {
|
|
1130
|
+
const stripe = makeStripe();
|
|
1131
|
+
stripe.v2.core.accounts.list.mockReturnValue(
|
|
1132
|
+
asyncIterable([
|
|
1133
|
+
{
|
|
1134
|
+
id: "acct_blank",
|
|
1135
|
+
metadata: { userId: "u" },
|
|
1136
|
+
identity: { individual: { email: "only@email.com" } },
|
|
1137
|
+
},
|
|
1138
|
+
]),
|
|
1139
|
+
);
|
|
1140
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
1141
|
+
const ctx = { runMutation, runQuery: vi.fn() } as unknown as RunCtx;
|
|
1142
|
+
|
|
1143
|
+
await syncAllAccounts(asStripe(stripe), makeComponent(), ctx);
|
|
1144
|
+
|
|
1145
|
+
const upsertArg = runMutation.mock.calls[0][1];
|
|
1146
|
+
expect(upsertArg.name).toBeUndefined();
|
|
1147
|
+
expect(upsertArg.email).toBe("only@email.com");
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
it("handles an empty account list", async () => {
|
|
1151
|
+
const stripe = makeStripe();
|
|
1152
|
+
stripe.v2.core.accounts.list.mockReturnValue(asyncIterable([]));
|
|
1153
|
+
const ctx = {
|
|
1154
|
+
runMutation: vi.fn(),
|
|
1155
|
+
runQuery: vi.fn(),
|
|
1156
|
+
} as unknown as RunCtx;
|
|
1157
|
+
|
|
1158
|
+
const result = await syncAllAccounts(
|
|
1159
|
+
asStripe(stripe),
|
|
1160
|
+
makeComponent(),
|
|
1161
|
+
ctx,
|
|
1162
|
+
);
|
|
1163
|
+
|
|
1164
|
+
expect(result).toEqual({ synced: 0, errors: [], errorCount: 0 });
|
|
1165
|
+
expect(stripe.v2.core.accounts.list).toHaveBeenCalledTimes(1);
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
it("syncs accounts beyond a single page (BTS-109 regression)", async () => {
|
|
1169
|
+
// Same rationale as the listStripeAccounts regression test: real V2
|
|
1170
|
+
// list responses never populate `has_more`, so a manual pagination loop
|
|
1171
|
+
// silently stops after page 1 while reporting `errors: []` (looking
|
|
1172
|
+
// fully synced). Draining a result set far larger than one page's
|
|
1173
|
+
// `limit` proves syncAllAccounts relies on the SDK's async iterator
|
|
1174
|
+
// instead.
|
|
1175
|
+
const stripe = makeStripe();
|
|
1176
|
+
const manyAccounts = Array.from({ length: 150 }, (_, i) => ({
|
|
1177
|
+
id: `acct_${i}`,
|
|
1178
|
+
metadata: { userId: `user_${i}` },
|
|
1179
|
+
}));
|
|
1180
|
+
stripe.v2.core.accounts.list.mockReturnValue(asyncIterable(manyAccounts));
|
|
1181
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
1182
|
+
const ctx = { runMutation, runQuery: vi.fn() } as unknown as RunCtx;
|
|
1183
|
+
|
|
1184
|
+
const result = await syncAllAccounts(
|
|
1185
|
+
asStripe(stripe),
|
|
1186
|
+
makeComponent(),
|
|
1187
|
+
ctx,
|
|
1188
|
+
);
|
|
1189
|
+
|
|
1190
|
+
expect(result).toEqual({ synced: 150, errors: [], errorCount: 0 });
|
|
1191
|
+
expect(runMutation).toHaveBeenCalledTimes(150);
|
|
1192
|
+
});
|
|
1193
|
+
});
|
|
1194
|
+
|
|
1195
|
+
describe("addCustomerConfiguration", () => {
|
|
1196
|
+
it("DEFAULT_CUSTOMER_CONFIGURATION requests the customer configuration", () => {
|
|
1197
|
+
expect(DEFAULT_CUSTOMER_CONFIGURATION).toEqual({ customer: {} });
|
|
1198
|
+
});
|
|
1199
|
+
|
|
1200
|
+
it("applies the customer configuration to the Stripe account", async () => {
|
|
1201
|
+
const stripe = makeStripe();
|
|
1202
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
1203
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({
|
|
1204
|
+
applied_configurations: ["customer"],
|
|
1205
|
+
});
|
|
1206
|
+
const runQuery = vi.fn().mockResolvedValue({ userId: "user_1" });
|
|
1207
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
1208
|
+
const ctx = { runQuery, runMutation } as unknown as RunCtx;
|
|
1209
|
+
|
|
1210
|
+
await addCustomerConfiguration(asStripe(stripe), makeComponent(), ctx, {
|
|
1211
|
+
stripeAccountId: "acct_1",
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
expect(stripe.v2.core.accounts.update).toHaveBeenCalledWith("acct_1", {
|
|
1215
|
+
configuration: { customer: {} },
|
|
1216
|
+
});
|
|
1217
|
+
});
|
|
1218
|
+
|
|
1219
|
+
it("never sends dashboard or defaults for a customer-only account", async () => {
|
|
1220
|
+
// A customer-only V2 account rejects `dashboard` and
|
|
1221
|
+
// `defaults.responsibilities` with `unsupported_field_for_configs`
|
|
1222
|
+
// (confirmed against the Stripe sandbox). Account config must be
|
|
1223
|
+
// configuration-aware: only recipient/merchant accounts set those.
|
|
1224
|
+
const stripe = makeStripe();
|
|
1225
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
1226
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({
|
|
1227
|
+
applied_configurations: ["customer"],
|
|
1228
|
+
});
|
|
1229
|
+
const ctx = {
|
|
1230
|
+
runQuery: vi.fn().mockResolvedValue({ userId: "user_1" }),
|
|
1231
|
+
runMutation: vi.fn().mockResolvedValue(undefined),
|
|
1232
|
+
} as unknown as RunCtx;
|
|
1233
|
+
|
|
1234
|
+
await addCustomerConfiguration(asStripe(stripe), makeComponent(), ctx, {
|
|
1235
|
+
stripeAccountId: "acct_1",
|
|
1236
|
+
});
|
|
1237
|
+
|
|
1238
|
+
const [, payload] = stripe.v2.core.accounts.update.mock.calls[0];
|
|
1239
|
+
expect(payload).not.toHaveProperty("dashboard");
|
|
1240
|
+
expect(payload).not.toHaveProperty("defaults");
|
|
1241
|
+
// ...and not nested inside `configuration` either.
|
|
1242
|
+
expect(payload.configuration).not.toHaveProperty("dashboard");
|
|
1243
|
+
expect(payload.configuration).not.toHaveProperty("defaults");
|
|
1244
|
+
});
|
|
1245
|
+
|
|
1246
|
+
it("records the Stripe-reported applied configurations on the component account", async () => {
|
|
1247
|
+
const stripe = makeStripe();
|
|
1248
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
1249
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({
|
|
1250
|
+
applied_configurations: ["customer"],
|
|
1251
|
+
});
|
|
1252
|
+
const runQuery = vi.fn().mockResolvedValue({ userId: "user_1" });
|
|
1253
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
1254
|
+
const ctx = { runQuery, runMutation } as unknown as RunCtx;
|
|
1255
|
+
|
|
1256
|
+
await addCustomerConfiguration(asStripe(stripe), makeComponent(), ctx, {
|
|
1257
|
+
stripeAccountId: "acct_1",
|
|
1258
|
+
});
|
|
1259
|
+
|
|
1260
|
+
// Read-back keyed by the Stripe id to recover the owning userId
|
|
1261
|
+
expect(runQuery).toHaveBeenCalledWith(
|
|
1262
|
+
refFor("core/queries/getAccountByStripeId"),
|
|
1263
|
+
{ stripeAccountId: "acct_1" },
|
|
1264
|
+
);
|
|
1265
|
+
// Applied configs come from the re-fetched Stripe account (source of truth)
|
|
1266
|
+
expect(runMutation).toHaveBeenCalledWith(
|
|
1267
|
+
refFor("core/mutations/upsertAccount"),
|
|
1268
|
+
{
|
|
1269
|
+
stripeAccountId: "acct_1",
|
|
1270
|
+
userId: "user_1",
|
|
1271
|
+
appliedConfigurations: ["customer"],
|
|
1272
|
+
},
|
|
1273
|
+
);
|
|
1274
|
+
});
|
|
1275
|
+
|
|
1276
|
+
it("returns success with the applied configurations", async () => {
|
|
1277
|
+
const stripe = makeStripe();
|
|
1278
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
1279
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({
|
|
1280
|
+
applied_configurations: ["customer", "merchant"],
|
|
1281
|
+
});
|
|
1282
|
+
const runQuery = vi.fn().mockResolvedValue({ userId: "user_1" });
|
|
1283
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
1284
|
+
const ctx = { runQuery, runMutation } as unknown as RunCtx;
|
|
1285
|
+
|
|
1286
|
+
const result = await addCustomerConfiguration(
|
|
1287
|
+
asStripe(stripe),
|
|
1288
|
+
makeComponent(),
|
|
1289
|
+
ctx,
|
|
1290
|
+
{ stripeAccountId: "acct_1" },
|
|
1291
|
+
);
|
|
1292
|
+
|
|
1293
|
+
expect(result).toEqual({
|
|
1294
|
+
success: true,
|
|
1295
|
+
appliedConfigurations: ["customer", "merchant"],
|
|
1296
|
+
});
|
|
1297
|
+
});
|
|
1298
|
+
|
|
1299
|
+
it("throws ACCOUNT_NOT_FOUND and never touches Stripe when the account is not in the component DB", async () => {
|
|
1300
|
+
const stripe = makeStripe();
|
|
1301
|
+
const runQuery = vi.fn().mockResolvedValue(null);
|
|
1302
|
+
const runMutation = vi.fn();
|
|
1303
|
+
const ctx = { runQuery, runMutation } as unknown as RunCtx;
|
|
1304
|
+
|
|
1305
|
+
await expect(
|
|
1306
|
+
addCustomerConfiguration(asStripe(stripe), makeComponent(), ctx, {
|
|
1307
|
+
stripeAccountId: "acct_missing",
|
|
1308
|
+
}),
|
|
1309
|
+
).rejects.toMatchObject({ data: { code: "ACCOUNT_NOT_FOUND" } });
|
|
1310
|
+
|
|
1311
|
+
expect(stripe.v2.core.accounts.update).not.toHaveBeenCalled();
|
|
1312
|
+
expect(runMutation).not.toHaveBeenCalled();
|
|
1313
|
+
});
|
|
1314
|
+
});
|
|
1315
|
+
|
|
1316
|
+
describe("ensureCustomerAccount (BTS-18)", () => {
|
|
1317
|
+
/** Build a ctx whose runQuery routes by component ref path. */
|
|
1318
|
+
function routedCtx(routes: Record<string, unknown>) {
|
|
1319
|
+
const runQuery = vi.fn(async (ref: Record<symbol, string>) => {
|
|
1320
|
+
const path = ref[TO_REF].replace(/^betterStripe\//, "");
|
|
1321
|
+
return routes[path] ?? null;
|
|
1322
|
+
});
|
|
1323
|
+
const runMutation = vi.fn().mockResolvedValue(undefined);
|
|
1324
|
+
return { runQuery, runMutation } as unknown as RunCtx & {
|
|
1325
|
+
runQuery: ReturnType<typeof vi.fn>;
|
|
1326
|
+
runMutation: ReturnType<typeof vi.fn>;
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
it("provisions a new buyer with the customer configuration", async () => {
|
|
1331
|
+
const stripe = makeStripe();
|
|
1332
|
+
stripe.v2.core.accounts.create.mockResolvedValue({ id: "acct_new" });
|
|
1333
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
1334
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({
|
|
1335
|
+
applied_configurations: ["customer"],
|
|
1336
|
+
});
|
|
1337
|
+
const ctx = routedCtx({
|
|
1338
|
+
"core/queries/getAccountByUserId": null, // no existing account
|
|
1339
|
+
"core/queries/getAccountByStripeId": {
|
|
1340
|
+
_id: "doc1",
|
|
1341
|
+
stripeAccountId: "acct_new",
|
|
1342
|
+
userId: "u1",
|
|
1343
|
+
appliedConfigurations: [],
|
|
1344
|
+
},
|
|
1345
|
+
});
|
|
1346
|
+
|
|
1347
|
+
const result = await ensureCustomerAccount(
|
|
1348
|
+
asStripe(stripe),
|
|
1349
|
+
makeComponent(),
|
|
1350
|
+
ctx,
|
|
1351
|
+
{ userId: "u1", email: "buyer@test.com" },
|
|
1352
|
+
);
|
|
1353
|
+
|
|
1354
|
+
expect(stripe.v2.core.accounts.create).toHaveBeenCalled();
|
|
1355
|
+
// customer configuration applied
|
|
1356
|
+
expect(stripe.v2.core.accounts.update).toHaveBeenCalledWith("acct_new", {
|
|
1357
|
+
configuration: { customer: {} },
|
|
1358
|
+
});
|
|
1359
|
+
expect(result.stripeAccountId).toBe("acct_new");
|
|
1360
|
+
expect(result.isNew).toBe(true);
|
|
1361
|
+
expect(result.appliedConfigurations).toContain("customer");
|
|
1362
|
+
});
|
|
1363
|
+
|
|
1364
|
+
it("adds the customer configuration to an existing account that lacks it", async () => {
|
|
1365
|
+
const stripe = makeStripe();
|
|
1366
|
+
stripe.v2.core.accounts.update.mockResolvedValue({});
|
|
1367
|
+
stripe.v2.core.accounts.retrieve.mockResolvedValue({
|
|
1368
|
+
applied_configurations: ["customer"],
|
|
1369
|
+
});
|
|
1370
|
+
const ctx = routedCtx({
|
|
1371
|
+
"core/queries/getAccountByUserId": {
|
|
1372
|
+
_id: "doc1",
|
|
1373
|
+
stripeAccountId: "acct_x",
|
|
1374
|
+
},
|
|
1375
|
+
"core/queries/getAccountByStripeId": {
|
|
1376
|
+
_id: "doc1",
|
|
1377
|
+
stripeAccountId: "acct_x",
|
|
1378
|
+
userId: "u1",
|
|
1379
|
+
appliedConfigurations: [],
|
|
1380
|
+
},
|
|
1381
|
+
});
|
|
1382
|
+
|
|
1383
|
+
const result = await ensureCustomerAccount(
|
|
1384
|
+
asStripe(stripe),
|
|
1385
|
+
makeComponent(),
|
|
1386
|
+
ctx,
|
|
1387
|
+
{ userId: "u1" },
|
|
1388
|
+
);
|
|
1389
|
+
|
|
1390
|
+
expect(stripe.v2.core.accounts.create).not.toHaveBeenCalled();
|
|
1391
|
+
expect(stripe.v2.core.accounts.update).toHaveBeenCalledWith("acct_x", {
|
|
1392
|
+
configuration: { customer: {} },
|
|
1393
|
+
});
|
|
1394
|
+
expect(result.isNew).toBe(false);
|
|
1395
|
+
});
|
|
1396
|
+
|
|
1397
|
+
it("is idempotent: does not re-provision an account that already has customer config", async () => {
|
|
1398
|
+
const stripe = makeStripe();
|
|
1399
|
+
const ctx = routedCtx({
|
|
1400
|
+
"core/queries/getAccountByUserId": {
|
|
1401
|
+
_id: "doc1",
|
|
1402
|
+
stripeAccountId: "acct_x",
|
|
1403
|
+
},
|
|
1404
|
+
"core/queries/getAccountByStripeId": {
|
|
1405
|
+
_id: "doc1",
|
|
1406
|
+
stripeAccountId: "acct_x",
|
|
1407
|
+
userId: "u1",
|
|
1408
|
+
appliedConfigurations: ["customer"],
|
|
1409
|
+
},
|
|
1410
|
+
});
|
|
1411
|
+
|
|
1412
|
+
const result = await ensureCustomerAccount(
|
|
1413
|
+
asStripe(stripe),
|
|
1414
|
+
makeComponent(),
|
|
1415
|
+
ctx,
|
|
1416
|
+
{ userId: "u1" },
|
|
1417
|
+
);
|
|
1418
|
+
|
|
1419
|
+
expect(stripe.v2.core.accounts.create).not.toHaveBeenCalled();
|
|
1420
|
+
expect(stripe.v2.core.accounts.update).not.toHaveBeenCalled();
|
|
1421
|
+
expect(result.appliedConfigurations).toEqual(["customer"]);
|
|
1422
|
+
});
|
|
1423
|
+
|
|
1424
|
+
it("preserves other configs (customer + merchant) without re-provisioning", async () => {
|
|
1425
|
+
const stripe = makeStripe();
|
|
1426
|
+
const ctx = routedCtx({
|
|
1427
|
+
"core/queries/getAccountByUserId": {
|
|
1428
|
+
_id: "doc1",
|
|
1429
|
+
stripeAccountId: "acct_x",
|
|
1430
|
+
},
|
|
1431
|
+
"core/queries/getAccountByStripeId": {
|
|
1432
|
+
_id: "doc1",
|
|
1433
|
+
stripeAccountId: "acct_x",
|
|
1434
|
+
userId: "u1",
|
|
1435
|
+
appliedConfigurations: ["customer", "merchant"],
|
|
1436
|
+
},
|
|
1437
|
+
});
|
|
1438
|
+
|
|
1439
|
+
const result = await ensureCustomerAccount(
|
|
1440
|
+
asStripe(stripe),
|
|
1441
|
+
makeComponent(),
|
|
1442
|
+
ctx,
|
|
1443
|
+
{ userId: "u1" },
|
|
1444
|
+
);
|
|
1445
|
+
|
|
1446
|
+
expect(stripe.v2.core.accounts.update).not.toHaveBeenCalled();
|
|
1447
|
+
expect(result.appliedConfigurations).toEqual(["customer", "merchant"]);
|
|
1448
|
+
});
|
|
1449
|
+
});
|
|
1450
|
+
|
|
1451
|
+
describe("setAccountStatementDescriptor (BTS-32)", () => {
|
|
1452
|
+
it("validates, trims, and stores the per-store suffix on the account record", async () => {
|
|
1453
|
+
const runMutation = vi.fn().mockResolvedValue(null);
|
|
1454
|
+
const ctx = { runMutation } as unknown as RunCtx;
|
|
1455
|
+
|
|
1456
|
+
const result = await setAccountStatementDescriptor(makeComponent(), ctx, {
|
|
1457
|
+
stripeAccountId: "acct_store",
|
|
1458
|
+
statementDescriptor: " MAYAS FITNESS ",
|
|
1459
|
+
});
|
|
1460
|
+
|
|
1461
|
+
expect(result).toEqual({ success: true });
|
|
1462
|
+
expect(runMutation).toHaveBeenCalledWith(
|
|
1463
|
+
refFor("core/mutations/setStatementDescriptor"),
|
|
1464
|
+
{ stripeAccountId: "acct_store", statementDescriptor: "MAYAS FITNESS" },
|
|
1465
|
+
);
|
|
1466
|
+
});
|
|
1467
|
+
|
|
1468
|
+
it("rejects an invalid suffix WITHOUT touching the component DB", async () => {
|
|
1469
|
+
const runMutation = vi.fn();
|
|
1470
|
+
const ctx = { runMutation } as unknown as RunCtx;
|
|
1471
|
+
|
|
1472
|
+
await expect(
|
|
1473
|
+
setAccountStatementDescriptor(makeComponent(), ctx, {
|
|
1474
|
+
stripeAccountId: "acct_store",
|
|
1475
|
+
statementDescriptor: "BAD*NAME",
|
|
1476
|
+
}),
|
|
1477
|
+
).rejects.toThrow(/character/i);
|
|
1478
|
+
expect(runMutation).not.toHaveBeenCalled();
|
|
1479
|
+
});
|
|
1480
|
+
|
|
1481
|
+
it("clears the suffix when passed null", async () => {
|
|
1482
|
+
const runMutation = vi.fn().mockResolvedValue(null);
|
|
1483
|
+
const ctx = { runMutation } as unknown as RunCtx;
|
|
1484
|
+
|
|
1485
|
+
const result = await setAccountStatementDescriptor(makeComponent(), ctx, {
|
|
1486
|
+
stripeAccountId: "acct_store",
|
|
1487
|
+
statementDescriptor: null,
|
|
1488
|
+
});
|
|
1489
|
+
|
|
1490
|
+
expect(result).toEqual({ success: true });
|
|
1491
|
+
expect(runMutation).toHaveBeenCalledWith(
|
|
1492
|
+
refFor("core/mutations/setStatementDescriptor"),
|
|
1493
|
+
{ stripeAccountId: "acct_store", statementDescriptor: null },
|
|
1494
|
+
);
|
|
1495
|
+
});
|
|
1496
|
+
});
|