mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
Load ACDC for Classic and Block checkouts for subscription products
This commit is contained in:
parent
e664052b62
commit
4a688fb351
4 changed files with 55 additions and 32 deletions
|
@ -1,30 +1,50 @@
|
|||
import {registerPaymentMethod} from '@woocommerce/blocks-registry';
|
||||
import {CardFields} from './Components/card-fields';
|
||||
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
||||
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 {PaymentMethodIcons} = components;
|
||||
return <>
|
||||
<span dangerouslySetInnerHTML={{__html: config.title}}/>
|
||||
<PaymentMethodIcons
|
||||
icons={ config.card_icons }
|
||||
align="right"
|
||||
/>
|
||||
</>
|
||||
}
|
||||
const Label = ( { components } ) => {
|
||||
const { PaymentMethodIcons } = components;
|
||||
return (
|
||||
<>
|
||||
<span dangerouslySetInnerHTML={ { __html: config?.title } } />
|
||||
<PaymentMethodIcons icons={ config?.card_icons } align="right" />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
registerPaymentMethod({
|
||||
name: config.id,
|
||||
label: <Label config={config}/>,
|
||||
content: <CardFields config={config}/>,
|
||||
edit: <CardFields config={config}/>,
|
||||
ariaLabel: config.title,
|
||||
canMakePayment: () => {
|
||||
return true;
|
||||
},
|
||||
supports: {
|
||||
showSavedCards: true,
|
||||
features: config.supports,
|
||||
},
|
||||
});
|
||||
registerPaymentMethod( {
|
||||
name: config?.id,
|
||||
label: <Label />,
|
||||
content: <CardFields config={ config } />,
|
||||
edit: <CardFields config={ config } />,
|
||||
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,
|
||||
},
|
||||
} );
|
||||
|
|
|
@ -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,10 +74,7 @@ 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' ) );
|
||||
}
|
||||
$payment_method_registry->register( $c->get( 'blocks.advanced-card-method' ) );
|
||||
}
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue