22 lines
778 B
JavaScript
22 lines
778 B
JavaScript
export const PAYMENT_METHOD_LABELS = {
|
|
wechat: '微信支付',
|
|
alipay: '支付宝支付',
|
|
wallet: '钱包支付'
|
|
};
|
|
|
|
export const normalizePaymentMethods = (methods) => {
|
|
if (!Array.isArray(methods)) return [];
|
|
|
|
return [...new Set(methods.filter((method) => Object.prototype.hasOwnProperty.call(PAYMENT_METHOD_LABELS, method)))];
|
|
};
|
|
|
|
export const getPaymentMethodOptions = (methods, preferredOrder = ['alipay', 'wechat', 'wallet']) => {
|
|
const normalized = normalizePaymentMethods(methods);
|
|
return preferredOrder
|
|
.filter((method) => normalized.includes(method))
|
|
.map((value) => ({ value, label: PAYMENT_METHOD_LABELS[value] }));
|
|
};
|
|
|
|
export const getDefaultPaymentMethod = (methods, preferredOrder) =>
|
|
getPaymentMethodOptions(methods, preferredOrder)[0]?.value || '';
|