mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Refactor selected payment gateway checking
This commit is contained in:
parent
3afb73d34c
commit
7050c8231e
2 changed files with 30 additions and 14 deletions
|
@ -1,6 +1,11 @@
|
|||
import ErrorHandler from '../ErrorHandler';
|
||||
import CheckoutActionHandler from '../ActionHandler/CheckoutActionHandler';
|
||||
import { setVisible } from '../Helper/Hiding';
|
||||
import {
|
||||
getCurrentPaymentMethod,
|
||||
isSavedCardSelected, ORDER_BUTTON_SELECTOR,
|
||||
PaymentMethods
|
||||
} from "../Helper/CheckoutMethodState";
|
||||
|
||||
class CheckoutBootstap {
|
||||
constructor(gateway, renderer, messages, spinner) {
|
||||
|
@ -9,7 +14,7 @@ class CheckoutBootstap {
|
|||
this.messages = messages;
|
||||
this.spinner = spinner;
|
||||
|
||||
this.standardOrderButtonSelector = '#place_order';
|
||||
this.standardOrderButtonSelector = ORDER_BUTTON_SELECTOR;
|
||||
|
||||
this.buttonChangeObserver = new MutationObserver((el) => {
|
||||
this.updateUi();
|
||||
|
@ -76,10 +81,10 @@ class CheckoutBootstap {
|
|||
}
|
||||
|
||||
updateUi() {
|
||||
const currentPaymentMethod = this.currentPaymentMethod();
|
||||
const isPaypal = currentPaymentMethod === 'ppcp-gateway';
|
||||
const isCard = currentPaymentMethod === 'ppcp-credit-card-gateway';
|
||||
const isSavedCard = isCard && this.isSavedCardSelected();
|
||||
const currentPaymentMethod = getCurrentPaymentMethod();
|
||||
const isPaypal = currentPaymentMethod === PaymentMethods.PAYPAL;
|
||||
const isCard = currentPaymentMethod === PaymentMethods.CARDS;
|
||||
const isSavedCard = isCard && isSavedCardSelected();
|
||||
const isNotOurGateway = !isPaypal && !isCard;
|
||||
|
||||
setVisible(this.standardOrderButtonSelector, isNotOurGateway || isSavedCard, true);
|
||||
|
@ -125,15 +130,6 @@ class CheckoutBootstap {
|
|||
jQuery('#ppcp-credit-card-vault').attr("disabled", false)
|
||||
this.renderer.enableCreditCardFields()
|
||||
}
|
||||
|
||||
currentPaymentMethod() {
|
||||
return jQuery('input[name="payment_method"]:checked').val();
|
||||
}
|
||||
|
||||
isSavedCardSelected() {
|
||||
const savedCardList = jQuery('#saved-credit-card');
|
||||
return savedCardList.length && savedCardList.val() !== '';
|
||||
}
|
||||
}
|
||||
|
||||
export default CheckoutBootstap
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
export const PaymentMethods = {
|
||||
PAYPAL: 'ppcp-gateway',
|
||||
CARDS: 'ppcp-credit-card-gateway',
|
||||
};
|
||||
|
||||
export const ORDER_BUTTON_SELECTOR = '#place_order';
|
||||
|
||||
export const getCurrentPaymentMethod = () => {
|
||||
const el = document.querySelector('input[name="payment_method"]:checked');
|
||||
if (!el) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return el.value;
|
||||
};
|
||||
|
||||
export const isSavedCardSelected = () => {
|
||||
const savedCardList = document.querySelector('#saved-credit-card');
|
||||
return savedCardList && savedCardList.value !== '';
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue