Fix groupPaymentMethodsForCheckout ignoring sortOrder

Hardcoded manual rows first, then the combined stripe option — so
"Online-Zahlung" (sortOrder 0) showed after "Überweisung (Vorkasse)"
(sortOrder 1) in checkout, contradicting the admin's own ordering.
Now preserves the fetch's sortOrder-sorted order, splicing the combined
entry in at the position of the first stripe row encountered.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Marco
2026-07-25 16:39:56 +00:00
parent 952b902702
commit 06a00d67e4
+22 -3
View File
@@ -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 = {