Skip to content

Commit

Permalink
Merge pull request #889 from mollie/feature/PIWOO-414-bancomat
Browse files Browse the repository at this point in the history
PIWOO-414 Add bancomat and fix in3, billie
  • Loading branch information
mmaymo authored Apr 9, 2024
2 parents c9d52ea + dedfade commit f6e195a
Show file tree
Hide file tree
Showing 16 changed files with 452 additions and 78 deletions.
2 changes: 1 addition & 1 deletion mollie-payments-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Mollie Payments for WooCommerce
* Plugin URI: https://www.mollie.com
* Description: Accept payments in WooCommerce with the official Mollie plugin
* Version: 7.5.1
* Version: 7.5.2-beta
* Author: Mollie
* Author URI: https://www.mollie.com
* Requires at least: 5.0
Expand Down
11 changes: 11 additions & 0 deletions public/images/bancomatpay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 44 additions & 2 deletions resources/js/blocks/molliePaymentMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,36 @@ const MollieComponent = (props) => {

}, [activePaymentMethod, onCheckoutValidation, billing.billingData, shippingData.shippingAddress, item, phoneString, inputBirthdate, inputPhone]);

useEffect(() => {
let phoneLabel = getPhoneField()?.labels?.[0] ?? null;
if (!phoneLabel || phoneLabel.length === 0) {
return
}
if (activePaymentMethod === 'mollie_wc_gateway_bancomatpay') {
phoneLabel.innerText = item.phonePlaceholder
} else {
if (phoneString !== false) {
phoneLabel.innerText = phoneString
}
}
let isPhoneEmpty = (billing.billingData.phone === '' && shippingData.shippingAddress.phone === '') && inputPhone === '';
const unsubscribeProcessing = onCheckoutValidation(

() => {
if (activePaymentMethod === 'mollie_wc_gateway_bancomatpay' && isPhoneEmpty) {
return {
errorMessage: item.errorMessage,
};
}
}
);
return () => {
unsubscribeProcessing()
};

}, [activePaymentMethod, onCheckoutValidation, billing.billingData, shippingData.shippingAddress, item, phoneString, inputPhone]);


onSubmitLocal = onSubmit
const updateIssuer = ( changeEvent ) => {
selectIssuer( changeEvent.target.value )
Expand All @@ -214,7 +244,9 @@ const MollieComponent = (props) => {
}

function fieldMarkup(id, fieldType, label, action, value) {
return <div><label htmlFor={id} dangerouslySetInnerHTML={{ __html: label }}></label><input type={fieldType} name={id} id={id} value={value} onChange={action}/></div>
const className = "wc-block-components-text-input wc-block-components-address-form__" + id;
return <div>
<input type={fieldType} name={id} id={id} value={value} onChange={action}></input><label htmlFor={id} dangerouslySetInnerHTML={{ __html: label }}></label></div>
}

if (item.name === "mollie_wc_gateway_billie"){
Expand All @@ -231,7 +263,17 @@ const MollieComponent = (props) => {
fields.push(fieldMarkup("billing-birthdate", "date", birthdateField, updateBirthdate, inputBirthdate));
if (!isPhoneFieldVisible) {
const phoneField = item.phonePlaceholder ? item.phonePlaceholder : "Phone";
fields.push(fieldMarkup("billing-phone", "tel", phoneField, updatePhone, inputPhone));
fields.push(fieldMarkup("billing-phone-in3", "tel", phoneField, updatePhone, inputPhone));
}

return <>{fields}</>;
}

if (item.name === "mollie_wc_gateway_bancomatpay"){
let fields = [];
if (!isPhoneFieldVisible) {
const phoneField = item.phonePlaceholder ? item.phonePlaceholder : "Phone";
fields.push(fieldMarkup("billing-phone-bancomatpay", "tel", phoneField, updatePhone, inputPhone));
}

return <>{fields}</>;
Expand Down
32 changes: 0 additions & 32 deletions resources/js/mollieBillie.js

This file was deleted.

25 changes: 11 additions & 14 deletions resources/js/mollieBlockIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,30 @@ import molliePaymentMethod from './blocks/molliePaymentMethod'
}
window.onload = (event) => {
const { registerPaymentMethod } = wc.wcBlocksRegistry;
const { checkoutData, defaultFields } = wc.wcSettings.allSettings;
const { billing_address, shipping_address } = checkoutData;
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 = document.getElementById('shipping-company');
let billingCompany = document.getElementById('billing-company');
let shippingCompany = shipping_address.company ?? false;
let billingCompany = billing_address.company ?? false;
return shippingCompany ? shippingCompany : billingCompany;
}

function getPhoneField()
{
const shippingPhone = document.getElementById('shipping-phone');
const billingPhone = document.getElementById('billing-phone');
const shippingPhone = shipping_address.phone ?? false;
const billingPhone = billing_address.phone ?? false
return billingPhone || shippingPhone;
}
function isFieldVisible(field)
{
return field && field.style.display !== 'none';
}
let companyField = getCompanyField();
const isCompanyFieldVisible = companyField && isFieldVisible(companyField);
const companyNameString = companyField && companyField.parentNode.querySelector('label') ? companyField.parentNode.querySelector('label').innerHTML : false;
let phoneField = getPhoneField();
const isPhoneFieldVisible = phoneField && isFieldVisible(phoneField);
const phoneString = phoneField && phoneField.parentNode.querySelector('label') ? phoneField.parentNode.querySelector('label').innerHTML : false;

const isCompanyFieldVisible = getCompanyField();
const companyNameString = defaultFields.company.label
const isPhoneFieldVisible = getPhoneField();
const phoneString = defaultFields.phone.label
let requiredFields = {
'companyNameString': companyNameString,
'phoneString': phoneString,
Expand Down
7 changes: 0 additions & 7 deletions src/Assets/AssetsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,6 @@ protected function registerFrontendScripts(string $pluginUrl, string $pluginPath
(string) filemtime($this->getPluginPath($pluginPath, '/public/js/gatewaySurcharge.min.js')),
true
);
wp_register_script(
'mollie-billie-classic-handles',
$this->getPluginUrl($pluginUrl, '/public/js/mollieBillie.min.js'),
['underscore', 'jquery'],
(string) filemtime($this->getPluginPath($pluginPath, '/public/js/mollieBillie.min.js')),
true
);
}

public function registerBlockScripts(string $pluginUrl, string $pluginPath): void
Expand Down
Loading

0 comments on commit f6e195a

Please sign in to comment.