mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Disable when express buttons
This commit is contained in:
parent
a64bd0b762
commit
e956115da8
1 changed files with 43 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
||||||
import ContextHandlerFactory from "./Context/ContextHandlerFactory";
|
import ContextHandlerFactory from "./Context/ContextHandlerFactory";
|
||||||
import {createAppleErrors} from "./Helper/applePayError";
|
import {createAppleErrors} from "./Helper/applePayError";
|
||||||
|
import {setVisible} from '../../../ppcp-button/resources/js/modules/Helper/Hiding';
|
||||||
|
import {setEnabled} from '../../../ppcp-button/resources/js/modules/Helper/ButtonDisabler';
|
||||||
|
|
||||||
class ApplepayButton {
|
class ApplepayButton {
|
||||||
|
|
||||||
|
@ -33,6 +35,7 @@ class ApplepayButton {
|
||||||
if (this.isInitialized) {
|
if (this.isInitialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.initEventHandlers();
|
||||||
this.isInitialized = true;
|
this.isInitialized = true;
|
||||||
this.applePayConfig = config;
|
this.applePayConfig = config;
|
||||||
const isEligible = this.applePayConfig.isEligible;
|
const isEligible = this.applePayConfig.isEligible;
|
||||||
|
@ -51,12 +54,48 @@ class ApplepayButton {
|
||||||
async fetchTransactionInfo() {
|
async fetchTransactionInfo() {
|
||||||
this.transactionInfo = await this.contextHandler.transactionInfo();
|
this.transactionInfo = await this.contextHandler.transactionInfo();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Returns configurations relative to this button context.
|
||||||
|
*/
|
||||||
|
contextConfig() {
|
||||||
|
let config = {
|
||||||
|
wrapper: this.buttonConfig.button.wrapper,
|
||||||
|
ppcpStyle: this.ppcpConfig.button.style,
|
||||||
|
//buttonStyle: this.buttonConfig.button.style,
|
||||||
|
ppcpButtonWrapper: this.ppcpConfig.button.wrapper
|
||||||
|
}
|
||||||
|
|
||||||
buildReadyToPayRequest(allowedPaymentMethods, baseRequest) {
|
if (this.context === 'mini-cart') {
|
||||||
return Object.assign({}, baseRequest, {
|
config.wrapper = this.buttonConfig.button.mini_cart_wrapper;
|
||||||
allowedPaymentMethods: allowedPaymentMethods,
|
config.ppcpStyle = this.ppcpConfig.button.mini_cart_style;
|
||||||
});
|
config.buttonStyle = this.buttonConfig.button.mini_cart_style;
|
||||||
|
config.ppcpButtonWrapper = this.ppcpConfig.button.mini_cart_wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (['cart-block', 'checkout-block'].indexOf(this.context) !== -1) {
|
||||||
|
config.ppcpButtonWrapper = '#express-payment-method-ppcp-gateway';
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
initEventHandlers() {
|
||||||
|
const { wrapper, ppcpButtonWrapper } = this.contextConfig();
|
||||||
|
|
||||||
|
const syncButtonVisibility = () => {
|
||||||
|
const $ppcpButtonWrapper = jQuery(ppcpButtonWrapper);
|
||||||
|
setVisible(wrapper, $ppcpButtonWrapper.is(':visible'));
|
||||||
|
setEnabled(wrapper, !$ppcpButtonWrapper.hasClass('ppcp-disabled'));
|
||||||
|
}
|
||||||
|
|
||||||
|
jQuery(document).on('ppcp-shown ppcp-hidden ppcp-enabled ppcp-disabled', (ev, data) => {
|
||||||
|
if (jQuery(data.selector).is(ppcpButtonWrapper)) {
|
||||||
|
syncButtonVisibility();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
syncButtonVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
applePaySession(paymentRequest) {
|
applePaySession(paymentRequest) {
|
||||||
const session = new ApplePaySession(4, paymentRequest)
|
const session = new ApplePaySession(4, paymentRequest)
|
||||||
session.begin()
|
session.begin()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue