mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
Merge pull request #2704 from woocommerce/PCP-3783-fastlane-allow-merchants-to-disable-specific-card-types
Axo: Add support for card icons in the Block Checkout and add card type limiting for both block and classic checkouts (3783)
This commit is contained in:
commit
c7dfe3293b
19 changed files with 240 additions and 144 deletions
|
@ -85,6 +85,8 @@ class AxoManager {
|
|||
},
|
||||
};
|
||||
|
||||
this.cardOptions = this.getCardOptions();
|
||||
|
||||
this.enabledShippingLocations =
|
||||
this.axoConfig.enabled_shipping_locations;
|
||||
|
||||
|
@ -664,6 +666,9 @@ class AxoManager {
|
|||
await this.fastlane.connect( {
|
||||
locale: this.locale,
|
||||
styles: this.styles,
|
||||
cardOptions: {
|
||||
allowedBrands: this.cardOptions,
|
||||
},
|
||||
shippingAddressOptions: {
|
||||
allowedLocations: this.enabledShippingLocations,
|
||||
},
|
||||
|
@ -1251,6 +1256,31 @@ class AxoManager {
|
|||
return this.axoConfig?.widgets?.email === 'use_widget';
|
||||
}
|
||||
|
||||
getCardOptions() {
|
||||
const DEFAULT_ALLOWED_CARDS = [
|
||||
'VISA',
|
||||
'MASTERCARD',
|
||||
'AMEX',
|
||||
'DISCOVER',
|
||||
];
|
||||
const merchantCountry = this.axoConfig.merchant_country || 'US';
|
||||
|
||||
const allowedCards = new Set(
|
||||
this.axoConfig.allowed_cards?.[ merchantCountry ] ||
|
||||
DEFAULT_ALLOWED_CARDS
|
||||
);
|
||||
|
||||
const disabledCards = new Set(
|
||||
( this.axoConfig.disable_cards || [] ).map( ( card ) =>
|
||||
card.toUpperCase()
|
||||
)
|
||||
);
|
||||
|
||||
return [ ...allowedCards ].filter(
|
||||
( card ) => ! disabledCards.has( card )
|
||||
);
|
||||
}
|
||||
|
||||
deleteKeysWithEmptyString = ( obj ) => {
|
||||
for ( const key of Object.keys( obj ) ) {
|
||||
if ( obj[ key ] === '' ) {
|
||||
|
|
|
@ -68,6 +68,7 @@ return array(
|
|||
$container->get( 'api.shop.currency.getter' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'axo.supported-country-card-type-matrix' ),
|
||||
$container->get( 'axo.shipping-wc-enabled-locations' )
|
||||
);
|
||||
},
|
||||
|
@ -111,7 +112,31 @@ return array(
|
|||
)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* The matrix which countries and card type combinations can be used for AXO.
|
||||
*/
|
||||
'axo.supported-country-card-type-matrix' => static function ( ContainerInterface $container ) : array {
|
||||
/**
|
||||
* Returns which countries and card type combinations can be used for AXO.
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_paypal_payments_axo_supported_country_card_type_matrix',
|
||||
array(
|
||||
'US' => array(
|
||||
'VISA',
|
||||
'MASTERCARD',
|
||||
'AMEX',
|
||||
'DISCOVER',
|
||||
),
|
||||
'CA' => array(
|
||||
'VISA',
|
||||
'MASTERCARD',
|
||||
'AMEX',
|
||||
'DISCOVER',
|
||||
),
|
||||
)
|
||||
);
|
||||
},
|
||||
'axo.settings-conflict-notice' => static function ( ContainerInterface $container ) : string {
|
||||
$settings_notice_generator = $container->get( 'axo.helpers.settings-notice-generator' );
|
||||
assert( $settings_notice_generator instanceof SettingsNoticeGenerator );
|
||||
|
|
|
@ -29,28 +29,28 @@ class AxoManager {
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $module_url;
|
||||
private string $module_url;
|
||||
|
||||
/**
|
||||
* The assets version.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $version;
|
||||
private string $version;
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
* @var Settings
|
||||
*/
|
||||
private $settings;
|
||||
private Settings $settings;
|
||||
|
||||
/**
|
||||
* The environment object.
|
||||
*
|
||||
* @var Environment
|
||||
*/
|
||||
private $environment;
|
||||
private Environment $environment;
|
||||
|
||||
/**
|
||||
* The Settings status helper.
|
||||
|
@ -71,22 +71,27 @@ class AxoManager {
|
|||
*
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* Session handler.
|
||||
*
|
||||
* @var SessionHandler
|
||||
*/
|
||||
private $session_handler;
|
||||
private SessionHandler $session_handler;
|
||||
|
||||
/**
|
||||
* The WcGateway module URL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $wcgateway_module_url;
|
||||
|
||||
private string $wcgateway_module_url;
|
||||
/**
|
||||
* The supported country card type matrix.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private array $supported_country_card_type_matrix;
|
||||
/**
|
||||
* The list of WooCommerce enabled shipping locations.
|
||||
*
|
||||
|
@ -106,6 +111,7 @@ class AxoManager {
|
|||
* @param CurrencyGetter $currency The getter of the 3-letter currency code of the shop.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param string $wcgateway_module_url The WcGateway module URL.
|
||||
* @param array $supported_country_card_type_matrix The supported country card type matrix for Axo.
|
||||
* @param array $enabled_shipping_locations The list of WooCommerce enabled shipping locations.
|
||||
*/
|
||||
public function __construct(
|
||||
|
@ -118,19 +124,21 @@ class AxoManager {
|
|||
CurrencyGetter $currency,
|
||||
LoggerInterface $logger,
|
||||
string $wcgateway_module_url,
|
||||
array $supported_country_card_type_matrix,
|
||||
array $enabled_shipping_locations
|
||||
) {
|
||||
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->settings = $settings;
|
||||
$this->environment = $environment;
|
||||
$this->settings_status = $settings_status;
|
||||
$this->currency = $currency;
|
||||
$this->logger = $logger;
|
||||
$this->wcgateway_module_url = $wcgateway_module_url;
|
||||
$this->enabled_shipping_locations = $enabled_shipping_locations;
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->settings = $settings;
|
||||
$this->environment = $environment;
|
||||
$this->settings_status = $settings_status;
|
||||
$this->currency = $currency;
|
||||
$this->logger = $logger;
|
||||
$this->wcgateway_module_url = $wcgateway_module_url;
|
||||
$this->supported_country_card_type_matrix = $supported_country_card_type_matrix;
|
||||
$this->enabled_shipping_locations = $enabled_shipping_locations;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,6 +201,8 @@ class AxoManager {
|
|||
'value' => WC()->cart->get_total( 'numeric' ),
|
||||
),
|
||||
),
|
||||
'allowed_cards' => $this->supported_country_card_type_matrix,
|
||||
'disable_cards' => $this->settings->has( 'disable_cards' ) ? (array) $this->settings->get( 'disable_cards' ) : array(),
|
||||
'enabled_shipping_locations' => $this->enabled_shipping_locations,
|
||||
'style_options' => array(
|
||||
'root' => array(
|
||||
|
@ -231,6 +241,7 @@ class AxoManager {
|
|||
'logging_enabled' => $this->settings->has( 'logging_enabled' ) ? $this->settings->get( 'logging_enabled' ) : '',
|
||||
'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
||||
'billing_email_button_text' => __( 'Continue', 'woocommerce-paypal-payments' ),
|
||||
'merchant_country' => WC()->countries->get_base_country(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue