Axo: Add support for the card type limiting in the Fastlane classic checkout

This commit is contained in:
Daniel Dudzic 2024-10-16 14:01:11 +02:00
parent 42805c4fb5
commit bbde7f7890
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
3 changed files with 53 additions and 11 deletions

View file

@ -53,7 +53,7 @@ class AxoManager {
cardView = null; cardView = null;
constructor( namespace, axoConfig, ppcpConfig ) { constructor( namespace, axoConfig, ppcpConfig ) {
this.namespace = namespace; this.namespace = namespace;
this.axoConfig = axoConfig; this.axoConfig = axoConfig;
this.ppcpConfig = ppcpConfig; this.ppcpConfig = ppcpConfig;
@ -85,6 +85,8 @@ class AxoManager {
}, },
}; };
this.cardOptions = this.getCardOptions();
this.registerEventHandlers(); this.registerEventHandlers();
this.shippingView = new ShippingView( this.shippingView = new ShippingView(
@ -661,6 +663,9 @@ class AxoManager {
await this.fastlane.connect( { await this.fastlane.connect( {
locale: this.locale, locale: this.locale,
styles: this.styles, styles: this.styles,
cardOptions: {
allowedBrands: this.cardOptions,
},
} ); } );
this.fastlane.setLocale( 'en_us' ); this.fastlane.setLocale( 'en_us' );
@ -1245,6 +1250,31 @@ class AxoManager {
return this.axoConfig?.widgets?.email === 'use_widget'; 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 ) => { deleteKeysWithEmptyString = ( obj ) => {
for ( const key of Object.keys( obj ) ) { for ( const key of Object.keys( obj ) ) {
if ( obj[ key ] === '' ) { if ( obj[ key ] === '' ) {

View file

@ -67,7 +67,8 @@ return array(
$container->get( 'wcgateway.settings.status' ), $container->get( 'wcgateway.settings.status' ),
$container->get( 'api.shop.currency.getter' ), $container->get( 'api.shop.currency.getter' ),
$container->get( 'woocommerce.logger.woocommerce' ), $container->get( 'woocommerce.logger.woocommerce' ),
$container->get( 'wcgateway.url' ) $container->get( 'wcgateway.url' ),
$container->get( 'axo.supported-country-card-type-matrix' )
); );
}, },

View file

@ -29,28 +29,28 @@ class AxoManager {
* *
* @var string * @var string
*/ */
private $module_url; private string $module_url;
/** /**
* The assets version. * The assets version.
* *
* @var string * @var string
*/ */
private $version; private string $version;
/** /**
* The settings. * The settings.
* *
* @var Settings * @var Settings
*/ */
private $settings; private Settings $settings;
/** /**
* The environment object. * The environment object.
* *
* @var Environment * @var Environment
*/ */
private $environment; private Environment $environment;
/** /**
* The Settings status helper. * The Settings status helper.
@ -71,22 +71,27 @@ class AxoManager {
* *
* @var LoggerInterface * @var LoggerInterface
*/ */
private $logger; private LoggerInterface $logger;
/** /**
* Session handler. * Session handler.
* *
* @var SessionHandler * @var SessionHandler
*/ */
private $session_handler; private SessionHandler $session_handler;
/** /**
* The WcGateway module URL. * The WcGateway module URL.
* *
* @var string * @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;
/** /**
* AxoManager constructor. * AxoManager constructor.
* *
@ -99,6 +104,7 @@ class AxoManager {
* @param CurrencyGetter $currency The getter of the 3-letter currency code of the shop. * @param CurrencyGetter $currency The getter of the 3-letter currency code of the shop.
* @param LoggerInterface $logger The logger. * @param LoggerInterface $logger The logger.
* @param string $wcgateway_module_url The WcGateway module URL. * @param string $wcgateway_module_url The WcGateway module URL.
* @param array $supported_country_card_type_matrix The supported country card type matrix for Axo.
*/ */
public function __construct( public function __construct(
string $module_url, string $module_url,
@ -109,7 +115,8 @@ class AxoManager {
SettingsStatus $settings_status, SettingsStatus $settings_status,
CurrencyGetter $currency, CurrencyGetter $currency,
LoggerInterface $logger, LoggerInterface $logger,
string $wcgateway_module_url string $wcgateway_module_url,
array $supported_country_card_type_matrix
) { ) {
$this->module_url = $module_url; $this->module_url = $module_url;
@ -121,6 +128,7 @@ class AxoManager {
$this->currency = $currency; $this->currency = $currency;
$this->logger = $logger; $this->logger = $logger;
$this->wcgateway_module_url = $wcgateway_module_url; $this->wcgateway_module_url = $wcgateway_module_url;
$this->supported_country_card_type_matrix = $supported_country_card_type_matrix;
} }
/** /**
@ -183,6 +191,8 @@ class AxoManager {
'value' => WC()->cart->get_total( 'numeric' ), '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(),
'style_options' => array( 'style_options' => array(
'root' => array( 'root' => array(
'backgroundColor' => $this->settings->has( 'axo_style_root_bg_color' ) ? $this->settings->get( 'axo_style_root_bg_color' ) : '', 'backgroundColor' => $this->settings->has( 'axo_style_root_bg_color' ) ? $this->settings->get( 'axo_style_root_bg_color' ) : '',
@ -220,6 +230,7 @@ class AxoManager {
'logging_enabled' => $this->settings->has( 'logging_enabled' ) ? $this->settings->get( 'logging_enabled' ) : '', 'logging_enabled' => $this->settings->has( 'logging_enabled' ) ? $this->settings->get( 'logging_enabled' ) : '',
'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, 'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
'billing_email_button_text' => __( 'Continue', 'woocommerce-paypal-payments' ), 'billing_email_button_text' => __( 'Continue', 'woocommerce-paypal-payments' ),
'merchant_country' => WC()->countries->get_base_country(),
); );
} }