From dae04f75dc3e562b780b400d7cba32cfe336de4c Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 29 Jul 2026 15:22:43 +0800 Subject: [PATCH] fix(payment): restore wallet order and English labels --- .../__tests__/stripe-payment-dialog.test.tsx | 44 +++++++++++++++---- .../payment/stripe-payment-dialog.tsx | 22 +++++----- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/app/_components/payment/__tests__/stripe-payment-dialog.test.tsx b/src/app/_components/payment/__tests__/stripe-payment-dialog.test.tsx index 77291e88..65ce1029 100644 --- a/src/app/_components/payment/__tests__/stripe-payment-dialog.test.tsx +++ b/src/app/_components/payment/__tests__/stripe-payment-dialog.test.tsx @@ -63,7 +63,7 @@ describe("StripePaymentDialog", () => { document.body.style.overflow = ""; }); - it("renders Express Checkout first and a collapsed Pay by card section last", () => { + it("renders express methods and wallets before card with English Stripe copy", () => { act(() => root.render( { expect(capturedElementsOptions).toMatchObject({ clientSecret: "pi_123_secret_payment", customerSessionClientSecret: "cuss_123_secret_saved", + locale: "en", }); expect(capturedExpressProps?.options).toMatchObject({ paymentMethodOrder: [ - "apple_pay", - "google_pay", "link", "paypal", "amazon_pay", "klarna", ], paymentMethods: { - applePay: "always", - googlePay: "always", + applePay: "never", + googlePay: "never", link: "auto", paypal: "auto", amazonPay: "auto", @@ -99,11 +98,11 @@ describe("StripePaymentDialog", () => { }); expect(capturedPaymentProps?.options).toMatchObject({ layout: { type: "accordion", defaultCollapsed: true }, - paymentMethodOrder: ["card"], - wallets: { applePay: "never", googlePay: "never", link: "never" }, + paymentMethodOrder: ["wechat_pay", "alipay", "card"], + wallets: { applePay: "auto", googlePay: "auto", link: "never" }, }); const text = document.body.textContent ?? ""; - expect(text).toContain("Pay by card"); + expect(text).toContain("Choose a payment method"); const express = document.body.querySelector('[data-testid="express-checkout"]'); const card = document.body.querySelector('[data-testid="payment-element"]'); expect(express).not.toBeNull(); @@ -114,6 +113,35 @@ describe("StripePaymentDialog", () => { ).toBeTruthy(); }); + it("keeps Payment Element wallet fallbacks when Express Checkout is unavailable", () => { + act(() => + root.render( + , + ), + ); + + const onReady = capturedExpressProps?.onReady as + | ((event: { availablePaymentMethods: undefined }) => void) + | undefined; + expect(onReady).toBeTypeOf("function"); + act(() => onReady?.({ availablePaymentMethods: undefined })); + + const expressSection = document.body.querySelector( + '[aria-label="Express payment methods"]', + ); + expect(expressSection).toHaveProperty("hidden", true); + expect( + document.body.querySelector('[data-testid="payment-element"]'), + ).not.toBeNull(); + expect(capturedPaymentProps?.options).toMatchObject({ + wallets: { applePay: "auto", googlePay: "auto", link: "never" }, + paymentMethodOrder: ["wechat_pay", "alipay", "card"], + }); + }); + it("does not pass an invalid or disabled Customer Session secret", () => { act(() => root.render( diff --git a/src/app/_components/payment/stripe-payment-dialog.tsx b/src/app/_components/payment/stripe-payment-dialog.tsx index 2dc35451..c326aabe 100644 --- a/src/app/_components/payment/stripe-payment-dialog.tsx +++ b/src/app/_components/payment/stripe-payment-dialog.tsx @@ -124,6 +124,7 @@ export function StripePaymentDialog({ stripe={stripePromise} options={{ clientSecret, + locale: "en", ...(savedCardClientSecret ? { customerSessionClientSecret: savedCardClientSecret } : {}), @@ -325,16 +326,14 @@ function StripePaymentForm({ -
-

- Pay by card +
+

+ Choose a payment method