mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Merge pull request #2745 from woocommerce/PCP-3615-acdc-not-visible-on-checkut-when-fastlane-enabled-and-subscription-product-in-cart
Load ACDC for Classic and Block checkouts for subscription products (3615)
This commit is contained in:
commit
594c9eb63b
4 changed files with 55 additions and 32 deletions
|
@ -377,11 +377,15 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
||||||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||||
|
|
||||||
|
$subscription_helper = $c->get( 'wc-subscriptions.helper' );
|
||||||
|
assert( $subscription_helper instanceof SubscriptionHelper );
|
||||||
|
|
||||||
return ! is_user_logged_in()
|
return ! is_user_logged_in()
|
||||||
&& CartCheckoutDetector::has_classic_checkout()
|
&& CartCheckoutDetector::has_classic_checkout()
|
||||||
&& $dcc_configuration->use_fastlane()
|
&& $dcc_configuration->use_fastlane()
|
||||||
&& ! $this->is_excluded_endpoint()
|
&& ! $this->is_excluded_endpoint()
|
||||||
&& is_checkout();
|
&& is_checkout()
|
||||||
|
&& ! $subscription_helper->cart_contains_subscription();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,29 +2,49 @@ import {registerPaymentMethod} from '@woocommerce/blocks-registry';
|
||||||
import { CardFields } from './Components/card-fields';
|
import { CardFields } from './Components/card-fields';
|
||||||
|
|
||||||
const config = wc.wcSettings.getSetting( 'ppcp-credit-card-gateway_data' );
|
const config = wc.wcSettings.getSetting( 'ppcp-credit-card-gateway_data' );
|
||||||
|
const isUserLoggedIn = config?.scriptData?.is_user_logged_in;
|
||||||
|
const axoConfig = wc.wcSettings.getSetting( 'ppcp-axo-gateway_data' );
|
||||||
|
const axoEnabled = axoConfig !== false;
|
||||||
|
|
||||||
const Label = ({components, config}) => {
|
const Label = ( { components } ) => {
|
||||||
const { PaymentMethodIcons } = components;
|
const { PaymentMethodIcons } = components;
|
||||||
return <>
|
return (
|
||||||
<span dangerouslySetInnerHTML={{__html: config.title}}/>
|
<>
|
||||||
<PaymentMethodIcons
|
<span dangerouslySetInnerHTML={ { __html: config?.title } } />
|
||||||
icons={ config.card_icons }
|
<PaymentMethodIcons icons={ config?.card_icons } align="right" />
|
||||||
align="right"
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
}
|
);
|
||||||
|
};
|
||||||
|
|
||||||
registerPaymentMethod( {
|
registerPaymentMethod( {
|
||||||
name: config.id,
|
name: config?.id,
|
||||||
label: <Label config={config}/>,
|
label: <Label />,
|
||||||
content: <CardFields config={ config } />,
|
content: <CardFields config={ config } />,
|
||||||
edit: <CardFields config={ config } />,
|
edit: <CardFields config={ config } />,
|
||||||
ariaLabel: config.title,
|
ariaLabel: config?.title,
|
||||||
canMakePayment: () => {
|
canMakePayment: ( cartData ) => {
|
||||||
return true;
|
const cartItems = cartData?.cart?.cartItems || [];
|
||||||
|
|
||||||
|
// Check if any item in the cart is a subscription
|
||||||
|
const hasSubscription = cartItems.some(
|
||||||
|
( item ) =>
|
||||||
|
item?.type === 'subscription' ||
|
||||||
|
item?.type === 'variable-subscription' ||
|
||||||
|
cartData?.paymentRequirements?.includes( 'subscriptions' )
|
||||||
|
);
|
||||||
|
|
||||||
|
// Show payment method if:
|
||||||
|
// 1. Axo is disabled, OR
|
||||||
|
// 2. User is logged in, OR
|
||||||
|
// 3. Axo is enabled AND cart has subscriptions
|
||||||
|
return !! (
|
||||||
|
! axoEnabled ||
|
||||||
|
isUserLoggedIn ||
|
||||||
|
( axoEnabled && hasSubscription )
|
||||||
|
);
|
||||||
},
|
},
|
||||||
supports: {
|
supports: {
|
||||||
showSavedCards: true,
|
showSavedCards: true,
|
||||||
features: config.supports,
|
features: config?.supports,
|
||||||
},
|
},
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -110,6 +110,7 @@ class AdvancedCardPaymentMethod extends AbstractPaymentMethodType {
|
||||||
*/
|
*/
|
||||||
public function get_payment_method_data() {
|
public function get_payment_method_data() {
|
||||||
$script_data = $this->smart_button_instance()->script_data();
|
$script_data = $this->smart_button_instance()->script_data();
|
||||||
|
$script_data = array_merge( $script_data, array( 'is_user_logged_in' => is_user_logged_in() ) );
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'id' => $this->name,
|
'id' => $this->name,
|
||||||
|
|
|
@ -18,6 +18,7 @@ use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameI
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
|
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BlocksModule
|
* Class BlocksModule
|
||||||
|
@ -73,11 +74,8 @@ class BlocksModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
||||||
$settings = $c->get( 'wcgateway.settings' );
|
$settings = $c->get( 'wcgateway.settings' );
|
||||||
assert( $settings instanceof Settings );
|
assert( $settings instanceof Settings );
|
||||||
|
|
||||||
// Include ACDC in the Block Checkout only in case Axo doesn't exist or is not available or the user is logged in.
|
|
||||||
if ( ( $settings->has( 'axo_enabled' ) && ! $settings->get( 'axo_enabled' ) ) || is_user_logged_in() ) {
|
|
||||||
$payment_method_registry->register( $c->get( 'blocks.advanced-card-method' ) );
|
$payment_method_registry->register( $c->get( 'blocks.advanced-card-method' ) );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
woocommerce_store_api_register_payment_requirements(
|
woocommerce_store_api_register_payment_requirements(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue