Skip to content

Commit

Permalink
Merge branch 'release/7.5.2-beta2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Apr 22, 2024
2 parents 67c049d + ab6fe7c commit d4ef2c1
Show file tree
Hide file tree
Showing 31 changed files with 475 additions and 188 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ jobs:
PHP_VERSION: 7.2
PLUGIN_MAIN_FILE: mollie-payments-for-woocommerce.php
ARCHIVE_NAME: mollie-payments-for-woocommerce
PRE_SCRIPT: |
echo 'hello world!';
POST_SCRIPT: |
mv dist/WooCommerce dist/mollie-payments-for-woocommerce
6 changes: 3 additions & 3 deletions mollie-payments-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
* 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
* Author: Mollie
* Author URI: https://www.mollie.com
* Requires at least: 5.0
* Tested up to: 6.4
* Tested up to: 6.5
* Text Domain: mollie-payments-for-woocommerce
* Domain Path: /languages
* License: GPLv2 or later
* WC requires at least: 3.9
* WC tested up to: 8.5
* WC tested up to: 8.7
* Requires PHP: 7.2
*/
declare(strict_types=1);
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.
6 changes: 4 additions & 2 deletions resources/js/blocks/molliePaymentMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,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 +233,7 @@ 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}</>;
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
2 changes: 1 addition & 1 deletion src/Buttons/ApplePayButton/AppleAjaxRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ protected function calculateTotalsCartPage(
$cart,
$customerAddress,
$shippingMethodId,
$shippingMethodId['identifier']
$shippingMethodId['identifier'] ?? null
);
}
$cart->calculate_shipping();
Expand Down
140 changes: 133 additions & 7 deletions src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

namespace Mollie\WooCommerce\Gateway;

use Automattic\WooCommerce\Admin\Overrides\Order;
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
use Automattic\WooCommerce\StoreApi\Exceptions\RouteException;
use Mollie\WooCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
use Mollie\WooCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
use Mollie\WooCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
Expand Down Expand Up @@ -103,14 +103,20 @@ public function services(): array
}
return $availableMethods;
},
'gateway.getKlarnaPaymentMethodsAfterFeatureFlag' => static function (ContainerInterface $container): array {
'gateway.getPaymentMethodsAfterFeatureFlag' => static function (ContainerInterface $container): array {
$availablePaymentMethods = $container->get('gateway.listAllMethodsAvailable');
$klarnaOneFlag = apply_filters('inpsyde.feature-flags.mollie-woocommerce.klarna_one_enabled', true);
if (!$klarnaOneFlag) {
return array_filter($availablePaymentMethods, static function ($method) {
return $method['id'] !== Constants::KLARNA;
});
}
$bancomatpayFlag = apply_filters('inpsyde.feature-flags.mollie-woocommerce.bancomatpay_enabled', true);
if (!$bancomatpayFlag) {
return array_filter($availablePaymentMethods, static function ($method) {
return $method['id'] !== Constants::BANCOMATPAY;
});
}
return $availablePaymentMethods;
},
'gateway.isSDDGatewayEnabled' => static function (ContainerInterface $container): bool {
Expand Down Expand Up @@ -264,7 +270,14 @@ static function () {
[$this, 'in3FieldsMandatoryPayForOrder'],
11
);
add_action(
'woocommerce_checkout_posted_data',
[$this, 'switchFields'],
11
);
add_action('woocommerce_rest_checkout_process_payment_with_context', [$this, 'addPhoneWhenRest'], 11);
}

// Set order to paid and processed when eventually completed without Mollie
add_action('woocommerce_payment_complete', [$this, 'setOrderPaidByOtherGateway'], 10, 1);
$appleGateway = isset($container->get('gateway.instances')['mollie_wc_gateway_applepay']) ? $container->get(
Expand Down Expand Up @@ -314,6 +327,17 @@ static function ($paymentContext) {
}
);
add_action('add_meta_boxes_woocommerce_page_wc-orders', [$this, 'addShopOrderMetabox'], 10);
add_filter('woocommerce_form_field_args', static function ($args, $key, $value) use ($container) {
if ($key !== 'billing_phone') {
return $args;
}
if ($args['required'] === true) {
update_option('mollie_wc_is_phone_required_flag', true);
} else {
update_option('mollie_wc_is_phone_required_flag', false);
}
return $args;
}, 10, 3);
return true;
}

Expand Down Expand Up @@ -583,7 +607,7 @@ public function instantiatePaymentMethodGateways(ContainerInterface $container):
protected function instantiatePaymentMethods($container): array
{
$paymentMethods = [];
$listAllAvailablePaymentMethods = $container->get('gateway.getKlarnaPaymentMethodsAfterFeatureFlag');
$listAllAvailablePaymentMethods = $container->get('gateway.getPaymentMethodsAfterFeatureFlag');
$iconFactory = $container->get(IconFactory::class);
assert($iconFactory instanceof IconFactory);
$settingsHelper = $container->get('settings.settings_helper');
Expand Down Expand Up @@ -630,18 +654,18 @@ public function BillieFieldsMandatory($fields, $errors)
public function in3FieldsMandatory($fields, $errors)
{
$gatewayName = "mollie_wc_gateway_in3";
$phoneField = 'billing_phone';
$phoneField = 'billing_phone_in3';
$birthdateField = self::FIELD_IN3_BIRTHDATE;
$phoneLabel = __('Phone', 'mollie-payments-for-woocommerce');
$birthDateLabel = __('Birthdate', 'mollie-payments-for-woocommerce');
$fields = $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $phoneField, $phoneLabel, $errors);
$fields = $this->addPaymentMethodMandatoryFieldsPhoneVerification($fields, $gatewayName, $phoneField, $phoneLabel, $errors);
return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $birthdateField, $birthDateLabel, $errors);
}

/**
* @param Order $order
* @param $order
*/
public function in3FieldsMandatoryPayForOrder(Order $order)
public function in3FieldsMandatoryPayForOrder($order)
{
$paymentMethod = filter_input(INPUT_POST, 'payment_method', FILTER_SANITIZE_SPECIAL_CHARS) ?? false;

Expand All @@ -661,6 +685,21 @@ public function in3FieldsMandatoryPayForOrder(Order $order)
'error'
);
}
$phoneValue = filter_input(INPUT_POST, 'billing_phone_in3', FILTER_SANITIZE_SPECIAL_CHARS) ?? false;
$phoneValue = $phoneValue && $this->isPhoneValid($phoneValue) ? $phoneValue : false;
$phoneLabel = __('Phone', 'mollie-payments-for-woocommerce');

if (!$phoneValue) {
wc_add_notice(
sprintf(
__('%s is a required field. Valid phone format +000000000', 'mollie-payments-for-woocommerce'),
"<strong>$phoneLabel</strong>"
),
'error'
);
} else {
$order->set_billing_phone($phoneValue);
}
}

/**
Expand Down Expand Up @@ -723,4 +762,91 @@ public function addPaymentMethodMandatoryFields($fields, string $gatewayName, st

return $fields;
}

public function addPaymentMethodMandatoryFieldsPhoneVerification(
$fields,
string $gatewayName,
string $field,
string $fieldLabel,
$errors
) {
if ($fields['payment_method'] !== $gatewayName) {
return $fields;
}
if (isset($fields['billing_phone']) && $this->isPhoneValid($fields['billing_phone'])) {
return $fields;
}
$fieldPosted = filter_input(INPUT_POST, $field, FILTER_SANITIZE_SPECIAL_CHARS) ?? false;
if (!$fieldPosted) {
$errors->add(
'validation',
sprintf(
__('%s is a required field.', 'woocommerce'),
"<strong>$fieldLabel</strong>"
)
);
return $fields;
}

if (!$this->isPhoneValid($fieldPosted)) {
$errors->add(
'validation',
sprintf(
__('%s is not a valid phone number. Valid phone format +00000000000', 'woocommerce'),
"<strong>$fieldLabel</strong>"
)
);
return $fields;
} else {
$fields['billing_phone'] = $fieldPosted;
}
return $fields;
}

public function switchFields($data)
{
if (isset($data['payment_method']) && $data['payment_method'] === 'mollie_wc_gateway_in3') {
$fieldPosted = filter_input(INPUT_POST, 'billing_phone_in3', FILTER_SANITIZE_SPECIAL_CHARS) ?? false;
if ($fieldPosted) {
$data['billing_phone'] = !empty($fieldPosted) ? $fieldPosted : $data['billing_phone'];
}
}
if (isset($data['payment_method']) && $data['payment_method'] === 'mollie_wc_gateway_billie') {
$fieldPosted = filter_input(INPUT_POST, 'billing_company_billie', FILTER_SANITIZE_SPECIAL_CHARS) ?? false;
if ($fieldPosted) {
$data['billing_company'] = !empty($fieldPosted) ? $fieldPosted : $data['billing_company'];
}
}
return $data;
}

private function isPhoneValid($billing_phone)
{
return preg_match('/^\+[1-9]\d{10,13}$/', $billing_phone);
}

public function addPhoneWhenRest($arrayContext)
{
$context = $arrayContext;
$phoneMandatoryGateways = ['mollie_wc_gateway_in3'];
$paymentMethod = $context->payment_data['payment_method'];
if (in_array($paymentMethod, $phoneMandatoryGateways)) {
$billingPhone = $context->order->get_billing_phone();
if (!empty($billingPhone) && $this->isPhoneValid($billingPhone)) {
return;
}
$billingPhone = $context->payment_data['billing_phone'];
if ($billingPhone) {
$context->order->set_billing_phone($billingPhone);
$context->order->save();
} else {
$message = __('Please introduce a valid phone number. +00000000000', 'mollie-payments-for-woocommerce');
throw new RouteException(
'woocommerce_rest_checkout_process_payment_error',
$message,
402
);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Log/WcPsrLoggerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function log($level, $message, array $context = [])
}

if (\WC_Log_Levels::get_level_severity($wcLevel) < \WC_Log_Levels::get_level_severity($this->loggingLevel)) {
throw new InvalidArgumentException("Unknown log level ${$wcLevel}");
throw new InvalidArgumentException("Unknown log level {$wcLevel}");
}

if (isset($context['source']) && $context['source'] !== $this-> loggerSource) {
Expand Down
Loading

0 comments on commit d4ef2c1

Please sign in to comment.