From cf40431d454361ca177b01b101db16c69883bd2b Mon Sep 17 00:00:00 2001 From: Damian Legawiec Date: Thu, 14 May 2026 12:52:52 +0200 Subject: [PATCH] Fixed gateway provider map to match Spree 5.5 format Also backwards compatible with Spree 5.4 --- src/lib/utils/payment-gateway.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/lib/utils/payment-gateway.ts b/src/lib/utils/payment-gateway.ts index 237cb9ff..19bf5146 100644 --- a/src/lib/utils/payment-gateway.ts +++ b/src/lib/utils/payment-gateway.ts @@ -1,7 +1,7 @@ /** * Gateway type registry for conditional SDK loading. * - * Maps Spree PaymentMethod.type (Rails STI class name) to a frontend gateway + * Maps Spree PaymentMethod.type (API shorthand) to a frontend gateway * identifier so the checkout can dynamically import the right SDK component. * * Only session-based gateways need this mapping. Non-session methods @@ -12,20 +12,41 @@ export type GatewayId = "stripe" | "adyen" | "paypal" | "razorpay" | "unknown"; /** - * Map Spree PaymentMethod.type (STI class name) → frontend gateway ID. + * Map Spree PaymentMethod.type (API shorthand) → frontend gateway ID. + * + * The Store API returns `Spree::Gateway.api_type` — for provider gems + * that ship a top-level `Gateway` class, that's the outer module name + * stripped of its `Spree` prefix and underscored: + * + * SpreeStripe::Gateway → "stripe" + * SpreeAdyen::Gateway → "adyen" + * SpreePaypalCheckout::Gateway → "paypal_checkout" + * SpreeRazorpayCheckout::Gateway → "razorpay_checkout" + * + * For gems whose shorthand already matches the frontend ID (`stripe`, + * `adyen`), the map mostly normalises the suffixed forms. Legacy Rails + * STI class names are kept for backwards compatibility with older Spree + * backends that haven't been upgraded yet. + * * Adding a new gateway integration is a single line here. */ const GATEWAY_TYPE_MAP: Record = { // Stripe (spree_stripe gem) + stripe: "stripe", "SpreeStripe::Gateway": "stripe", "Spree::Gateway::StripeGateway": "stripe", // Adyen (spree_adyen gem) + adyen: "adyen", "SpreeAdyen::Gateway": "adyen", "Spree::Gateway::AdyenGateway": "adyen", // PayPal (spree_paypal_checkout gem) + paypal_checkout: "paypal", + paypal: "paypal", "SpreePaypalCheckout::Gateway": "paypal", "Spree::Gateway::PayPalExpress": "paypal", // Razorpay (spree_razorpay_checkout gem) + razorpay_checkout: "razorpay", + razorpay: "razorpay", "SpreeRazorpayCheckout::Gateway": "razorpay", "Spree::Gateway::RazorpayGateway": "razorpay", };