mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Merge branch 'trunk' into PCP-3170-add-es-lint-and-testing-library-for-js-code
This commit is contained in:
commit
fef4566f52
17 changed files with 472 additions and 104 deletions
|
@ -1,6 +1,6 @@
|
||||||
*** Changelog ***
|
*** Changelog ***
|
||||||
|
|
||||||
= 2.8.1 - xxxx-xx-xx =
|
= 2.8.1 - 2024-07-01 =
|
||||||
* Fix - Don't render tracking metabox if PayPal order does not belong to connected merchant #2360
|
* Fix - Don't render tracking metabox if PayPal order does not belong to connected merchant #2360
|
||||||
* Fix - Fatal error when the ppcp-paylater-configurator module is disabled via code snippet #2327
|
* Fix - Fatal error when the ppcp-paylater-configurator module is disabled via code snippet #2327
|
||||||
* Fix - Apple Pay & Google Pay buttons no longer visible in Standard Payments button previews after moving the configuration to Advanced Card Processing tab #2325
|
* Fix - Apple Pay & Google Pay buttons no longer visible in Standard Payments button previews after moving the configuration to Advanced Card Processing tab #2325
|
||||||
|
|
|
@ -4,23 +4,22 @@
|
||||||
--apple-pay-button-min-height: 35px;
|
--apple-pay-button-min-height: 35px;
|
||||||
--apple-pay-button-width: 100%;
|
--apple-pay-button-width: 100%;
|
||||||
--apple-pay-button-max-width: 750px;
|
--apple-pay-button-max-width: 750px;
|
||||||
--apple-pay-button-border-radius: 4px;
|
--apple-pay-button-border-radius: var(--apm-button-border-radius);
|
||||||
--apple-pay-button-overflow: hidden;
|
--apple-pay-button-overflow: hidden;
|
||||||
|
--apple-pay-button-box-sizing: border-box;
|
||||||
|
|
||||||
.ppcp-width-min & {
|
.ppcp-width-min & {
|
||||||
--apple-pay-button-height: 35px;
|
--apple-pay-button-height: 35px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ppcp-width-300 & {
|
.ppcp-width-300 & {
|
||||||
--apple-pay-button-height: 45px;
|
--apple-pay-button-height: 45px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ppcp-width-500 & {
|
.ppcp-width-500 & {
|
||||||
--apple-pay-button-height: 55px;
|
--apple-pay-button-height: 55px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.ppcp-button-pill {
|
|
||||||
--apple-pay-button-border-radius: 50px;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.ppcp-button-minicart {
|
&.ppcp-button-minicart {
|
||||||
--apple-pay-button-display: block;
|
--apple-pay-button-display: block;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {loadCustomScript} from "@paypal/paypal-js";
|
import {loadCustomScript} from "@paypal/paypal-js";
|
||||||
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
|
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
|
||||||
import ApplepayManager from "./ApplepayManager";
|
import ApplepayManager from "./ApplepayManager";
|
||||||
|
import {setupButtonEvents} from '../../../ppcp-button/resources/js/modules/Helper/ButtonRefreshHelper';
|
||||||
|
|
||||||
(function ({
|
(function ({
|
||||||
buttonConfig,
|
buttonConfig,
|
||||||
|
@ -15,21 +16,12 @@ import ApplepayManager from "./ApplepayManager";
|
||||||
manager.init();
|
manager.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
jQuery(document.body).on('updated_cart_totals updated_checkout', () => {
|
setupButtonEvents(function() {
|
||||||
if (manager) {
|
if (manager) {
|
||||||
manager.reinit();
|
manager.reinit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Use set timeout as it's unnecessary to refresh upon Minicart initial render.
|
|
||||||
setTimeout(() => {
|
|
||||||
jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', () => {
|
|
||||||
if (manager) {
|
|
||||||
manager.reinit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
'DOMContentLoaded',
|
'DOMContentLoaded',
|
||||||
() => {
|
() => {
|
||||||
|
|
|
@ -505,6 +505,30 @@ const PayPalComponent = ({
|
||||||
|
|
||||||
const PayPalButton = paypal.Buttons.driver("react", { React, ReactDOM });
|
const PayPalButton = paypal.Buttons.driver("react", { React, ReactDOM });
|
||||||
|
|
||||||
|
const getOnShippingOptionsChange = (fundingSource) => {
|
||||||
|
if(fundingSource === 'venmo') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (data, actions) => {
|
||||||
|
shouldHandleShippingInPayPal()
|
||||||
|
? handleShippingOptionsChange(data, actions)
|
||||||
|
: null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const getOnShippingAddressChange = (fundingSource) => {
|
||||||
|
if(fundingSource === 'venmo') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (data, actions) => {
|
||||||
|
shouldHandleShippingInPayPal()
|
||||||
|
? handleShippingAddressChange(data, actions)
|
||||||
|
: null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if(isPayPalSubscription(config.scriptData)) {
|
if(isPayPalSubscription(config.scriptData)) {
|
||||||
return (
|
return (
|
||||||
<PayPalButton
|
<PayPalButton
|
||||||
|
@ -515,16 +539,8 @@ const PayPalComponent = ({
|
||||||
onError={onClose}
|
onError={onClose}
|
||||||
createSubscription={createSubscription}
|
createSubscription={createSubscription}
|
||||||
onApprove={handleApproveSubscription}
|
onApprove={handleApproveSubscription}
|
||||||
onShippingOptionsChange={(data, actions) => {
|
onShippingOptionsChange={getOnShippingOptionsChange(fundingSource)}
|
||||||
shouldHandleShippingInPayPal()
|
onShippingAddressChange={getOnShippingAddressChange(fundingSource)}
|
||||||
? handleSubscriptionShippingOptionsChange(data, actions)
|
|
||||||
: null;
|
|
||||||
}}
|
|
||||||
onShippingAddressChange={(data, actions) => {
|
|
||||||
shouldHandleShippingInPayPal()
|
|
||||||
? handleSubscriptionShippingAddressChange(data, actions)
|
|
||||||
: null;
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -538,16 +554,8 @@ const PayPalComponent = ({
|
||||||
onError={onClose}
|
onError={onClose}
|
||||||
createOrder={createOrder}
|
createOrder={createOrder}
|
||||||
onApprove={handleApprove}
|
onApprove={handleApprove}
|
||||||
onShippingOptionsChange={(data, actions) => {
|
onShippingOptionsChange={getOnShippingOptionsChange(fundingSource)}
|
||||||
shouldHandleShippingInPayPal()
|
onShippingAddressChange={getOnShippingAddressChange(fundingSource)}
|
||||||
? handleShippingOptionsChange(data, actions)
|
|
||||||
: null;
|
|
||||||
}}
|
|
||||||
onShippingAddressChange={(data, actions) => {
|
|
||||||
shouldHandleShippingInPayPal()
|
|
||||||
? handleShippingAddressChange(data, actions)
|
|
||||||
: null;
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
|
|
||||||
@mixin button {
|
@mixin button {
|
||||||
|
--apm-button-border-radius: 4px;
|
||||||
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
max-width: 750px;
|
max-width: 750px;
|
||||||
line-height: 0;
|
line-height: 0;
|
||||||
border-radius: 4px;
|
border-radius: var(--apm-button-border-radius);
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
height: 45px;
|
height: 45px;
|
||||||
margin-top: 14px;
|
margin-top: 14px;
|
||||||
|
|
||||||
&.ppcp-button-pill {
|
&.ppcp-button-pill {
|
||||||
border-radius: 50px;
|
--apm-button-border-radius: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.ppcp-button-minicart {
|
&.ppcp-button-minicart {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import {
|
||||||
import {setVisibleByClass} from "./modules/Helper/Hiding";
|
import {setVisibleByClass} from "./modules/Helper/Hiding";
|
||||||
import {isChangePaymentPage} from "./modules/Helper/Subscriptions";
|
import {isChangePaymentPage} from "./modules/Helper/Subscriptions";
|
||||||
import FreeTrialHandler from "./modules/ActionHandler/FreeTrialHandler";
|
import FreeTrialHandler from "./modules/ActionHandler/FreeTrialHandler";
|
||||||
|
import MultistepCheckoutHelper from "./modules/Helper/MultistepCheckoutHelper";
|
||||||
import FormSaver from './modules/Helper/FormSaver';
|
import FormSaver from './modules/Helper/FormSaver';
|
||||||
import FormValidator from "./modules/Helper/FormValidator";
|
import FormValidator from "./modules/Helper/FormValidator";
|
||||||
import {loadPaypalScript} from "./modules/Helper/ScriptLoading";
|
import {loadPaypalScript} from "./modules/Helper/ScriptLoading";
|
||||||
|
@ -53,6 +54,8 @@ const bootstrap = () => {
|
||||||
|
|
||||||
const freeTrialHandler = new FreeTrialHandler(PayPalCommerceGateway, checkoutFormSelector, formSaver, formValidator, spinner, errorHandler);
|
const freeTrialHandler = new FreeTrialHandler(PayPalCommerceGateway, checkoutFormSelector, formSaver, formValidator, spinner, errorHandler);
|
||||||
|
|
||||||
|
new MultistepCheckoutHelper(checkoutFormSelector);
|
||||||
|
|
||||||
jQuery('form.woocommerce-checkout input').on('keydown', e => {
|
jQuery('form.woocommerce-checkout input').on('keydown', e => {
|
||||||
if (e.key === 'Enter' && [
|
if (e.key === 'Enter' && [
|
||||||
PaymentMethods.PAYPAL,
|
PaymentMethods.PAYPAL,
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
import { debounce } from '../../../../../ppcp-blocks/resources/js/Helper/debounce';
|
||||||
|
|
||||||
|
const REFRESH_BUTTON_EVENT = 'ppcp_refresh_payment_buttons';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers a refresh of the payment buttons.
|
||||||
|
* This function dispatches a custom event that the button components listen for.
|
||||||
|
*
|
||||||
|
* Use this function on the front-end to update payment buttons after the checkout form was updated.
|
||||||
|
*/
|
||||||
|
export function refreshButtons() {
|
||||||
|
document.dispatchEvent(new Event(REFRESH_BUTTON_EVENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up event listeners for various cart and checkout update events.
|
||||||
|
* When these events occur, it triggers a refresh of the payment buttons.
|
||||||
|
*
|
||||||
|
* @param {Function} refresh - Callback responsible to re-render the payment button.
|
||||||
|
*/
|
||||||
|
export function setupButtonEvents(refresh) {
|
||||||
|
const miniCartInitDelay = 1000;
|
||||||
|
const debouncedRefresh = debounce(refresh, 50);
|
||||||
|
|
||||||
|
// Listen for our custom refresh event.
|
||||||
|
document.addEventListener(REFRESH_BUTTON_EVENT, debouncedRefresh);
|
||||||
|
|
||||||
|
// Listen for cart and checkout update events.
|
||||||
|
document.body.addEventListener('updated_cart_totals', debouncedRefresh);
|
||||||
|
document.body.addEventListener('updated_checkout', debouncedRefresh);
|
||||||
|
|
||||||
|
// Use setTimeout for fragment events to avoid unnecessary refresh on initial render.
|
||||||
|
setTimeout(() => {
|
||||||
|
document.body.addEventListener('wc_fragments_loaded', debouncedRefresh);
|
||||||
|
document.body.addEventListener('wc_fragments_refreshed', debouncedRefresh);
|
||||||
|
}, miniCartInitDelay);
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
import { refreshButtons } from './ButtonRefreshHelper';
|
||||||
|
|
||||||
|
const DEFAULT_TRIGGER_ELEMENT_SELECTOR = '.woocommerce-checkout-payment';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The MultistepCheckoutHelper class ensures the initialization of payment buttons
|
||||||
|
* on websites using a multistep checkout plugin. These plugins usually hide the
|
||||||
|
* payment button on page load up and reveal it later using JS. During the
|
||||||
|
* invisibility period of wrappers, some payment buttons fail to initialize,
|
||||||
|
* so we wait for the payment element to be visible.
|
||||||
|
*
|
||||||
|
* @property {HTMLElement} form - Checkout form element.
|
||||||
|
* @property {HTMLElement} triggerElement - Element, which visibility we need to detect.
|
||||||
|
* @property {boolean} isVisible - Whether the triggerElement is visible.
|
||||||
|
*/
|
||||||
|
class MultistepCheckoutHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selector that defines the HTML element we are waiting to become visible.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
#triggerElementSelector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interval (in milliseconds) in which the visibility of the trigger element is checked.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
#intervalTime = 150;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The interval ID returned by the setInterval() method.
|
||||||
|
* @type {number|false}
|
||||||
|
*/
|
||||||
|
#intervalId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selector passed to the constructor that identifies the checkout form
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
#formSelector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} formSelector - Selector of the checkout form
|
||||||
|
* @param {string} triggerElementSelector - Optional. Selector of the dependant element.
|
||||||
|
*/
|
||||||
|
constructor(formSelector, triggerElementSelector = '') {
|
||||||
|
this.#formSelector = formSelector;
|
||||||
|
this.#triggerElementSelector = triggerElementSelector || DEFAULT_TRIGGER_ELEMENT_SELECTOR;
|
||||||
|
this.#intervalId = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start the visibility checker after a brief delay. This allows eventual multistep plugins to
|
||||||
|
dynamically prepare the checkout page, so we can decide whether this helper is needed.
|
||||||
|
*/
|
||||||
|
setTimeout(() => {
|
||||||
|
if (this.form && !this.isVisible) {
|
||||||
|
this.start();
|
||||||
|
}
|
||||||
|
}, 250);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The checkout form element.
|
||||||
|
* @returns {Element|null} - Form element or null.
|
||||||
|
*/
|
||||||
|
get form() {
|
||||||
|
return document.querySelector(this.#formSelector);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The element which must be visible before payment buttons should be initialized.
|
||||||
|
* @returns {Element|null} - Trigger element or null.
|
||||||
|
*/
|
||||||
|
get triggerElement() {
|
||||||
|
return this.form?.querySelector(this.#triggerElementSelector);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the visibility of the payment button wrapper.
|
||||||
|
* @returns {boolean} - returns boolean value on the basis of visibility of element.
|
||||||
|
*/
|
||||||
|
get isVisible() {
|
||||||
|
const box = this.triggerElement?.getBoundingClientRect();
|
||||||
|
|
||||||
|
return !!(box && box.width && box.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the observation of the DOM, initiates monitoring the checkout form.
|
||||||
|
* To ensure multiple calls to start don't create multiple intervals, we first call stop.
|
||||||
|
*/
|
||||||
|
start() {
|
||||||
|
this.stop();
|
||||||
|
this.#intervalId = setInterval(() => this.checkElement(), this.#intervalTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the observation of the checkout form.
|
||||||
|
* Multiple calls to stop are safe as clearInterval doesn't throw if provided ID doesn't exist.
|
||||||
|
*/
|
||||||
|
stop() {
|
||||||
|
if (this.#intervalId) {
|
||||||
|
clearInterval(this.#intervalId);
|
||||||
|
this.#intervalId = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the trigger element is visible.
|
||||||
|
* If visible, it initialises the payment buttons and stops the observation.
|
||||||
|
*/
|
||||||
|
checkElement() {
|
||||||
|
if (this.isVisible) {
|
||||||
|
refreshButtons();
|
||||||
|
this.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MultistepCheckoutHelper;
|
|
@ -16,6 +16,7 @@ use WooCommerce\PayPalCommerce\Button\Helper\CartProductsHelper;
|
||||||
use WooCommerce\PayPalCommerce\Button\Helper\CheckoutFormSaver;
|
use WooCommerce\PayPalCommerce\Button\Helper\CheckoutFormSaver;
|
||||||
use WooCommerce\PayPalCommerce\Button\Endpoint\SaveCheckoutFormEndpoint;
|
use WooCommerce\PayPalCommerce\Button\Endpoint\SaveCheckoutFormEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
|
use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
|
||||||
|
use WooCommerce\PayPalCommerce\Button\Helper\DisabledFundingSources;
|
||||||
use WooCommerce\PayPalCommerce\Button\Helper\WooCommerceOrderCreator;
|
use WooCommerce\PayPalCommerce\Button\Helper\WooCommerceOrderCreator;
|
||||||
use WooCommerce\PayPalCommerce\Button\Validation\CheckoutFormValidator;
|
use WooCommerce\PayPalCommerce\Button\Validation\CheckoutFormValidator;
|
||||||
use WooCommerce\PayPalCommerce\Button\Endpoint\ValidateCheckoutEndpoint;
|
use WooCommerce\PayPalCommerce\Button\Endpoint\ValidateCheckoutEndpoint;
|
||||||
|
@ -149,7 +150,8 @@ return array(
|
||||||
$container->get( 'vaulting.vault-v3-enabled' ),
|
$container->get( 'vaulting.vault-v3-enabled' ),
|
||||||
$container->get( 'api.endpoint.payment-tokens' ),
|
$container->get( 'api.endpoint.payment-tokens' ),
|
||||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||||
$container->get( 'button.handle-shipping-in-paypal' )
|
$container->get( 'button.handle-shipping-in-paypal' ),
|
||||||
|
$container->get( 'button.helper.disabled-funding-sources' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'button.url' => static function ( ContainerInterface $container ): string {
|
'button.url' => static function ( ContainerInterface $container ): string {
|
||||||
|
@ -306,12 +308,10 @@ return array(
|
||||||
$container->get( 'woocommerce.logger.woocommerce' )
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
'button.helper.cart-products' => static function ( ContainerInterface $container ): CartProductsHelper {
|
'button.helper.cart-products' => static function ( ContainerInterface $container ): CartProductsHelper {
|
||||||
$data_store = \WC_Data_Store::load( 'product' );
|
$data_store = \WC_Data_Store::load( 'product' );
|
||||||
return new CartProductsHelper( $data_store );
|
return new CartProductsHelper( $data_store );
|
||||||
},
|
},
|
||||||
|
|
||||||
'button.helper.three-d-secure' => static function ( ContainerInterface $container ): ThreeDSecure {
|
'button.helper.three-d-secure' => static function ( ContainerInterface $container ): ThreeDSecure {
|
||||||
return new ThreeDSecure(
|
return new ThreeDSecure(
|
||||||
$container->get( 'api.factory.card-authentication-result-factory' ),
|
$container->get( 'api.factory.card-authentication-result-factory' ),
|
||||||
|
@ -323,7 +323,12 @@ return array(
|
||||||
$container->get( 'api.shop.country' )
|
$container->get( 'api.shop.country' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
'button.helper.disabled-funding-sources' => static function ( ContainerInterface $container ): DisabledFundingSources {
|
||||||
|
return new DisabledFundingSources(
|
||||||
|
$container->get( 'wcgateway.settings' ),
|
||||||
|
$container->get( 'wcgateway.all-funding-sources' )
|
||||||
|
);
|
||||||
|
},
|
||||||
'button.is-logged-in' => static function ( ContainerInterface $container ): bool {
|
'button.is-logged-in' => static function ( ContainerInterface $container ): bool {
|
||||||
return is_user_logged_in();
|
return is_user_logged_in();
|
||||||
},
|
},
|
||||||
|
|
|
@ -32,6 +32,7 @@ use WooCommerce\PayPalCommerce\Button\Endpoint\SimulateCartEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\Button\Endpoint\StartPayPalVaultingEndpoint;
|
use WooCommerce\PayPalCommerce\Button\Endpoint\StartPayPalVaultingEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\Button\Endpoint\ValidateCheckoutEndpoint;
|
use WooCommerce\PayPalCommerce\Button\Endpoint\ValidateCheckoutEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
|
use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
|
||||||
|
use WooCommerce\PayPalCommerce\Button\Helper\DisabledFundingSources;
|
||||||
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
||||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||||
use WooCommerce\PayPalCommerce\PayLaterBlock\PayLaterBlockModule;
|
use WooCommerce\PayPalCommerce\PayLaterBlock\PayLaterBlockModule;
|
||||||
|
@ -225,6 +226,13 @@ class SmartButton implements SmartButtonInterface {
|
||||||
*/
|
*/
|
||||||
private $should_handle_shipping_in_paypal;
|
private $should_handle_shipping_in_paypal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of funding sources to be disabled.
|
||||||
|
*
|
||||||
|
* @var DisabledFundingSources
|
||||||
|
*/
|
||||||
|
private $disabled_funding_sources;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SmartButton constructor.
|
* SmartButton constructor.
|
||||||
*
|
*
|
||||||
|
@ -251,6 +259,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
* @param PaymentTokensEndpoint $payment_tokens_endpoint Payment tokens endpoint.
|
* @param PaymentTokensEndpoint $payment_tokens_endpoint Payment tokens endpoint.
|
||||||
* @param LoggerInterface $logger The logger.
|
* @param LoggerInterface $logger The logger.
|
||||||
* @param bool $should_handle_shipping_in_paypal Whether the shipping should be handled in PayPal.
|
* @param bool $should_handle_shipping_in_paypal Whether the shipping should be handled in PayPal.
|
||||||
|
* @param DisabledFundingSources $disabled_funding_sources List of funding sources to be disabled.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $module_url,
|
string $module_url,
|
||||||
|
@ -275,7 +284,8 @@ class SmartButton implements SmartButtonInterface {
|
||||||
bool $vault_v3_enabled,
|
bool $vault_v3_enabled,
|
||||||
PaymentTokensEndpoint $payment_tokens_endpoint,
|
PaymentTokensEndpoint $payment_tokens_endpoint,
|
||||||
LoggerInterface $logger,
|
LoggerInterface $logger,
|
||||||
bool $should_handle_shipping_in_paypal
|
bool $should_handle_shipping_in_paypal,
|
||||||
|
DisabledFundingSources $disabled_funding_sources
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$this->module_url = $module_url;
|
$this->module_url = $module_url;
|
||||||
|
@ -301,6 +311,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->payment_tokens_endpoint = $payment_tokens_endpoint;
|
$this->payment_tokens_endpoint = $payment_tokens_endpoint;
|
||||||
$this->should_handle_shipping_in_paypal = $should_handle_shipping_in_paypal;
|
$this->should_handle_shipping_in_paypal = $should_handle_shipping_in_paypal;
|
||||||
|
$this->disabled_funding_sources = $disabled_funding_sources;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1400,54 +1411,18 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$disable_funding = $this->settings->has( 'disable_funding' )
|
$disabled_funding_sources = $this->disabled_funding_sources->sources( $context );
|
||||||
? $this->settings->get( 'disable_funding' )
|
|
||||||
: array();
|
|
||||||
|
|
||||||
if ( ! is_checkout() ) {
|
|
||||||
$disable_funding[] = 'card';
|
|
||||||
}
|
|
||||||
|
|
||||||
$is_dcc_enabled = $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' );
|
|
||||||
|
|
||||||
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
|
|
||||||
$is_separate_card_enabled = isset( $available_gateways[ CardButtonGateway::ID ] );
|
|
||||||
|
|
||||||
if ( is_checkout() && ( $is_dcc_enabled || $is_separate_card_enabled ) ) {
|
|
||||||
$key = array_search( 'card', $disable_funding, true );
|
|
||||||
if ( false !== $key ) {
|
|
||||||
unset( $disable_funding[ $key ] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( in_array( $context, array( 'checkout-block', 'cart-block' ), true ) ) {
|
|
||||||
$disable_funding = array_merge(
|
|
||||||
$disable_funding,
|
|
||||||
array_diff(
|
|
||||||
array_keys( $this->all_funding_sources ),
|
|
||||||
array( 'venmo', 'paylater', 'paypal', 'card' )
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $this->is_free_trial_cart() ) {
|
|
||||||
$all_sources = array_keys( $this->all_funding_sources );
|
|
||||||
if ( $is_dcc_enabled || $is_separate_card_enabled ) {
|
|
||||||
$all_sources = array_diff( $all_sources, array( 'card' ) );
|
|
||||||
}
|
|
||||||
$disable_funding = $all_sources;
|
|
||||||
}
|
|
||||||
|
|
||||||
$enable_funding = array( 'venmo' );
|
$enable_funding = array( 'venmo' );
|
||||||
|
|
||||||
if ( $this->is_pay_later_button_enabled_for_location( $context ) ) {
|
if ( $this->is_pay_later_button_enabled_for_location( $context ) ) {
|
||||||
$enable_funding[] = 'paylater';
|
$enable_funding[] = 'paylater';
|
||||||
} else {
|
} else {
|
||||||
$disable_funding[] = 'paylater';
|
$disabled_funding_sources[] = 'paylater';
|
||||||
}
|
}
|
||||||
|
|
||||||
$disable_funding = array_filter(
|
$disabled_funding_sources = array_filter(
|
||||||
$disable_funding,
|
$disabled_funding_sources,
|
||||||
/**
|
/**
|
||||||
* Make sure paypal is not sent in disable funding.
|
* Make sure paypal is not sent in disable funding.
|
||||||
*
|
*
|
||||||
|
@ -1460,8 +1435,8 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( count( $disable_funding ) > 0 ) {
|
if ( count( $disabled_funding_sources ) > 0 ) {
|
||||||
$params['disable-funding'] = implode( ',', array_unique( $disable_funding ) );
|
$params['disable-funding'] = implode( ',', array_unique( $disabled_funding_sources ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $this->is_free_trial_cart() ) {
|
if ( $this->is_free_trial_cart() ) {
|
||||||
|
|
109
modules/ppcp-button/src/Helper/DisabledFundingSources.php
Normal file
109
modules/ppcp-button/src/Helper/DisabledFundingSources.php
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Creates the list of disabled funding sources.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\Button\Helper
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\Button\Helper;
|
||||||
|
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
|
use WooCommerce\PayPalCommerce\WcSubscriptions\FreeTrialHandlerTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DisabledFundingSources
|
||||||
|
*/
|
||||||
|
class DisabledFundingSources {
|
||||||
|
|
||||||
|
use FreeTrialHandlerTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The settings.
|
||||||
|
*
|
||||||
|
* @var Settings
|
||||||
|
*/
|
||||||
|
private $settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All existing funding sources.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $all_funding_sources;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DisabledFundingSources constructor.
|
||||||
|
*
|
||||||
|
* @param Settings $settings The settings.
|
||||||
|
* @param array $all_funding_sources All existing funding sources.
|
||||||
|
*/
|
||||||
|
public function __construct( Settings $settings, array $all_funding_sources ) {
|
||||||
|
$this->settings = $settings;
|
||||||
|
$this->all_funding_sources = $all_funding_sources;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list of funding sources to be disabled.
|
||||||
|
*
|
||||||
|
* @param string $context The context.
|
||||||
|
* @return array|int[]|mixed|string[]
|
||||||
|
* @throws NotFoundException When the setting is not found.
|
||||||
|
*/
|
||||||
|
public function sources( string $context ) {
|
||||||
|
$disable_funding = $this->settings->has( 'disable_funding' )
|
||||||
|
? $this->settings->get( 'disable_funding' )
|
||||||
|
: array();
|
||||||
|
|
||||||
|
$is_dcc_enabled = $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' );
|
||||||
|
|
||||||
|
if (
|
||||||
|
! is_checkout()
|
||||||
|
|| ( $is_dcc_enabled && in_array( $context, array( 'checkout-block', 'cart-block' ), true ) )
|
||||||
|
) {
|
||||||
|
$disable_funding[] = 'card';
|
||||||
|
}
|
||||||
|
|
||||||
|
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
|
||||||
|
$is_separate_card_enabled = isset( $available_gateways[ CardButtonGateway::ID ] );
|
||||||
|
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
is_checkout()
|
||||||
|
&& ! in_array( $context, array( 'checkout-block', 'cart-block' ), true )
|
||||||
|
)
|
||||||
|
&& (
|
||||||
|
$is_dcc_enabled
|
||||||
|
|| $is_separate_card_enabled
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
$key = array_search( 'card', $disable_funding, true );
|
||||||
|
if ( false !== $key ) {
|
||||||
|
unset( $disable_funding[ $key ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( in_array( $context, array( 'checkout-block', 'cart-block' ), true ) ) {
|
||||||
|
$disable_funding = array_merge(
|
||||||
|
$disable_funding,
|
||||||
|
array_diff(
|
||||||
|
array_keys( $this->all_funding_sources ),
|
||||||
|
array( 'venmo', 'paylater', 'paypal', 'card' )
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $this->is_free_trial_cart() ) {
|
||||||
|
$all_sources = array_keys( $this->all_funding_sources );
|
||||||
|
if ( $is_dcc_enabled || $is_separate_card_enabled ) {
|
||||||
|
$all_sources = array_diff( $all_sources, array( 'card' ) );
|
||||||
|
}
|
||||||
|
$disable_funding = $all_sources;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $disable_funding;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,11 @@
|
||||||
.ppcp-button-googlepay {
|
.ppcp-button-googlepay {
|
||||||
min-height: 40px;
|
min-height: 40px;
|
||||||
|
|
||||||
|
.gpay-card-info-container,
|
||||||
|
.gpay-button {
|
||||||
|
outline-offset: -1px;
|
||||||
|
border-radius: var(--apm-button-border-radius);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.wp-block-woocommerce-checkout, .wp-block-woocommerce-cart {
|
.wp-block-woocommerce-checkout, .wp-block-woocommerce-cart {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {loadCustomScript} from "@paypal/paypal-js";
|
import {loadCustomScript} from "@paypal/paypal-js";
|
||||||
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
|
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
|
||||||
import GooglepayManager from "./GooglepayManager";
|
import GooglepayManager from "./GooglepayManager";
|
||||||
|
import {setupButtonEvents} from '../../../ppcp-button/resources/js/modules/Helper/ButtonRefreshHelper';
|
||||||
|
|
||||||
(function ({
|
(function ({
|
||||||
buttonConfig,
|
buttonConfig,
|
||||||
|
@ -15,21 +16,12 @@ import GooglepayManager from "./GooglepayManager";
|
||||||
manager.init();
|
manager.init();
|
||||||
};
|
};
|
||||||
|
|
||||||
jQuery(document.body).on('updated_cart_totals updated_checkout', () => {
|
setupButtonEvents(function() {
|
||||||
if (manager) {
|
if (manager) {
|
||||||
manager.reinit();
|
manager.reinit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Use set timeout as it's unnecessary to refresh upon Minicart initial render.
|
|
||||||
setTimeout(() => {
|
|
||||||
jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', () => {
|
|
||||||
if (manager) {
|
|
||||||
manager.reinit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
'DOMContentLoaded',
|
'DOMContentLoaded',
|
||||||
() => {
|
() => {
|
||||||
|
|
|
@ -57,7 +57,8 @@ return array(
|
||||||
$container->get( 'order-tracking.allowed-shipping-statuses' ),
|
$container->get( 'order-tracking.allowed-shipping-statuses' ),
|
||||||
$container->get( 'order-tracking.available-carriers' ),
|
$container->get( 'order-tracking.available-carriers' ),
|
||||||
$container->get( 'order-tracking.endpoint.controller' ),
|
$container->get( 'order-tracking.endpoint.controller' ),
|
||||||
$container->get( 'order-tracking.should-use-second-version-of-api' )
|
$container->get( 'order-tracking.should-use-second-version-of-api' ),
|
||||||
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'order-tracking.allowed-shipping-statuses' => static function ( ContainerInterface $container ): array {
|
'order-tracking.allowed-shipping-statuses' => static function ( ContainerInterface $container ): array {
|
||||||
|
|
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
||||||
namespace WooCommerce\PayPalCommerce\OrderTracking;
|
namespace WooCommerce\PayPalCommerce\OrderTracking;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use WC_Order;
|
use WC_Order;
|
||||||
use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint;
|
use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentInterface;
|
use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentInterface;
|
||||||
|
@ -54,6 +55,13 @@ class MetaBoxRenderer {
|
||||||
*/
|
*/
|
||||||
protected $should_use_new_api;
|
protected $should_use_new_api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The logger.
|
||||||
|
*
|
||||||
|
* @var LoggerInterface
|
||||||
|
*/
|
||||||
|
protected $logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MetaBoxRenderer constructor.
|
* MetaBoxRenderer constructor.
|
||||||
*
|
*
|
||||||
|
@ -62,18 +70,21 @@ class MetaBoxRenderer {
|
||||||
* @psalm-param Carriers $carriers
|
* @psalm-param Carriers $carriers
|
||||||
* @param OrderTrackingEndpoint $order_tracking_endpoint The order tracking endpoint.
|
* @param OrderTrackingEndpoint $order_tracking_endpoint The order tracking endpoint.
|
||||||
* @param bool $should_use_new_api Whether new API should be used.
|
* @param bool $should_use_new_api Whether new API should be used.
|
||||||
|
* @param LoggerInterface $logger The logger.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
array $allowed_statuses,
|
array $allowed_statuses,
|
||||||
array $carriers,
|
array $carriers,
|
||||||
OrderTrackingEndpoint $order_tracking_endpoint,
|
OrderTrackingEndpoint $order_tracking_endpoint,
|
||||||
bool $should_use_new_api
|
bool $should_use_new_api,
|
||||||
|
LoggerInterface $logger
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$this->allowed_statuses = $allowed_statuses;
|
$this->allowed_statuses = $allowed_statuses;
|
||||||
$this->carriers = $carriers;
|
$this->carriers = $carriers;
|
||||||
$this->order_tracking_endpoint = $order_tracking_endpoint;
|
$this->order_tracking_endpoint = $order_tracking_endpoint;
|
||||||
$this->should_use_new_api = $should_use_new_api;
|
$this->should_use_new_api = $should_use_new_api;
|
||||||
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,12 +97,17 @@ class MetaBoxRenderer {
|
||||||
$order_items = $wc_order->get_items();
|
$order_items = $wc_order->get_items();
|
||||||
$order_item_count = ! empty( $order_items ) ? count( $order_items ) : 0;
|
$order_item_count = ! empty( $order_items ) ? count( $order_items ) : 0;
|
||||||
|
|
||||||
/**
|
try {
|
||||||
* The shipments
|
/**
|
||||||
*
|
* The shipments
|
||||||
* @var ShipmentInterface[] $shipments
|
*
|
||||||
*/
|
* @var ShipmentInterface[] $shipments
|
||||||
$shipments = $this->order_tracking_endpoint->list_tracking_information( $wc_order->get_id() ) ?? array();
|
*/
|
||||||
|
$shipments = $this->order_tracking_endpoint->list_tracking_information( $wc_order->get_id() ) ?? array();
|
||||||
|
} catch ( Exception $exception ) {
|
||||||
|
$this->logger->log( 'warning', $exception->getMessage() );
|
||||||
|
return;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<div class="ppcp-tracking-columns-wrapper">
|
<div class="ppcp-tracking-columns-wrapper">
|
||||||
<div class="ppcp-tracking-column">
|
<div class="ppcp-tracking-column">
|
||||||
|
|
|
@ -179,7 +179,7 @@ If you encounter issues with the PayPal buttons not appearing after an update, p
|
||||||
|
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
= 2.8.1 - xxxx-xx-xx =
|
= 2.8.1 - 2024-07-01 =
|
||||||
* Fix - Don't render tracking metabox if PayPal order does not belong to connected merchant #2360
|
* Fix - Don't render tracking metabox if PayPal order does not belong to connected merchant #2360
|
||||||
* Fix - Fatal error when the ppcp-paylater-configurator module is disabled via code snippet #2327
|
* Fix - Fatal error when the ppcp-paylater-configurator module is disabled via code snippet #2327
|
||||||
* Fix - Apple Pay & Google Pay buttons no longer visible in Standard Payments button previews after moving the configuration to Advanced Card Processing tab #2325
|
* Fix - Apple Pay & Google Pay buttons no longer visible in Standard Payments button previews after moving the configuration to Advanced Card Processing tab #2325
|
||||||
|
|
103
tests/PHPUnit/Button/Helper/DisabledFundingSourcesTest.php
Normal file
103
tests/PHPUnit/Button/Helper/DisabledFundingSourcesTest.php
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\Button\Helper;
|
||||||
|
|
||||||
|
use Mockery;
|
||||||
|
use WC_Payment_Gateways;
|
||||||
|
use WooCommerce;
|
||||||
|
use WooCommerce\PayPalCommerce\TestCase;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
|
use function Brain\Monkey\Functions\when;
|
||||||
|
|
||||||
|
class DisabledFundingSourcesTest extends TestCase
|
||||||
|
{
|
||||||
|
private $settings;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->settings = Mockery::mock(Settings::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Block checkout page configured in WC "Checkout page" setting,
|
||||||
|
* `is_checkout` returns true when visiting the block checkout page.
|
||||||
|
*/
|
||||||
|
public function test_is_checkout_true_add_card_when_checkout_block_context()
|
||||||
|
{
|
||||||
|
$sut = new DisabledFundingSources($this->settings, []);
|
||||||
|
|
||||||
|
$this->setExpectations();
|
||||||
|
$this->setWcPaymentGateways();
|
||||||
|
|
||||||
|
when('is_checkout')->justReturn(true);
|
||||||
|
|
||||||
|
$this->assertEquals(['card'], $sut->sources('checkout-block'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classic checkout page configured in WC "Checkout page" setting,
|
||||||
|
* `is_checkout` returns false when visiting the block checkout page.
|
||||||
|
*/
|
||||||
|
public function test_is_checkout_false_add_card_when_checkout_context()
|
||||||
|
{
|
||||||
|
$sut = new DisabledFundingSources($this->settings, []);
|
||||||
|
|
||||||
|
$this->setExpectations();
|
||||||
|
$this->setWcPaymentGateways();
|
||||||
|
|
||||||
|
when('is_checkout')->justReturn(false);
|
||||||
|
|
||||||
|
$this->assertEquals(['card'], $sut->sources('checkout'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_is_checkout_true_add_allowed_sources_when_checkout_block_context()
|
||||||
|
{
|
||||||
|
$sut = new DisabledFundingSources($this->settings, [
|
||||||
|
'card' => 'Credit or debit cards',
|
||||||
|
'paypal' => 'PayPal',
|
||||||
|
'foo' => 'Bar',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->setExpectations();
|
||||||
|
$this->setWcPaymentGateways();
|
||||||
|
|
||||||
|
when('is_checkout')->justReturn(true);
|
||||||
|
|
||||||
|
$this->assertEquals(['card', 'foo'], $sut->sources('checkout-block'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setExpectations(
|
||||||
|
array $disabledFundings = [],
|
||||||
|
bool $dccEnambled = true
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$this->settings->shouldReceive('has')
|
||||||
|
->with('disable_funding')
|
||||||
|
->andReturn(true);
|
||||||
|
|
||||||
|
$this->settings->shouldReceive('get')
|
||||||
|
->with('disable_funding')
|
||||||
|
->andReturn($disabledFundings);
|
||||||
|
|
||||||
|
$this->settings->shouldReceive('has')
|
||||||
|
->with('dcc_enabled')
|
||||||
|
->andReturn(true);
|
||||||
|
|
||||||
|
$this->settings->shouldReceive('get')
|
||||||
|
->with('dcc_enabled')
|
||||||
|
->andReturn($dccEnambled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setWcPaymentGateways(array $paymentGateways = []): void
|
||||||
|
{
|
||||||
|
$woocommerce = Mockery::mock(WooCommerce::class);
|
||||||
|
$payment_gateways = Mockery::mock(WC_Payment_Gateways::class);
|
||||||
|
when('WC')->justReturn($woocommerce);
|
||||||
|
$woocommerce->payment_gateways = $payment_gateways;
|
||||||
|
$payment_gateways->shouldReceive('get_available_payment_gateways')
|
||||||
|
->andReturn($paymentGateways);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue