@funnelsgrove/payments 0.79.0 → 0.80.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/README.md CHANGED
@@ -299,6 +299,8 @@ When a live funnel still uses one of these, migrate the funnel deliberately with
299
299
 
300
300
  Funnels should call `resolvePublishedBillingRuntime` once at their runtime-provider boundary. Screens consume its resolved view and should not parse offer sets or pricing-experiment variants themselves. Pass the resolved `stripePublishableKey` into shared Stripe checkout hooks so Stripe.js can load while the Checkout Session request is still in flight; the key returned by that request remains the compatibility fallback.
301
301
 
302
+ The resolved `provider` is `'stripe' | 'solidgate' | 'paypal' | 'paddle'`; `'paddle'` was added in payments 0.75.0 with runtime 0.47.0. Type funnel props that receive it as `ResolvedPublishedBillingRuntime['provider']` instead of a literal union, so a new provider does not break the funnel build.
303
+
302
304
  ## Client implementation structure
303
305
 
304
306
  Provider-neutral plan types, selection and recurrence live in
@@ -359,8 +361,8 @@ The build normalizes generated relative ESM imports to explicit `.js` files for
359
361
  [Checkout email recovery](../../docs/product-specs/billing.md#checkout-email-recovery)
360
362
  owns the behavior. Pass `onCustomerEmailCommit` to wallet surfaces and the card
361
363
  checkout dialog. It must save the access email, adopt the returned Funnel User, and
362
- update the `customerEmail` and `userId` inputs used by checkout. A wallet surface
363
- renders a Continue control and `CheckoutEmailDialog` when repair is required.
364
+ update the `customerEmail` and `userId` inputs used by checkout. Missing or invalid
365
+ email hides the wallet surface; the funnel's primary CTA collects it. Provider rejection can open the surface's repair dialog.
364
366
  `onResolveCustomerEmail` can resolve a known identity before asking for input;
365
367
  its caller must also adopt the resolved identity. `emailDialogContent` customizes
366
368
  prompt copy. Keep `beforeConfirm` for immediate preparation only, without awaiting
@@ -1 +1 @@
1
- export declare const PAYMENTS_PACKAGE_VERSION = "0.79.0";
1
+ export declare const PAYMENTS_PACKAGE_VERSION = "0.80.0";
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/generate-package-version.mjs.
2
- export const PAYMENTS_PACKAGE_VERSION = "0.79.0";
2
+ export const PAYMENTS_PACKAGE_VERSION = "0.80.0";
@@ -24,9 +24,15 @@ type Props = ComponentProps<typeof ExpressCheckoutElement> & {
24
24
  /** The sheet shows the Checkout Session's amount and currency. Renders nothing until the session has loaded. */
25
25
  export declare function ManualWalletExpressCheckoutElement({ checkout, stripePromise, walletRef, ...element }: Props): import("react/jsx-runtime").JSX.Element | null;
26
26
  /**
27
- * Creates the PaymentMethod from the confirmed wallet sheet, which closes the sheet.
28
27
  * Confirming a Checkout Session with a PaymentMethod requires the email on the PaymentMethod.
28
+ * The Stripe wallet contract test confirms real test-mode sessions with these params.
29
29
  */
30
+ export declare const manualWalletPaymentMethodParams: (email: string) => {
31
+ billing_details: {
32
+ email: string;
33
+ };
34
+ };
35
+ /** Creates the PaymentMethod from the confirmed wallet sheet, which closes the sheet. */
30
36
  export declare function createManualWalletPaymentMethod({ elements, stripe }: ManualWallet, email: string): Promise<{
31
37
  paymentMethodId: string;
32
38
  } | {
@@ -41,15 +41,17 @@ export function ManualWalletExpressCheckoutElement(_a) {
41
41
  return (_jsxs(Elements, { stripe: stripePromise, options: options, children: [_jsx(ManualWalletBridge, { walletRef: walletRef }), _jsx(ExpressCheckoutElement, Object.assign({}, element))] }));
42
42
  }
43
43
  /**
44
- * Creates the PaymentMethod from the confirmed wallet sheet, which closes the sheet.
45
44
  * Confirming a Checkout Session with a PaymentMethod requires the email on the PaymentMethod.
45
+ * The Stripe wallet contract test confirms real test-mode sessions with these params.
46
46
  */
47
+ export const manualWalletPaymentMethodParams = (email) => ({ billing_details: { email } });
48
+ /** Creates the PaymentMethod from the confirmed wallet sheet, which closes the sheet. */
47
49
  export async function createManualWalletPaymentMethod({ elements, stripe }, email) {
48
50
  if (!elements || !stripe)
49
51
  return { error: undefined };
50
52
  const submitted = await elements.submit();
51
53
  if (submitted.error)
52
54
  return { error: submitted.error };
53
- const created = await stripe.createPaymentMethod({ elements, params: { billing_details: { email } } });
55
+ const created = await stripe.createPaymentMethod({ elements, params: manualWalletPaymentMethodParams(email) });
54
56
  return created.paymentMethod ? { paymentMethodId: created.paymentMethod.id } : { error: created.error };
55
57
  }
@@ -4,6 +4,13 @@ import { type StripeCheckoutErrorDetails } from '../services/stripeCheckoutError
4
4
  export type StripeWalletCheckoutSuccess = {
5
5
  checkoutSessionId: string | null;
6
6
  };
7
+ /**
8
+ * The `email` for checkout.confirm(). A Checkout Session created with `customer_email`, or with a
9
+ * `customer` that has an email, already carries it, and stripe.js throws when confirm() sets it again.
10
+ */
11
+ export declare const walletConfirmEmailParams: (sessionEmail: string | null | undefined, customerEmail: string | null | undefined) => {
12
+ email?: string;
13
+ };
7
14
  export type StripeCheckoutExpressCheckoutButtonProps = {
8
15
  amountCents: number;
9
16
  beforeConfirm?: () => Promise<string | null>;
@@ -10,6 +10,14 @@ import { getUnsupportedCheckoutCountryMessage, normalizeSupportedCheckoutCountri
10
10
  import { trackCheckoutCanceled, trackCheckoutFailureShown, } from '../../../services/checkoutObservability.service.js';
11
11
  import { createManualWalletPaymentMethod, ManualWalletExpressCheckoutElement } from './ManualWalletExpressCheckoutElement.js';
12
12
  import { isStripeCheckoutAlreadyPaidError, normalizeStripeCheckoutError } from '../services/stripeCheckoutError.js';
13
+ /**
14
+ * The `email` for checkout.confirm(). A Checkout Session created with `customer_email`, or with a
15
+ * `customer` that has an email, already carries it, and stripe.js throws when confirm() sets it again.
16
+ */
17
+ export const walletConfirmEmailParams = (sessionEmail, customerEmail) => {
18
+ const email = customerEmail === null || customerEmail === void 0 ? void 0 : customerEmail.trim();
19
+ return (sessionEmail === null || sessionEmail === void 0 ? void 0 : sessionEmail.trim()) || !email ? {} : { email };
20
+ };
13
21
  const ExpressCheckoutElementWithCancel = ExpressCheckoutElement;
14
22
  const WALLET_DECLINE_SHEET_MESSAGE = 'Your bank declined this card. Choose another card or approve the payment in your bank app.';
15
23
  const buildDefaultOptions = () => ({
@@ -281,9 +289,23 @@ export function StripeCheckoutExpressCheckoutButton({ beforeConfirm, checkoutAna
281
289
  // Creating the PaymentMethod closed the wallet sheet; the charge result shows on the page.
282
290
  paymentMethodId = created.paymentMethodId;
283
291
  }
284
- const result = await checkoutState.checkout.confirm(Object.assign(Object.assign(Object.assign({}, (confirmEmail
285
- ? { email: preparedCustomerEmail || (customerEmail === null || customerEmail === void 0 ? void 0 : customerEmail.trim()) || undefined }
286
- : {})), (paymentMethodId ? { paymentMethod: paymentMethodId } : { expressCheckoutConfirmEvent: event })), { redirect: 'if_required' }));
292
+ let result;
293
+ try {
294
+ result = await checkoutState.checkout.confirm(Object.assign(Object.assign(Object.assign({}, (confirmEmail
295
+ ? walletConfirmEmailParams(checkoutState.checkout.email, preparedCustomerEmail || customerEmail)
296
+ : {})), (paymentMethodId ? { paymentMethod: paymentMethodId } : { expressCheckoutConfirmEvent: event })), { redirect: 'if_required' }));
297
+ }
298
+ catch (confirmError) {
299
+ // stripe.js throws on invalid confirm() input instead of returning an error result;
300
+ // without this the wallet sheet closes and the customer sees nothing.
301
+ const message = confirmError instanceof Error && confirmError.message
302
+ ? confirmError.message
303
+ : 'Wallet checkout failed.';
304
+ reportFailure(message, 'wallet_confirmation', event.expressPaymentType, confirmError);
305
+ if (!paymentMethodId)
306
+ event.paymentFailed({ reason: 'fail', message });
307
+ return;
308
+ }
287
309
  if (result.type === 'error' && !isStripeCheckoutAlreadyPaidError(result.error)) {
288
310
  const message = result.error.message || 'Wallet checkout failed.';
289
311
  const details = reportFailure(message, 'wallet_confirmation', event.expressPaymentType, result.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/payments",
3
- "version": "0.79.0",
3
+ "version": "0.80.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/The-Solid-Grove/funnelsgrove.git",
@@ -29,7 +29,8 @@
29
29
  "lint": "eslint .",
30
30
  "prepublishOnly": "npm run build",
31
31
  "smoke:wallet": "npm run build && node scripts/wallet-checkout-smoke.mjs",
32
- "test:run": "vitest run --passWithNoTests"
32
+ "test:run": "vitest run --passWithNoTests",
33
+ "test:stripe-contract": "vitest run --config vitest.contract.config.ts"
33
34
  },
34
35
  "dependencies": {
35
36
  "@solidgate/react-sdk": "1.34.0",
@@ -44,6 +45,7 @@
44
45
  "@types/react": "^19",
45
46
  "@types/react-dom": "^19",
46
47
  "jsdom": "20.0.3",
48
+ "playwright": "1.58.2",
47
49
  "typescript": "^5",
48
50
  "vitest": "^3.2.4",
49
51
  "@funnelsgrove/runtime": "0.49.0",