fix(invoice): localize Shopify payment-gateway names on the PDF

Customer reported that on the German invoice PDF the payment method
showed up as 'Zahlart: Bank Deposit' while the order-confirmation page
on the storefront localized it correctly to 'Bank\u00fc1berweisung'. Cause:
Shopify's Admin GraphQL API only ever returns the *English* template
name in 'Order.paymentGatewayNames', even when the shop / order locale
is German \u2014 the localization happens client-side at checkout but is
NOT exposed via the API. So the PDF and the storefront naturally
diverge unless we mirror the translations ourselves.

Fix: introduce a per-language 'paymentGatewayLabels' map on
'InvoiceStrings' covering the built-in Shopify manual-payment
templates (Bank Deposit, Money Order, Cash on Delivery) plus the
standard non-manual gateways (Shopify Payments, PayPal, Klarna,
Sofort, Giropay, Bogus). 'prettifyGatewayName' now takes this map
and looks up the normalized key (lowercased, separators collapsed),
falling back to a title-cased rendering for unknown values.

DE result: 'Zahlart: Bank\u00fc1berweisung', 'Manuelle Zahlung', 'Nachnahme'.
EN result: unchanged.

New smoke assertions verify the DE PDF now shows 'Manuelle Zahlung'
for the AT B2B fixture's 'manual' gateway and that the raw English
'Manual' no longer appears next to the 'Zahlart' label.

Note on other Shopify-sourced strings on the PDF: 'shippingLine.title'
(e.g. 'Standard') is similarly merchant/locale-dependent, but unlike
gateway names it's fully customizable per-shop in Shopify Admin and
is not a fixed enum we can translate \u2014 left untouched pending an
explicit report. Product titles, discount codes and addresses are
likewise merchant-/customer-supplied and flow through verbatim by
design.
This commit is contained in:
Gerhard Scheikl
2026-05-15 16:08:19 +02:00
parent 2a4a7fd983
commit c24d567ae4
3 changed files with 67 additions and 17 deletions
+42
View File
@@ -68,6 +68,16 @@ export interface InvoiceStrings {
/** Used as the meta-row label when the order is a local pickup. The row
* value is then the pickup location name (e.g. "Lager Graz"). */
pickupLocationLabel: string;
/** Localized labels for Shopify's built-in payment-gateway names. The
* Admin GraphQL API only ever returns the *English* template name
* (e.g. "Bank Deposit") in `Order.paymentGatewayNames`, even when the
* storefront / order-confirmation page renders the localized variant
* ("Banküberweisung"). We mirror Shopify's checkout copy here so the
* printed PDF matches what the customer saw at checkout. Lookup is
* case-insensitive on the normalized key (lowercased, separators
* collapsed). Unknown gateways fall back to a title-cased rendering
* of the raw name. */
paymentGatewayLabels: Record<string, string>;
}
/** Status displayed for the order's payment, derived from Shopify's
@@ -171,6 +181,23 @@ const de: InvoiceStrings = {
discountCodeLabel: "Rabattcode",
pickupLabel: "Abholung",
pickupLocationLabel: "Abholort",
paymentGatewayLabels: {
// Built-in Shopify manual payment methods (template names).
"bank deposit": "Banküberweisung",
"bank transfer": "Banküberweisung",
"money order": "Postanweisung",
"cash on delivery": "Nachnahme",
"cash on delivery (cod)": "Nachnahme",
// Generic / technical gateways.
manual: "Manuelle Zahlung",
bogus: "Bogus (Test)",
"shopify payments": "Shopify Payments",
paypal: "PayPal",
"paypal express checkout": "PayPal",
klarna: "Klarna",
sofort: "Sofort",
giropay: "Giropay",
},
};
const en: InvoiceStrings = {
@@ -241,6 +268,21 @@ const en: InvoiceStrings = {
discountCodeLabel: "Discount code",
pickupLabel: "Pick-up",
pickupLocationLabel: "Pick-up location",
paymentGatewayLabels: {
"bank deposit": "Bank deposit",
"bank transfer": "Bank transfer",
"money order": "Money order",
"cash on delivery": "Cash on delivery",
"cash on delivery (cod)": "Cash on delivery (COD)",
manual: "Manual",
bogus: "Bogus (Test)",
"shopify payments": "Shopify Payments",
paypal: "PayPal",
"paypal express checkout": "PayPal",
klarna: "Klarna",
sofort: "Sofort",
giropay: "Giropay",
},
};
// Locale → invoice language. We only render in German (`de`) when the