Merge pull request #2219 from woocommerce/PCP-3088-fastlane-must-override-default-payment-method-for-guests

AXO: Make AXO the default payment method for guest customers (3088)
This commit is contained in:
Emili Castells 2024-05-13 17:43:41 +02:00 committed by GitHub
commit 97c1a95a8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 5 deletions

View file

@ -70,7 +70,7 @@ return array(
'type' => 'checkbox',
'label' => __( 'Enable Fastlane by PayPal', 'woocommerce-paypal-payments' )
. '<p class="description">'
. __( 'Help accelerate checkout for guests with PayPal\'s autofill solution.', 'woocommerce-paypal-payments' )
. __( 'Help accelerate the checkout process for guests with PayPal\'s autofill solution. When enabled, Fastlane is presented as the default payment method for guests.', 'woocommerce-paypal-payments' )
. '</p>',
'default' => 'yes',
'screens' => array( State::STATE_ONBOARDED ),

View file

@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Authentication\SdkClientToken;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Axo\Assets\AxoManager;
use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway;
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
@ -22,6 +23,7 @@ use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector;
/**
* Class AxoModule
@ -198,6 +200,19 @@ class AxoModule implements ModuleInterface {
2
);
// Set Axo as the default payment method on checkout for guest customers.
add_action(
'template_redirect',
function () use ( $c ) {
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
if ( $this->should_render_fastlane( $settings ) ) {
WC()->session->set( 'chosen_payment_method', AxoGateway::ID );
}
}
);
},
1
);
@ -259,11 +274,22 @@ class AxoModule implements ModuleInterface {
* @return bool
*/
private function hide_credit_card_when_using_fastlane( array $methods, Settings $settings ): bool {
return $this->should_render_fastlane( $settings ) && isset( $methods[ CreditCardGateway::ID ] );
}
/**
* Condition to evaluate if Fastlane should be rendered.
*
* Fastlane should only render on the classic checkout, when Fastlane is enabled in the settings and also only for guest customers.
*
* @param Settings $settings The settings.
* @return bool
*/
private function should_render_fastlane( Settings $settings): bool {
$is_axo_enabled = $settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' ) ?? false;
return ! is_admin()
&& is_user_logged_in() === false
&& isset( $methods[ CreditCardGateway::ID ] )
return ! is_user_logged_in()
&& CartCheckoutDetector::has_classic_checkout()
&& $is_axo_enabled;
}
}

View file

@ -159,7 +159,7 @@ class AxoGateway extends WC_Payment_Gateway {
$this->card_icons_axo = $card_icons_axo;
$this->method_title = __( 'Fastlane Debit & Credit Cards', 'woocommerce-paypal-payments' );
$this->method_description = __( 'PayPal Fastlane offers an accelerated checkout experience that recognizes guest shoppers and autofills their details so they can pay in seconds.', 'woocommerce-paypal-payments' );
$this->method_description = __( 'Fastlane accelerates the checkout experience for guest shoppers and autofills their details so they can pay in seconds. When enabled, Fastlane is presented as the default payment method for guests.', 'woocommerce-paypal-payments' );
$is_axo_enabled = $this->ppcp_settings->has( 'axo_enabled' ) && $this->ppcp_settings->get( 'axo_enabled' );
$this->update_option( 'enabled', $is_axo_enabled ? 'yes' : 'no' );