🔀 Merge branch 'trunk'

# Conflicts:
#	modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js
#	modules/ppcp-button/resources/js/modules/Helper/CheckoutMethodState.js
This commit is contained in:
Philipp Stracker 2024-07-24 18:42:57 +02:00
commit 9f39a58f07
No known key found for this signature in database
26 changed files with 662 additions and 110 deletions

View file

@ -1,6 +1,6 @@
*** Changelog *** *** Changelog ***
= 2.8.2 - xxxx-xx-xx = = 2.8.2 - 2024-07-22 =
* Fix - Sold individually checkbox automatically disabled after adding product to the cart more than once #2415 * Fix - Sold individually checkbox automatically disabled after adding product to the cart more than once #2415
* Fix - All products "Sold individually" when PayPal Subscriptions selected as Subscriptions Mode #2400 * Fix - All products "Sold individually" when PayPal Subscriptions selected as Subscriptions Mode #2400
* Fix - W3 Total Cache: Remove type from file parameter as sometimes null gets passed causing errors #2403 * Fix - W3 Total Cache: Remove type from file parameter as sometimes null gets passed causing errors #2403

View file

@ -52,7 +52,7 @@ class AdvancedCardPaymentMethod extends AbstractPaymentMethodType {
* *
* @var Settings * @var Settings
*/ */
protected $settings; protected $plugin_settings;
/** /**
* AdvancedCardPaymentMethod constructor. * AdvancedCardPaymentMethod constructor.
@ -70,12 +70,12 @@ class AdvancedCardPaymentMethod extends AbstractPaymentMethodType {
$smart_button, $smart_button,
Settings $settings Settings $settings
) { ) {
$this->name = CreditCardGateway::ID; $this->name = CreditCardGateway::ID;
$this->module_url = $module_url; $this->module_url = $module_url;
$this->version = $version; $this->version = $version;
$this->gateway = $gateway; $this->gateway = $gateway;
$this->smart_button = $smart_button; $this->smart_button = $smart_button;
$this->settings = $settings; $this->plugin_settings = $settings;
} }
/** /**
@ -118,8 +118,8 @@ class AdvancedCardPaymentMethod extends AbstractPaymentMethodType {
'scriptData' => $script_data, 'scriptData' => $script_data,
'supports' => $this->gateway->supports, 'supports' => $this->gateway->supports,
'save_card_text' => esc_html__( 'Save your card', 'woocommerce-paypal-payments' ), 'save_card_text' => esc_html__( 'Save your card', 'woocommerce-paypal-payments' ),
'is_vaulting_enabled' => $this->settings->has( 'vault_enabled_dcc' ) && $this->settings->get( 'vault_enabled_dcc' ), 'is_vaulting_enabled' => $this->plugin_settings->has( 'vault_enabled_dcc' ) && $this->plugin_settings->get( 'vault_enabled_dcc' ),
'card_icons' => $this->settings->has( 'card_icons' ) ? (array) $this->settings->get( 'card_icons' ) : array(), 'card_icons' => $this->plugin_settings->has( 'card_icons' ) ? (array) $this->plugin_settings->get( 'card_icons' ) : array(),
); );
} }

View file

@ -183,6 +183,8 @@ class CheckoutBootstap {
const isSeparateButtonGateway = [ PaymentMethods.CARD_BUTTON ].includes( const isSeparateButtonGateway = [ PaymentMethods.CARD_BUTTON ].includes(
currentPaymentMethod currentPaymentMethod
); );
const isGooglePayMethod =
currentPaymentMethod === PaymentMethods.GOOGLEPAY;
const isApplePayMethod = const isApplePayMethod =
currentPaymentMethod === PaymentMethods.APPLEPAY; currentPaymentMethod === PaymentMethods.APPLEPAY;
const isSavedCard = isCard && isSavedCardSelected(); const isSavedCard = isCard && isSavedCardSelected();
@ -190,6 +192,7 @@ class CheckoutBootstap {
! isPaypal && ! isPaypal &&
! isCard && ! isCard &&
! isSeparateButtonGateway && ! isSeparateButtonGateway &&
! isGooglePayMethod &&
! isApplePayMethod; ! isApplePayMethod;
const isFreeTrial = PayPalCommerceGateway.is_free_trial_cart; const isFreeTrial = PayPalCommerceGateway.is_free_trial_cart;
const hasVaultedPaypal = const hasVaultedPaypal =
@ -234,6 +237,7 @@ class CheckoutBootstap {
} }
} }
setVisible( '#ppc-button-ppcp-googlepay', isGooglePayMethod );
setVisible( '#ppc-button-ppcp-applepay', isApplePayMethod ); setVisible( '#ppc-button-ppcp-applepay', isApplePayMethod );
jQuery( document.body ).trigger( 'ppcp_checkout_rendered' ); jQuery( document.body ).trigger( 'ppcp_checkout_rendered' );

View file

@ -7,6 +7,7 @@ import { getPlanIdFromVariation } from '../Helper/Subscriptions';
import SimulateCart from '../Helper/SimulateCart'; import SimulateCart from '../Helper/SimulateCart';
import { strRemoveWord, strAddWord, throttle } from '../Helper/Utils'; import { strRemoveWord, strAddWord, throttle } from '../Helper/Utils';
import merge from 'deepmerge'; import merge from 'deepmerge';
import { debounce } from '../../../../../ppcp-blocks/resources/js/Helper/debounce';
class SingleProductBootstap { class SingleProductBootstap {
constructor( gateway, renderer, errorHandler ) { constructor( gateway, renderer, errorHandler ) {
@ -20,9 +21,13 @@ class SingleProductBootstap {
// Prevent simulate cart being called too many times in a burst. // Prevent simulate cart being called too many times in a burst.
this.simulateCartThrottled = throttle( this.simulateCartThrottled = throttle(
this.simulateCart, this.simulateCart.bind( this ),
this.gateway.simulate_cart.throttling || 5000 this.gateway.simulate_cart.throttling || 5000
); );
this.debouncedHandleChange = debounce(
this.handleChange.bind( this ),
100
);
this.renderer.onButtonsInit( this.renderer.onButtonsInit(
this.gateway.button.wrapper, this.gateway.button.wrapper,
@ -74,7 +79,7 @@ class SingleProductBootstap {
} }
jQuery( document ).on( 'change', this.formSelector, () => { jQuery( document ).on( 'change', this.formSelector, () => {
this.handleChange(); this.debouncedHandleChange();
} ); } );
this.mutationObserver.observe( form, { this.mutationObserver.observe( form, {
childList: true, childList: true,

View file

@ -3,6 +3,7 @@ export const PaymentMethods = {
CARDS: 'ppcp-credit-card-gateway', CARDS: 'ppcp-credit-card-gateway',
OXXO: 'ppcp-oxxo-gateway', OXXO: 'ppcp-oxxo-gateway',
CARD_BUTTON: 'ppcp-card-button-gateway', CARD_BUTTON: 'ppcp-card-button-gateway',
GOOGLEPAY: 'ppcp-googlepay',
APPLEPAY: 'ppcp-applepay', APPLEPAY: 'ppcp-applepay',
}; };

View file

@ -14,8 +14,10 @@ use WC_Cart;
use WC_Order; use WC_Order;
use WC_Order_Item_Product; use WC_Order_Item_Product;
use WC_Order_Item_Shipping; use WC_Order_Item_Shipping;
use WC_Product;
use WC_Subscription; use WC_Subscription;
use WC_Subscriptions_Product; use WC_Subscriptions_Product;
use WC_Tax;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order; use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer; use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Shipping; use WooCommerce\PayPalCommerce\ApiClient\Entity\Shipping;
@ -106,6 +108,7 @@ class WooCommerceOrderCreator {
* @param Payer|null $payer The payer. * @param Payer|null $payer The payer.
* @param Shipping|null $shipping The shipping. * @param Shipping|null $shipping The shipping.
* @return void * @return void
* @psalm-suppress InvalidScalarArgument
*/ */
protected function configure_line_items( WC_Order $wc_order, WC_Cart $wc_cart, ?Payer $payer, ?Shipping $shipping ): void { protected function configure_line_items( WC_Order $wc_order, WC_Cart $wc_cart, ?Payer $payer, ?Shipping $shipping ): void {
$cart_contents = $wc_cart->get_cart(); $cart_contents = $wc_cart->get_cart();
@ -130,18 +133,21 @@ class WooCommerceOrderCreator {
return; return;
} }
$total = $product->get_price() * $quantity; $subtotal = wc_get_price_excluding_tax( $product, array( 'qty' => $quantity ) );
$subtotal = apply_filters( 'woocommerce_paypal_payments_shipping_callback_cart_line_item_total', $subtotal, $cart_item );
$item->set_name( $product->get_name() ); $item->set_name( $product->get_name() );
$item->set_subtotal( $total ); $item->set_subtotal( $subtotal );
$item->set_total( $total ); $item->set_total( $subtotal );
$this->configure_taxes( $product, $item, $subtotal );
$product_id = $product->get_id(); $product_id = $product->get_id();
if ( $this->is_subscription( $product_id ) ) { if ( $this->is_subscription( $product_id ) ) {
$subscription = $this->create_subscription( $wc_order, $product_id ); $subscription = $this->create_subscription( $wc_order, $product_id );
$sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $product ); $sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee( $product );
$subscription_total = $total + $sign_up_fee; $subscription_total = (float) $subtotal + (float) $sign_up_fee;
$item->set_subtotal( $subscription_total ); $item->set_subtotal( $subscription_total );
$item->set_total( $subscription_total ); $item->set_total( $subscription_total );
@ -282,6 +288,30 @@ class WooCommerceOrderCreator {
} }
} }
/**
* Configures the taxes.
*
* @param WC_Product $product The Product.
* @param WC_Order_Item_Product $item The line item.
* @param float|string $subtotal The subtotal.
* @return void
* @psalm-suppress InvalidScalarArgument
*/
protected function configure_taxes( WC_Product $product, WC_Order_Item_Product $item, $subtotal ): void {
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() );
$taxes = WC_Tax::calc_tax( $subtotal, $tax_rates, true );
$item->set_tax_class( $product->get_tax_class() );
$item->set_total_tax( (float) array_sum( $taxes ) );
foreach ( $taxes as $tax_rate_id => $tax_amount ) {
if ( $tax_amount > 0 ) {
$item->add_meta_data( 'tax_rate_id', $tax_rate_id, true );
$item->add_meta_data( 'tax_amount', $tax_amount, true );
}
}
}
/** /**
* Checks if the product with given ID is WC subscription. * Checks if the product with given ID is WC subscription.
* *

View file

@ -83,6 +83,9 @@ return array(
'compat.wc_shipping_tax.is_supported_plugin_version_active' => function (): bool { 'compat.wc_shipping_tax.is_supported_plugin_version_active' => function (): bool {
return class_exists( 'WC_Connect_Loader' ); return class_exists( 'WC_Connect_Loader' );
}, },
'compat.nyp.is_supported_plugin_version_active' => function (): bool {
return function_exists( 'wc_nyp_init' );
},
'compat.module.url' => static function ( ContainerInterface $container ): string { 'compat.module.url' => static function ( ContainerInterface $container ): string {
/** /**

View file

@ -56,6 +56,11 @@ class CompatModule implements ModuleInterface {
$this->fix_page_builders(); $this->fix_page_builders();
$this->exclude_cache_plugins_js_minification( $c ); $this->exclude_cache_plugins_js_minification( $c );
$this->set_elementor_checkout_context(); $this->set_elementor_checkout_context();
$is_nyp_active = $c->get( 'compat.nyp.is_supported_plugin_version_active' );
if ( $is_nyp_active ) {
$this->initialize_nyp_compat_layer();
}
} }
/** /**
@ -387,4 +392,24 @@ class CompatModule implements ModuleInterface {
3 3
); );
} }
/**
* Sets up the compatibility layer for PayPal Shipping callback & WooCommerce Name Your Price plugin.
*
* @return void
*/
protected function initialize_nyp_compat_layer(): void {
add_filter(
'woocommerce_paypal_payments_shipping_callback_cart_line_item_total',
static function( string $total, array $cart_item ) {
if ( ! isset( $cart_item['nyp'] ) ) {
return $total;
}
return $cart_item['nyp'];
},
10,
2
);
}
} }

View file

@ -13,3 +13,7 @@
min-width: 0 !important; min-width: 0 !important;
} }
} }
#ppc-button-ppcp-googlepay {
display: none;
}

View file

@ -1,4 +1,3 @@
import ContextHandlerFactory from './Context/ContextHandlerFactory';
import { setVisible } from '../../../ppcp-button/resources/js/modules/Helper/Hiding'; import { setVisible } from '../../../ppcp-button/resources/js/modules/Helper/Hiding';
import { setEnabled } from '../../../ppcp-button/resources/js/modules/Helper/ButtonDisabler'; import { setEnabled } from '../../../ppcp-button/resources/js/modules/Helper/ButtonDisabler';
import widgetBuilder from '../../../ppcp-button/resources/js/modules/Renderer/WidgetBuilder'; import widgetBuilder from '../../../ppcp-button/resources/js/modules/Renderer/WidgetBuilder';
@ -6,7 +5,13 @@ import UpdatePaymentData from './Helper/UpdatePaymentData';
import { apmButtonsInit } from '../../../ppcp-button/resources/js/modules/Helper/ApmButtons'; import { apmButtonsInit } from '../../../ppcp-button/resources/js/modules/Helper/ApmButtons';
class GooglepayButton { class GooglepayButton {
constructor( context, externalHandler, buttonConfig, ppcpConfig ) { constructor(
context,
externalHandler,
buttonConfig,
ppcpConfig,
contextHandler
) {
apmButtonsInit( ppcpConfig ); apmButtonsInit( ppcpConfig );
this.isInitialized = false; this.isInitialized = false;
@ -15,16 +20,10 @@ class GooglepayButton {
this.externalHandler = externalHandler; this.externalHandler = externalHandler;
this.buttonConfig = buttonConfig; this.buttonConfig = buttonConfig;
this.ppcpConfig = ppcpConfig; this.ppcpConfig = ppcpConfig;
this.contextHandler = contextHandler;
this.paymentsClient = null; this.paymentsClient = null;
this.contextHandler = ContextHandlerFactory.create(
this.context,
this.buttonConfig,
this.ppcpConfig,
this.externalHandler
);
this.log = function () { this.log = function () {
if ( this.buttonConfig.is_debug ) { if ( this.buttonConfig.is_debug ) {
//console.log('[GooglePayButton]', ...arguments); //console.log('[GooglePayButton]', ...arguments);
@ -32,7 +31,7 @@ class GooglepayButton {
}; };
} }
init( config ) { init( config, transactionInfo ) {
if ( this.isInitialized ) { if ( this.isInitialized ) {
return; return;
} }
@ -47,6 +46,7 @@ class GooglepayButton {
} }
this.googlePayConfig = config; this.googlePayConfig = config;
this.transactionInfo = transactionInfo;
this.allowedPaymentMethods = config.allowedPaymentMethods; this.allowedPaymentMethods = config.allowedPaymentMethods;
this.baseCardPaymentMethod = this.allowedPaymentMethods[ 0 ]; this.baseCardPaymentMethod = this.allowedPaymentMethods[ 0 ];
@ -62,6 +62,39 @@ class GooglepayButton {
) )
.then( ( response ) => { .then( ( response ) => {
if ( response.result ) { if ( response.result ) {
if (
( this.context === 'checkout' ||
this.context === 'pay-now' ) &&
this.buttonConfig.is_wc_gateway_enabled === '1'
) {
const wrapper = document.getElementById(
'ppc-button-ppcp-googlepay'
);
if ( wrapper ) {
const { ppcpStyle, buttonStyle } =
this.contextConfig();
wrapper.classList.add(
`ppcp-button-${ ppcpStyle.shape }`,
'ppcp-button-apm',
'ppcp-button-googlepay'
);
if ( ppcpStyle.height ) {
wrapper.style.height = `${ ppcpStyle.height }px`;
}
this.addButtonCheckout(
this.baseCardPaymentMethod,
wrapper,
buttonStyle
);
return;
}
}
this.addButton( this.baseCardPaymentMethod ); this.addButton( this.baseCardPaymentMethod );
} }
} ) } )
@ -76,7 +109,7 @@ class GooglepayButton {
} }
this.isInitialized = false; this.isInitialized = false;
this.init( this.googlePayConfig ); this.init( this.googlePayConfig, this.transactionInfo );
} }
validateConfig() { validateConfig() {
@ -221,6 +254,19 @@ class GooglepayButton {
} ); } );
} }
addButtonCheckout( baseCardPaymentMethod, wrapper, buttonStyle ) {
const button = this.paymentsClient.createButton( {
onClick: this.onButtonClick.bind( this ),
allowedPaymentMethods: [ baseCardPaymentMethod ],
buttonColor: buttonStyle.color || 'black',
buttonType: buttonStyle.type || 'pay',
buttonLocale: buttonStyle.language || 'en',
buttonSizeMode: 'fill',
} );
wrapper.appendChild( button );
}
waitForWrapper( selector, callback, delay = 100, timeout = 2000 ) { waitForWrapper( selector, callback, delay = 100, timeout = 2000 ) {
const startTime = Date.now(); const startTime = Date.now();
const interval = setInterval( () => { const interval = setInterval( () => {
@ -243,10 +289,11 @@ class GooglepayButton {
/** /**
* Show Google Pay payment sheet when Google Pay payment button is clicked * Show Google Pay payment sheet when Google Pay payment button is clicked
*/ */
async onButtonClick() { onButtonClick() {
this.log( 'onButtonClick', this.context ); this.log( 'onButtonClick', this.context );
const paymentDataRequest = await this.paymentDataRequest(); const paymentDataRequest = this.paymentDataRequest();
this.log( this.log(
'onButtonClick: paymentDataRequest', 'onButtonClick: paymentDataRequest',
paymentDataRequest, paymentDataRequest,
@ -258,7 +305,7 @@ class GooglepayButton {
this.paymentsClient.loadPaymentData( paymentDataRequest ); this.paymentsClient.loadPaymentData( paymentDataRequest );
} }
async paymentDataRequest() { paymentDataRequest() {
const baseRequest = { const baseRequest = {
apiVersion: 2, apiVersion: 2,
apiVersionMinor: 0, apiVersionMinor: 0,
@ -268,8 +315,7 @@ class GooglepayButton {
const paymentDataRequest = Object.assign( {}, baseRequest ); const paymentDataRequest = Object.assign( {}, baseRequest );
paymentDataRequest.allowedPaymentMethods = paymentDataRequest.allowedPaymentMethods =
googlePayConfig.allowedPaymentMethods; googlePayConfig.allowedPaymentMethods;
paymentDataRequest.transactionInfo = paymentDataRequest.transactionInfo = this.transactionInfo;
await this.contextHandler.transactionInfo();
paymentDataRequest.merchantInfo = googlePayConfig.merchantInfo; paymentDataRequest.merchantInfo = googlePayConfig.merchantInfo;
if ( if (
@ -308,43 +354,51 @@ class GooglepayButton {
this.log( 'paymentData', paymentData ); this.log( 'paymentData', paymentData );
return new Promise( async ( resolve, reject ) => { return new Promise( async ( resolve, reject ) => {
const paymentDataRequestUpdate = {}; try {
const paymentDataRequestUpdate = {};
const updatedData = await new UpdatePaymentData( const updatedData = await new UpdatePaymentData(
this.buttonConfig.ajax.update_payment_data this.buttonConfig.ajax.update_payment_data
).update( paymentData ); ).update( paymentData );
const transactionInfo = await this.contextHandler.transactionInfo(); const transactionInfo = this.transactionInfo;
this.log( 'onPaymentDataChanged:updatedData', updatedData ); this.log( 'onPaymentDataChanged:updatedData', updatedData );
this.log( 'onPaymentDataChanged:transactionInfo', transactionInfo ); this.log(
'onPaymentDataChanged:transactionInfo',
transactionInfo
);
updatedData.country_code = transactionInfo.countryCode; updatedData.country_code = transactionInfo.countryCode;
updatedData.currency_code = transactionInfo.currencyCode; updatedData.currency_code = transactionInfo.currencyCode;
updatedData.total_str = transactionInfo.totalPrice; updatedData.total_str = transactionInfo.totalPrice;
// Handle unserviceable address.
if ( ! updatedData.shipping_options?.shippingOptions?.length ) {
paymentDataRequestUpdate.error =
this.unserviceableShippingAddressError();
resolve( paymentDataRequestUpdate );
return;
}
switch ( paymentData.callbackTrigger ) {
case 'INITIALIZE':
case 'SHIPPING_ADDRESS':
paymentDataRequestUpdate.newShippingOptionParameters =
updatedData.shipping_options;
paymentDataRequestUpdate.newTransactionInfo =
this.calculateNewTransactionInfo( updatedData );
break;
case 'SHIPPING_OPTION':
paymentDataRequestUpdate.newTransactionInfo =
this.calculateNewTransactionInfo( updatedData );
break;
}
// Handle unserviceable address.
if ( ! updatedData.shipping_options?.shippingOptions?.length ) {
paymentDataRequestUpdate.error =
this.unserviceableShippingAddressError();
resolve( paymentDataRequestUpdate ); resolve( paymentDataRequestUpdate );
return; } catch ( error ) {
console.error( 'Error during onPaymentDataChanged:', error );
reject( error );
} }
switch ( paymentData.callbackTrigger ) {
case 'INITIALIZE':
case 'SHIPPING_ADDRESS':
paymentDataRequestUpdate.newShippingOptionParameters =
updatedData.shipping_options;
paymentDataRequestUpdate.newTransactionInfo =
this.calculateNewTransactionInfo( updatedData );
break;
case 'SHIPPING_OPTION':
paymentDataRequestUpdate.newTransactionInfo =
this.calculateNewTransactionInfo( updatedData );
break;
}
resolve( paymentDataRequestUpdate );
} ); } );
} }

View file

@ -1,39 +1,76 @@
import buttonModuleWatcher from '../../../ppcp-button/resources/js/modules/ButtonModuleWatcher'; import buttonModuleWatcher from '../../../ppcp-button/resources/js/modules/ButtonModuleWatcher';
import GooglepayButton from './GooglepayButton'; import GooglepayButton from './GooglepayButton';
import ContextHandlerFactory from './Context/ContextHandlerFactory';
class GooglepayManager { class GooglepayManager {
constructor( buttonConfig, ppcpConfig ) { constructor( buttonConfig, ppcpConfig ) {
this.buttonConfig = buttonConfig; this.buttonConfig = buttonConfig;
this.ppcpConfig = ppcpConfig; this.ppcpConfig = ppcpConfig;
this.googlePayConfig = null; this.googlePayConfig = null;
this.transactionInfo = null;
this.contextHandler = null;
this.buttons = []; this.buttons = [];
buttonModuleWatcher.watchContextBootstrap( ( bootstrap ) => { buttonModuleWatcher.watchContextBootstrap( async ( bootstrap ) => {
this.contextHandler = ContextHandlerFactory.create(
bootstrap.context,
buttonConfig,
ppcpConfig,
bootstrap.handler
);
const button = new GooglepayButton( const button = new GooglepayButton(
bootstrap.context, bootstrap.context,
bootstrap.handler, bootstrap.handler,
buttonConfig, buttonConfig,
ppcpConfig ppcpConfig,
this.contextHandler
); );
this.buttons.push( button ); this.buttons.push( button );
if ( this.googlePayConfig ) { // Initialize button only if googlePayConfig and transactionInfo are already fetched.
button.init( this.googlePayConfig ); if ( this.googlePayConfig && this.transactionInfo ) {
button.init( this.googlePayConfig, this.transactionInfo );
} else {
await this.init();
if ( this.googlePayConfig && this.transactionInfo ) {
button.init( this.googlePayConfig, this.transactionInfo );
}
} }
} ); } );
} }
init() { async init() {
( async () => { try {
// Gets GooglePay configuration of the PayPal merchant. if ( ! this.googlePayConfig ) {
this.googlePayConfig = await paypal.Googlepay().config(); // Gets GooglePay configuration of the PayPal merchant.
this.googlePayConfig = await paypal.Googlepay().config();
}
if ( ! this.transactionInfo ) {
this.transactionInfo = await this.fetchTransactionInfo();
}
for ( const button of this.buttons ) { for ( const button of this.buttons ) {
button.init( this.googlePayConfig ); button.init( this.googlePayConfig, this.transactionInfo );
} }
} )(); } catch ( error ) {
console.error( 'Error during initialization:', error );
}
}
async fetchTransactionInfo() {
try {
if ( ! this.contextHandler ) {
throw new Error( 'ContextHandler is not initialized' );
}
return await this.contextHandler.transactionInfo();
} catch ( error ) {
console.error( 'Error fetching transaction info:', error );
throw error;
}
} }
reinit() { reinit() {

View file

@ -1,6 +1,7 @@
import GooglepayButton from './GooglepayButton'; import GooglepayButton from './GooglepayButton';
import PreviewButton from '../../../ppcp-button/resources/js/modules/Renderer/PreviewButton'; import PreviewButton from '../../../ppcp-button/resources/js/modules/Renderer/PreviewButton';
import PreviewButtonManager from '../../../ppcp-button/resources/js/modules/Renderer/PreviewButtonManager'; import PreviewButtonManager from '../../../ppcp-button/resources/js/modules/Renderer/PreviewButtonManager';
import ContextHandlerFactory from './Context/ContextHandlerFactory';
/** /**
* Accessor that creates and returns a single PreviewButtonManager instance. * Accessor that creates and returns a single PreviewButtonManager instance.
@ -95,14 +96,22 @@ class GooglePayPreviewButton extends PreviewButton {
} }
createButton( buttonConfig ) { createButton( buttonConfig ) {
const contextHandler = ContextHandlerFactory.create(
'preview',
buttonConfig,
this.ppcpConfig,
null
);
const button = new GooglepayButton( const button = new GooglepayButton(
'preview', 'preview',
null, null,
buttonConfig, buttonConfig,
this.ppcpConfig this.ppcpConfig,
contextHandler
); );
button.init( this.apiConfig ); button.init( this.apiConfig, null );
} }
/** /**

View file

@ -938,5 +938,14 @@ return array(
esc_html( $button_text ) esc_html( $button_text )
); );
}, },
'googlepay.wc-gateway' => static function ( ContainerInterface $container ): GooglePayGateway {
return new GooglePayGateway(
$container->get( 'wcgateway.order-processor' ),
$container->get( 'api.factory.paypal-checkout-url' ),
$container->get( 'wcgateway.processor.refunds' ),
$container->get( 'wcgateway.transaction-url-provider' ),
$container->get( 'session.handler' ),
$container->get( 'googlepay.url' )
);
},
); );

View file

@ -13,7 +13,9 @@ use Exception;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use WC_Countries; use WC_Countries;
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface; use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
use WooCommerce\PayPalCommerce\Googlepay\Endpoint\UpdatePaymentDataEndpoint; use WooCommerce\PayPalCommerce\Googlepay\Endpoint\UpdatePaymentDataEndpoint;
use WooCommerce\PayPalCommerce\Googlepay\GooglePayGateway;
use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Session\SessionHandler; use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
@ -25,6 +27,8 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
*/ */
class Button implements ButtonInterface { class Button implements ButtonInterface {
use ContextTrait;
/** /**
* The URL to the module. * The URL to the module.
* *
@ -409,7 +413,7 @@ class Button implements ButtonInterface {
*/ */
public function script_data(): array { public function script_data(): array {
$shipping = array( $shipping = array(
'enabled' => $this->settings->has( 'googlepay_button_shipping_enabled' ) 'enabled' => $this->settings->has( 'googlepay_button_shipping_enabled' )
? boolval( $this->settings->get( 'googlepay_button_shipping_enabled' ) ) ? boolval( $this->settings->get( 'googlepay_button_shipping_enabled' ) )
: false, : false,
'configured' => wc_shipping_enabled() && wc_get_shipping_method_count( false, true ) > 0, 'configured' => wc_shipping_enabled() && wc_get_shipping_method_count( false, true ) > 0,
@ -421,19 +425,23 @@ class Button implements ButtonInterface {
$is_enabled = $this->settings->has( 'googlepay_button_enabled' ) && $this->settings->get( 'googlepay_button_enabled' ); $is_enabled = $this->settings->has( 'googlepay_button_enabled' ) && $this->settings->get( 'googlepay_button_enabled' );
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
$is_wc_gateway_enabled = isset( $available_gateways[ GooglePayGateway::ID ] );
return array( return array(
'environment' => $this->environment->current_environment_is( Environment::SANDBOX ) ? 'TEST' : 'PRODUCTION', 'environment' => $this->environment->current_environment_is( Environment::SANDBOX ) ? 'TEST' : 'PRODUCTION',
'is_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, 'is_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
'is_enabled' => $is_enabled, 'is_enabled' => $is_enabled,
'sdk_url' => $this->sdk_url, 'is_wc_gateway_enabled' => $is_wc_gateway_enabled,
'button' => array( 'sdk_url' => $this->sdk_url,
'button' => array(
'wrapper' => '#ppc-button-googlepay-container', 'wrapper' => '#ppc-button-googlepay-container',
'style' => $this->button_styles_for_context( 'cart' ), // For now use cart. Pass the context if necessary. 'style' => $this->button_styles_for_context( 'cart' ), // For now use cart. Pass the context if necessary.
'mini_cart_wrapper' => '#ppc-button-googlepay-container-minicart', 'mini_cart_wrapper' => '#ppc-button-googlepay-container-minicart',
'mini_cart_style' => $this->button_styles_for_context( 'mini-cart' ), 'mini_cart_style' => $this->button_styles_for_context( 'mini-cart' ),
), ),
'shipping' => $shipping, 'shipping' => $shipping,
'ajax' => array( 'ajax' => array(
'update_payment_data' => array( 'update_payment_data' => array(
'endpoint' => \WC_AJAX::get_endpoint( UpdatePaymentDataEndpoint::ENDPOINT ), 'endpoint' => \WC_AJAX::get_endpoint( UpdatePaymentDataEndpoint::ENDPOINT ),
'nonce' => wp_create_nonce( UpdatePaymentDataEndpoint::nonce() ), 'nonce' => wp_create_nonce( UpdatePaymentDataEndpoint::nonce() ),

View file

@ -0,0 +1,238 @@
<?php
/**
* The Google Pay Payment Gateway
*
* @package WooCommerce\PayPalCommerce\Googlepay
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Googlepay;
use Exception;
use WC_Order;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\WcGateway\Exception\GatewayGenericException;
use WooCommerce\PayPalCommerce\WcGateway\Exception\PayPalOrderMissingException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\Messages;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\ProcessPaymentTrait;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
/**
* Class GooglePayGateway
*/
class GooglePayGateway extends WC_Payment_Gateway {
use ProcessPaymentTrait;
const ID = 'ppcp-googlepay';
/**
* The processor for orders.
*
* @var OrderProcessor
*/
protected $order_processor;
/**
* The function return the PayPal checkout URL for the given order ID.
*
* @var callable(string):string
*/
private $paypal_checkout_url_factory;
/**
* The Refund Processor.
*
* @var RefundProcessor
*/
private $refund_processor;
/**
* Service able to provide transaction url for an order.
*
* @var TransactionUrlProvider
*/
protected $transaction_url_provider;
/**
* The Session Handler.
*
* @var SessionHandler
*/
protected $session_handler;
/**
* The URL to the module.
*
* @var string
*/
private $module_url;
/**
* GooglePayGateway constructor.
*
* @param OrderProcessor $order_processor The Order Processor.
* @param callable(string):string $paypal_checkout_url_factory The function return the PayPal checkout URL for the given order ID.
* @param RefundProcessor $refund_processor The Refund Processor.
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
* @param SessionHandler $session_handler The Session Handler.
* @param string $module_url The URL to the module.
*/
public function __construct(
OrderProcessor $order_processor,
callable $paypal_checkout_url_factory,
RefundProcessor $refund_processor,
TransactionUrlProvider $transaction_url_provider,
SessionHandler $session_handler,
string $module_url
) {
$this->id = self::ID;
$this->method_title = __( 'Google Pay (via PayPal) ', 'woocommerce-paypal-payments' );
$this->method_description = __( 'The separate payment gateway with the Google Pay button. If disabled, the button is included in the PayPal gateway.', 'woocommerce-paypal-payments' );
$this->title = $this->get_option( 'title', __( 'Google Pay', 'woocommerce-paypal-payments' ) );
$this->description = $this->get_option( 'description', '' );
$this->module_url = $module_url;
$this->icon = esc_url( $this->module_url ) . 'assets/images/googlepay.png';
$this->init_form_fields();
$this->init_settings();
$this->order_processor = $order_processor;
$this->paypal_checkout_url_factory = $paypal_checkout_url_factory;
$this->refund_processor = $refund_processor;
$this->transaction_url_provider = $transaction_url_provider;
$this->session_handler = $session_handler;
add_action(
'woocommerce_update_options_payment_gateways_' . $this->id,
array(
$this,
'process_admin_options',
)
);
}
/**
* Initialize the form fields.
*/
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __( 'Google Pay', 'woocommerce-paypal-payments' ),
'default' => 'no',
'desc_tip' => true,
'description' => __( 'Enable/Disable Google Pay payment gateway.', 'woocommerce-paypal-payments' ),
),
'title' => array(
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
'type' => 'text',
'default' => $this->title,
'desc_tip' => true,
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments' ),
),
'description' => array(
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
'type' => 'text',
'default' => $this->description,
'desc_tip' => true,
'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments' ),
),
);
}
/**
* Process payment for a WooCommerce order.
*
* @param int $order_id The WooCommerce order id.
*
* @return array
*/
public function process_payment( $order_id ) {
$wc_order = wc_get_order( $order_id );
if ( ! is_a( $wc_order, WC_Order::class ) ) {
return $this->handle_payment_failure(
null,
new GatewayGenericException( new Exception( 'WC order was not found.' ) )
);
}
/**
* If the WC_Order is paid through the approved webhook.
*/
//phpcs:disable WordPress.Security.NonceVerification.Recommended
if ( isset( $_REQUEST['ppcp-resume-order'] ) && $wc_order->has_status( 'processing' ) ) {
return $this->handle_payment_success( $wc_order );
}
//phpcs:enable WordPress.Security.NonceVerification.Recommended
do_action( 'woocommerce_paypal_payments_before_process_order', $wc_order );
try {
try {
$this->order_processor->process( $wc_order );
do_action( 'woocommerce_paypal_payments_before_handle_payment_success', $wc_order );
return $this->handle_payment_success( $wc_order );
} catch ( PayPalOrderMissingException $exc ) {
$order = $this->order_processor->create_order( $wc_order );
return array(
'result' => 'success',
'redirect' => ( $this->paypal_checkout_url_factory )( $order->id() ),
);
}
} catch ( PayPalApiException $error ) {
return $this->handle_payment_failure(
$wc_order,
new Exception(
Messages::generic_payment_error_message() . ' ' . $error->getMessage(),
$error->getCode(),
$error
)
);
} catch ( Exception $error ) {
return $this->handle_payment_failure( $wc_order, $error );
}
}
/**
* Process refund.
*
* If the gateway declares 'refunds' support, this will allow it to refund.
* a passed in amount.
*
* @param int $order_id Order ID.
* @param float $amount Refund amount.
* @param string $reason Refund reason.
* @return boolean True or false based on success, or a WP_Error object.
*/
public function process_refund( $order_id, $amount = null, $reason = '' ) {
$order = wc_get_order( $order_id );
if ( ! is_a( $order, \WC_Order::class ) ) {
return false;
}
return $this->refund_processor->process( $order, (float) $amount, (string) $reason );
}
/**
* Return transaction url for this gateway and given order.
*
* @param \WC_Order $order WC order to get transaction url by.
*
* @return string
*/
public function get_transaction_url( $order ): string {
$this->view_transaction_url = $this->transaction_url_provider->get_transaction_url_base( $order );
return parent::get_transaction_url( $order );
}
}

View file

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Googlepay; namespace WooCommerce\PayPalCommerce\Googlepay;
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry; use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface; use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface; use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
use WooCommerce\PayPalCommerce\Googlepay\Endpoint\UpdatePaymentDataEndpoint; use WooCommerce\PayPalCommerce\Googlepay\Endpoint\UpdatePaymentDataEndpoint;
@ -159,6 +160,46 @@ class GooglepayModule implements ModuleInterface {
}, },
1 1
); );
add_filter(
'woocommerce_payment_gateways',
/**
* Param types removed to avoid third-party issues.
*
* @psalm-suppress MissingClosureParamType
*/
static function ( $methods ) use ( $c ): array {
if ( ! is_array( $methods ) ) {
return $methods;
}
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
if ( $settings->has( 'googlepay_button_enabled' ) && $settings->get( 'googlepay_button_enabled' ) ) {
$googlepay_gateway = $c->get( 'googlepay.wc-gateway' );
assert( $googlepay_gateway instanceof WC_Payment_Gateway );
$methods[] = $googlepay_gateway;
}
return $methods;
}
);
add_action(
'woocommerce_review_order_after_submit',
function () {
echo '<div id="ppc-button-' . esc_attr( GooglePayGateway::ID ) . '"></div>';
}
);
add_action(
'woocommerce_pay_order_after_submit',
function () {
echo '<div id="ppc-button-' . esc_attr( GooglePayGateway::ID ) . '"></div>';
}
);
} }
/** /**

View file

@ -96,21 +96,21 @@ class OnboardingAssets {
*/ */
public function register(): bool { public function register(): bool {
$url = untrailingslashit( $this->module_url ) . '/assets/css/onboarding.css';
wp_register_style( wp_register_style(
'ppcp-onboarding', 'ppcp-onboarding',
$url, $this->module_url . '/assets/css/onboarding.css',
array(), array(),
$this->version $this->version
); );
$url = untrailingslashit( $this->module_url ) . '/assets/js/settings.js';
wp_register_script( wp_register_script(
'ppcp-settings', 'ppcp-settings',
$url, $this->module_url . '/assets/js/settings.js',
array(), array(),
$this->version, $this->version,
true true
); );
wp_localize_script( wp_localize_script(
'ppcp-settings', 'ppcp-settings',
'PayPalCommerceSettings', 'PayPalCommerceSettings',
@ -122,14 +122,14 @@ class OnboardingAssets {
) )
); );
$url = untrailingslashit( $this->module_url ) . '/assets/js/onboarding.js';
wp_register_script( wp_register_script(
'ppcp-onboarding', 'ppcp-onboarding',
$url, $this->module_url . '/assets/js/onboarding.js',
array( 'jquery' ), array( 'jquery' ),
$this->version, $this->version,
true true
); );
wp_localize_script( wp_localize_script(
'ppcp-onboarding', 'ppcp-onboarding',
'PayPalCommerceGatewayOnboarding', 'PayPalCommerceGatewayOnboarding',
@ -164,17 +164,22 @@ class OnboardingAssets {
/** /**
* Enqueues the necessary scripts. * Enqueues the necessary scripts.
* *
* @return bool * @return void
*/ */
public function enqueue(): bool { public function enqueue(): void {
wp_enqueue_style( 'ppcp-onboarding' ); // Do not enqueue anything when we are not on a PayPal Payments settings tab.
wp_enqueue_script( 'ppcp-settings' ); if ( ! $this->page_id ) {
if ( ! $this->should_render_onboarding_script() ) { return;
return false;
} }
wp_enqueue_script( 'ppcp-onboarding' ); // Enqueue general assets for the plugin's settings page.
return true; wp_enqueue_script( 'ppcp-settings' );
wp_enqueue_style( 'ppcp-onboarding' ); // File also contains general settings styles.
// Conditionally enqueue the onboarding script, when needed.
if ( $this->should_render_onboarding_script() ) {
wp_enqueue_script( 'ppcp-onboarding' );
}
} }
/** /**

View file

@ -188,10 +188,6 @@ document.addEventListener( 'DOMContentLoaded', () => {
} }
function shouldDisableCardButton() { function shouldDisableCardButton() {
if ( currentTabId() === 'ppcp-card-button-gateway' ) {
return false;
}
return ( return (
PayPalCommerceGatewaySettings.is_acdc_enabled || PayPalCommerceGatewaySettings.is_acdc_enabled ||
jQuery( '#ppcp-allow_card_button_gateway' ).is( ':checked' ) jQuery( '#ppcp-allow_card_button_gateway' ).is( ':checked' )
@ -230,6 +226,14 @@ document.addEventListener( 'DOMContentLoaded', () => {
} }
if ( shouldDisableCardButton() ) { if ( shouldDisableCardButton() ) {
const standardCardButtonInput = document.querySelector(
'#woocommerce_ppcp-card-button-gateway_enabled'
);
if ( standardCardButtonInput ) {
standardCardButtonInput.disabled = true;
}
disabledSources = disabledSources.concat( 'card' ); disabledSources = disabledSources.concat( 'card' );
} }

View file

@ -20,6 +20,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway; use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway;
use WooCommerce\PayPalCommerce\Button\Helper\MessagesDisclaimers; use WooCommerce\PayPalCommerce\Button\Helper\MessagesDisclaimers;
use WooCommerce\PayPalCommerce\Common\Pattern\SingletonDecorator; use WooCommerce\PayPalCommerce\Common\Pattern\SingletonDecorator;
use WooCommerce\PayPalCommerce\Googlepay\GooglePayGateway;
use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer; use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer;
use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Onboarding\State;
@ -196,6 +197,7 @@ return array(
OXXOGateway::ID, OXXOGateway::ID,
Settings::PAY_LATER_TAB_ID, Settings::PAY_LATER_TAB_ID,
AxoGateway::ID, AxoGateway::ID,
GooglePayGateway::ID,
), ),
true true
); );
@ -217,6 +219,7 @@ return array(
CardButtonGateway::ID, CardButtonGateway::ID,
Settings::PAY_LATER_TAB_ID, Settings::PAY_LATER_TAB_ID,
Settings::CONNECTION_TAB_ID, Settings::CONNECTION_TAB_ID,
GooglePayGateway::ID,
), ),
true true
); );

View file

@ -106,6 +106,12 @@ class DisableGateways {
return $methods; return $methods;
} }
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$payment_method = wc_clean( wp_unslash( $_POST['payment_method'] ?? '' ) );
if ( $payment_method && is_string( $payment_method ) ) {
return array( $payment_method => $methods[ $payment_method ] );
}
return array( PayPalGateway::ID => $methods[ PayPalGateway::ID ] ); return array( PayPalGateway::ID => $methods[ PayPalGateway::ID ] );
} }

View file

@ -19,9 +19,10 @@ use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
* Creates the admin message about the gateway being enabled without the PayPal gateway. * Creates the admin message about the gateway being enabled without the PayPal gateway.
*/ */
class GatewayWithoutPayPalAdminNotice { class GatewayWithoutPayPalAdminNotice {
private const NOTICE_OK = ''; private const NOTICE_OK = '';
private const NOTICE_DISABLED_GATEWAY = 'disabled_gateway'; private const NOTICE_DISABLED_GATEWAY = 'disabled_gateway';
private const NOTICE_DISABLED_LOCATION = 'disabled_location'; private const NOTICE_DISABLED_LOCATION = 'disabled_location';
private const NOTICE_DISABLED_CARD_BUTTON = 'disabled_card';
/** /**
* The gateway ID. * The gateway ID.
@ -99,6 +100,9 @@ class GatewayWithoutPayPalAdminNotice {
public function message(): ?Message { public function message(): ?Message {
$notice_type = $this->check(); $notice_type = $this->check();
$url1 = '';
$url2 = '';
switch ( $notice_type ) { switch ( $notice_type ) {
case self::NOTICE_DISABLED_GATEWAY: case self::NOTICE_DISABLED_GATEWAY:
/* translators: %1$s the gateway name, %2$s URL. */ /* translators: %1$s the gateway name, %2$s URL. */
@ -114,6 +118,15 @@ class GatewayWithoutPayPalAdminNotice {
'woocommerce-paypal-payments' 'woocommerce-paypal-payments'
); );
break; break;
case self::NOTICE_DISABLED_CARD_BUTTON:
/* translators: %1$s Standard Card Button section URL, %2$s Advanced Card Processing section URL. */
$text = __(
'The <a href="%1$s">Standard Card Button</a> cannot be used while <a href="%2$s">Advanced Card Processing</a> is enabled.',
'woocommerce-paypal-payments'
);
$url1 = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-card-button-gateway' );
$url2 = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&ppcp-tab=ppcp-credit-card-gateway' );
break;
default: default:
return null; return null;
} }
@ -130,6 +143,15 @@ class GatewayWithoutPayPalAdminNotice {
$name, $name,
admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway' ) admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway' )
); );
if ( $notice_type === self::NOTICE_DISABLED_CARD_BUTTON ) {
$message = sprintf(
$text,
$url1,
$url2
);
}
return new Message( $message, 'warning' ); return new Message( $message, 'warning' );
} }
@ -160,6 +182,13 @@ class GatewayWithoutPayPalAdminNotice {
return self::NOTICE_DISABLED_LOCATION; return self::NOTICE_DISABLED_LOCATION;
} }
$is_dcc_enabled = $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' ) ?? false;
$is_card_button_allowed = $this->settings->has( 'allow_card_button_gateway' ) && $this->settings->get( 'allow_card_button_gateway' );
if ( $is_dcc_enabled && $is_card_button_allowed ) {
return self::NOTICE_DISABLED_CARD_BUTTON;
}
return self::NOTICE_OK; return self::NOTICE_OK;
} }

View file

@ -528,6 +528,14 @@ class WCGatewayModule implements ModuleInterface {
return $methods; return $methods;
} }
$is_dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ) ?? false;
$standard_card_button = get_option( 'woocommerce_ppcp-card-button-gateway_settings' );
if ( $is_dcc_enabled && isset( $standard_card_button['enabled'] ) ) {
$standard_card_button['enabled'] = 'no';
update_option( 'woocommerce_ppcp-card-button-gateway_settings', $standard_card_button );
}
$dcc_applies = $container->get( 'api.helpers.dccapplies' ); $dcc_applies = $container->get( 'api.helpers.dccapplies' );
assert( $dcc_applies instanceof DccApplies ); assert( $dcc_applies instanceof DccApplies );

View file

@ -416,7 +416,9 @@ class WcSubscriptionsModule implements ModuleInterface {
$settings = $c->get( 'wcgateway.settings' ); $settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings ); assert( $settings instanceof Settings );
if ( $subscriptions_helper->plugin_is_active() ) { $subscriptions_mode = $settings->has( 'subscriptions_mode' ) ? $settings->get( 'subscriptions_mode' ) : '';
if ( 'disable_paypal_subscriptions' !== $subscriptions_mode && $subscriptions_helper->plugin_is_active() ) {
$supports = array( $supports = array(
'subscriptions', 'subscriptions',
'subscription_cancellation', 'subscription_cancellation',
@ -442,7 +444,12 @@ class WcSubscriptionsModule implements ModuleInterface {
$subscriptions_helper = $c->get( 'wc-subscriptions.helper' ); $subscriptions_helper = $c->get( 'wc-subscriptions.helper' );
assert( $subscriptions_helper instanceof SubscriptionHelper ); assert( $subscriptions_helper instanceof SubscriptionHelper );
if ( $subscriptions_helper->plugin_is_active() ) { $settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
$vaulting_enabled = $settings->has( 'vault_enabled_dcc' ) && $settings->get( 'vault_enabled_dcc' );
if ( $vaulting_enabled && $subscriptions_helper->plugin_is_active() ) {
$supports = array( $supports = array(
'subscriptions', 'subscriptions',
'subscription_cancellation', 'subscription_cancellation',
@ -467,7 +474,12 @@ class WcSubscriptionsModule implements ModuleInterface {
$subscriptions_helper = $c->get( 'wc-subscriptions.helper' ); $subscriptions_helper = $c->get( 'wc-subscriptions.helper' );
assert( $subscriptions_helper instanceof SubscriptionHelper ); assert( $subscriptions_helper instanceof SubscriptionHelper );
if ( $subscriptions_helper->plugin_is_active() ) { $settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
$subscriptions_mode = $settings->has( 'subscriptions_mode' ) ? $settings->get( 'subscriptions_mode' ) : '';
if ( 'disable_paypal_subscriptions' !== $subscriptions_mode && $subscriptions_helper->plugin_is_active() ) {
$supports = array( $supports = array(
'subscriptions', 'subscriptions',
'subscription_cancellation', 'subscription_cancellation',

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Webhooks; namespace WooCommerce\PayPalCommerce\Webhooks;
use WC_Order;
use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider; use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface; use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;

View file

@ -1,5 +1,5 @@
=== WooCommerce PayPal Payments === === WooCommerce PayPal Payments ===
Contributors: woocommerce, automattic, inpsyde Contributors: woocommerce, automattic, syde
Tags: woocommerce, paypal, payments, ecommerce, checkout, cart, pay later, apple pay, subscriptions, debit card, credit card, google pay Tags: woocommerce, paypal, payments, ecommerce, checkout, cart, pay later, apple pay, subscriptions, debit card, credit card, google pay
Requires at least: 5.3 Requires at least: 5.3
Tested up to: 6.6 Tested up to: 6.6
@ -179,7 +179,7 @@ If you encounter issues with the PayPal buttons not appearing after an update, p
== Changelog == == Changelog ==
= 2.8.2 - xxxx-xx-xx = = 2.8.2 - 2024-07-22 =
* Fix - Sold individually checkbox automatically disabled after adding product to the cart more than once #2415 * Fix - Sold individually checkbox automatically disabled after adding product to the cart more than once #2415
* Fix - All products "Sold individually" when PayPal Subscriptions selected as Subscriptions Mode #2400 * Fix - All products "Sold individually" when PayPal Subscriptions selected as Subscriptions Mode #2400
* Fix - W3 Total Cache: Remove type from file parameter as sometimes null gets passed causing errors #2403 * Fix - W3 Total Cache: Remove type from file parameter as sometimes null gets passed causing errors #2403

View file

@ -223,6 +223,22 @@ define( 'PPCP_PAYPAL_BN_CODE', 'Woo_PPCP' );
} }
); );
add_action(
'in_plugin_update_message-woocommerce-paypal-payments/woocommerce-paypal-payments.php',
static function( array $plugin_data, \stdClass $new_data ) {
if ( version_compare( $plugin_data['Version'], '3.0.0', '<' ) &&
version_compare( $new_data->new_version, '3.0.0', '>=' ) ) {
printf(
'<br /><strong>%s</strong>: %s',
esc_html__( 'Warning', 'woocommerce-paypal-payments' ),
esc_html__( 'WooCommerce PayPal Payments version 3.0.0 contains significant changes that may impact your website. We strongly recommend reviewing the changes and testing the update on a staging site before updating it on your production environment.', 'woocommerce-paypal-payments' )
);
}
},
10,
2
);
/** /**
* Check if WooCommerce is active. * Check if WooCommerce is active.
* *