diff --git a/packages/js/admin-e2e-tests/src/pages/PaymentsSetup.ts b/packages/js/admin-e2e-tests/src/pages/PaymentsSetup.ts index ea711a63e85..8efc7dc4ed4 100644 --- a/packages/js/admin-e2e-tests/src/pages/PaymentsSetup.ts +++ b/packages/js/admin-e2e-tests/src/pages/PaymentsSetup.ts @@ -23,6 +23,9 @@ export class PaymentsSetup extends BasePage { async possiblyCloseHelpModal(): Promise< void > { try { + await waitForElementByText( 'div', "We're here for help", { + timeout: 2000, + } ); await this.clickButtonWithText( 'Got it' ); } catch ( e ) {} } diff --git a/packages/js/admin-e2e-tests/src/specs/tasks/payment.ts b/packages/js/admin-e2e-tests/src/specs/tasks/payment.ts index 1571fea5fcc..9d377b05db0 100644 --- a/packages/js/admin-e2e-tests/src/specs/tasks/payment.ts +++ b/packages/js/admin-e2e-tests/src/specs/tasks/payment.ts @@ -52,9 +52,8 @@ const testAdminPaymentSetupTask = () => { await paymentsSetup.isDisplayed(); } ); - it.skip( 'Saving valid bank account transfer details enables the payment method', async () => { + it( 'Saving valid bank account transfer details enables the payment method', async () => { await paymentsSetup.showOtherPaymentMethods(); - await waitForTimeout( 500 ); await paymentsSetup.goToPaymentMethodSetup( 'bacs' ); await bankTransferSetup.saveAccountDetails( { accountNumber: '1234', @@ -68,10 +67,9 @@ const testAdminPaymentSetupTask = () => { expect( await settings.paymentMethodIsEnabled( 'bacs' ) ).toBe( true ); - await homeScreen.navigate(); } ); - it.skip( 'Enabling cash on delivery enables the payment method', async () => { + it( 'Enabling cash on delivery enables the payment method', async () => { await settings.cleanPaymentMethods(); await homeScreen.navigate(); await homeScreen.isDisplayed(); @@ -80,7 +78,6 @@ const testAdminPaymentSetupTask = () => { await paymentsSetup.possiblyCloseHelpModal(); await paymentsSetup.isDisplayed(); await paymentsSetup.showOtherPaymentMethods(); - await waitForTimeout( 500 ); await paymentsSetup.enableCashOnDelivery(); await waitForTimeout( 1500 ); expect( await settings.paymentMethodIsEnabled( 'cod' ) ).toBe( diff --git a/plugins/woocommerce-admin/client/tasks/fills/PaymentGatewaySuggestions/index.js b/plugins/woocommerce-admin/client/tasks/fills/PaymentGatewaySuggestions/index.js index 185f050c284..894f5673994 100644 --- a/plugins/woocommerce-admin/client/tasks/fills/PaymentGatewaySuggestions/index.js +++ b/plugins/woocommerce-admin/client/tasks/fills/PaymentGatewaySuggestions/index.js @@ -25,26 +25,17 @@ import { List, Placeholder as ListPlaceholder } from './components/List'; import { Setup, Placeholder as SetupPlaceholder } from './components/Setup'; import { Toggle } from './components/Toggle/Toggle'; import { WCPaySuggestion } from './components/WCPay'; -import { getPluginSlug } from '~/utils'; import { getCountryCode } from '~/dashboard/utils'; +import { + getEnrichedPaymentGateways, + getSplitGateways, + getIsWCPayOrOtherCategoryDoneSetup, + getIsGatewayWCPay, + comparePaymentGatewaysByPriority, +} from './utils'; import './plugins/Bacs'; import './payment-gateway-suggestions.scss'; -const comparePaymentGatewaysByPriority = ( a, b ) => - a.recommendation_priority - b.recommendation_priority; - -const isGatewayWCPay = ( gateway ) => - gateway.plugins?.length === 1 && - gateway.plugins[ 0 ] === 'woocommerce-payments'; - -const isGatewayOtherCategory = ( gateway, countryCode ) => - gateway.category_other && - gateway.category_other.indexOf( countryCode ) !== -1; - -const isGatewayAdditionalCategory = ( gateway, countryCode ) => - gateway.category_additional && - gateway.category_additional.indexOf( countryCode ) !== -1; - export const PaymentGatewaySuggestions = ( { onComplete, query } ) => { const { updatePaymentGateway } = useDispatch( PAYMENT_GATEWAYS_STORE_NAME ); const { @@ -73,54 +64,14 @@ export const PaymentGatewaySuggestions = ( { onComplete, query } ) => { }; }, [] ); - const getEnrichedPaymentGateways = () => { - const mappedPaymentGateways = installedPaymentGateways.reduce( - ( map, gateway ) => { - map[ gateway.id ] = gateway; - return map; - }, - {} - ); - - return paymentGatewaySuggestions.reduce( ( map, suggestion ) => { - // A colon ':' is used sometimes to have multiple configs for the same gateway ex: woocommerce_payments:us. - const id = getPluginSlug( suggestion.id ); - const installedGateway = mappedPaymentGateways[ id ] - ? mappedPaymentGateways[ id ] - : {}; - - const enrichedSuggestion = { - installed: !! mappedPaymentGateways[ id ], - postInstallScripts: installedGateway.post_install_scripts, - hasPlugins: !! ( - suggestion.plugins && suggestion.plugins.length - ), - enabled: installedGateway.enabled || false, - needsSetup: installedGateway.needs_setup, - settingsUrl: installedGateway.settings_url, - connectionUrl: installedGateway.connection_url, - setupHelpText: installedGateway.setup_help_text, - title: installedGateway.title, - requiredSettings: installedGateway.required_settings_keys - ? installedGateway.required_settings_keys - .map( - ( settingKey ) => - installedGateway.settings[ settingKey ] - ) - .filter( Boolean ) - : [], - ...suggestion, - }; - - map.set( suggestion.id, enrichedSuggestion ); - return map; - }, new Map() ); - }; - - const paymentGateways = useMemo( getEnrichedPaymentGateways, [ - installedPaymentGateways, - paymentGatewaySuggestions, - ] ); + const paymentGateways = useMemo( + () => + getEnrichedPaymentGateways( + installedPaymentGateways, + paymentGatewaySuggestions + ), + [ installedPaymentGateways, paymentGatewaySuggestions ] + ); useEffect( () => { if ( paymentGateways.size ) { @@ -201,86 +152,30 @@ export const PaymentGatewaySuggestions = ( { onComplete, query } ) => { return gateway; }, [ isResolving, query, paymentGateways ] ); - const isWCPayOrOtherCategoryDoneSetup = useMemo( () => { - for ( const [ , gateway ] of paymentGateways.entries() ) { - if ( ! gateway.installed || gateway.needsSetup ) { - continue; - } - - if ( isGatewayWCPay( gateway ) ) { - return true; - } - - if ( isGatewayOtherCategory( gateway, countryCode ) ) { - return true; - } - } - return false; - }, [ countryCode, paymentGateways ] ); + const isWCPayOrOtherCategoryDoneSetup = useMemo( + () => + getIsWCPayOrOtherCategoryDoneSetup( paymentGateways, countryCode ), + [ countryCode, paymentGateways ] + ); const isWCPaySupported = - Array.from( paymentGateways.values() ).findIndex( isGatewayWCPay ) !== - -1; + Array.from( paymentGateways.values() ).findIndex( + getIsGatewayWCPay + ) !== -1; const [ wcPayGateway, offlineGateways, additionalGateways ] = useMemo( () => - Array.from( paymentGateways.values() ) - .sort( ( a, b ) => { - if ( a.hasPlugins === b.hasPlugins ) { - return comparePaymentGatewaysByPriority( a, b ); - } - - // hasPlugins payment first - if ( a.hasPlugins ) { - return -1; - } - - return 1; - } ) - .reduce( - ( all, gateway ) => { - const [ wcPay, offline, additional ] = all; - - // WCPay is handled separately when not installed and configured - if ( - isGatewayWCPay( gateway ) && - ! ( gateway.installed && ! gateway.needsSetup ) - ) { - wcPay.push( gateway ); - } else if ( gateway.is_offline ) { - offline.push( gateway ); - } else if ( gateway.enabled ) { - // Enabled gateways should be ignored. - } else if ( isWCPayOrOtherCategoryDoneSetup ) { - // If WCPay or "other" gateway is enabled in an WCPay-eligible country, only - // allow to list "additional" gateways. - if ( - isGatewayAdditionalCategory( - gateway, - countryCode - ) - ) { - additional.push( gateway ); - } - } else if ( ! isWCPaySupported ) { - // When WCPay-ineligible, just show all gateways. - additional.push( gateway ); - } else if ( - isGatewayOtherCategory( gateway, countryCode ) - ) { - // When nothing is set up and eligible for WCPay, only show "other" gateways. - additional.push( gateway ); - } - - return all; - }, - [ [], [], [] ] - ), + getSplitGateways( + paymentGateways, + countryCode, + isWCPaySupported, + isWCPayOrOtherCategoryDoneSetup + ), [ + paymentGateways, countryCode, isWCPaySupported, isWCPayOrOtherCategoryDoneSetup, - paymentGateways, ] ); diff --git a/plugins/woocommerce-admin/client/tasks/fills/PaymentGatewaySuggestions/test/utils.js b/plugins/woocommerce-admin/client/tasks/fills/PaymentGatewaySuggestions/test/utils.js new file mode 100644 index 00000000000..60de40fea76 --- /dev/null +++ b/plugins/woocommerce-admin/client/tasks/fills/PaymentGatewaySuggestions/test/utils.js @@ -0,0 +1,131 @@ +/** + * Internal dependencies + */ +import { getSplitGateways, getIsWCPayOrOtherCategoryDoneSetup } from '../utils'; + +const wcpay = { + plugins: [ 'woocommerce-payments' ], + installed: false, + needsSetup: true, +}; + +const cod = { + is_offline: true, +}; + +const bacs = { + is_offline: true, +}; + +const paypal = { + id: 'paypal', + category_other: [ 'CA' ], + category_additional: [ 'CA' ], +}; + +const stripe = { + id: 'stripe', + category_other: [ 'US' ], + category_additional: [ 'US' ], +}; + +const klarna = { + id: 'klarna', + category_other: [ '' ], + category_additional: [ 'US' ], +}; + +describe( 'getSplitGateways()', () => { + it( 'Returns WCPay gateways', () => { + const [ wcpayGateways ] = getSplitGateways( [ wcpay, cod, paypal ] ); + expect( wcpayGateways ).toEqual( [ wcpay ] ); + } ); + + it( 'Returns offline gateways', () => { + const [ , offlineGateways ] = getSplitGateways( [ + wcpay, + cod, + bacs, + paypal, + ] ); + expect( offlineGateways ).toEqual( [ cod, bacs ] ); + } ); + + it( 'Excludes enabled gateways', () => { + const [ , , additionalGateways ] = getSplitGateways( [ + wcpay, + cod, + bacs, + { + ...paypal, + enabled: true, + }, + ] ); + expect( additionalGateways ).toEqual( [] ); + } ); + + describe( 'Additional gateways with eligible WCPay', () => { + it( 'Returns only "other" category gateways when WCPay or "other" category gateway isnt set up', () => { + const [ , , additionalGateways ] = getSplitGateways( + [ wcpay, cod, bacs, paypal, stripe, klarna ], + 'US', + true, + false + ); + expect( additionalGateways ).toEqual( [ stripe ] ); + } ); + it( 'Returns only "additional" category gateways when WCPay or "other" category gateway is set up', () => { + const [ , , additionalGateways ] = getSplitGateways( + [ wcpay, cod, bacs, paypal, stripe, klarna ], + 'US', + true, + true + ); + expect( additionalGateways ).toEqual( [ stripe, klarna ] ); + } ); + } ); + + describe( 'Additional gateways with ineligible WCPay', () => { + it( 'Returns all gateways when "other" gateways isnt set up', () => { + const [ , , additionalGateways ] = getSplitGateways( + [ wcpay, cod, bacs, paypal, stripe, klarna ], + 'US', + false, + false + ); + expect( additionalGateways ).toEqual( [ paypal, stripe, klarna ] ); + } ); + it( 'Returns only "additional" category gateways when "other" gateways is set up', () => { + const [ , , additionalGateways ] = getSplitGateways( + [ wcpay, cod, bacs, paypal, stripe, klarna ], + 'US', + false, + true + ); + expect( additionalGateways ).toEqual( [ stripe, klarna ] ); + } ); + } ); +} ); + +describe( 'getIsWCPayOrOtherCategoryDoneSetup()', () => { + it( 'False when nothing is set up', () => { + expect( + getIsWCPayOrOtherCategoryDoneSetup( [ wcpay, cod, paypal ] ) + ).toEqual( false ); + } ); + it( 'True when WCPay is set up', () => { + expect( + getIsWCPayOrOtherCategoryDoneSetup( [ + { ...wcpay, installed: true, needsSetup: false }, + ] ) + ).toEqual( true ); + } ); + it( 'True when "other" category gateway is set up', () => { + expect( + getIsWCPayOrOtherCategoryDoneSetup( + [ { ...stripe, installed: true, needsSetup: false } ], + 'US' + ) + ).toEqual( true ); + } ); +} ); diff --git a/plugins/woocommerce-admin/client/tasks/fills/PaymentGatewaySuggestions/utils.js b/plugins/woocommerce-admin/client/tasks/fills/PaymentGatewaySuggestions/utils.js new file mode 100644 index 00000000000..907db9819c3 --- /dev/null +++ b/plugins/woocommerce-admin/client/tasks/fills/PaymentGatewaySuggestions/utils.js @@ -0,0 +1,140 @@ +/** + * Internal dependencies + */ +import { getPluginSlug } from '~/utils'; + +export const comparePaymentGatewaysByPriority = ( a, b ) => + a.recommendation_priority - b.recommendation_priority; + +export const getIsGatewayWCPay = ( gateway ) => + gateway.plugins?.length === 1 && + gateway.plugins[ 0 ] === 'woocommerce-payments'; + +export const getIsGatewayOtherCategory = ( gateway, countryCode ) => + gateway.category_other && + gateway.category_other.indexOf( countryCode ) !== -1; + +export const getIsGatewayAdditionalCategory = ( gateway, countryCode ) => + gateway.category_additional && + gateway.category_additional.indexOf( countryCode ) !== -1; + +export const getEnrichedPaymentGateways = ( + installedPaymentGateways, + paymentGatewaySuggestions +) => { + const mappedPaymentGateways = installedPaymentGateways.reduce( + ( map, gateway ) => { + map[ gateway.id ] = gateway; + return map; + }, + {} + ); + + return paymentGatewaySuggestions.reduce( ( map, suggestion ) => { + // A colon ':' is used sometimes to have multiple configs for the same gateway ex: woocommerce_payments:us. + const id = getPluginSlug( suggestion.id ); + const installedGateway = mappedPaymentGateways[ id ] + ? mappedPaymentGateways[ id ] + : {}; + + const enrichedSuggestion = { + installed: !! mappedPaymentGateways[ id ], + postInstallScripts: installedGateway.post_install_scripts, + hasPlugins: !! ( suggestion.plugins && suggestion.plugins.length ), + enabled: installedGateway.enabled || false, + needsSetup: installedGateway.needs_setup, + settingsUrl: installedGateway.settings_url, + connectionUrl: installedGateway.connection_url, + setupHelpText: installedGateway.setup_help_text, + title: installedGateway.title, + requiredSettings: installedGateway.required_settings_keys + ? installedGateway.required_settings_keys + .map( + ( settingKey ) => + installedGateway.settings[ settingKey ] + ) + .filter( Boolean ) + : [], + ...suggestion, + }; + + map.set( suggestion.id, enrichedSuggestion ); + return map; + }, new Map() ); +}; + +export const getIsWCPayOrOtherCategoryDoneSetup = ( + paymentGateways, + countryCode +) => { + for ( const [ , gateway ] of paymentGateways.entries() ) { + if ( ! gateway.installed || gateway.needsSetup ) { + continue; + } + + if ( getIsGatewayWCPay( gateway ) ) { + return true; + } + + if ( getIsGatewayOtherCategory( gateway, countryCode ) ) { + return true; + } + } + return false; +}; + +export const getSplitGateways = ( + paymentGateways, + countryCode, + isWCPaySupported, + isWCPayOrOtherCategoryDoneSetup +) => + Array.from( paymentGateways.values() ) + .sort( ( a, b ) => { + if ( a.hasPlugins === b.hasPlugins ) { + return comparePaymentGatewaysByPriority( a, b ); + } + + // hasPlugins payment first + if ( a.hasPlugins ) { + return -1; + } + + return 1; + } ) + .reduce( + ( all, gateway ) => { + const [ wcPay, offline, additional ] = all; + + // WCPay is handled separately when not installed and configured + if ( + getIsGatewayWCPay( gateway ) && + ! ( gateway.installed && ! gateway.needsSetup ) + ) { + wcPay.push( gateway ); + } else if ( gateway.is_offline ) { + offline.push( gateway ); + } else if ( gateway.enabled ) { + // Enabled gateways should be ignored. + } else if ( isWCPayOrOtherCategoryDoneSetup ) { + // If WCPay or "other" gateway is enabled in an WCPay-eligible country, only + // allow to list "additional" gateways. + if ( + getIsGatewayAdditionalCategory( gateway, countryCode ) + ) { + additional.push( gateway ); + } + } else if ( ! isWCPaySupported ) { + // When WCPay-ineligible, just show all gateways. + additional.push( gateway ); + } else if ( + getIsGatewayOtherCategory( gateway, countryCode ) + ) { + // When nothing is set up and eligible for WCPay, only show "other" gateways. + additional.push( gateway ); + } + + return all; + }, + [ [], [], [] ] + ); diff --git a/plugins/woocommerce/changelog/update-refactor-and-improve-tests-payments-task b/plugins/woocommerce/changelog/update-refactor-and-improve-tests-payments-task new file mode 100644 index 00000000000..740381593c8 --- /dev/null +++ b/plugins/woocommerce/changelog/update-refactor-and-improve-tests-payments-task @@ -0,0 +1,4 @@ +Significance: patch +Type: tweak + +Refactor and improve tests payments task diff --git a/plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/DefaultPaymentGateways.php b/plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/DefaultPaymentGateways.php index 31b7556793e..38482c878ab 100644 --- a/plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/DefaultPaymentGateways.php +++ b/plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/DefaultPaymentGateways.php @@ -22,17 +22,17 @@ class DefaultPaymentGateways { public static function get_all() { return array( array( - 'id' => 'payfast', - 'title' => __( 'PayFast', 'woocommerce' ), - 'content' => __( 'The PayFast extension for WooCommerce enables you to accept payments by Credit Card and EFT via one of South Africa’s most popular payment gateways. No setup fees or monthly subscription costs. Selecting this extension will configure your store to use South African rands as the selected currency.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/payfast.png', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/payfast.png', - 'plugins' => array( 'woocommerce-payfast-gateway' ), - 'is_visible' => array( + 'id' => 'payfast', + 'title' => __( 'PayFast', 'woocommerce' ), + 'content' => __( 'The PayFast extension for WooCommerce enables you to accept payments by Credit Card and EFT via one of South Africa’s most popular payment gateways. No setup fees or monthly subscription costs. Selecting this extension will configure your store to use South African rands as the selected currency.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/payfast.png', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/payfast.png', + 'plugins' => array( 'woocommerce-payfast-gateway' ), + 'is_visible' => array( self::get_rules_for_countries( array( 'ZA', 'GH', 'NG' ) ), self::get_rules_for_cbd( false ), ), - 'category_other' => array( 'ZA', 'GH', 'NG' ), + 'category_other' => array( 'ZA', 'GH', 'NG' ), 'category_additional' => array(), ), array( @@ -49,67 +49,67 @@ class DefaultPaymentGateways { ), self::get_rules_for_cbd( false ), ), - 'category_other' => array( 'AU', 'AT', 'BE', 'BG', 'BR', 'CA', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HK', 'IN', 'IE', 'IT', 'JP', 'LV', 'LT', 'LU', 'MY', 'MT', 'MX', 'NL', 'NZ', 'NO', 'PL', 'PT', 'RO', 'SG', 'SK', 'SI', 'ES', 'SE', 'CH', 'GB', 'US', 'PR', 'HU', 'SL', 'ID', 'MY', 'SI', 'PR' ), - 'category_additional' => array(), + 'category_other' => array( 'AU', 'AT', 'BE', 'BG', 'BR', 'CA', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HK', 'IN', 'IE', 'IT', 'JP', 'LV', 'LT', 'LU', 'MY', 'MT', 'MX', 'NL', 'NZ', 'NO', 'PL', 'PT', 'RO', 'SG', 'SK', 'SI', 'ES', 'SE', 'CH', 'GB', 'US', 'PR', 'HU', 'SL', 'ID', 'MY', 'SI', 'PR' ), + 'category_additional' => array(), 'recommendation_priority' => 3, ), array( - 'id' => 'paystack', - 'title' => __( 'Paystack', 'woocommerce' ), - 'content' => __( 'Paystack helps African merchants accept one-time and recurring payments online with a modern, safe, and secure payment gateway.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/paystack.png', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/paystack.png', - 'plugins' => array( 'woo-paystack' ), - 'is_visible' => array( + 'id' => 'paystack', + 'title' => __( 'Paystack', 'woocommerce' ), + 'content' => __( 'Paystack helps African merchants accept one-time and recurring payments online with a modern, safe, and secure payment gateway.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/paystack.png', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/paystack.png', + 'plugins' => array( 'woo-paystack' ), + 'is_visible' => array( self::get_rules_for_countries( array( 'ZA', 'GH', 'NG' ) ), self::get_rules_for_cbd( false ), ), - 'category_other' => array( 'ZA', 'GH', 'NG' ), + 'category_other' => array( 'ZA', 'GH', 'NG' ), 'category_additional' => array(), ), array( - 'id' => 'kco', - 'title' => __( 'Klarna Checkout', 'woocommerce' ), - 'content' => __( 'Choose the payment that you want, pay now, pay later or slice it. No credit card numbers, no passwords, no worries.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/klarna-black.png', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/klarna.png', - 'plugins' => array( 'klarna-checkout-for-woocommerce' ), - 'is_visible' => array( + 'id' => 'kco', + 'title' => __( 'Klarna Checkout', 'woocommerce' ), + 'content' => __( 'Choose the payment that you want, pay now, pay later or slice it. No credit card numbers, no passwords, no worries.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/klarna-black.png', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/klarna.png', + 'plugins' => array( 'klarna-checkout-for-woocommerce' ), + 'is_visible' => array( self::get_rules_for_countries( array( 'SE', 'FI', 'NO' ) ), self::get_rules_for_cbd( false ), ), - 'category_other' => array( 'SE', 'FI', 'NO' ), + 'category_other' => array( 'SE', 'FI', 'NO' ), 'category_additional' => array(), ), array( - 'id' => 'klarna_payments', - 'title' => __( 'Klarna Payments', 'woocommerce' ), - 'content' => __( 'Choose the payment that you want, pay now, pay later or slice it. No credit card numbers, no passwords, no worries.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/klarna-black.png', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/klarna.png', - 'plugins' => array( 'klarna-payments-for-woocommerce' ), - 'is_visible' => array( + 'id' => 'klarna_payments', + 'title' => __( 'Klarna Payments', 'woocommerce' ), + 'content' => __( 'Choose the payment that you want, pay now, pay later or slice it. No credit card numbers, no passwords, no worries.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/klarna-black.png', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/klarna.png', + 'plugins' => array( 'klarna-payments-for-woocommerce' ), + 'is_visible' => array( self::get_rules_for_countries( array( 'US', 'CA', 'DK', 'DE', 'AT', 'NL', 'CH', 'BE', 'SP', 'PL', 'FR', 'IT', 'GB', 'ES', 'FI', 'NO', 'SE', 'ES', 'FI', 'NO', 'SE' ) ), self::get_rules_for_cbd( false ), ), - 'category_other' => array(), + 'category_other' => array(), 'category_additional' => array( 'US', 'CA', 'DK', 'DE', 'AT', 'NL', 'CH', 'BE', 'SP', 'PL', 'FR', 'IT', 'GB', 'ES', 'FI', 'NO', 'SE', 'ES', 'FI', 'NO', 'SE' ), ), array( - 'id' => 'mollie_wc_gateway_banktransfer', - 'title' => __( 'Mollie', 'woocommerce' ), - 'content' => __( 'Effortless payments by Mollie: Offer global and local payment methods, get onboarded in minutes, and supported in your language.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/mollie.svg', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/mollie.png', - 'plugins' => array( 'mollie-payments-for-woocommerce' ), - 'is_visible' => array( + 'id' => 'mollie_wc_gateway_banktransfer', + 'title' => __( 'Mollie', 'woocommerce' ), + 'content' => __( 'Effortless payments by Mollie: Offer global and local payment methods, get onboarded in minutes, and supported in your language.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/mollie.svg', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/mollie.png', + 'plugins' => array( 'mollie-payments-for-woocommerce' ), + 'is_visible' => array( self::get_rules_for_countries( array( 'FR', 'DE', 'GB', 'AT', 'CH', 'ES', 'IT', 'PL', 'FI', 'NL', 'BE' ) ), ), - 'category_other' => array( 'FR', 'DE', 'GB', 'AT', 'CH', 'ES', 'IT', 'PL', 'FI', 'NL', 'BE' ), + 'category_other' => array( 'FR', 'DE', 'GB', 'AT', 'CH', 'ES', 'IT', 'PL', 'FI', 'NL', 'BE' ), 'category_additional' => array(), ), array( @@ -124,17 +124,17 @@ class DefaultPaymentGateways { ), 'recommendation_priority' => 2, 'is_local_partner' => true, - 'category_other' => array( 'AR', 'BR', 'CL', 'CO', 'MX', 'PE', 'UY' ), - 'category_additional' => array(), + 'category_other' => array( 'AR', 'BR', 'CL', 'CO', 'MX', 'PE', 'UY' ), + 'category_additional' => array(), ), array( - 'id' => 'ppcp-gateway', - 'title' => __( 'PayPal Payments', 'woocommerce' ), - 'content' => __( "Safe and secure payments using credit cards or your customer's PayPal account.", 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/paypal.png', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/paypal.png', - 'plugins' => array( 'woocommerce-paypal-payments' ), - 'is_visible' => array( + 'id' => 'ppcp-gateway', + 'title' => __( 'PayPal Payments', 'woocommerce' ), + 'content' => __( "Safe and secure payments using credit cards or your customer's PayPal account.", 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/paypal.png', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/paypal.png', + 'plugins' => array( 'woocommerce-paypal-payments' ), + 'is_visible' => array( (object) array( 'type' => 'base_location_country', 'value' => 'IN', @@ -142,30 +142,30 @@ class DefaultPaymentGateways { ), self::get_rules_for_cbd( false ), ), - 'category_other' => array( 'US', 'CA', 'AT', 'BE', 'BG', 'HR', 'CH', 'CY', 'CZ', 'DK', 'EE', 'ES', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SK', 'SL', 'SE', 'MX', 'BR', 'AR', 'CL', 'CO', 'EC', 'PE', 'UY', 'VE', 'AU', 'NZ', 'HK', 'JP', 'SG', 'CN', 'ID', 'ZA', 'NG', 'GH' ), + 'category_other' => array( 'US', 'CA', 'AT', 'BE', 'BG', 'HR', 'CH', 'CY', 'CZ', 'DK', 'EE', 'ES', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SK', 'SL', 'SE', 'MX', 'BR', 'AR', 'CL', 'CO', 'EC', 'PE', 'UY', 'VE', 'AU', 'NZ', 'HK', 'JP', 'SG', 'CN', 'ID', 'ZA', 'NG', 'GH' ), 'category_additional' => array( 'US', 'CA', 'AT', 'BE', 'BG', 'HR', 'CH', 'CY', 'CZ', 'DK', 'EE', 'ES', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SK', 'SL', 'SE', 'MX', 'BR', 'AR', 'CL', 'CO', 'EC', 'PE', 'UY', 'VE', 'AU', 'NZ', 'HK', 'JP', 'SG', 'CN', 'ID', 'IN', 'ZA', 'NG', 'GH' ), ), array( - 'id' => 'cod', - 'title' => __( 'Cash on delivery', 'woocommerce' ), - 'content' => __( 'Take payments in cash upon delivery.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/cod.svg', + 'id' => 'cod', + 'title' => __( 'Cash on delivery', 'woocommerce' ), + 'content' => __( 'Take payments in cash upon delivery.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/cod.svg', 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/cod.png', - 'is_visible' => array( + 'is_visible' => array( self::get_rules_for_cbd( false ), ), - 'is_offline' => true, + 'is_offline' => true, ), array( - 'id' => 'bacs', - 'title' => __( 'Direct bank transfer', 'woocommerce' ), - 'content' => __( 'Take payments via bank transfer.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/bacs.svg', + 'id' => 'bacs', + 'title' => __( 'Direct bank transfer', 'woocommerce' ), + 'content' => __( 'Take payments via bank transfer.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/bacs.svg', 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/bacs.png', - 'is_visible' => array( + 'is_visible' => array( self::get_rules_for_cbd( false ), ), - 'is_offline' => true, + 'is_offline' => true, ), array( 'id' => 'woocommerce_payments', @@ -281,13 +281,13 @@ class DefaultPaymentGateways { 'recommendation_priority' => 1, ), array( - 'id' => 'razorpay', - 'title' => __( 'Razorpay', 'woocommerce' ), - 'content' => __( 'The official Razorpay extension for WooCommerce allows you to accept credit cards, debit cards, netbanking, wallet, and UPI payments.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/razorpay.svg', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/razorpay.png', - 'plugins' => array( 'woo-razorpay' ), - 'is_visible' => array( + 'id' => 'razorpay', + 'title' => __( 'Razorpay', 'woocommerce' ), + 'content' => __( 'The official Razorpay extension for WooCommerce allows you to accept credit cards, debit cards, netbanking, wallet, and UPI payments.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/razorpay.svg', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/razorpay.png', + 'plugins' => array( 'woo-razorpay' ), + 'is_visible' => array( (object) array( 'type' => 'base_location_country', 'value' => 'IN', @@ -295,17 +295,17 @@ class DefaultPaymentGateways { ), self::get_rules_for_cbd( false ), ), - 'category_other' => array( 'IN' ), + 'category_other' => array( 'IN' ), 'category_additional' => array(), ), array( - 'id' => 'payubiz', - 'title' => __( 'PayU for WooCommerce', 'woocommerce' ), - 'content' => __( 'Enable PayU’s exclusive plugin for WooCommerce to start accepting payments in 100+ payment methods available in India including credit cards, debit cards, UPI, & more!', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/payu.svg', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/payu.png', - 'plugins' => array( 'payu-india' ), - 'is_visible' => array( + 'id' => 'payubiz', + 'title' => __( 'PayU for WooCommerce', 'woocommerce' ), + 'content' => __( 'Enable PayU’s exclusive plugin for WooCommerce to start accepting payments in 100+ payment methods available in India including credit cards, debit cards, UPI, & more!', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/payu.svg', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/payu.png', + 'plugins' => array( 'payu-india' ), + 'is_visible' => array( (object) array( 'type' => 'base_location_country', 'value' => 'IN', @@ -313,31 +313,31 @@ class DefaultPaymentGateways { ), self::get_rules_for_cbd( false ), ), - 'category_other' => array( 'IN' ), + 'category_other' => array( 'IN' ), 'category_additional' => array(), ), array( - 'id' => 'eway', - 'title' => __( 'Eway', 'woocommerce' ), - 'content' => __( 'The Eway extension for WooCommerce allows you to take credit card payments directly on your store without redirecting your customers to a third party site to make payment.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/eway.png', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/eway.png', - 'plugins' => array( 'woocommerce-gateway-eway' ), - 'is_visible' => array( + 'id' => 'eway', + 'title' => __( 'Eway', 'woocommerce' ), + 'content' => __( 'The Eway extension for WooCommerce allows you to take credit card payments directly on your store without redirecting your customers to a third party site to make payment.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/eway.png', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/eway.png', + 'plugins' => array( 'woocommerce-gateway-eway' ), + 'is_visible' => array( self::get_rules_for_countries( array( 'AU', 'NZ' ) ), self::get_rules_for_cbd( false ), ), - 'category_other' => array( 'AU', 'NZ' ), + 'category_other' => array( 'AU', 'NZ' ), 'category_additional' => array(), ), array( - 'id' => 'square_credit_card', - 'title' => __( 'Square', 'woocommerce' ), - 'content' => __( 'Securely accept credit and debit cards with one low rate, no surprise fees (custom rates available). Sell online and in store and track sales and inventory in one place.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/square-black.png', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/square.png', - 'plugins' => array( 'woocommerce-square' ), - 'is_visible' => array( + 'id' => 'square_credit_card', + 'title' => __( 'Square', 'woocommerce' ), + 'content' => __( 'Securely accept credit and debit cards with one low rate, no surprise fees (custom rates available). Sell online and in store and track sales and inventory in one place.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/square-black.png', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/square.png', + 'plugins' => array( 'woocommerce-square' ), + 'is_visible' => array( (object) array( 'type' => 'or', 'operands' => (object) array( @@ -352,47 +352,47 @@ class DefaultPaymentGateways { ), ), ), - 'category_other' => array( 'US', 'CA', 'JP', 'GB', 'AU', 'IE', 'FR', 'ES', 'FI' ), + 'category_other' => array( 'US', 'CA', 'JP', 'GB', 'AU', 'IE', 'FR', 'ES', 'FI' ), 'category_additional' => array(), ), array( - 'id' => 'afterpay', - 'title' => __( 'Afterpay', 'woocommerce' ), - 'content' => __( 'Afterpay allows customers to receive products immediately and pay for purchases over four installments, always interest-free.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/afterpay.png', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/afterpay.png', - 'plugins' => array( 'afterpay-gateway-for-woocommerce' ), - 'is_visible' => array( + 'id' => 'afterpay', + 'title' => __( 'Afterpay', 'woocommerce' ), + 'content' => __( 'Afterpay allows customers to receive products immediately and pay for purchases over four installments, always interest-free.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/afterpay.png', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/afterpay.png', + 'plugins' => array( 'afterpay-gateway-for-woocommerce' ), + 'is_visible' => array( self::get_rules_for_countries( array( 'US', 'CA' ) ), ), - 'category_other' => array(), + 'category_other' => array(), 'category_additional' => array( 'US', 'CA' ), ), array( - 'id' => 'amazon_payments_advanced', - 'title' => __( 'Amazon Pay', 'woocommerce' ), - 'content' => __( 'Enable a familiar, fast checkout for hundreds of millions of active Amazon customers globally.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/amazonpay.png', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/amazonpay.png', - 'plugins' => array( 'woocommerce-gateway-amazon-payments-advanced' ), - 'is_visible' => array( + 'id' => 'amazon_payments_advanced', + 'title' => __( 'Amazon Pay', 'woocommerce' ), + 'content' => __( 'Enable a familiar, fast checkout for hundreds of millions of active Amazon customers globally.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/amazonpay.png', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/amazonpay.png', + 'plugins' => array( 'woocommerce-gateway-amazon-payments-advanced' ), + 'is_visible' => array( self::get_rules_for_countries( array( 'US', 'CA' ) ), ), - 'category_other' => array(), + 'category_other' => array(), 'category_additional' => array( 'US', 'CA' ), ), array( - 'id' => 'affirm', - 'title' => __( 'Affirm', 'woocommerce' ), - 'content' => __( 'Affirm’s tailored Buy Now Pay Later programs remove price as a barrier, turning browsers into buyers, increasing average order value, and expanding your customer base.', 'woocommerce' ), - 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/affirm.png', - 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/affirm.png', - 'plugins' => array(), - 'external_link' => 'https://woocommerce.com/products/woocommerce-gateway-affirm', - 'is_visible' => array( + 'id' => 'affirm', + 'title' => __( 'Affirm', 'woocommerce' ), + 'content' => __( 'Affirm’s tailored Buy Now Pay Later programs remove price as a barrier, turning browsers into buyers, increasing average order value, and expanding your customer base.', 'woocommerce' ), + 'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/affirm.png', + 'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/affirm.png', + 'plugins' => array(), + 'external_link' => 'https://woocommerce.com/products/woocommerce-gateway-affirm', + 'is_visible' => array( self::get_rules_for_countries( array( 'US', 'CA' ) ), ), - 'category_other' => array(), + 'category_other' => array(), 'category_additional' => array( 'US', 'CA' ), ), );