Filter enabled payment methods

This commit is contained in:
Emili Castells Guasch 2025-02-07 16:03:26 +01:00
parent 68644c3d62
commit 7ebf94a600
2 changed files with 19 additions and 2 deletions

View file

@ -1,17 +1,29 @@
import { __ } from '@wordpress/i18n';
import { StylingHooks } from '../../../../../../data';
import { PaymentHooks, StylingHooks } from '../../../../../../data';
import { CheckboxStylingSection } from '../Layout';
const SectionPaymentMethods = ( { location } ) => {
const { paymentMethods, setPaymentMethods, choices } =
StylingHooks.usePaymentMethodProps( location );
const methods = PaymentHooks.usePaymentMethods();
const methodIds = [];
methods.all.forEach( ( method ) => {
if ( method.enabled === true ) {
methodIds.push( method.id );
}
} );
const filteredChoices = choices.filter( ( choice ) => {
return methodIds.includes( choice.paymentMethod );
} );
return (
<CheckboxStylingSection
name="payment-methods"
title={ __( 'Payment Methods', 'woocommerce-paypal-payments' ) }
options={ choices }
options={ filteredChoices }
value={ paymentMethods }
onChange={ setPaymentMethods }
/>

View file

@ -109,23 +109,28 @@ export const STYLING_PAYMENT_METHODS = {
label: __( 'PayPal', 'woocommerce-paypal-payments' ),
checked: true,
disabled: true,
paymentMethod: 'ppcp-gateway',
},
venmo: {
value: 'venmo',
label: __( 'Venmo', 'woocommerce-paypal-payments' ),
isFunding: true,
paymentMethod: 'venmo',
},
paylater: {
value: 'paylater',
label: __( 'Pay Later', 'woocommerce-paypal-payments' ),
isFunding: true,
paymentMethod: 'pay-later',
},
googlepay: {
value: 'googlepay',
label: __( 'Google Pay', 'woocommerce-paypal-payments' ),
paymentMethod: 'ppcp-googlepay',
},
applepay: {
value: 'applepay',
label: __( 'Apple Pay', 'woocommerce-paypal-payments' ),
paymentMethod: 'ppcp-applepay',
},
};