@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,1848 @@
|
|
|
1
|
+
import { ConvexError } from "convex/values";
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { isBetterStripeError } from "./errors.js";
|
|
5
|
+
import { components as _components } from "./setup.test.js";
|
|
6
|
+
|
|
7
|
+
const components = _components;
|
|
8
|
+
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Mock Stripe SDK
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
const mockStripeInstance = {
|
|
14
|
+
v2: {
|
|
15
|
+
core: {
|
|
16
|
+
accounts: {
|
|
17
|
+
create: vi.fn(),
|
|
18
|
+
update: vi.fn(),
|
|
19
|
+
retrieve: vi.fn(),
|
|
20
|
+
list: vi.fn(),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
products: {
|
|
25
|
+
create: vi.fn(),
|
|
26
|
+
update: vi.fn(),
|
|
27
|
+
list: vi.fn(),
|
|
28
|
+
},
|
|
29
|
+
prices: {
|
|
30
|
+
create: vi.fn(),
|
|
31
|
+
update: vi.fn(),
|
|
32
|
+
list: vi.fn(),
|
|
33
|
+
},
|
|
34
|
+
checkout: {
|
|
35
|
+
sessions: {
|
|
36
|
+
create: vi.fn(),
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
subscriptions: {
|
|
40
|
+
update: vi.fn(),
|
|
41
|
+
cancel: vi.fn(),
|
|
42
|
+
retrieve: vi.fn(),
|
|
43
|
+
list: vi.fn(),
|
|
44
|
+
},
|
|
45
|
+
subscriptionItems: {
|
|
46
|
+
update: vi.fn(),
|
|
47
|
+
},
|
|
48
|
+
refunds: {
|
|
49
|
+
create: vi.fn(),
|
|
50
|
+
},
|
|
51
|
+
paymentIntents: {
|
|
52
|
+
retrieve: vi.fn(),
|
|
53
|
+
},
|
|
54
|
+
charges: {
|
|
55
|
+
retrieve: vi.fn(),
|
|
56
|
+
},
|
|
57
|
+
disputes: {
|
|
58
|
+
update: vi.fn(),
|
|
59
|
+
close: vi.fn(),
|
|
60
|
+
},
|
|
61
|
+
paymentMethods: {
|
|
62
|
+
list: vi.fn(),
|
|
63
|
+
attach: vi.fn(),
|
|
64
|
+
detach: vi.fn(),
|
|
65
|
+
},
|
|
66
|
+
invoices: {
|
|
67
|
+
retrieve: vi.fn(),
|
|
68
|
+
},
|
|
69
|
+
accountLinks: {
|
|
70
|
+
create: vi.fn(),
|
|
71
|
+
},
|
|
72
|
+
accountSessions: {
|
|
73
|
+
create: vi.fn(),
|
|
74
|
+
},
|
|
75
|
+
accounts: {
|
|
76
|
+
createLoginLink: vi.fn(),
|
|
77
|
+
},
|
|
78
|
+
payouts: {
|
|
79
|
+
create: vi.fn(),
|
|
80
|
+
},
|
|
81
|
+
transfers: {
|
|
82
|
+
createReversal: vi.fn(),
|
|
83
|
+
retrieve: vi.fn(),
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
vi.mock("stripe", () => ({
|
|
88
|
+
default: class StripeMock {
|
|
89
|
+
constructor() {
|
|
90
|
+
return mockStripeInstance;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
}));
|
|
94
|
+
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// Import BetterStripe after the mock is set up
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
const { BetterStripe } = await import("./index.js");
|
|
100
|
+
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// Helpers
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
function createMockCtx() {
|
|
106
|
+
return {
|
|
107
|
+
runQuery: vi.fn(),
|
|
108
|
+
runMutation: vi.fn(),
|
|
109
|
+
runAction: vi.fn(),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
// Tests
|
|
115
|
+
// ---------------------------------------------------------------------------
|
|
116
|
+
|
|
117
|
+
describe("BetterStripe", () => {
|
|
118
|
+
let mockCtx: ReturnType<typeof createMockCtx>;
|
|
119
|
+
|
|
120
|
+
beforeEach(() => {
|
|
121
|
+
vi.clearAllMocks();
|
|
122
|
+
mockCtx = createMockCtx();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// =========================================================================
|
|
126
|
+
// Constructor & apiKey
|
|
127
|
+
// =========================================================================
|
|
128
|
+
|
|
129
|
+
describe("constructor & apiKey", () => {
|
|
130
|
+
it("accepts STRIPE_SECRET_KEY", () => {
|
|
131
|
+
expect(
|
|
132
|
+
() =>
|
|
133
|
+
new BetterStripe(components.betterStripe, {
|
|
134
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
135
|
+
}),
|
|
136
|
+
).not.toThrow();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("apiKey throws when not set", () => {
|
|
140
|
+
const bs = new BetterStripe(components.betterStripe);
|
|
141
|
+
expect(() => bs.apiKey).toThrow("STRIPE_SECRET_KEY is not set");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("validates platformFee at construction and exposes it", () => {
|
|
145
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
146
|
+
platformFee: { percent: 10, fixed: 30 },
|
|
147
|
+
});
|
|
148
|
+
expect(bs.platformFee).toEqual({ percent: 10, fixed: 30 });
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("throws on an invalid platformFee config", () => {
|
|
152
|
+
expect(
|
|
153
|
+
() =>
|
|
154
|
+
new BetterStripe(components.betterStripe, {
|
|
155
|
+
platformFee: { percent: 150 },
|
|
156
|
+
}),
|
|
157
|
+
).toThrow(/platformFee/);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("validates statementDescriptorSuffix at construction and exposes the trimmed value", () => {
|
|
161
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
162
|
+
statementDescriptorSuffix: " ACME STORE ",
|
|
163
|
+
});
|
|
164
|
+
expect(bs.statementDescriptorSuffix).toBe("ACME STORE");
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("throws on an invalid statementDescriptorSuffix", () => {
|
|
168
|
+
expect(
|
|
169
|
+
() =>
|
|
170
|
+
new BetterStripe(components.betterStripe, {
|
|
171
|
+
statementDescriptorSuffix: "BAD*SUFFIX",
|
|
172
|
+
}),
|
|
173
|
+
).toThrow(/statement descriptor/i);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("statementDescriptorSuffix is undefined when not configured", () => {
|
|
177
|
+
const bs = new BetterStripe(components.betterStripe);
|
|
178
|
+
expect(bs.statementDescriptorSuffix).toBeUndefined();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("platformFee is undefined when not configured", () => {
|
|
182
|
+
const bs = new BetterStripe(components.betterStripe);
|
|
183
|
+
expect(bs.platformFee).toBeUndefined();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("does not retain or re-expose the caller's mutable fee object", () => {
|
|
187
|
+
const input = { percent: 10, tiers: [{ upTo: null, percent: 10 }] };
|
|
188
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
189
|
+
platformFee: input,
|
|
190
|
+
});
|
|
191
|
+
// Mutating the original input must not change stored config.
|
|
192
|
+
input.percent = 999;
|
|
193
|
+
input.tiers[0].percent = 999;
|
|
194
|
+
expect(bs.platformFee).toEqual({
|
|
195
|
+
percent: 10,
|
|
196
|
+
tiers: [{ upTo: null, percent: 10 }],
|
|
197
|
+
});
|
|
198
|
+
// Mutating a returned copy must not change internal state either.
|
|
199
|
+
const returned = bs.platformFee!;
|
|
200
|
+
returned.percent = 42;
|
|
201
|
+
expect(bs.platformFee!.percent).toBe(10);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// =========================================================================
|
|
206
|
+
// Account methods
|
|
207
|
+
// =========================================================================
|
|
208
|
+
|
|
209
|
+
describe("createAccount", () => {
|
|
210
|
+
it("calls Stripe V2 API + upsertAccount mutation", async () => {
|
|
211
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
212
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
const fakeAccount = { id: "acct_123" };
|
|
216
|
+
mockStripeInstance.v2.core.accounts.create.mockResolvedValue(fakeAccount);
|
|
217
|
+
mockCtx.runQuery.mockResolvedValue({ _id: "internal_id_1" });
|
|
218
|
+
|
|
219
|
+
const result = await bs.createAccount(mockCtx, {
|
|
220
|
+
userId: "user_1",
|
|
221
|
+
email: "test@example.com",
|
|
222
|
+
name: "Test User",
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
expect(mockStripeInstance.v2.core.accounts.create).toHaveBeenCalledWith(
|
|
226
|
+
expect.objectContaining({
|
|
227
|
+
contact_email: "test@example.com",
|
|
228
|
+
metadata: expect.objectContaining({ userId: "user_1" }),
|
|
229
|
+
}),
|
|
230
|
+
);
|
|
231
|
+
expect(mockCtx.runMutation).toHaveBeenCalledWith(
|
|
232
|
+
components.betterStripe.core.mutations.upsertAccount,
|
|
233
|
+
expect.objectContaining({
|
|
234
|
+
stripeAccountId: "acct_123",
|
|
235
|
+
userId: "user_1",
|
|
236
|
+
email: "test@example.com",
|
|
237
|
+
name: "Test User",
|
|
238
|
+
onboardingStatus: "pending",
|
|
239
|
+
}),
|
|
240
|
+
);
|
|
241
|
+
expect(result).toEqual({
|
|
242
|
+
accountId: "internal_id_1",
|
|
243
|
+
stripeAccountId: "acct_123",
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe("listTransfersByCharge", () => {
|
|
249
|
+
it("reads a sale's split legs via the component query (passthrough)", async () => {
|
|
250
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
251
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
252
|
+
});
|
|
253
|
+
const rows = [
|
|
254
|
+
{ stripeTransferId: "tr_store", role: "store", amount: 8000 },
|
|
255
|
+
{ stripeTransferId: "tr_aff", role: "affiliate", amount: 2000 },
|
|
256
|
+
];
|
|
257
|
+
mockCtx.runQuery.mockResolvedValue(rows);
|
|
258
|
+
|
|
259
|
+
const result = await bs.listTransfersByCharge(mockCtx, {
|
|
260
|
+
sourceChargeId: "ch_split",
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
expect(mockCtx.runQuery).toHaveBeenCalledTimes(1);
|
|
264
|
+
expect(mockCtx.runQuery.mock.calls[0][1]).toEqual({
|
|
265
|
+
sourceChargeId: "ch_split",
|
|
266
|
+
});
|
|
267
|
+
expect(result).toBe(rows);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe("listTransfersByAccount", () => {
|
|
272
|
+
it("reads a recipient's transfer ledger via the component query (passthrough)", async () => {
|
|
273
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
274
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
275
|
+
});
|
|
276
|
+
const rows = [{ stripeTransferId: "tr_aff", amount: 2000 }];
|
|
277
|
+
mockCtx.runQuery.mockResolvedValue(rows);
|
|
278
|
+
|
|
279
|
+
const result = await bs.listTransfersByAccount(mockCtx, {
|
|
280
|
+
destinationAccountId: "acct_avery",
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
expect(mockCtx.runQuery).toHaveBeenCalledTimes(1);
|
|
284
|
+
expect(mockCtx.runQuery.mock.calls[0][1]).toEqual({
|
|
285
|
+
destinationAccountId: "acct_avery",
|
|
286
|
+
});
|
|
287
|
+
expect(result).toBe(rows);
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
describe("reverseTransfers", () => {
|
|
292
|
+
it("takes the atomic claimReversalSlices path when operationId is provided", async () => {
|
|
293
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
294
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
mockCtx.runMutation.mockImplementation(async (ref: Record<symbol, string>) => {
|
|
298
|
+
const TO_REF = Symbol.for("toReferencePath");
|
|
299
|
+
const claimRef = components.betterStripe.connect.mutations
|
|
300
|
+
.claimReversalSlices as unknown as Record<symbol, string>;
|
|
301
|
+
if (ref[TO_REF] === claimRef[TO_REF]) {
|
|
302
|
+
return {
|
|
303
|
+
replay: false,
|
|
304
|
+
slices: [
|
|
305
|
+
{
|
|
306
|
+
stripeTransferId: "tr_store",
|
|
307
|
+
from: 0,
|
|
308
|
+
to: 8000,
|
|
309
|
+
confirmed: 0,
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
return undefined;
|
|
315
|
+
});
|
|
316
|
+
mockStripeInstance.transfers.createReversal.mockResolvedValue({
|
|
317
|
+
id: "trr_1",
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
const result = await bs.reverseTransfers(mockCtx, {
|
|
321
|
+
sourceChargeId: "ch_1",
|
|
322
|
+
operationId: "dp_1",
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
expect(mockCtx.runMutation).toHaveBeenCalledWith(
|
|
326
|
+
components.betterStripe.connect.mutations.claimReversalSlices,
|
|
327
|
+
expect.objectContaining({
|
|
328
|
+
operationId: "dp_1",
|
|
329
|
+
sourceChargeId: "ch_1",
|
|
330
|
+
mode: { kind: "full" },
|
|
331
|
+
}),
|
|
332
|
+
);
|
|
333
|
+
expect(mockStripeInstance.transfers.createReversal).toHaveBeenCalledWith(
|
|
334
|
+
"tr_store",
|
|
335
|
+
{ amount: 8000 },
|
|
336
|
+
{ idempotencyKey: "bs_rev_dp_1_tr_store" },
|
|
337
|
+
);
|
|
338
|
+
expect(result).toEqual({
|
|
339
|
+
reversals: [{ stripeTransferId: "tr_store", amount: 8000 }],
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
describe("addCustomerConfiguration", () => {
|
|
345
|
+
it("applies the customer configuration and records applied configs", async () => {
|
|
346
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
347
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
mockCtx.runQuery.mockResolvedValue({ userId: "user_1" });
|
|
351
|
+
mockStripeInstance.v2.core.accounts.update.mockResolvedValue({});
|
|
352
|
+
mockStripeInstance.v2.core.accounts.retrieve.mockResolvedValue({
|
|
353
|
+
applied_configurations: ["customer"],
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
const result = await bs.addCustomerConfiguration(mockCtx, {
|
|
357
|
+
stripeAccountId: "acct_123",
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
expect(mockStripeInstance.v2.core.accounts.update).toHaveBeenCalledWith(
|
|
361
|
+
"acct_123",
|
|
362
|
+
{ configuration: { customer: {} } },
|
|
363
|
+
);
|
|
364
|
+
expect(mockCtx.runMutation).toHaveBeenCalledWith(
|
|
365
|
+
components.betterStripe.core.mutations.upsertAccount,
|
|
366
|
+
expect.objectContaining({
|
|
367
|
+
stripeAccountId: "acct_123",
|
|
368
|
+
userId: "user_1",
|
|
369
|
+
appliedConfigurations: ["customer"],
|
|
370
|
+
}),
|
|
371
|
+
);
|
|
372
|
+
expect(result).toEqual({
|
|
373
|
+
success: true,
|
|
374
|
+
appliedConfigurations: ["customer"],
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// =========================================================================
|
|
380
|
+
// Product methods
|
|
381
|
+
// =========================================================================
|
|
382
|
+
|
|
383
|
+
describe("createProduct", () => {
|
|
384
|
+
it("calls Stripe API + upsertProduct mutation", async () => {
|
|
385
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
386
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
const fakeProduct = {
|
|
390
|
+
id: "prod_123",
|
|
391
|
+
name: "My Product",
|
|
392
|
+
description: "A product",
|
|
393
|
+
active: true,
|
|
394
|
+
metadata: {},
|
|
395
|
+
};
|
|
396
|
+
mockStripeInstance.products.create.mockResolvedValue(fakeProduct);
|
|
397
|
+
mockCtx.runQuery.mockResolvedValue({ _id: "internal_prod_1" });
|
|
398
|
+
|
|
399
|
+
const result = await bs.createProduct(mockCtx, {
|
|
400
|
+
name: "My Product",
|
|
401
|
+
description: "A product",
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
expect(mockStripeInstance.products.create).toHaveBeenCalledWith(
|
|
405
|
+
expect.objectContaining({
|
|
406
|
+
name: "My Product",
|
|
407
|
+
description: "A product",
|
|
408
|
+
active: true,
|
|
409
|
+
}),
|
|
410
|
+
);
|
|
411
|
+
expect(mockCtx.runMutation).toHaveBeenCalledWith(
|
|
412
|
+
components.betterStripe.products.mutations.upsertProduct,
|
|
413
|
+
expect.objectContaining({
|
|
414
|
+
stripeProductId: "prod_123",
|
|
415
|
+
name: "My Product",
|
|
416
|
+
active: true,
|
|
417
|
+
}),
|
|
418
|
+
);
|
|
419
|
+
expect(result).toEqual({
|
|
420
|
+
productId: "internal_prod_1",
|
|
421
|
+
stripeProductId: "prod_123",
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
// =========================================================================
|
|
427
|
+
// Price methods
|
|
428
|
+
// =========================================================================
|
|
429
|
+
|
|
430
|
+
describe("createPrice", () => {
|
|
431
|
+
it("calls Stripe API + upsertPrice mutation", async () => {
|
|
432
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
433
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
const fakePrice = {
|
|
437
|
+
id: "price_123",
|
|
438
|
+
nickname: "Monthly",
|
|
439
|
+
unit_amount: 1999,
|
|
440
|
+
currency: "usd",
|
|
441
|
+
active: true,
|
|
442
|
+
metadata: {},
|
|
443
|
+
};
|
|
444
|
+
mockStripeInstance.prices.create.mockResolvedValue(fakePrice);
|
|
445
|
+
mockCtx.runQuery.mockResolvedValue({ _id: "internal_prod_1" });
|
|
446
|
+
|
|
447
|
+
const result = await bs.createPrice(mockCtx, {
|
|
448
|
+
stripeProductId: "prod_123",
|
|
449
|
+
unitAmount: 1999,
|
|
450
|
+
currency: "usd",
|
|
451
|
+
type: "recurring",
|
|
452
|
+
interval: "month",
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
expect(mockStripeInstance.prices.create).toHaveBeenCalledWith(
|
|
456
|
+
expect.objectContaining({
|
|
457
|
+
product: "prod_123",
|
|
458
|
+
unit_amount: 1999,
|
|
459
|
+
currency: "usd",
|
|
460
|
+
recurring: { interval: "month", interval_count: 1 },
|
|
461
|
+
}),
|
|
462
|
+
);
|
|
463
|
+
expect(mockCtx.runMutation).toHaveBeenCalledWith(
|
|
464
|
+
components.betterStripe.products.mutations.upsertPrice,
|
|
465
|
+
expect.objectContaining({
|
|
466
|
+
stripePriceId: "price_123",
|
|
467
|
+
productId: "internal_prod_1",
|
|
468
|
+
stripeProductId: "prod_123",
|
|
469
|
+
unitAmount: 1999,
|
|
470
|
+
type: "recurring",
|
|
471
|
+
interval: "month",
|
|
472
|
+
}),
|
|
473
|
+
);
|
|
474
|
+
expect(result).toEqual({ stripePriceId: "price_123" });
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
// =========================================================================
|
|
479
|
+
// Checkout methods
|
|
480
|
+
// =========================================================================
|
|
481
|
+
|
|
482
|
+
describe("createCheckoutSession", () => {
|
|
483
|
+
it("returns clientSecret for embedded ui_mode", async () => {
|
|
484
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
485
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
mockStripeInstance.checkout.sessions.create.mockResolvedValue({
|
|
489
|
+
id: "cs_123",
|
|
490
|
+
client_secret: "cs_secret_xxx",
|
|
491
|
+
status: "open",
|
|
492
|
+
url: null,
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
const result = await bs.createCheckoutSession(mockCtx, {
|
|
496
|
+
userId: "user_1",
|
|
497
|
+
stripePriceId: "price_123",
|
|
498
|
+
mode: "subscription",
|
|
499
|
+
uiMode: "embedded",
|
|
500
|
+
returnUrl: "https://example.com/return",
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
expect(mockStripeInstance.checkout.sessions.create).toHaveBeenCalledWith(
|
|
504
|
+
expect.objectContaining({
|
|
505
|
+
ui_mode: "embedded_page",
|
|
506
|
+
return_url: "https://example.com/return",
|
|
507
|
+
}),
|
|
508
|
+
);
|
|
509
|
+
expect(result.clientSecret).toBe("cs_secret_xxx");
|
|
510
|
+
expect(result.stripeSessionId).toBe("cs_123");
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
it("returns url for redirect ui_mode", async () => {
|
|
514
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
515
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
mockStripeInstance.checkout.sessions.create.mockResolvedValue({
|
|
519
|
+
id: "cs_456",
|
|
520
|
+
client_secret: null,
|
|
521
|
+
status: "open",
|
|
522
|
+
url: "https://checkout.stripe.com/pay/cs_456",
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
const result = await bs.createCheckoutSession(mockCtx, {
|
|
526
|
+
userId: "user_1",
|
|
527
|
+
stripePriceId: "price_123",
|
|
528
|
+
mode: "subscription",
|
|
529
|
+
uiMode: "redirect",
|
|
530
|
+
returnUrl: "https://example.com/return",
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
expect(mockStripeInstance.checkout.sessions.create).toHaveBeenCalledWith(
|
|
534
|
+
expect.objectContaining({
|
|
535
|
+
success_url:
|
|
536
|
+
"https://example.com/return?session_id={CHECKOUT_SESSION_ID}",
|
|
537
|
+
cancel_url: "https://example.com/return",
|
|
538
|
+
}),
|
|
539
|
+
);
|
|
540
|
+
expect(result.url).toBe("https://checkout.stripe.com/pay/cs_456");
|
|
541
|
+
expect(result.stripeSessionId).toBe("cs_456");
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("passes the configured default statement-descriptor suffix through to destination charges (BTS-32)", async () => {
|
|
545
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
546
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
547
|
+
statementDescriptorSuffix: "PLATFORM DEF",
|
|
548
|
+
});
|
|
549
|
+
// No component account record for the store → falls back to the default.
|
|
550
|
+
mockCtx.runQuery.mockResolvedValue(null);
|
|
551
|
+
mockStripeInstance.checkout.sessions.create.mockResolvedValue({
|
|
552
|
+
id: "cs_sd",
|
|
553
|
+
client_secret: "cs_secret_sd",
|
|
554
|
+
status: "open",
|
|
555
|
+
url: null,
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
await bs.createCheckoutSession(mockCtx, {
|
|
559
|
+
userId: "user_1",
|
|
560
|
+
stripePriceId: "price_123",
|
|
561
|
+
mode: "payment",
|
|
562
|
+
returnUrl: "https://example.com/return",
|
|
563
|
+
destinationAccountId: "acct_store",
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
expect(mockStripeInstance.checkout.sessions.create).toHaveBeenCalledWith(
|
|
567
|
+
expect.objectContaining({
|
|
568
|
+
payment_intent_data: expect.objectContaining({
|
|
569
|
+
statement_descriptor_suffix: "PLATFORM DEF",
|
|
570
|
+
}),
|
|
571
|
+
}),
|
|
572
|
+
);
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
// =========================================================================
|
|
577
|
+
// Subscription methods
|
|
578
|
+
// =========================================================================
|
|
579
|
+
|
|
580
|
+
describe("cancelSubscription", () => {
|
|
581
|
+
it("uses update with cancel_at_period_end when atPeriodEnd", async () => {
|
|
582
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
583
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
mockStripeInstance.subscriptions.update.mockResolvedValue({});
|
|
587
|
+
|
|
588
|
+
await bs.cancelSubscription(mockCtx, {
|
|
589
|
+
stripeSubscriptionId: "sub_123",
|
|
590
|
+
cancelAtPeriodEnd: true,
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
expect(mockStripeInstance.subscriptions.update).toHaveBeenCalledWith(
|
|
594
|
+
"sub_123",
|
|
595
|
+
{ cancel_at_period_end: true },
|
|
596
|
+
);
|
|
597
|
+
expect(mockStripeInstance.subscriptions.cancel).not.toHaveBeenCalled();
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
it("uses cancel for immediate cancellation", async () => {
|
|
601
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
602
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
mockStripeInstance.subscriptions.cancel.mockResolvedValue({});
|
|
606
|
+
|
|
607
|
+
await bs.cancelSubscription(mockCtx, {
|
|
608
|
+
stripeSubscriptionId: "sub_123",
|
|
609
|
+
cancelAtPeriodEnd: false,
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
expect(mockStripeInstance.subscriptions.cancel).toHaveBeenCalledWith(
|
|
613
|
+
"sub_123",
|
|
614
|
+
);
|
|
615
|
+
expect(mockStripeInstance.subscriptions.update).not.toHaveBeenCalled();
|
|
616
|
+
});
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
describe("reactivateSubscription", () => {
|
|
620
|
+
it("sets cancel_at_period_end to false", async () => {
|
|
621
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
622
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
mockStripeInstance.subscriptions.update.mockResolvedValue({});
|
|
626
|
+
|
|
627
|
+
await bs.reactivateSubscription(mockCtx, {
|
|
628
|
+
stripeSubscriptionId: "sub_123",
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
expect(mockStripeInstance.subscriptions.update).toHaveBeenCalledWith(
|
|
632
|
+
"sub_123",
|
|
633
|
+
{ cancel_at_period_end: false },
|
|
634
|
+
);
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
describe("updateSubscriptionQuantity", () => {
|
|
639
|
+
it("retrieves the subscription and updates the first item quantity", async () => {
|
|
640
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
641
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
mockStripeInstance.subscriptions.retrieve.mockResolvedValue({
|
|
645
|
+
items: { data: [{ id: "si_1" }] },
|
|
646
|
+
});
|
|
647
|
+
mockStripeInstance.subscriptionItems.update.mockResolvedValue({});
|
|
648
|
+
|
|
649
|
+
const result = await bs.updateSubscriptionQuantity(mockCtx, {
|
|
650
|
+
stripeSubscriptionId: "sub_123",
|
|
651
|
+
quantity: 3,
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
expect(mockStripeInstance.subscriptions.retrieve).toHaveBeenCalledWith(
|
|
655
|
+
"sub_123",
|
|
656
|
+
);
|
|
657
|
+
expect(mockStripeInstance.subscriptionItems.update).toHaveBeenCalledWith(
|
|
658
|
+
"si_1",
|
|
659
|
+
{ quantity: 3 },
|
|
660
|
+
);
|
|
661
|
+
expect(result).toEqual({ success: true });
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
it("rejects when the subscription has no items and does not call update", async () => {
|
|
665
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
666
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
mockStripeInstance.subscriptions.retrieve.mockResolvedValue({
|
|
670
|
+
items: { data: [] },
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
await expect(
|
|
674
|
+
bs.updateSubscriptionQuantity(mockCtx, {
|
|
675
|
+
stripeSubscriptionId: "sub_123",
|
|
676
|
+
quantity: 3,
|
|
677
|
+
}),
|
|
678
|
+
).rejects.toThrow("Subscription has no items");
|
|
679
|
+
|
|
680
|
+
expect(
|
|
681
|
+
mockStripeInstance.subscriptionItems.update,
|
|
682
|
+
).not.toHaveBeenCalled();
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
it("surfaces a STRIPE_API_ERROR when the retrieve call throws", async () => {
|
|
686
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
687
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
mockStripeInstance.subscriptions.retrieve.mockRejectedValue(
|
|
691
|
+
new Error("boom"),
|
|
692
|
+
);
|
|
693
|
+
|
|
694
|
+
await expect(
|
|
695
|
+
bs.updateSubscriptionQuantity(mockCtx, {
|
|
696
|
+
stripeSubscriptionId: "sub_123",
|
|
697
|
+
quantity: 3,
|
|
698
|
+
}),
|
|
699
|
+
).rejects.toMatchObject({ data: { code: "STRIPE_API_ERROR" } });
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
describe("cancelSubscription error handling", () => {
|
|
704
|
+
it("surfaces a STRIPE_API_ERROR when the Stripe call throws", async () => {
|
|
705
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
706
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
mockStripeInstance.subscriptions.update.mockRejectedValue(
|
|
710
|
+
new Error("boom"),
|
|
711
|
+
);
|
|
712
|
+
|
|
713
|
+
await expect(
|
|
714
|
+
bs.cancelSubscription(mockCtx, {
|
|
715
|
+
stripeSubscriptionId: "sub_123",
|
|
716
|
+
cancelAtPeriodEnd: true,
|
|
717
|
+
}),
|
|
718
|
+
).rejects.toMatchObject({ data: { code: "STRIPE_API_ERROR" } });
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
describe("pauseSubscription", () => {
|
|
723
|
+
it("defaults behavior to keep_as_draft when omitted", async () => {
|
|
724
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
725
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
mockStripeInstance.subscriptions.update.mockResolvedValue({});
|
|
729
|
+
|
|
730
|
+
const result = await bs.pauseSubscription(mockCtx, {
|
|
731
|
+
stripeSubscriptionId: "sub_123",
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
expect(mockStripeInstance.subscriptions.update).toHaveBeenCalledWith(
|
|
735
|
+
"sub_123",
|
|
736
|
+
{ pause_collection: { behavior: "keep_as_draft" } },
|
|
737
|
+
);
|
|
738
|
+
expect(result).toEqual({ success: true });
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
it("passes resumes_at and behavior when provided", async () => {
|
|
742
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
743
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
mockStripeInstance.subscriptions.update.mockResolvedValue({});
|
|
747
|
+
|
|
748
|
+
await bs.pauseSubscription(mockCtx, {
|
|
749
|
+
stripeSubscriptionId: "sub_123",
|
|
750
|
+
behavior: "void",
|
|
751
|
+
resumesAt: 1893456000,
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
expect(mockStripeInstance.subscriptions.update).toHaveBeenCalledWith(
|
|
755
|
+
"sub_123",
|
|
756
|
+
{ pause_collection: { behavior: "void", resumes_at: 1893456000 } },
|
|
757
|
+
);
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
it("surfaces a STRIPE_API_ERROR when the Stripe call throws", async () => {
|
|
761
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
762
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
mockStripeInstance.subscriptions.update.mockRejectedValue(
|
|
766
|
+
new Error("boom"),
|
|
767
|
+
);
|
|
768
|
+
|
|
769
|
+
await expect(
|
|
770
|
+
bs.pauseSubscription(mockCtx, { stripeSubscriptionId: "sub_123" }),
|
|
771
|
+
).rejects.toMatchObject({ data: { code: "STRIPE_API_ERROR" } });
|
|
772
|
+
});
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
describe("resumeSubscription", () => {
|
|
776
|
+
it("clears pause_collection with the empty-string sentinel", async () => {
|
|
777
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
778
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
mockStripeInstance.subscriptions.update.mockResolvedValue({});
|
|
782
|
+
|
|
783
|
+
const result = await bs.resumeSubscription(mockCtx, {
|
|
784
|
+
stripeSubscriptionId: "sub_123",
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
expect(mockStripeInstance.subscriptions.update).toHaveBeenCalledWith(
|
|
788
|
+
"sub_123",
|
|
789
|
+
{ pause_collection: "" },
|
|
790
|
+
);
|
|
791
|
+
expect(result).toEqual({ success: true });
|
|
792
|
+
});
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
describe("updateSubscriptionPrice", () => {
|
|
796
|
+
it("retrieves the item id and defaults proration_behavior to none", async () => {
|
|
797
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
798
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
mockStripeInstance.subscriptions.retrieve.mockResolvedValue({
|
|
802
|
+
items: { data: [{ id: "si_1" }] },
|
|
803
|
+
});
|
|
804
|
+
mockStripeInstance.subscriptions.update.mockResolvedValue({});
|
|
805
|
+
|
|
806
|
+
const result = await bs.updateSubscriptionPrice(mockCtx, {
|
|
807
|
+
stripeSubscriptionId: "sub_123",
|
|
808
|
+
stripePriceId: "price_new",
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
expect(mockStripeInstance.subscriptions.retrieve).toHaveBeenCalledWith(
|
|
812
|
+
"sub_123",
|
|
813
|
+
);
|
|
814
|
+
expect(mockStripeInstance.subscriptions.update).toHaveBeenCalledWith(
|
|
815
|
+
"sub_123",
|
|
816
|
+
{
|
|
817
|
+
items: [{ id: "si_1", price: "price_new" }],
|
|
818
|
+
proration_behavior: "none",
|
|
819
|
+
},
|
|
820
|
+
);
|
|
821
|
+
expect(result).toEqual({ success: true });
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
it("passes through a caller-provided prorationBehavior", async () => {
|
|
825
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
826
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
mockStripeInstance.subscriptions.retrieve.mockResolvedValue({
|
|
830
|
+
items: { data: [{ id: "si_1" }] },
|
|
831
|
+
});
|
|
832
|
+
mockStripeInstance.subscriptions.update.mockResolvedValue({});
|
|
833
|
+
|
|
834
|
+
await bs.updateSubscriptionPrice(mockCtx, {
|
|
835
|
+
stripeSubscriptionId: "sub_123",
|
|
836
|
+
stripePriceId: "price_new",
|
|
837
|
+
prorationBehavior: "always_invoice",
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
expect(mockStripeInstance.subscriptions.update).toHaveBeenCalledWith(
|
|
841
|
+
"sub_123",
|
|
842
|
+
{
|
|
843
|
+
items: [{ id: "si_1", price: "price_new" }],
|
|
844
|
+
proration_behavior: "always_invoice",
|
|
845
|
+
},
|
|
846
|
+
);
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
it("rejects when the subscription has no items and does not call update", async () => {
|
|
850
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
851
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
mockStripeInstance.subscriptions.retrieve.mockResolvedValue({
|
|
855
|
+
items: { data: [] },
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
await expect(
|
|
859
|
+
bs.updateSubscriptionPrice(mockCtx, {
|
|
860
|
+
stripeSubscriptionId: "sub_123",
|
|
861
|
+
stripePriceId: "price_new",
|
|
862
|
+
}),
|
|
863
|
+
).rejects.toThrow("Subscription has no items");
|
|
864
|
+
|
|
865
|
+
expect(mockStripeInstance.subscriptions.update).not.toHaveBeenCalled();
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
it("surfaces a STRIPE_API_ERROR when the update call throws after a successful retrieve", async () => {
|
|
869
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
870
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
mockStripeInstance.subscriptions.retrieve.mockResolvedValue({
|
|
874
|
+
items: { data: [{ id: "si_1" }] },
|
|
875
|
+
});
|
|
876
|
+
mockStripeInstance.subscriptions.update.mockRejectedValue(
|
|
877
|
+
new Error("boom"),
|
|
878
|
+
);
|
|
879
|
+
|
|
880
|
+
await expect(
|
|
881
|
+
bs.updateSubscriptionPrice(mockCtx, {
|
|
882
|
+
stripeSubscriptionId: "sub_123",
|
|
883
|
+
stripePriceId: "price_new",
|
|
884
|
+
}),
|
|
885
|
+
).rejects.toMatchObject({ data: { code: "STRIPE_API_ERROR" } });
|
|
886
|
+
});
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
describe("updateSubscriptionMetadata", () => {
|
|
890
|
+
it("calls update with the provided metadata", async () => {
|
|
891
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
892
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
mockStripeInstance.subscriptions.update.mockResolvedValue({});
|
|
896
|
+
|
|
897
|
+
const result = await bs.updateSubscriptionMetadata(mockCtx, {
|
|
898
|
+
stripeSubscriptionId: "sub_123",
|
|
899
|
+
metadata: { plan: "pro" },
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
expect(mockStripeInstance.subscriptions.update).toHaveBeenCalledWith(
|
|
903
|
+
"sub_123",
|
|
904
|
+
{ metadata: { plan: "pro" } },
|
|
905
|
+
);
|
|
906
|
+
expect(result).toEqual({ success: true });
|
|
907
|
+
});
|
|
908
|
+
});
|
|
909
|
+
|
|
910
|
+
describe("updateSubscriptionTrialEnd", () => {
|
|
911
|
+
it("ends the trial immediately with 'now'", async () => {
|
|
912
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
913
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
914
|
+
});
|
|
915
|
+
|
|
916
|
+
mockStripeInstance.subscriptions.update.mockResolvedValue({});
|
|
917
|
+
|
|
918
|
+
const result = await bs.updateSubscriptionTrialEnd(mockCtx, {
|
|
919
|
+
stripeSubscriptionId: "sub_123",
|
|
920
|
+
trialEnd: "now",
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
expect(mockStripeInstance.subscriptions.update).toHaveBeenCalledWith(
|
|
924
|
+
"sub_123",
|
|
925
|
+
{ trial_end: "now" },
|
|
926
|
+
);
|
|
927
|
+
expect(result).toEqual({ success: true });
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
it("passes a numeric timestamp through unchanged", async () => {
|
|
931
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
932
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
933
|
+
});
|
|
934
|
+
|
|
935
|
+
mockStripeInstance.subscriptions.update.mockResolvedValue({});
|
|
936
|
+
|
|
937
|
+
await bs.updateSubscriptionTrialEnd(mockCtx, {
|
|
938
|
+
stripeSubscriptionId: "sub_123",
|
|
939
|
+
trialEnd: 1893456000,
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
expect(mockStripeInstance.subscriptions.update).toHaveBeenCalledWith(
|
|
943
|
+
"sub_123",
|
|
944
|
+
{ trial_end: 1893456000 },
|
|
945
|
+
);
|
|
946
|
+
});
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
// =========================================================================
|
|
950
|
+
// Invoice methods
|
|
951
|
+
// =========================================================================
|
|
952
|
+
|
|
953
|
+
describe("getInvoice", () => {
|
|
954
|
+
it("runs the getInvoiceByStripeId component query with the invoice id", async () => {
|
|
955
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
956
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
const fakeInvoice = {
|
|
960
|
+
stripeInvoiceId: "in_123",
|
|
961
|
+
status: "paid",
|
|
962
|
+
amountDue: 1000,
|
|
963
|
+
};
|
|
964
|
+
mockCtx.runQuery.mockResolvedValue(fakeInvoice);
|
|
965
|
+
|
|
966
|
+
const result = await bs.getInvoice(mockCtx, {
|
|
967
|
+
stripeInvoiceId: "in_123",
|
|
968
|
+
});
|
|
969
|
+
|
|
970
|
+
expect(mockCtx.runQuery).toHaveBeenCalledWith(
|
|
971
|
+
components.betterStripe.billing.queries.getInvoiceByStripeId,
|
|
972
|
+
{ stripeInvoiceId: "in_123" },
|
|
973
|
+
);
|
|
974
|
+
expect(result).toEqual(fakeInvoice);
|
|
975
|
+
});
|
|
976
|
+
|
|
977
|
+
it("returns null when the invoice is not found", async () => {
|
|
978
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
979
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
980
|
+
});
|
|
981
|
+
|
|
982
|
+
mockCtx.runQuery.mockResolvedValue(null);
|
|
983
|
+
|
|
984
|
+
const result = await bs.getInvoice(mockCtx, {
|
|
985
|
+
stripeInvoiceId: "in_missing",
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
expect(result).toBeNull();
|
|
989
|
+
});
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
describe("getInvoiceByStripeId", () => {
|
|
993
|
+
it("is an alias that runs the same component query", async () => {
|
|
994
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
995
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
const fakeInvoice = { stripeInvoiceId: "in_456", status: "open" };
|
|
999
|
+
mockCtx.runQuery.mockResolvedValue(fakeInvoice);
|
|
1000
|
+
|
|
1001
|
+
const result = await bs.getInvoiceByStripeId(mockCtx, {
|
|
1002
|
+
stripeInvoiceId: "in_456",
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
expect(mockCtx.runQuery).toHaveBeenCalledWith(
|
|
1006
|
+
components.betterStripe.billing.queries.getInvoiceByStripeId,
|
|
1007
|
+
{ stripeInvoiceId: "in_456" },
|
|
1008
|
+
);
|
|
1009
|
+
expect(result).toEqual(fakeInvoice);
|
|
1010
|
+
});
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
describe("listInvoices", () => {
|
|
1014
|
+
it("maps stripeAccountId to the component accountId arg", async () => {
|
|
1015
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1016
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
mockCtx.runQuery.mockResolvedValue([]);
|
|
1020
|
+
|
|
1021
|
+
await bs.listInvoices(mockCtx, {
|
|
1022
|
+
stripeAccountId: "acct_map_001",
|
|
1023
|
+
status: "paid",
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
expect(mockCtx.runQuery).toHaveBeenCalledWith(
|
|
1027
|
+
components.betterStripe.billing.queries.listInvoices,
|
|
1028
|
+
{ accountId: "acct_map_001", status: "paid" },
|
|
1029
|
+
);
|
|
1030
|
+
});
|
|
1031
|
+
|
|
1032
|
+
it("passes no accountId when stripeAccountId is omitted", async () => {
|
|
1033
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1034
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
mockCtx.runQuery.mockResolvedValue([]);
|
|
1038
|
+
|
|
1039
|
+
await bs.listInvoices(mockCtx, { userId: "user_map_001" });
|
|
1040
|
+
|
|
1041
|
+
expect(mockCtx.runQuery).toHaveBeenCalledWith(
|
|
1042
|
+
components.betterStripe.billing.queries.listInvoices,
|
|
1043
|
+
{ userId: "user_map_001" },
|
|
1044
|
+
);
|
|
1045
|
+
});
|
|
1046
|
+
});
|
|
1047
|
+
|
|
1048
|
+
describe("listSubscriptions", () => {
|
|
1049
|
+
it("maps stripeAccountId to the component accountId arg", async () => {
|
|
1050
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1051
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1052
|
+
});
|
|
1053
|
+
|
|
1054
|
+
mockCtx.runQuery.mockResolvedValue([]);
|
|
1055
|
+
|
|
1056
|
+
await bs.listSubscriptions(mockCtx, {
|
|
1057
|
+
stripeAccountId: "acct_map_sub_001",
|
|
1058
|
+
status: "active",
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
expect(mockCtx.runQuery).toHaveBeenCalledWith(
|
|
1062
|
+
components.betterStripe.billing.queries.listSubscriptions,
|
|
1063
|
+
{ accountId: "acct_map_sub_001", status: "active" },
|
|
1064
|
+
);
|
|
1065
|
+
});
|
|
1066
|
+
|
|
1067
|
+
it("passes no accountId when stripeAccountId is omitted", async () => {
|
|
1068
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1069
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
mockCtx.runQuery.mockResolvedValue([]);
|
|
1073
|
+
|
|
1074
|
+
await bs.listSubscriptions(mockCtx, { status: "canceled" });
|
|
1075
|
+
|
|
1076
|
+
expect(mockCtx.runQuery).toHaveBeenCalledWith(
|
|
1077
|
+
components.betterStripe.billing.queries.listSubscriptions,
|
|
1078
|
+
{ status: "canceled" },
|
|
1079
|
+
);
|
|
1080
|
+
});
|
|
1081
|
+
});
|
|
1082
|
+
|
|
1083
|
+
describe("listPayouts", () => {
|
|
1084
|
+
it("maps stripeAccountId to the component accountId arg", async () => {
|
|
1085
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1086
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1087
|
+
});
|
|
1088
|
+
|
|
1089
|
+
mockCtx.runQuery.mockResolvedValue([]);
|
|
1090
|
+
|
|
1091
|
+
await bs.listPayouts(mockCtx, {
|
|
1092
|
+
stripeAccountId: "acct_map_po_001",
|
|
1093
|
+
status: "paid",
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
expect(mockCtx.runQuery).toHaveBeenCalledWith(
|
|
1097
|
+
components.betterStripe.connect.queries.listPayouts,
|
|
1098
|
+
{ accountId: "acct_map_po_001", status: "paid" },
|
|
1099
|
+
);
|
|
1100
|
+
});
|
|
1101
|
+
|
|
1102
|
+
it("passes no accountId when stripeAccountId is omitted", async () => {
|
|
1103
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1104
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
mockCtx.runQuery.mockResolvedValue([]);
|
|
1108
|
+
|
|
1109
|
+
await bs.listPayouts(mockCtx, { status: "pending", limit: 10 });
|
|
1110
|
+
|
|
1111
|
+
expect(mockCtx.runQuery).toHaveBeenCalledWith(
|
|
1112
|
+
components.betterStripe.connect.queries.listPayouts,
|
|
1113
|
+
{ status: "pending", limit: 10 },
|
|
1114
|
+
);
|
|
1115
|
+
});
|
|
1116
|
+
});
|
|
1117
|
+
|
|
1118
|
+
// =========================================================================
|
|
1119
|
+
// Payout: createPayout
|
|
1120
|
+
// =========================================================================
|
|
1121
|
+
|
|
1122
|
+
describe("createPayout", () => {
|
|
1123
|
+
it("calls payouts.create with the stripeAccount routing header and default currency", async () => {
|
|
1124
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1125
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
mockStripeInstance.payouts.create.mockResolvedValue({ id: "po_1" });
|
|
1129
|
+
|
|
1130
|
+
const result = await bs.createPayout(mockCtx, {
|
|
1131
|
+
stripeAccountId: "acct_1",
|
|
1132
|
+
amount: 5000,
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
expect(mockStripeInstance.payouts.create).toHaveBeenCalledWith(
|
|
1136
|
+
{ amount: 5000, currency: "usd", metadata: undefined },
|
|
1137
|
+
{ stripeAccount: "acct_1" },
|
|
1138
|
+
);
|
|
1139
|
+
expect(result).toEqual({ stripePayoutId: "po_1" });
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1142
|
+
it("passes through a currency override and returns stripePayoutId", async () => {
|
|
1143
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1144
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1147
|
+
mockStripeInstance.payouts.create.mockResolvedValue({ id: "po_2" });
|
|
1148
|
+
|
|
1149
|
+
const result = await bs.createPayout(mockCtx, {
|
|
1150
|
+
stripeAccountId: "acct_1",
|
|
1151
|
+
amount: 10000,
|
|
1152
|
+
currency: "gbp",
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
expect(mockStripeInstance.payouts.create).toHaveBeenCalledWith(
|
|
1156
|
+
{ amount: 10000, currency: "gbp", metadata: undefined },
|
|
1157
|
+
{ stripeAccount: "acct_1" },
|
|
1158
|
+
);
|
|
1159
|
+
expect(result).toEqual({ stripePayoutId: "po_2" });
|
|
1160
|
+
});
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
// =========================================================================
|
|
1164
|
+
// Refund methods
|
|
1165
|
+
// =========================================================================
|
|
1166
|
+
|
|
1167
|
+
describe("createRefund", () => {
|
|
1168
|
+
it("creates a refund for a payment intent and returns the refund id", async () => {
|
|
1169
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1170
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1171
|
+
});
|
|
1172
|
+
|
|
1173
|
+
mockStripeInstance.refunds.create.mockResolvedValue({ id: "re_1" });
|
|
1174
|
+
// Plain (non-marketplace) charge: no fee/transfer → no flags sent.
|
|
1175
|
+
mockStripeInstance.paymentIntents.retrieve.mockResolvedValue({
|
|
1176
|
+
id: "pi_1",
|
|
1177
|
+
latest_charge: "ch_1",
|
|
1178
|
+
});
|
|
1179
|
+
mockStripeInstance.charges.retrieve.mockResolvedValue({
|
|
1180
|
+
id: "ch_1",
|
|
1181
|
+
transfer: null,
|
|
1182
|
+
application_fee: null,
|
|
1183
|
+
});
|
|
1184
|
+
|
|
1185
|
+
const result = await bs.createRefund(mockCtx, {
|
|
1186
|
+
stripePaymentIntentId: "pi_1",
|
|
1187
|
+
amount: 250,
|
|
1188
|
+
reason: "requested_by_customer",
|
|
1189
|
+
});
|
|
1190
|
+
|
|
1191
|
+
expect(mockStripeInstance.refunds.create).toHaveBeenCalledWith(
|
|
1192
|
+
{
|
|
1193
|
+
payment_intent: "pi_1",
|
|
1194
|
+
amount: 250,
|
|
1195
|
+
reason: "requested_by_customer",
|
|
1196
|
+
},
|
|
1197
|
+
undefined,
|
|
1198
|
+
);
|
|
1199
|
+
expect(result).toEqual({ stripeRefundId: "re_1" });
|
|
1200
|
+
});
|
|
1201
|
+
|
|
1202
|
+
it("routes to a connected account when stripeAccountId is given", async () => {
|
|
1203
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1204
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1205
|
+
});
|
|
1206
|
+
|
|
1207
|
+
mockStripeInstance.refunds.create.mockResolvedValue({ id: "re_2" });
|
|
1208
|
+
mockStripeInstance.charges.retrieve.mockResolvedValue({
|
|
1209
|
+
id: "ch_1",
|
|
1210
|
+
transfer: null,
|
|
1211
|
+
application_fee: null,
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
await bs.createRefund(mockCtx, {
|
|
1215
|
+
stripeChargeId: "ch_1",
|
|
1216
|
+
stripeAccountId: "acct_1",
|
|
1217
|
+
});
|
|
1218
|
+
|
|
1219
|
+
expect(mockStripeInstance.refunds.create).toHaveBeenCalledWith(
|
|
1220
|
+
{ charge: "ch_1" },
|
|
1221
|
+
{ stripeAccount: "acct_1" },
|
|
1222
|
+
);
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
it("rejects with REFUND_CREATE_FAILED when neither PI nor charge is given", async () => {
|
|
1226
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1227
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1228
|
+
});
|
|
1229
|
+
|
|
1230
|
+
await expect(bs.createRefund(mockCtx, {})).rejects.toMatchObject({
|
|
1231
|
+
data: { code: "REFUND_CREATE_FAILED" },
|
|
1232
|
+
});
|
|
1233
|
+
expect(mockStripeInstance.refunds.create).not.toHaveBeenCalled();
|
|
1234
|
+
});
|
|
1235
|
+
|
|
1236
|
+
it("rejects with REFUND_CREATE_FAILED when both PI and charge are given", async () => {
|
|
1237
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1238
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
await expect(
|
|
1242
|
+
bs.createRefund(mockCtx, {
|
|
1243
|
+
stripePaymentIntentId: "pi_1",
|
|
1244
|
+
stripeChargeId: "ch_1",
|
|
1245
|
+
}),
|
|
1246
|
+
).rejects.toMatchObject({ data: { code: "REFUND_CREATE_FAILED" } });
|
|
1247
|
+
expect(mockStripeInstance.refunds.create).not.toHaveBeenCalled();
|
|
1248
|
+
});
|
|
1249
|
+
|
|
1250
|
+
it("surfaces a STRIPE API failure as REFUND_CREATE_FAILED", async () => {
|
|
1251
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1252
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1253
|
+
});
|
|
1254
|
+
|
|
1255
|
+
mockStripeInstance.refunds.create.mockRejectedValue(new Error("boom"));
|
|
1256
|
+
|
|
1257
|
+
await expect(
|
|
1258
|
+
bs.createRefund(mockCtx, { stripePaymentIntentId: "pi_1" }),
|
|
1259
|
+
).rejects.toMatchObject({ data: { code: "REFUND_CREATE_FAILED" } });
|
|
1260
|
+
});
|
|
1261
|
+
});
|
|
1262
|
+
|
|
1263
|
+
describe("listRefunds / getRefundByStripeId", () => {
|
|
1264
|
+
it("forwards reads to the component, mapping stripeAccountId to accountId", async () => {
|
|
1265
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1266
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1267
|
+
});
|
|
1268
|
+
|
|
1269
|
+
mockCtx.runQuery.mockResolvedValue([]);
|
|
1270
|
+
|
|
1271
|
+
await bs.listRefunds(mockCtx, {
|
|
1272
|
+
stripeAccountId: "acct_1",
|
|
1273
|
+
status: "succeeded",
|
|
1274
|
+
});
|
|
1275
|
+
|
|
1276
|
+
expect(mockCtx.runQuery).toHaveBeenCalledWith(expect.anything(), {
|
|
1277
|
+
accountId: "acct_1",
|
|
1278
|
+
status: "succeeded",
|
|
1279
|
+
});
|
|
1280
|
+
});
|
|
1281
|
+
});
|
|
1282
|
+
|
|
1283
|
+
// =========================================================================
|
|
1284
|
+
// Dispute methods
|
|
1285
|
+
// =========================================================================
|
|
1286
|
+
|
|
1287
|
+
describe("updateDispute", () => {
|
|
1288
|
+
it("submits evidence with the submit flag", async () => {
|
|
1289
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1290
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1291
|
+
});
|
|
1292
|
+
|
|
1293
|
+
mockStripeInstance.disputes.update.mockResolvedValue({});
|
|
1294
|
+
|
|
1295
|
+
const result = await bs.updateDispute(mockCtx, {
|
|
1296
|
+
stripeDisputeId: "dp_1",
|
|
1297
|
+
evidence: { product_description: "A widget" },
|
|
1298
|
+
submit: true,
|
|
1299
|
+
});
|
|
1300
|
+
|
|
1301
|
+
expect(mockStripeInstance.disputes.update).toHaveBeenCalledWith(
|
|
1302
|
+
"dp_1",
|
|
1303
|
+
{ evidence: { product_description: "A widget" }, submit: true },
|
|
1304
|
+
undefined,
|
|
1305
|
+
);
|
|
1306
|
+
expect(result).toEqual({ success: true });
|
|
1307
|
+
});
|
|
1308
|
+
|
|
1309
|
+
it("surfaces a STRIPE API failure as DISPUTE_UPDATE_FAILED", async () => {
|
|
1310
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1311
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1312
|
+
});
|
|
1313
|
+
|
|
1314
|
+
mockStripeInstance.disputes.update.mockRejectedValue(new Error("boom"));
|
|
1315
|
+
|
|
1316
|
+
await expect(
|
|
1317
|
+
bs.updateDispute(mockCtx, { stripeDisputeId: "dp_1", submit: true }),
|
|
1318
|
+
).rejects.toMatchObject({ data: { code: "DISPUTE_UPDATE_FAILED" } });
|
|
1319
|
+
});
|
|
1320
|
+
});
|
|
1321
|
+
|
|
1322
|
+
describe("closeDispute", () => {
|
|
1323
|
+
it("closes the dispute, passing routing options in the third arg", async () => {
|
|
1324
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1325
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1326
|
+
});
|
|
1327
|
+
|
|
1328
|
+
mockStripeInstance.disputes.close.mockResolvedValue({});
|
|
1329
|
+
|
|
1330
|
+
const result = await bs.closeDispute(mockCtx, {
|
|
1331
|
+
stripeDisputeId: "dp_1",
|
|
1332
|
+
stripeAccountId: "acct_1",
|
|
1333
|
+
});
|
|
1334
|
+
|
|
1335
|
+
expect(mockStripeInstance.disputes.close).toHaveBeenCalledWith(
|
|
1336
|
+
"dp_1",
|
|
1337
|
+
{},
|
|
1338
|
+
{ stripeAccount: "acct_1" },
|
|
1339
|
+
);
|
|
1340
|
+
expect(result).toEqual({ success: true });
|
|
1341
|
+
});
|
|
1342
|
+
});
|
|
1343
|
+
|
|
1344
|
+
// =========================================================================
|
|
1345
|
+
// Payment method: listPaymentMethods
|
|
1346
|
+
// =========================================================================
|
|
1347
|
+
|
|
1348
|
+
describe("listPaymentMethods", () => {
|
|
1349
|
+
it("defaults to card type and uses the V2 customer_account param", async () => {
|
|
1350
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1351
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1352
|
+
});
|
|
1353
|
+
|
|
1354
|
+
mockStripeInstance.paymentMethods.list.mockResolvedValue({ data: [] });
|
|
1355
|
+
|
|
1356
|
+
await bs.listPaymentMethods(mockCtx, { stripeCustomerId: "acct_1" });
|
|
1357
|
+
|
|
1358
|
+
expect(mockStripeInstance.paymentMethods.list).toHaveBeenCalledWith({
|
|
1359
|
+
customer_account: "acct_1",
|
|
1360
|
+
type: "card",
|
|
1361
|
+
});
|
|
1362
|
+
});
|
|
1363
|
+
|
|
1364
|
+
it("passes through an explicit type", async () => {
|
|
1365
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1366
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1367
|
+
});
|
|
1368
|
+
|
|
1369
|
+
mockStripeInstance.paymentMethods.list.mockResolvedValue({ data: [] });
|
|
1370
|
+
|
|
1371
|
+
await bs.listPaymentMethods(mockCtx, {
|
|
1372
|
+
stripeCustomerId: "acct_1",
|
|
1373
|
+
type: "us_bank_account",
|
|
1374
|
+
});
|
|
1375
|
+
|
|
1376
|
+
expect(mockStripeInstance.paymentMethods.list).toHaveBeenCalledWith({
|
|
1377
|
+
customer_account: "acct_1",
|
|
1378
|
+
type: "us_bank_account",
|
|
1379
|
+
});
|
|
1380
|
+
});
|
|
1381
|
+
});
|
|
1382
|
+
|
|
1383
|
+
// =========================================================================
|
|
1384
|
+
// Payment method: attachPaymentMethod
|
|
1385
|
+
// =========================================================================
|
|
1386
|
+
|
|
1387
|
+
describe("attachPaymentMethod", () => {
|
|
1388
|
+
it("attaches with the V2 customer_account param and returns success", async () => {
|
|
1389
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1390
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1391
|
+
});
|
|
1392
|
+
|
|
1393
|
+
mockStripeInstance.paymentMethods.attach.mockResolvedValue({});
|
|
1394
|
+
|
|
1395
|
+
const result = await bs.attachPaymentMethod(mockCtx, {
|
|
1396
|
+
paymentMethodId: "pm_1",
|
|
1397
|
+
stripeCustomerId: "acct_1",
|
|
1398
|
+
});
|
|
1399
|
+
|
|
1400
|
+
expect(mockStripeInstance.paymentMethods.attach).toHaveBeenCalledWith(
|
|
1401
|
+
"pm_1",
|
|
1402
|
+
{ customer_account: "acct_1" },
|
|
1403
|
+
);
|
|
1404
|
+
expect(result).toEqual({ success: true });
|
|
1405
|
+
});
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
// =========================================================================
|
|
1409
|
+
// Payment method: detachPaymentMethod
|
|
1410
|
+
// =========================================================================
|
|
1411
|
+
|
|
1412
|
+
describe("detachPaymentMethod", () => {
|
|
1413
|
+
it("calls paymentMethods.detach with the payment method id", async () => {
|
|
1414
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1415
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1416
|
+
});
|
|
1417
|
+
|
|
1418
|
+
mockStripeInstance.paymentMethods.detach.mockResolvedValue({});
|
|
1419
|
+
|
|
1420
|
+
await bs.detachPaymentMethod(mockCtx, { paymentMethodId: "pm_1" });
|
|
1421
|
+
|
|
1422
|
+
expect(mockStripeInstance.paymentMethods.detach).toHaveBeenCalledWith(
|
|
1423
|
+
"pm_1",
|
|
1424
|
+
);
|
|
1425
|
+
});
|
|
1426
|
+
});
|
|
1427
|
+
|
|
1428
|
+
// =========================================================================
|
|
1429
|
+
// Payment method: setDefaultPaymentMethod
|
|
1430
|
+
// =========================================================================
|
|
1431
|
+
|
|
1432
|
+
describe("setDefaultPaymentMethod", () => {
|
|
1433
|
+
it("throws not-yet-implemented error", async () => {
|
|
1434
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1435
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1436
|
+
});
|
|
1437
|
+
|
|
1438
|
+
await expect(
|
|
1439
|
+
bs.setDefaultPaymentMethod(mockCtx, {
|
|
1440
|
+
stripeAccountId: "acct_123",
|
|
1441
|
+
paymentMethodId: "pm_123",
|
|
1442
|
+
}),
|
|
1443
|
+
).rejects.toThrow("not yet implemented for V2 Accounts");
|
|
1444
|
+
});
|
|
1445
|
+
});
|
|
1446
|
+
|
|
1447
|
+
// =========================================================================
|
|
1448
|
+
// Account link methods: createAccountSession
|
|
1449
|
+
// =========================================================================
|
|
1450
|
+
|
|
1451
|
+
describe("createAccountSession", () => {
|
|
1452
|
+
it("calls Stripe accountSessions.create and returns the clientSecret", async () => {
|
|
1453
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1454
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1455
|
+
});
|
|
1456
|
+
|
|
1457
|
+
mockStripeInstance.accountSessions.create.mockResolvedValue({
|
|
1458
|
+
client_secret: "as_secret_123",
|
|
1459
|
+
});
|
|
1460
|
+
|
|
1461
|
+
const result = await bs.createAccountSession(mockCtx, {
|
|
1462
|
+
stripeAccountId: "acct_123",
|
|
1463
|
+
components: {
|
|
1464
|
+
account_management: { enabled: true },
|
|
1465
|
+
},
|
|
1466
|
+
});
|
|
1467
|
+
|
|
1468
|
+
expect(mockStripeInstance.accountSessions.create).toHaveBeenCalledWith({
|
|
1469
|
+
account: "acct_123",
|
|
1470
|
+
components: {
|
|
1471
|
+
account_management: { enabled: true },
|
|
1472
|
+
},
|
|
1473
|
+
});
|
|
1474
|
+
expect(result).toEqual({ clientSecret: "as_secret_123" });
|
|
1475
|
+
});
|
|
1476
|
+
|
|
1477
|
+
it("wraps Stripe failures in a structured STRIPE_API_ERROR", async () => {
|
|
1478
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1479
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1480
|
+
});
|
|
1481
|
+
|
|
1482
|
+
mockStripeInstance.accountSessions.create.mockRejectedValue(
|
|
1483
|
+
Object.assign(new Error("No such account: acct_missing"), {
|
|
1484
|
+
type: "StripeInvalidRequestError",
|
|
1485
|
+
code: "resource_missing",
|
|
1486
|
+
}),
|
|
1487
|
+
);
|
|
1488
|
+
|
|
1489
|
+
const error = await bs
|
|
1490
|
+
.createAccountSession(mockCtx, {
|
|
1491
|
+
stripeAccountId: "acct_missing",
|
|
1492
|
+
components: { account_onboarding: { enabled: true } },
|
|
1493
|
+
})
|
|
1494
|
+
.catch((e: unknown) => e);
|
|
1495
|
+
|
|
1496
|
+
expect(error).toBeInstanceOf(ConvexError);
|
|
1497
|
+
expect((error as { data: Record<string, unknown> }).data).toMatchObject({
|
|
1498
|
+
code: "STRIPE_API_ERROR",
|
|
1499
|
+
stripeError: {
|
|
1500
|
+
type: "StripeInvalidRequestError",
|
|
1501
|
+
code: "resource_missing",
|
|
1502
|
+
message: "No such account: acct_missing",
|
|
1503
|
+
},
|
|
1504
|
+
});
|
|
1505
|
+
});
|
|
1506
|
+
});
|
|
1507
|
+
|
|
1508
|
+
// =========================================================================
|
|
1509
|
+
// syncAllProducts
|
|
1510
|
+
// =========================================================================
|
|
1511
|
+
|
|
1512
|
+
describe("syncAllProducts", () => {
|
|
1513
|
+
/** Helper: returns an async iterable from an array (matches Stripe's auto-pagination API). */
|
|
1514
|
+
async function* asyncIter<T>(items: T[]): AsyncIterable<T> {
|
|
1515
|
+
for (const item of items) {
|
|
1516
|
+
yield item;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
it("calls getProductByStripeId exactly once per distinct product even with multiple prices", async () => {
|
|
1521
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1522
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1523
|
+
});
|
|
1524
|
+
|
|
1525
|
+
mockStripeInstance.products.list.mockReturnValue(
|
|
1526
|
+
asyncIter([
|
|
1527
|
+
{
|
|
1528
|
+
id: "prod_1",
|
|
1529
|
+
name: "Product 1",
|
|
1530
|
+
active: true,
|
|
1531
|
+
description: null,
|
|
1532
|
+
metadata: {},
|
|
1533
|
+
},
|
|
1534
|
+
]),
|
|
1535
|
+
);
|
|
1536
|
+
|
|
1537
|
+
// Three prices all belonging to the same product
|
|
1538
|
+
mockStripeInstance.prices.list.mockReturnValue(
|
|
1539
|
+
asyncIter([
|
|
1540
|
+
{
|
|
1541
|
+
id: "price_1",
|
|
1542
|
+
product: "prod_1",
|
|
1543
|
+
active: true,
|
|
1544
|
+
currency: "usd",
|
|
1545
|
+
unit_amount: 1000,
|
|
1546
|
+
type: "one_time",
|
|
1547
|
+
recurring: null,
|
|
1548
|
+
nickname: null,
|
|
1549
|
+
metadata: {},
|
|
1550
|
+
},
|
|
1551
|
+
{
|
|
1552
|
+
id: "price_2",
|
|
1553
|
+
product: "prod_1",
|
|
1554
|
+
active: true,
|
|
1555
|
+
currency: "usd",
|
|
1556
|
+
unit_amount: 2000,
|
|
1557
|
+
type: "one_time",
|
|
1558
|
+
recurring: null,
|
|
1559
|
+
nickname: null,
|
|
1560
|
+
metadata: {},
|
|
1561
|
+
},
|
|
1562
|
+
{
|
|
1563
|
+
id: "price_3",
|
|
1564
|
+
product: "prod_1",
|
|
1565
|
+
active: true,
|
|
1566
|
+
currency: "usd",
|
|
1567
|
+
unit_amount: 3000,
|
|
1568
|
+
type: "one_time",
|
|
1569
|
+
recurring: null,
|
|
1570
|
+
nickname: null,
|
|
1571
|
+
metadata: {},
|
|
1572
|
+
},
|
|
1573
|
+
]),
|
|
1574
|
+
);
|
|
1575
|
+
|
|
1576
|
+
// Resolve query for prod_1 → an internal product
|
|
1577
|
+
mockCtx.runQuery.mockResolvedValue({ _id: "internal_prod_1" });
|
|
1578
|
+
// runMutation succeeds silently
|
|
1579
|
+
mockCtx.runMutation.mockResolvedValue(undefined);
|
|
1580
|
+
|
|
1581
|
+
const result = await bs.syncAllProducts(mockCtx);
|
|
1582
|
+
|
|
1583
|
+
// 1 product upserted + 3 prices upserted
|
|
1584
|
+
expect(result.productsSynced).toBe(1);
|
|
1585
|
+
expect(result.pricesSynced).toBe(3);
|
|
1586
|
+
|
|
1587
|
+
// getProductByStripeId must have been queried exactly once (cache hit on 2nd/3rd price)
|
|
1588
|
+
const queryCallsForGetProduct = mockCtx.runQuery.mock.calls.filter(
|
|
1589
|
+
(call) =>
|
|
1590
|
+
(call[1] as { stripeProductId?: string } | undefined)
|
|
1591
|
+
?.stripeProductId === "prod_1",
|
|
1592
|
+
);
|
|
1593
|
+
expect(queryCallsForGetProduct).toHaveLength(1);
|
|
1594
|
+
});
|
|
1595
|
+
});
|
|
1596
|
+
|
|
1597
|
+
// =========================================================================
|
|
1598
|
+
// syncAllAccounts
|
|
1599
|
+
// =========================================================================
|
|
1600
|
+
|
|
1601
|
+
describe("syncAllAccounts", () => {
|
|
1602
|
+
/** Helper: returns an async iterable from an array (matches Stripe's V2 auto-pagination API). */
|
|
1603
|
+
async function* asyncIter<T>(items: T[]): AsyncIterable<T> {
|
|
1604
|
+
for (const item of items) {
|
|
1605
|
+
yield item;
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
it("drains every V2 account the SDK's auto-pagination iterator yields", async () => {
|
|
1610
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1611
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1612
|
+
});
|
|
1613
|
+
|
|
1614
|
+
mockStripeInstance.v2.core.accounts.list.mockReturnValue(
|
|
1615
|
+
asyncIter([
|
|
1616
|
+
{
|
|
1617
|
+
id: "acct_1",
|
|
1618
|
+
metadata: { userId: "u1" },
|
|
1619
|
+
configuration: { customer: { applied: true } },
|
|
1620
|
+
},
|
|
1621
|
+
{
|
|
1622
|
+
id: "acct_2",
|
|
1623
|
+
metadata: { userId: "u2" },
|
|
1624
|
+
configuration: { customer: { applied: true } },
|
|
1625
|
+
},
|
|
1626
|
+
{
|
|
1627
|
+
id: "acct_3",
|
|
1628
|
+
metadata: { userId: "u3" },
|
|
1629
|
+
configuration: { customer: { applied: true } },
|
|
1630
|
+
},
|
|
1631
|
+
]),
|
|
1632
|
+
);
|
|
1633
|
+
|
|
1634
|
+
const result = await bs.syncAllAccounts(mockCtx);
|
|
1635
|
+
|
|
1636
|
+
expect(result.synced).toBe(3);
|
|
1637
|
+
expect(result.errorCount).toBe(0);
|
|
1638
|
+
|
|
1639
|
+
expect(mockStripeInstance.v2.core.accounts.list).toHaveBeenCalledTimes(1);
|
|
1640
|
+
expect(mockStripeInstance.v2.core.accounts.list).toHaveBeenCalledWith({
|
|
1641
|
+
limit: 20,
|
|
1642
|
+
});
|
|
1643
|
+
|
|
1644
|
+
// Verify upsertAccount was called 3 times
|
|
1645
|
+
expect(mockCtx.runMutation).toHaveBeenCalledTimes(3);
|
|
1646
|
+
});
|
|
1647
|
+
|
|
1648
|
+
it("derives onboarding status from account requirements", async () => {
|
|
1649
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1650
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1651
|
+
});
|
|
1652
|
+
|
|
1653
|
+
mockStripeInstance.v2.core.accounts.list.mockReturnValue(
|
|
1654
|
+
asyncIter([
|
|
1655
|
+
{
|
|
1656
|
+
id: "acct_restricted",
|
|
1657
|
+
metadata: { userId: "u_restricted" },
|
|
1658
|
+
requirements: {
|
|
1659
|
+
entries: [
|
|
1660
|
+
{
|
|
1661
|
+
description: "business_type",
|
|
1662
|
+
awaiting_action_from: "user",
|
|
1663
|
+
errors: [],
|
|
1664
|
+
impact: { restricts_capabilities: [] },
|
|
1665
|
+
minimum_deadline: { status: "currently_due" },
|
|
1666
|
+
requested_reasons: [],
|
|
1667
|
+
},
|
|
1668
|
+
{
|
|
1669
|
+
description: "tos_acceptance",
|
|
1670
|
+
awaiting_action_from: "user",
|
|
1671
|
+
errors: [],
|
|
1672
|
+
impact: { restricts_capabilities: [] },
|
|
1673
|
+
minimum_deadline: { status: "currently_due" },
|
|
1674
|
+
requested_reasons: [],
|
|
1675
|
+
},
|
|
1676
|
+
],
|
|
1677
|
+
summary: {
|
|
1678
|
+
minimum_deadline: { status: "past_due" },
|
|
1679
|
+
},
|
|
1680
|
+
},
|
|
1681
|
+
configuration: {},
|
|
1682
|
+
},
|
|
1683
|
+
]),
|
|
1684
|
+
);
|
|
1685
|
+
|
|
1686
|
+
const result = await bs.syncAllAccounts(mockCtx);
|
|
1687
|
+
|
|
1688
|
+
expect(result.synced).toBe(1);
|
|
1689
|
+
expect(mockCtx.runMutation).toHaveBeenCalledWith(
|
|
1690
|
+
components.betterStripe.core.mutations.upsertAccount,
|
|
1691
|
+
expect.objectContaining({
|
|
1692
|
+
stripeAccountId: "acct_restricted",
|
|
1693
|
+
onboardingStatus: "restricted",
|
|
1694
|
+
missingRequirements: expect.arrayContaining([
|
|
1695
|
+
"business_type",
|
|
1696
|
+
"tos_acceptance",
|
|
1697
|
+
]),
|
|
1698
|
+
}),
|
|
1699
|
+
);
|
|
1700
|
+
});
|
|
1701
|
+
});
|
|
1702
|
+
|
|
1703
|
+
// =========================================================================
|
|
1704
|
+
// Structured error alignment — one test per converted raw-throw site
|
|
1705
|
+
// =========================================================================
|
|
1706
|
+
|
|
1707
|
+
describe("structured error alignment", () => {
|
|
1708
|
+
it("createAccountWithOnboarding throws BetterStripeError ACCOUNT_CREATE_FAILED on config error", async () => {
|
|
1709
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1710
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1711
|
+
});
|
|
1712
|
+
|
|
1713
|
+
const fakeAccount = {
|
|
1714
|
+
id: "acct_err",
|
|
1715
|
+
applied_configurations: [],
|
|
1716
|
+
configuration: {},
|
|
1717
|
+
metadata: {},
|
|
1718
|
+
requirements: {
|
|
1719
|
+
entries: [],
|
|
1720
|
+
summary: { minimum_deadline: { status: "no_requirements" } },
|
|
1721
|
+
},
|
|
1722
|
+
};
|
|
1723
|
+
mockStripeInstance.v2.core.accounts.create.mockResolvedValue(fakeAccount);
|
|
1724
|
+
mockStripeInstance.v2.core.accounts.update.mockRejectedValue({
|
|
1725
|
+
type: "api_error",
|
|
1726
|
+
code: "resource_missing",
|
|
1727
|
+
message: "config failed",
|
|
1728
|
+
});
|
|
1729
|
+
mockCtx.runMutation.mockResolvedValue(undefined);
|
|
1730
|
+
|
|
1731
|
+
let caught: unknown;
|
|
1732
|
+
try {
|
|
1733
|
+
await bs.createAccountWithOnboarding(mockCtx, {
|
|
1734
|
+
userId: "user_123",
|
|
1735
|
+
country: "US",
|
|
1736
|
+
refreshUrl: "https://example.com/refresh",
|
|
1737
|
+
returnUrl: "https://example.com/return",
|
|
1738
|
+
});
|
|
1739
|
+
expect.unreachable("should have thrown");
|
|
1740
|
+
} catch (e) {
|
|
1741
|
+
caught = e;
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
expect(isBetterStripeError(caught)).toBe(true);
|
|
1745
|
+
const data = (caught as ConvexError<{ code: string; message: string }>)
|
|
1746
|
+
.data;
|
|
1747
|
+
expect(data.code).toBe("ACCOUNT_CREATE_FAILED");
|
|
1748
|
+
expect(data.message).toContain(
|
|
1749
|
+
"Failed to apply account configuration after create",
|
|
1750
|
+
);
|
|
1751
|
+
});
|
|
1752
|
+
|
|
1753
|
+
it("updateSubscriptionQuantity throws BetterStripeError SUBSCRIPTION_UPDATE_FAILED when sub has no items", async () => {
|
|
1754
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1755
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1756
|
+
});
|
|
1757
|
+
|
|
1758
|
+
mockStripeInstance.subscriptions.retrieve.mockResolvedValue({
|
|
1759
|
+
id: "sub_no_items",
|
|
1760
|
+
items: { data: [] },
|
|
1761
|
+
});
|
|
1762
|
+
|
|
1763
|
+
let caught: unknown;
|
|
1764
|
+
try {
|
|
1765
|
+
await bs.updateSubscriptionQuantity(mockCtx, {
|
|
1766
|
+
stripeSubscriptionId: "sub_no_items",
|
|
1767
|
+
quantity: 2,
|
|
1768
|
+
});
|
|
1769
|
+
expect.unreachable("should have thrown");
|
|
1770
|
+
} catch (e) {
|
|
1771
|
+
caught = e;
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
expect(isBetterStripeError(caught)).toBe(true);
|
|
1775
|
+
const data = (caught as ConvexError<{ code: string; message: string }>)
|
|
1776
|
+
.data;
|
|
1777
|
+
expect(data.code).toBe("SUBSCRIPTION_UPDATE_FAILED");
|
|
1778
|
+
expect(data.message).toBe("Subscription has no items");
|
|
1779
|
+
});
|
|
1780
|
+
|
|
1781
|
+
it("createPrice throws BetterStripeError PRODUCT_NOT_FOUND when product missing from DB", async () => {
|
|
1782
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1783
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1784
|
+
});
|
|
1785
|
+
|
|
1786
|
+
mockStripeInstance.prices.create.mockResolvedValue({
|
|
1787
|
+
id: "price_new",
|
|
1788
|
+
nickname: null,
|
|
1789
|
+
unit_amount: 500,
|
|
1790
|
+
currency: "usd",
|
|
1791
|
+
active: true,
|
|
1792
|
+
metadata: {},
|
|
1793
|
+
});
|
|
1794
|
+
// runQuery returns null — product not found in component DB
|
|
1795
|
+
mockCtx.runQuery.mockResolvedValue(null);
|
|
1796
|
+
|
|
1797
|
+
let caught: unknown;
|
|
1798
|
+
try {
|
|
1799
|
+
await bs.createPrice(mockCtx, {
|
|
1800
|
+
stripeProductId: "prod_missing",
|
|
1801
|
+
unitAmount: 500,
|
|
1802
|
+
currency: "usd",
|
|
1803
|
+
type: "one_time",
|
|
1804
|
+
});
|
|
1805
|
+
expect.unreachable("should have thrown");
|
|
1806
|
+
} catch (e) {
|
|
1807
|
+
caught = e;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
expect(isBetterStripeError(caught)).toBe(true);
|
|
1811
|
+
const data = (caught as ConvexError<{ code: string; message: string }>)
|
|
1812
|
+
.data;
|
|
1813
|
+
expect(data.code).toBe("PRODUCT_NOT_FOUND");
|
|
1814
|
+
expect(data.message).toContain("prod_missing");
|
|
1815
|
+
|
|
1816
|
+
// Validate-first: the product is missing, so we must throw BEFORE any
|
|
1817
|
+
// Stripe write. Calling prices.create here would orphan a price in
|
|
1818
|
+
// Stripe with no corresponding component record (BTS-2).
|
|
1819
|
+
expect(mockStripeInstance.prices.create).not.toHaveBeenCalled();
|
|
1820
|
+
expect(mockCtx.runMutation).not.toHaveBeenCalled();
|
|
1821
|
+
});
|
|
1822
|
+
|
|
1823
|
+
it("setDefaultPaymentMethod throws BetterStripeError PAYMENT_METHOD_FAILED", async () => {
|
|
1824
|
+
const bs = new BetterStripe(components.betterStripe, {
|
|
1825
|
+
STRIPE_SECRET_KEY: "sk_test_xxx",
|
|
1826
|
+
});
|
|
1827
|
+
|
|
1828
|
+
let caught: unknown;
|
|
1829
|
+
try {
|
|
1830
|
+
await bs.setDefaultPaymentMethod(mockCtx, {
|
|
1831
|
+
stripeAccountId: "acct_123",
|
|
1832
|
+
paymentMethodId: "pm_123",
|
|
1833
|
+
});
|
|
1834
|
+
expect.unreachable("should have thrown");
|
|
1835
|
+
} catch (e) {
|
|
1836
|
+
caught = e;
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
expect(isBetterStripeError(caught)).toBe(true);
|
|
1840
|
+
const data = (caught as ConvexError<{ code: string; message: string }>)
|
|
1841
|
+
.data;
|
|
1842
|
+
expect(data.code).toBe("PAYMENT_METHOD_FAILED");
|
|
1843
|
+
expect(data.message).toContain(
|
|
1844
|
+
"setDefaultPaymentMethod is not yet implemented",
|
|
1845
|
+
);
|
|
1846
|
+
});
|
|
1847
|
+
});
|
|
1848
|
+
});
|