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' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
|
||||
$subscription_helper = $c->get( 'wc-subscriptions.helper' );
|
||||
assert( $subscription_helper instanceof SubscriptionHelper );
|
||||
|
||||
return ! is_user_logged_in()
|
||||
&& CartCheckoutDetector::has_classic_checkout()
|
||||
&& $dcc_configuration->use_fastlane()
|
||||
&& ! $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';
|
||||
|
||||
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;
|
||||
return <>
|
||||
<span dangerouslySetInnerHTML={{__html: config.title}}/>
|
||||
<PaymentMethodIcons
|
||||
icons={ config.card_icons }
|
||||
align="right"
|
||||
/>
|
||||
return (
|
||||
<>
|
||||
<span dangerouslySetInnerHTML={ { __html: config?.title } } />
|
||||
<PaymentMethodIcons icons={ config?.card_icons } align="right" />
|
||||
</>
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
registerPaymentMethod( {
|
||||
name: config.id,
|
||||
label: <Label config={config}/>,
|
||||
name: config?.id,
|
||||
label: <Label />,
|
||||
content: <CardFields config={ config } />,
|
||||
edit: <CardFields config={ config } />,
|
||||
ariaLabel: config.title,
|
||||
canMakePayment: () => {
|
||||
return true;
|
||||
ariaLabel: config?.title,
|
||||
canMakePayment: ( cartData ) => {
|
||||
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: {
|
||||
showSavedCards: true,
|
||||
features: config.supports,
|
||||
features: config?.supports,
|
||||
},
|
||||
} );
|
||||
|
|
|
@ -110,6 +110,7 @@ class AdvancedCardPaymentMethod extends AbstractPaymentMethodType {
|
|||
*/
|
||||
public function get_payment_method_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(
|
||||
'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\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
|
||||
|
||||
/**
|
||||
* Class BlocksModule
|
||||
|
@ -73,11 +74,8 @@ class BlocksModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
$settings = $c->get( 'wcgateway.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' ) );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
woocommerce_store_api_register_payment_requirements(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue