diff --git a/src/app/_components/payment/__tests__/payment-method-selector.test.tsx b/src/app/_components/payment/__tests__/payment-method-selector.test.tsx index b8218137..4aa16944 100644 --- a/src/app/_components/payment/__tests__/payment-method-selector.test.tsx +++ b/src/app/_components/payment/__tests__/payment-method-selector.test.tsx @@ -7,8 +7,11 @@ describe("PaymentMethodSelector", () => { it("orders the default channel first and renders page analytics", () => { const html = renderToStaticMarkup( undefined} @@ -40,6 +43,10 @@ describe("PaymentMethodSelector", () => { it("disables both payment methods while payment is busy", () => { const html = renderToStaticMarkup( { 'data-analytics-key="subscription.payment_method"', ); }); + + it("does not render when payment method selection is unavailable", () => { + const html = renderToStaticMarkup( + undefined} + />, + ); + + expect(html).toBe(""); + }); }); diff --git a/src/app/_components/payment/payment-method-selector.tsx b/src/app/_components/payment/payment-method-selector.tsx index 5064446c..cd1b0e71 100644 --- a/src/app/_components/payment/payment-method-selector.tsx +++ b/src/app/_components/payment/payment-method-selector.tsx @@ -3,6 +3,7 @@ import Image from "next/image"; import type { PayChannel } from "@/data/schemas/payment"; +import type { PaymentMethodConfig } from "@/lib/payment/payment_method"; const PAYMENT_METHODS: readonly { channel: PayChannel; @@ -21,24 +22,28 @@ const PAYMENT_METHODS: readonly { ]; export interface PaymentMethodSelectorProps { + config: PaymentMethodConfig; value: PayChannel; - defaultChannel?: PayChannel; disabled?: boolean; caption?: string; + className?: string; analyticsKey: string; onChange: (channel: PayChannel) => void; } export function PaymentMethodSelector({ + config, value, - defaultChannel = "stripe", disabled = false, caption = "Stripe by default", + className, analyticsKey, onChange, }: PaymentMethodSelectorProps) { + if (!config.canChoosePaymentMethod) return null; + const paymentMethods = - defaultChannel === "ezpay" + config.initialPayChannel === "ezpay" ? [...PAYMENT_METHODS].sort((a, b) => a.channel === "ezpay" ? -1 : b.channel === "ezpay" ? 1 : 0, ) @@ -46,7 +51,7 @@ export function PaymentMethodSelector({ return (
diff --git a/src/app/subscription/subscription-screen.tsx b/src/app/subscription/subscription-screen.tsx index d60c7cd5..960c12d3 100644 --- a/src/app/subscription/subscription-screen.tsx +++ b/src/app/subscription/subscription-screen.tsx @@ -224,18 +224,15 @@ export function SubscriptionScreen({ />
- {paymentMethodConfig.canChoosePaymentMethod ? ( -
- -
- ) : null} +
- {paymentMethodConfig.canChoosePaymentMethod ? ( -
- -
- ) : null} + {showMissingPlan ? (