import plugins from 'plugins'; import Settings from 'settings'; import { useAppSelector } from '../redux/hooks'; import { RootState } from 'redux/store'; export const usePaymentOptions = () => { const { paymentOptions } = useAppSelector( (state: RootState) => state.checkout ); const initialTypes = new Set([ 'credit_card', 'funds_transfer', 'redirection', 'wallet' ]); const paymentTypeToPluginMap = { pay_on_delivery: 'pz-pay-on-delivery', bkm_express: 'pz-bkm', credit_payment: 'pz-credit-payment', masterpass: 'pz-masterpass', saved_card: 'pz-saved-card', gpay: 'pz-gpay', masterpass_rest: 'pz-masterpass-rest' }; const isInitialTypeIncluded = (type: string) => initialTypes.has(type); const isPluginMapIncluded = (type: string) => paymentTypeToPluginMap[type] ? plugins.includes(paymentTypeToPluginMap[type]) : false; const isExtraTypeIncluded = (type: string) => { const extraPaymentTypes = Settings?.checkout?.extraPaymentTypes || []; return ( extraPaymentTypes.includes(type) && !initialTypes.has(type) && !paymentTypeToPluginMap[type] ); }; const filteredPaymentOptions = paymentOptions.filter((option) => { const { payment_type } = option; return ( isInitialTypeIncluded(payment_type) || isPluginMapIncluded(payment_type) || isExtraTypeIncluded(payment_type) ); }); return { filteredPaymentOptions }; };