Skip to content

Commit

Permalink
add 471 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Dec 4, 2024
1 parent f146aec commit 536044f
Showing 1 changed file with 57 additions and 63 deletions.
120 changes: 57 additions & 63 deletions resources/js/mollieBlockIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,71 @@ import molliePaymentMethod from './blocks/molliePaymentMethod'
import ApplePayButtonComponent from './blocks/ApplePayButtonComponent'

(
function ({ mollieBlockData, wc, _, jQuery}) {
function ({mollieBlockData, wc, _, jQuery}) {
if (_.isEmpty(mollieBlockData)) {
return;
}
const {registerPaymentMethod} = wc.wcBlocksRegistry;
const {checkoutData, defaultFields} = wc.wcSettings.allSettings;
let billing_address, shipping_address;
if (checkoutData) {
({billing_address, shipping_address} = checkoutData);
} else {
billing_address = {};
shipping_address = {};
}
const {ajaxUrl, filters, gatewayData, availableGateways} = mollieBlockData.gatewayData;
const {useEffect} = wp.element;
const isAppleSession = typeof window.ApplePaySession === "function"
const isBlockEditor = !!wp?.blockEditor;

window.onload = (event) => {
const { registerPaymentMethod } = wc.wcBlocksRegistry;
const { checkoutData, defaultFields } = wc.wcSettings.allSettings;
let billing_address, shipping_address;

if (checkoutData) {
({ billing_address, shipping_address } = checkoutData);
} else {
billing_address = {};
shipping_address = {};
}
const { ajaxUrl, filters, gatewayData, availableGateways } = mollieBlockData.gatewayData;
const {useEffect} = wp.element;
const isAppleSession = typeof window.ApplePaySession === "function"
const isBlockEditor = !!wp?.blockEditor;

function getCompanyField() {
let shippingCompany = shipping_address.company ?? false;
let billingCompany = billing_address.company ?? false;
return shippingCompany ? shippingCompany : billingCompany;
}
function getCompanyField() {
let shippingCompany = shipping_address.company ?? false;
let billingCompany = billing_address.company ?? false;
return shippingCompany ? shippingCompany : billingCompany;
}

function getPhoneField()
{
const phoneFieldDataset = document.querySelector('[data-show-phone-field]');
if (!phoneFieldDataset) {
return true;
}
return phoneFieldDataset.dataset.showPhoneField !== "false"
function getPhoneField() {
const phoneFieldDataset = document.querySelector('[data-show-phone-field]');
if (!phoneFieldDataset) {
return true;
}
return phoneFieldDataset.dataset.showPhoneField !== "false"
}

const isCompanyFieldVisible = getCompanyField();
const companyNameString = defaultFields.company.label
const isPhoneFieldVisible = getPhoneField();
const phoneString = defaultFields.phone.label
let requiredFields = {
'companyNameString': companyNameString,
'phoneString': phoneString,
}
gatewayData.forEach(item => {
let register = () => registerPaymentMethod(molliePaymentMethod(useEffect, ajaxUrl, filters, gatewayData, availableGateways, item, jQuery, requiredFields, isCompanyFieldVisible, isPhoneFieldVisible));
if (item.name === 'mollie_wc_gateway_applepay' && !isBlockEditor) {
const {isExpressEnabled} = item;
if ((isAppleSession && window.ApplePaySession.canMakePayments())) {
register();
if (isExpressEnabled !== true) {
return;
}
const {registerExpressPaymentMethod} = wc.wcBlocksRegistry;
registerExpressPaymentMethod({
name: 'mollie_wc_gateway_applepay_express',
content: <ApplePayButtonComponent />,
edit: <ApplePayButtonComponent />,
ariaLabel: 'Apple Pay',
canMakePayment: () => true,
paymentMethodId: 'mollie_wc_gateway_applepay',
supports: {
features: ['products'],
},
})
const isCompanyFieldVisible = getCompanyField();
const companyNameString = defaultFields.company.label
const isPhoneFieldVisible = getPhoneField();
const phoneString = defaultFields.phone.label
let requiredFields = {
'companyNameString': companyNameString,
'phoneString': phoneString,
}
gatewayData.forEach(item => {
let register = () => registerPaymentMethod(molliePaymentMethod(useEffect, ajaxUrl, filters, gatewayData, availableGateways, item, jQuery, requiredFields, isCompanyFieldVisible, isPhoneFieldVisible));
if (item.name === 'mollie_wc_gateway_applepay' && !isBlockEditor) {
const {isExpressEnabled} = item;
if ((isAppleSession && window.ApplePaySession.canMakePayments())) {
register();
if (isExpressEnabled !== true) {
return;
}
return;
const {registerExpressPaymentMethod} = wc.wcBlocksRegistry;
registerExpressPaymentMethod({
name: 'mollie_wc_gateway_applepay_express',
content: <ApplePayButtonComponent/>,
edit: <ApplePayButtonComponent/>,
ariaLabel: 'Apple Pay',
canMakePayment: () => true,
paymentMethodId: 'mollie_wc_gateway_applepay',
supports: {
features: ['products'],
},
})
}
register();
});
};

return;
}
register();
});
}
)(window, wc)

0 comments on commit 536044f

Please sign in to comment.