From ee85c46f3ad2493c777c94134a596aa83737bb50 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 27 Aug 2025 12:57:42 +0200 Subject: [PATCH 01/65] Use only is_available from backend and clean --- resources/js/blocks/molliePaymentMethod.js | 118 ++------------------- resources/js/mollieBlockIndex.js | 5 +- src/Assets/MollieCheckoutBlocksSupport.php | 37 ------- 3 files changed, 10 insertions(+), 150 deletions(-) diff --git a/resources/js/blocks/molliePaymentMethod.js b/resources/js/blocks/molliePaymentMethod.js index 735754d5a..dc74dbfa6 100644 --- a/resources/js/blocks/molliePaymentMethod.js +++ b/resources/js/blocks/molliePaymentMethod.js @@ -1,70 +1,10 @@ -let cachedAvailableGateways = {}; - -function setAvailableGateways(country, currencyCode, data) { - cachedAvailableGateways = { - ...cachedAvailableGateways, - ...data - }; -} -function useMollieAvailableGateways(billing, currencyCode, cartTotal, filters, ajaxUrl) { - let country = billing.country; - const code = currencyCode; - const value = cartTotal; - if (!country) { - country = wcSettings?.baseLocation?.country; - } - - wp.element.useEffect(() => { - if (!country) return; - const currencyCode = code; - const cartTotal = value; - const currentFilterKey = currencyCode + "-" + country; - if (cachedAvailableGateways.hasOwnProperty(currentFilterKey)) { - return; - } - fetch( - ajaxUrl, - { - method: 'POST', - headers: { - "Content-Type": "application/x-www-form-urlencoded", - }, - body: new URLSearchParams({ - action: 'mollie_checkout_blocks_canmakepayment', - currency: currencyCode, - billingCountry: country, - cartTotal, - paymentLocale: filters.paymentLocale - }), - } - ).then(response => response.json()).then(data => { - setAvailableGateways(country, currencyCode, data.data); - const cartTotals = wp.data.select('wc/store/cart').getCartTotals(); - // Dispatch them again to trigger a re-render: - wp.data.dispatch('wc/store/cart').setCartData({...cartTotals}); - }); - }, [billing, currencyCode, filters.paymentLocale]); - - return cachedAvailableGateways; -} - -// Component that runs the hook but does not render anything. -function MollieGatewayUpdater({ billing, currencyCode, cartTotal, filters, ajaxUrl}) { - - useMollieAvailableGateways(billing, currencyCode, cartTotal, filters, ajaxUrl); - return null; -} let onSubmitLocal -let activePaymentMethodLocal let creditCardSelected = new Event("mollie_creditcard_component_selected", {bubbles: true}); const MollieComponent = (props) => { - let {onSubmit, activePaymentMethod, billing, item, useEffect, ajaxUrl, jQuery, emitResponse, eventRegistration, requiredFields, shippingData, isPhoneFieldVisible} = props + let {onSubmit, activePaymentMethod, billing, item, useEffect, jQuery, emitResponse, eventRegistration, requiredFields, shippingData, isPhoneFieldVisible} = props const { responseTypes } = emitResponse; const {onPaymentSetup, onCheckoutValidation} = eventRegistration; - if (!item || !item.name) { - return
Loading payment methods...
; - } const [ selectedIssuer, selectIssuer ] = wp.element.useState(''); const [ inputPhone, selectPhone ] = wp.element.useState(''); const [ inputBirthdate, selectBirthdate ] = wp.element.useState(''); @@ -190,7 +130,7 @@ const MollieComponent = (props) => { const className = "wc-block-components-text-input wc-block-components-address-form__" + id; return
- +
} @@ -261,28 +201,15 @@ const MollieComponent = (props) => { return
{itemContentP}
} -const Label = ({ item, filters, ajaxUrl }) => { - const cartData = wp.data.useSelect((select) => - select('wc/store/cart').getCartData(), - [] - ); - const cartTotals = wp.data.useSelect( (select) => select('wc/store/cart').getCartTotals(), [ ] ); - const cartTotal = cartTotals?.total_price || 0; +const Label = ({ item }) => { return ( <>
- ); }; -const molliePaymentMethod = (useEffect, ajaxUrl, filters, gatewayData, availableGateways, item, jQuery, requiredFields, isCompanyFieldVisible, isPhoneFieldVisible) =>{ +const molliePaymentMethod = (useEffect, item, jQuery, requiredFields, isPhoneFieldVisible) =>{ if (item.name === "mollie_wc_gateway_creditcard") { document.addEventListener('mollie_components_ready_to_submit', function () { @@ -299,50 +226,19 @@ const molliePaymentMethod = (useEffect, ajaxUrl, filters, gatewayData, available name: item.name, label: