mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Axo: Add support for the card type limiting in the Fastlane classic checkout
This commit is contained in:
parent
42805c4fb5
commit
bbde7f7890
3 changed files with 53 additions and 11 deletions
|
@ -53,7 +53,7 @@ class AxoManager {
|
|||
cardView = null;
|
||||
|
||||
constructor( namespace, axoConfig, ppcpConfig ) {
|
||||
this.namespace = namespace;
|
||||
this.namespace = namespace;
|
||||
this.axoConfig = axoConfig;
|
||||
this.ppcpConfig = ppcpConfig;
|
||||
|
||||
|
@ -85,6 +85,8 @@ class AxoManager {
|
|||
},
|
||||
};
|
||||
|
||||
this.cardOptions = this.getCardOptions();
|
||||
|
||||
this.registerEventHandlers();
|
||||
|
||||
this.shippingView = new ShippingView(
|
||||
|
@ -661,6 +663,9 @@ class AxoManager {
|
|||
await this.fastlane.connect( {
|
||||
locale: this.locale,
|
||||
styles: this.styles,
|
||||
cardOptions: {
|
||||
allowedBrands: this.cardOptions,
|
||||
},
|
||||
} );
|
||||
|
||||
this.fastlane.setLocale( 'en_us' );
|
||||
|
@ -1245,6 +1250,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 ] === '' ) {
|
||||
|
|
|
@ -67,7 +67,8 @@ return array(
|
|||
$container->get( 'wcgateway.settings.status' ),
|
||||
$container->get( 'api.shop.currency.getter' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'wcgateway.url' )
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'axo.supported-country-card-type-matrix' )
|
||||
);
|
||||
},
|
||||
|
||||
|
|
|
@ -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;
|
||||
/**
|
||||
* AxoManager constructor.
|
||||
*
|
||||
|
@ -99,6 +104,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.
|
||||
*/
|
||||
public function __construct(
|
||||
string $module_url,
|
||||
|
@ -109,7 +115,8 @@ class AxoManager {
|
|||
SettingsStatus $settings_status,
|
||||
CurrencyGetter $currency,
|
||||
LoggerInterface $logger,
|
||||
string $wcgateway_module_url
|
||||
string $wcgateway_module_url,
|
||||
array $supported_country_card_type_matrix
|
||||
) {
|
||||
|
||||
$this->module_url = $module_url;
|
||||
|
@ -121,6 +128,7 @@ class AxoManager {
|
|||
$this->currency = $currency;
|
||||
$this->logger = $logger;
|
||||
$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' ),
|
||||
),
|
||||
),
|
||||
'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(
|
||||
'root' => array(
|
||||
'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' ) : '',
|
||||
'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