From 91454b64d01e71073d63b000efd1be8a078a03cf Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Tue, 11 Feb 2025 10:11:01 +0100 Subject: [PATCH 1/2] Add online card payments conditionally --- .../Settings/Tabs/TabPaymentMethods.js | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabPaymentMethods.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabPaymentMethods.js index 48da574f0..6b8899ba9 100644 --- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabPaymentMethods.js +++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabPaymentMethods.js @@ -3,7 +3,7 @@ import { useCallback } from '@wordpress/element'; import SettingsCard from '../../../ReusableComponents/SettingsCard'; import { PaymentMethodsBlock } from '../../../ReusableComponents/SettingsBlocks'; -import { PaymentHooks } from '../../../../data'; +import { CommonHooks, PaymentHooks } from '../../../../data'; import { useActiveModal } from '../../../../data/common/hooks'; import Modal from '../Components/Payment/Modal'; @@ -45,6 +45,8 @@ const TabPaymentMethods = () => { [ changePaymentSettings, setActiveModal, setPersistent ] ); + const merchant = CommonHooks.useMerchant(); + return (
{ methods={ methods.paypal } onTriggerModal={ setActiveModal } /> - + { merchant.isBusinessSeller && ( + + ) } Date: Tue, 11 Feb 2025 14:20:12 +0100 Subject: [PATCH 2/2] Register card button gateway and hide items in payment methods screen conditionally --- .../Screens/Settings/Tabs/TabPaymentMethods.js | 5 +++-- modules/ppcp-settings/src/SettingsModule.php | 11 +++++++++-- modules/ppcp-wc-gateway/src/WCGatewayModule.php | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabPaymentMethods.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabPaymentMethods.js index 6b8899ba9..fe4cffe69 100644 --- a/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabPaymentMethods.js +++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings/Tabs/TabPaymentMethods.js @@ -3,7 +3,7 @@ import { useCallback } from '@wordpress/element'; import SettingsCard from '../../../ReusableComponents/SettingsCard'; import { PaymentMethodsBlock } from '../../../ReusableComponents/SettingsBlocks'; -import { CommonHooks, PaymentHooks } from '../../../../data'; +import { CommonHooks, OnboardingHooks, PaymentHooks } from '../../../../data'; import { useActiveModal } from '../../../../data/common/hooks'; import Modal from '../Components/Payment/Modal'; @@ -46,6 +46,7 @@ const TabPaymentMethods = () => { ); const merchant = CommonHooks.useMerchant(); + const { canUseCardPayments } = OnboardingHooks.useFlags(); return (
@@ -60,7 +61,7 @@ const TabPaymentMethods = () => { methods={ methods.paypal } onTriggerModal={ setActiveModal } /> - { merchant.isBusinessSeller && ( + { merchant.isBusinessSeller && canUseCardPayments && ( get( 'api.helpers.dccapplies' ); assert( $dcc_applies instanceof DCCApplies ); - // Unset BCDC if merchant is eligible for ACDC. - if ( $dcc_product_status->is_active() && ! $container->get( 'wcgateway.settings.allow_card_button_gateway' ) ) { + // Unset BCDC if merchant is eligible for ACDC and country is eligible for card fields. + $card_fields_eligible = $container->get( 'card-fields.eligible' ); + if ( $dcc_product_status->is_active() && $card_fields_eligible ) { unset( $payment_methods[ CardButtonGateway::ID ] ); } @@ -366,6 +367,9 @@ class SettingsModule implements ServiceModule, ExecutableModule { return $methods; } + $card_button_gateway = $container->get( 'wcgateway.card-button-gateway' ); + assert( $card_button_gateway instanceof CardButtonGateway ); + $googlepay_gateway = $container->get( 'googlepay.wc-gateway' ); assert( $googlepay_gateway instanceof WC_Payment_Gateway ); @@ -375,6 +379,7 @@ class SettingsModule implements ServiceModule, ExecutableModule { $axo_gateway = $container->get( 'axo.gateway' ); assert( $axo_gateway instanceof WC_Payment_Gateway ); + $methods[] = $card_button_gateway; $methods[] = $googlepay_gateway; $methods[] = $applepay_gateway; $methods[] = $axo_gateway; @@ -400,6 +405,8 @@ class SettingsModule implements ServiceModule, ExecutableModule { 2 ); + add_filter( 'woocommerce_paypal_payments_card_button_gateway_should_register_gateway', '__return_true' ); + add_filter( 'woocommerce_paypal_payments_credit_card_gateway_form_fields', function( array $form_fields ) { diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index f8b54f534..6606380b8 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -648,7 +648,7 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul $methods[] = $container->get( 'wcgateway.credit-card-gateway' ); } - if ( $paypal_gateway_enabled && $container->get( 'wcgateway.settings.allow_card_button_gateway' ) ) { + if ( $paypal_gateway_enabled && apply_filters( 'woocommerce_paypal_payments_card_button_gateway_should_register_gateway', $container->get( 'wcgateway.settings.allow_card_button_gateway' ) ) ) { $methods[] = $container->get( 'wcgateway.card-button-gateway' ); }