Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AXO: Disable Fastlane for subscription products (3295) #2358

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions modules/ppcp-axo/src/AxoModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector;
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener;

use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
/**
* Class AxoModule
*/
Expand Down Expand Up @@ -107,12 +107,9 @@ function ( $methods ) use ( $c ): array {
return $methods;
}

$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );

if ( apply_filters(
'woocommerce_paypal_payments_axo_hide_credit_card_gateway',
$this->hide_credit_card_when_using_fastlane( $methods, $settings )
$this->hide_credit_card_when_using_fastlane( $methods, $c )
) ) {
unset( $methods[ CreditCardGateway::ID ] );
}
Expand Down Expand Up @@ -160,13 +157,10 @@ function () use ( $c ) {
'wp_enqueue_scripts',
static function () use ( $c, $manager, $module ) {

$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );

$smart_button = $c->get( 'button.smart-button' );
assert( $smart_button instanceof SmartButtonInterface );

if ( $module->should_render_fastlane( $settings ) && $smart_button->should_load_ppcp_script() ) {
if ( $module->should_render_fastlane( $c ) && $smart_button->should_load_ppcp_script() ) {
$manager->enqueue();
}
}
Expand Down Expand Up @@ -243,10 +237,8 @@ function ( $rows, $renderer ): array {
add_action(
'template_redirect',
function () use ( $c ) {
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );

if ( $this->should_render_fastlane( $settings ) ) {
if ( $this->should_render_fastlane( $c ) ) {
WC()->session->set( 'chosen_payment_method', AxoGateway::ID );
}
}
Expand Down Expand Up @@ -320,31 +312,38 @@ public function getKey() {
/**
* Condition to evaluate if Credit Card gateway should be hidden.
*
* @param array $methods WC payment methods.
* @param Settings $settings The settings.
* @param array $methods WC payment methods.
* @param ContainerInterface $c The container.
* @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 ] );
private function hide_credit_card_when_using_fastlane( array $methods, ContainerInterface $c ): bool {
return $this->should_render_fastlane( $c ) && 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.
* @param ContainerInterface $c The container.
* @return bool
*/
private function should_render_fastlane( Settings $settings ): bool {
private function should_render_fastlane( ContainerInterface $c ): bool {
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );

$is_axo_enabled = $settings->has( 'axo_enabled' ) && $settings->get( 'axo_enabled' ) ?? false;
$is_dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ) ?? false;

$subscription_helper = $c->get( 'wc-subscriptions.helper' );
assert( $subscription_helper instanceof SubscriptionHelper );

return ! is_user_logged_in()
&& CartCheckoutDetector::has_classic_checkout()
&& $is_axo_enabled
&& $is_dcc_enabled
&& ! $this->is_excluded_endpoint();
&& ! $this->is_excluded_endpoint()
&& ! $subscription_helper->cart_contains_subscription();
}

/**
Expand All @@ -354,10 +353,8 @@ private function should_render_fastlane( Settings $settings ): bool {
* @return void
*/
private function add_checkout_loader_markup( ContainerInterface $c ): void {
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );

if ( $this->should_render_fastlane( $settings ) ) {
if ( $this->should_render_fastlane( $c ) ) {
add_action(
'woocommerce_checkout_before_customer_details',
function () {
Expand Down
Loading