mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge pull request #3021 from woocommerce/PCP-4077-conditionally-display-payment-methods
Conditionally display payment methods (4077)
This commit is contained in:
commit
f47487d8ff
4 changed files with 89 additions and 6 deletions
|
@ -166,12 +166,13 @@ export const usePaymentMethodsModal = () => {
|
|||
|
||||
export const usePaymentMethodsPayPalCheckout = () => {
|
||||
const { paypal, venmo, payLater, creditCard } = useHooks();
|
||||
|
||||
const paymentMethodsPayPalCheckout = [
|
||||
paypal,
|
||||
venmo,
|
||||
payLater,
|
||||
creditCard,
|
||||
];
|
||||
].filter( ( item ) => Object.keys( item ).length !== 0 );
|
||||
|
||||
return {
|
||||
paymentMethodsPayPalCheckout,
|
||||
|
@ -185,7 +186,7 @@ export const usePaymentMethodsOnlineCardPayments = () => {
|
|||
fastlane,
|
||||
applePay,
|
||||
googlePay,
|
||||
];
|
||||
].filter( ( item ) => Object.keys( item ).length !== 0 );
|
||||
|
||||
return {
|
||||
paymentMethodsOnlineCardPayments,
|
||||
|
@ -217,7 +218,7 @@ export const usePaymentMethodsAlternative = () => {
|
|||
multibanco,
|
||||
pui,
|
||||
oxxo,
|
||||
];
|
||||
].filter( ( item ) => Object.keys( item ).length !== 0 );
|
||||
|
||||
return {
|
||||
paymentMethodsAlternative,
|
||||
|
|
|
@ -687,7 +687,7 @@ class PaymentRestEndpoint extends RestEndpoint {
|
|||
$gateway_settings['fastlaneCardholderName'] = $this->settings->get_fastlane_cardholder_name();
|
||||
$gateway_settings['fastlaneDisplayWatermark'] = $this->settings->get_fastlane_display_watermark();
|
||||
|
||||
return $this->return_success( $gateway_settings );
|
||||
return $this->return_success( apply_filters( 'woocommerce_paypal_payments_payment_methods', $gateway_settings ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,17 @@ declare( strict_types = 1 );
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Settings;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\Applepay\Assets\AppleProductStatus;
|
||||
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
|
||||
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\BancontactGateway;
|
||||
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\BlikGateway;
|
||||
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\EPSGateway;
|
||||
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\IDealGateway;
|
||||
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\MultibancoGateway;
|
||||
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\MyBankGateway;
|
||||
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\P24Gateway;
|
||||
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\TrustlyGateway;
|
||||
use WooCommerce\PayPalCommerce\Settings\Ajax\SwitchSettingsUiEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\RestEndpoint;
|
||||
|
@ -17,6 +28,11 @@ use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule
|
|||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO\OXXO;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayUponInvoice\PayUponInvoiceGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCProductStatus;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
|
@ -263,6 +279,69 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
}
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'woocommerce_paypal_payments_payment_methods',
|
||||
function( array $payment_methods ) use ( $container ) : array {
|
||||
$all_payment_methods = $payment_methods;
|
||||
|
||||
$dcc_product_status = $container->get( 'wcgateway.helper.dcc-product-status' );
|
||||
assert( $dcc_product_status instanceof DCCProductStatus );
|
||||
|
||||
$googlepay_product_status = $container->get( 'googlepay.helpers.apm-product-status' );
|
||||
assert( $googlepay_product_status instanceof ApmProductStatus );
|
||||
|
||||
$applepay_product_status = $container->get( 'applepay.apple-product-status' );
|
||||
assert( $applepay_product_status instanceof AppleProductStatus );
|
||||
|
||||
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
||||
assert( $dcc_applies instanceof DCCApplies );
|
||||
|
||||
// Unset BCDC if merchant is eligible for ACDC.
|
||||
if ( $dcc_product_status->dcc_is_active() && ! $container->get( 'wcgateway.settings.allow_card_button_gateway' ) ) {
|
||||
unset( $payment_methods[ CardButtonGateway::ID ] );
|
||||
}
|
||||
|
||||
// Unset Venmo when store location is not United States.
|
||||
if ( $container->get( 'api.shop.country' ) !== 'US' ) {
|
||||
unset( $payment_methods['venmo'] );
|
||||
}
|
||||
|
||||
// Unset if not eligible for Google Pay.
|
||||
if ( ! $googlepay_product_status->is_active() ) {
|
||||
unset( $payment_methods['ppcp-googlepay'] );
|
||||
}
|
||||
|
||||
// Unset if not eligible for Apple Pay.
|
||||
if ( ! $applepay_product_status->is_active() ) {
|
||||
unset( $payment_methods['ppcp-applepay'] );
|
||||
}
|
||||
|
||||
// Unset Fastlane if store location is not United States or merchant is not eligible for ACDC.
|
||||
if ( $container->get( 'api.shop.country' ) !== 'US' || ! $dcc_product_status->dcc_is_active() ) {
|
||||
unset( $payment_methods['ppcp-axo-gateway'] );
|
||||
}
|
||||
|
||||
// For non-ACDC regions unset ACDC, local APMs and set BCDC.
|
||||
if ( ! $dcc_applies ) {
|
||||
unset( $payment_methods[ CreditCardGateway::ID ] );
|
||||
unset( $payment_methods[ BancontactGateway::ID ] );
|
||||
unset( $payment_methods[ BlikGateway::ID ] );
|
||||
unset( $payment_methods[ EPSGateway::ID ] );
|
||||
unset( $payment_methods[ IDealGateway::ID ] );
|
||||
unset( $payment_methods[ MyBankGateway::ID ] );
|
||||
unset( $payment_methods[ P24Gateway::ID ] );
|
||||
unset( $payment_methods[ TrustlyGateway::ID ] );
|
||||
unset( $payment_methods[ MultibancoGateway::ID ] );
|
||||
unset( $payment_methods[ PayUponInvoiceGateway::ID ] );
|
||||
unset( $payment_methods[ OXXO::ID ] );
|
||||
|
||||
$payment_methods[ CardButtonGateway::ID ] = $all_payment_methods[ CardButtonGateway::ID ];
|
||||
}
|
||||
|
||||
return $payment_methods;
|
||||
}
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1659,9 +1659,12 @@ return array(
|
|||
$settings = $container->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof ContainerInterface );
|
||||
|
||||
return $settings->has( 'allow_card_button_gateway' ) ?
|
||||
return apply_filters(
|
||||
'woocommerce_paypal_payments_enable_standard_card_button_gateway_settings',
|
||||
$settings->has( 'allow_card_button_gateway' ) ?
|
||||
(bool) $settings->get( 'allow_card_button_gateway' ) :
|
||||
$container->get( 'wcgateway.settings.allow_card_button_gateway.default' );
|
||||
$container->get( 'wcgateway.settings.allow_card_button_gateway.default' )
|
||||
);
|
||||
},
|
||||
'wcgateway.settings.has_enabled_separate_button_gateways' => static function ( ContainerInterface $container ): bool {
|
||||
return (bool) $container->get( 'wcgateway.settings.allow_card_button_gateway' );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue