woocommerce-paypal-payments/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabPaymentMethods.js

149 lines
4.3 KiB
JavaScript
Raw Normal View History

2024-10-29 12:39:44 +01:00
import { __ } from '@wordpress/i18n';
import { useCallback } from '@wordpress/element';
import { CommonHooks, OnboardingHooks, PaymentHooks } from '../../../../data';
import { useActiveModal, useWooSettings } from '../../../../data/common/hooks';
2025-01-27 11:14:24 +01:00
import Modal from '../Components/Payment/Modal';
import PaymentMethodCard from '../Components/Payment/PaymentMethodCard';
import { useFeatures } from '../../../../data/features/hooks';
2024-10-29 12:39:44 +01:00
const TabPaymentMethods = () => {
const methods = PaymentHooks.usePaymentMethods();
const store = PaymentHooks.useStore();
const { setPersistent, changePaymentSettings } = store;
const { activeModal, setActiveModal } = useActiveModal();
const { features } = useFeatures();
2024-10-29 12:39:44 +01:00
// Get all methods as a map for dependency checking
const methodsMap = {};
methods.all.forEach( ( method ) => {
methodsMap[ method.id ] = method;
} );
const getActiveMethod = () => {
if ( ! activeModal ) {
return null;
}
return methods.all.find( ( method ) => method.id === activeModal );
};
const handleSave = useCallback(
( methodId, settings ) => {
changePaymentSettings( methodId, {
title: settings.checkoutPageTitle,
description: settings.checkoutPageDescription,
} );
const persistentSettings = [
'paypalShowLogo',
'threeDSecure',
'fastlaneCardholderName',
'fastlaneDisplayWatermark',
];
persistentSettings.forEach( ( setting ) => {
if ( setting in settings ) {
// TODO: Create a dedicated setter for those values.
setPersistent( setting, settings[ setting ] );
}
} );
setActiveModal( null );
},
[ changePaymentSettings, setActiveModal, setPersistent ]
);
2025-02-11 10:11:01 +01:00
const merchant = CommonHooks.useMerchant();
const { storeCountry } = useWooSettings();
const { canUseCardPayments } = OnboardingHooks.useFlags();
2025-02-11 10:11:01 +01:00
2025-03-25 16:46:52 +01:00
const showCardPayments =
methods.cardPayment.length > 0 &&
merchant.isBusinessSeller &&
canUseCardPayments &&
// Show ACDC if the merchant has the feature enabled in PayPal account.
features.some(
( feature ) =>
feature.id === 'advanced_credit_and_debit_cards' &&
feature.enabled
);
// Hide BCDC for all countries except Mexico when ACDC is turned on.
const filteredPayPalMethods = methods.paypal.filter(
( method ) =>
method.id !== 'ppcp-card-button-gateway' ||
storeCountry === 'MX' ||
! features.some(
( feature ) =>
feature.id === 'advanced_credit_and_debit_cards' &&
feature.enabled === true
)
);
2025-03-25 16:46:52 +01:00
2025-04-29 18:01:42 +02:00
const showApms = methods.apm.length > 0 && merchant.isBusinessSeller;
2024-10-29 12:39:44 +01:00
return (
<div className="ppcp-r-payment-methods">
<PaymentMethodCard
id="ppcp-paypal-checkout-card"
2024-10-29 12:39:44 +01:00
title={ __( 'PayPal Checkout', 'woocommerce-paypal-payments' ) }
description={ __(
'Select your preferred checkout option with PayPal for easy payment processing.',
'woocommerce-paypal-payments'
) }
icon="icon-checkout-standard.svg"
methods={ filteredPayPalMethods }
onTriggerModal={ setActiveModal }
methodsMap={ methodsMap }
/>
2025-03-25 16:46:52 +01:00
{ showCardPayments && (
2025-02-11 10:11:01 +01:00
<PaymentMethodCard
id="ppcp-card-payments-card"
title={ __(
'Online Card Payments',
'woocommerce-paypal-payments'
) }
description={ __(
'Select your preferred card payment options for efficient payment processing.',
'woocommerce-paypal-payments'
) }
icon="icon-checkout-online-methods.svg"
methods={ methods.cardPayment }
onTriggerModal={ setActiveModal }
methodsMap={ methodsMap }
2025-02-11 10:11:01 +01:00
/>
) }
2025-03-25 16:46:52 +01:00
{ showApms && (
<PaymentMethodCard
id="ppcp-alternative-payments-card"
title={ __(
'Alternative Payment Methods',
'woocommerce-paypal-payments'
) }
description={ __(
'With alternative payment methods, customers across the globe can pay with their bank accounts and other local payment methods.',
'woocommerce-paypal-payments'
) }
icon="icon-checkout-alternative-methods.svg"
methods={ methods.apm }
onTriggerModal={ setActiveModal }
methodsMap={ methodsMap }
2025-04-15 12:54:25 +02:00
showBulkToggle={ methods.apm.length > 1 }
groupName="Alternative Payment"
2025-03-25 16:46:52 +01:00
/>
) }
{ activeModal && (
<Modal
method={ getActiveMethod() }
setModalIsVisible={ () => setActiveModal( null ) }
onSave={ handleSave }
/>
) }
2024-10-29 12:39:44 +01:00
</div>
);
};
export default TabPaymentMethods;