Implement first ACDC/BCDC condition in wizard

This commit is contained in:
Philipp Stracker 2025-02-07 19:12:53 +01:00
parent 5e00c7d082
commit 055847a83e
No known key found for this signature in database

View file

@ -17,15 +17,22 @@ import {
// Default configuration, used for all countries, unless they override individual attributes below. // Default configuration, used for all countries, unless they override individual attributes below.
const defaultConfig = { const defaultConfig = {
// Included: Items in the left column.
includedMethods: [ includedMethods: [
{ name: 'PayWithPayPal', Component: PayWithPayPal }, { name: 'PayWithPayPal', Component: PayWithPayPal },
{ name: 'PayLater', Component: PayLater }, { name: 'PayLater', Component: PayLater },
], ],
optionalMethods: [
{ name: 'CreditDebitCards', Component: CreditDebitCards }, // Basic: Items on right side for BCDC-flow.
basicMethods: [ { name: 'CreditDebitCards', Component: CreditDebitCards } ],
// Extended: Items on right side for ACDC-flow.
extendedMethods: [
{ name: 'DigitalWallets', Component: DigitalWallets }, { name: 'DigitalWallets', Component: DigitalWallets },
{ name: 'APMs', Component: AlternativePaymentMethods }, { name: 'APMs', Component: AlternativePaymentMethods },
], ],
// Title, Description: Header above the right column items.
optionalTitle: __( optionalTitle: __(
'Optional payment methods', 'Optional payment methods',
'woocommerce-paypal-payments' 'woocommerce-paypal-payments'
@ -44,7 +51,10 @@ const countrySpecificConfigs = {
{ name: 'Venmo', Component: Venmo }, { name: 'Venmo', Component: Venmo },
{ name: 'Crypto', Component: Crypto }, { name: 'Crypto', Component: Crypto },
], ],
optionalMethods: [ basicMethods: [
{ name: 'CreditDebitCards', Component: CreditDebitCards },
],
extendedMethods: [
{ name: 'CardFields', Component: CardFields }, { name: 'CardFields', Component: CardFields },
{ name: 'DigitalWallets', Component: DigitalWallets }, { name: 'DigitalWallets', Component: DigitalWallets },
{ name: 'APMs', Component: AlternativePaymentMethods }, { name: 'APMs', Component: AlternativePaymentMethods },
@ -81,18 +91,25 @@ export const usePaymentConfig = (
const config = { ...defaultConfig, ...countryConfig }; const config = { ...defaultConfig, ...countryConfig };
const learnMoreConfig = learnMoreLinks[ country ] || {}; const learnMoreConfig = learnMoreLinks[ country ] || {};
// Filter the "left side" list. PayLater is conditional.
const includedMethods = filterMethods( config.includedMethods, [ const includedMethods = filterMethods( config.includedMethods, [
( method ) => isPayLater || method.name !== 'PayLater', ( method ) => isPayLater || method.name !== 'PayLater',
] ); ] );
const optionalMethods = filterMethods( config.optionalMethods, [ // Determine the "right side" items: Either BCDC or ACDC items.
const optionalMethods = useAcdc
? config.extendedMethods
: config.basicMethods;
// Remove conditional items from the right side list.
const availableOptionalMethods = filterMethods( optionalMethods, [
( method ) => method.name !== 'Fastlane' || isFastlane, ( method ) => method.name !== 'Fastlane' || isFastlane,
] ); ] );
return { return {
...config, ...config,
includedMethods, includedMethods,
optionalMethods, optionalMethods: availableOptionalMethods,
learnMoreConfig, learnMoreConfig,
}; };
}, [ country, isPayLater, useAcdc, isFastlane ] ); }, [ country, isPayLater, useAcdc, isFastlane ] );