mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
✨ Re-implement conditional OXXO and PUI methods
This commit is contained in:
parent
e9a37da091
commit
7146163301
1 changed files with 57 additions and 49 deletions
|
@ -1,36 +1,34 @@
|
|||
import { __ } from '@wordpress/i18n';
|
||||
import { useMemo } from '@wordpress/element';
|
||||
|
||||
import SettingsCard from '../../ReusableComponents/SettingsCard';
|
||||
import PaymentMethodsBlock from '../../ReusableComponents/SettingsBlocks/PaymentMethodsBlock';
|
||||
import { CommonHooks } from '../../../data';
|
||||
import ModalPayPal from './Modals/ModalPayPal';
|
||||
import ModalFastlane from './Modals/ModalFastlane';
|
||||
import ModalAcdc from './Modals/ModalAcdc';
|
||||
import { CommonHooks } from '../../../data';
|
||||
|
||||
const TabPaymentMethods = () => {
|
||||
const renderPaymentMethods = ( data ) => {
|
||||
const { storeCountry, storeCurrency } = CommonHooks.useWooSettings();
|
||||
const { storeCountry, storeCurrency } = CommonHooks.useWooSettings();
|
||||
|
||||
const conditionallyUpdatedPaymentMethods = [
|
||||
...data,
|
||||
...( storeCountry === 'DE' && storeCurrency === 'EUR'
|
||||
? [ puiPaymentMethod ]
|
||||
: [] ),
|
||||
...( storeCountry === 'MX' && storeCurrency === 'MXN'
|
||||
? [ oxxoPaymentMethod ]
|
||||
: [] ),
|
||||
];
|
||||
const filteredPaymentMethods = useMemo( () => {
|
||||
const contextProps = { storeCountry, storeCurrency };
|
||||
|
||||
return (
|
||||
<div className="ppcp-r-payment-method-item-list">
|
||||
{ conditionallyUpdatedPaymentMethods.map( ( paymentMethod ) => (
|
||||
<PaymentMethodItem
|
||||
key={ paymentMethod.id }
|
||||
{ ...paymentMethod }
|
||||
/>
|
||||
) ) }
|
||||
</div>
|
||||
);
|
||||
};
|
||||
return {
|
||||
payPalCheckout: filterPaymentMethods(
|
||||
paymentMethodsPayPalCheckout,
|
||||
contextProps
|
||||
),
|
||||
onlineCardPayments: filterPaymentMethods(
|
||||
paymentMethodsOnlineCardPayments,
|
||||
contextProps
|
||||
),
|
||||
alternative: filterPaymentMethods(
|
||||
paymentMethodsAlternative,
|
||||
contextProps
|
||||
),
|
||||
};
|
||||
}, [ storeCountry, storeCurrency ] );
|
||||
|
||||
return (
|
||||
<div className="ppcp-r-payment-methods">
|
||||
|
@ -44,7 +42,7 @@ const TabPaymentMethods = () => {
|
|||
contentContainer={ false }
|
||||
>
|
||||
<PaymentMethodsBlock
|
||||
paymentMethods={ paymentMethodsPayPalCheckoutDefault }
|
||||
paymentMethods={ filteredPaymentMethods.payPalCheckout }
|
||||
/>
|
||||
</SettingsCard>
|
||||
<SettingsCard
|
||||
|
@ -60,7 +58,7 @@ const TabPaymentMethods = () => {
|
|||
contentContainer={ false }
|
||||
>
|
||||
<PaymentMethodsBlock
|
||||
paymentMethods={ paymentMethodsOnlineCardPaymentsDefault }
|
||||
paymentMethods={ filteredPaymentMethods.onlineCardPayments }
|
||||
/>
|
||||
</SettingsCard>
|
||||
<SettingsCard
|
||||
|
@ -76,14 +74,22 @@ const TabPaymentMethods = () => {
|
|||
contentContainer={ false }
|
||||
>
|
||||
<PaymentMethodsBlock
|
||||
paymentMethods={ paymentMethodsAlternativeDefault }
|
||||
paymentMethods={ filteredPaymentMethods.alternative }
|
||||
/>
|
||||
</SettingsCard>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const paymentMethodsPayPalCheckoutDefault = [
|
||||
function filterPaymentMethods( paymentMethods, contextProps ) {
|
||||
return paymentMethods.filter( ( method ) =>
|
||||
typeof method.condition === 'function'
|
||||
? method.condition( contextProps )
|
||||
: true
|
||||
);
|
||||
}
|
||||
|
||||
const paymentMethodsPayPalCheckout = [
|
||||
{
|
||||
id: 'paypal',
|
||||
title: __( 'PayPal', 'woocommerce-paypal-payments' ),
|
||||
|
@ -126,7 +132,7 @@ const paymentMethodsPayPalCheckoutDefault = [
|
|||
},
|
||||
];
|
||||
|
||||
const paymentMethodsOnlineCardPaymentsDefault = [
|
||||
const paymentMethodsOnlineCardPayments = [
|
||||
{
|
||||
id: 'advanced_credit_and_debit_card_payments',
|
||||
title: __(
|
||||
|
@ -170,7 +176,7 @@ const paymentMethodsOnlineCardPaymentsDefault = [
|
|||
},
|
||||
];
|
||||
|
||||
const paymentMethodsAlternativeDefault = [
|
||||
const paymentMethodsAlternative = [
|
||||
{
|
||||
id: 'bancontact',
|
||||
title: __( 'Bancontact', 'woocommerce-paypal-payments' ),
|
||||
|
@ -243,26 +249,28 @@ const paymentMethodsAlternativeDefault = [
|
|||
),
|
||||
icon: 'payment-method-multibanco',
|
||||
},
|
||||
{
|
||||
id: 'pui',
|
||||
title: __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
|
||||
description: __(
|
||||
'Pay upon Invoice is an invoice payment method in Germany. It is a local buy now, pay later payment method that allows the buyer to place an order, receive the goods, try them, verify they are in good order, and then pay the invoice within 30 days.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
icon: 'payment-method-ratepay',
|
||||
condition: ( { storeCountry, storeCurrency } ) =>
|
||||
storeCountry === 'DE' && storeCurrency === 'EUR',
|
||||
},
|
||||
{
|
||||
id: 'oxxo',
|
||||
title: __( 'OXXO', 'woocommerce-paypal-payments' ),
|
||||
description: __(
|
||||
'OXXO is a Mexican chain of convenience stores. *Get PayPal account permission to use OXXO payment functionality by contacting us at (+52) 800–925–0304',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
icon: 'payment-method-oxxo',
|
||||
condition: ( { storeCountry, storeCurrency } ) =>
|
||||
storeCountry === 'MX' && storeCurrency === 'MXN',
|
||||
},
|
||||
];
|
||||
|
||||
const puiPaymentMethod = {
|
||||
id: 'pui',
|
||||
title: __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
|
||||
description: __(
|
||||
'Pay upon Invoice is an invoice payment method in Germany. It is a local buy now, pay later payment method that allows the buyer to place an order, receive the goods, try them, verify they are in good order, and then pay the invoice within 30 days.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
icon: 'payment-method-ratepay',
|
||||
};
|
||||
|
||||
const oxxoPaymentMethod = {
|
||||
id: 'oxxo',
|
||||
title: __( 'OXXO', 'woocommerce-paypal-payments' ),
|
||||
description: __(
|
||||
'OXXO is a Mexican chain of convenience stores. *Get PayPal account permission to use OXXO payment functionality by contacting us at (+52) 800–925–0304',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
icon: 'payment-method-oxxo',
|
||||
};
|
||||
|
||||
export default TabPaymentMethods;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue