Skip to content

Commit 29c03e7

Browse files
committed
feat: sort if available unzer invoice as first payment provider and paypal as last
1 parent 0e09d07 commit 29c03e7

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/composables/payment.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ export const usePayment = defineStore("usePaymentStore", () => {
5454
options.push(currentOption)
5555
}
5656

57+
// Sort: SORT_FIRST providers on top, SORT_LAST at the bottom, rest unchanged
58+
const SORT_FIRST = ["unzer-paylater_invoice"]
59+
const SORT_LAST = ["unzer-paypal", "amazonpay"]
60+
61+
options.sort((a, b) => {
62+
const weight = (key) => {
63+
const firstIdx = SORT_FIRST.indexOf(key)
64+
if (firstIdx !== -1) return -SORT_FIRST.length + firstIdx
65+
const lastIdx = SORT_LAST.indexOf(key)
66+
if (lastIdx !== -1) return 1 + lastIdx
67+
return 0
68+
}
69+
return weight(a.paymenttype) - weight(b.paymenttype)
70+
})
5771

5872
return options
5973
}

0 commit comments

Comments
 (0)