diff --git a/app/lib/payload.ts b/app/lib/payload.ts index f491efc..5ba34c6 100644 --- a/app/lib/payload.ts +++ b/app/lib/payload.ts @@ -638,9 +638,8 @@ export type CheckoutPaymentOption = PaymentMethod & { hint?: string }; // `manual` rows (Überweisung) pass through unchanged — one real gateway // there, one option, nothing to collapse. export function groupPaymentMethodsForCheckout(methods: PaymentMethod[]): CheckoutPaymentOption[] { - const manual = methods.filter((m) => m.provider !== "stripe"); const stripeMethods = methods.filter((m) => m.provider === "stripe"); - if (stripeMethods.length === 0) return manual; + if (stripeMethods.length === 0) return methods; const combinedIcons = Array.from(new Set(stripeMethods.flatMap((m) => m.icons))); const online: CheckoutPaymentOption = { @@ -650,7 +649,27 @@ export function groupPaymentMethodsForCheckout(methods: PaymentMethod[]): Checko provider: "stripe", hint: "Kreditkarte, PayPal & weitere Methoden — die genaue Zahlungsart wählst du im nächsten Schritt.", }; - return [...manual, online]; + + // Preserve `methods`' own order (already sortOrder-sorted by the fetch) + // instead of hardcoding manual-first — a real bug: "Online-Zahlung" had + // a lower sortOrder than "Überweisung (Vorkasse)" in the admin, but + // this function always put manual rows first regardless, so the + // checkout showed them in the wrong order. Splice the combined entry in + // at the position of the *first* stripe row encountered, drop any + // further stripe rows (already folded into `online`). + const result: CheckoutPaymentOption[] = []; + let onlineInserted = false; + for (const m of methods) { + if (m.provider === "stripe") { + if (!onlineInserted) { + result.push(online); + onlineInserted = true; + } + continue; + } + result.push(m); + } + return result; } export type WerkzeugeCard = {