Skip to content

Commit

Permalink
Merge pull request #924 from mollie/release/7.7.0
Browse files Browse the repository at this point in the history
Release version 7.7.0
  • Loading branch information
mmaymo authored Aug 6, 2024
2 parents 149c74d + 5aae2fb commit add1dd0
Show file tree
Hide file tree
Showing 27 changed files with 688 additions and 92 deletions.
10 changes: 10 additions & 0 deletions inc/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,13 @@ function transformPhoneToNLFormat($phone)
}
return $phone;
}

function isMollieBirthValid($billing_birthdate)
{
$today = new DateTime();
$birthdate = DateTime::createFromFormat('Y-m-d', $billing_birthdate);
if ($birthdate >= $today) {
return false;
}
return true;
}
3 changes: 3 additions & 0 deletions inc/woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ function is_order_received_page()
*/
function untrailingslashit($string)
{
if ($string === null) {
return '';
}
return rtrim($string, '/');
}
}
Expand Down
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.6.0
* Version: 7.7.0-beta
* Author: Mollie
* Author URI: https://www.mollie.com
* Requires at least: 5.0
* Tested up to: 6.5
* Tested up to: 6.6
* Text Domain: mollie-payments-for-woocommerce
* Domain Path: /languages
* License: GPLv2 or later
* WC requires at least: 3.9
* WC tested up to: 9.0
* WC tested up to: 9.1
* Requires PHP: 7.2
* Requires Plugins: woocommerce
*/
Expand Down
1 change: 1 addition & 0 deletions public/images/payconiq.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/images/riverty.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 51 additions & 30 deletions resources/js/blocks/molliePaymentMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,17 @@ const MollieComponent = (props) => {
}, [activePaymentMethod, onCheckoutValidation, billing.billingData, shippingData.shippingAddress, item, phoneString, inputBirthdate, inputPhone]);

onSubmitLocal = onSubmit
const updateIssuer = ( changeEvent ) => {
selectIssuer( changeEvent.target.value )
};
const updateCompany = ( changeEvent ) => {
selectCompany( changeEvent.target.value )
};
const updatePhone = ( changeEvent ) => {
selectPhone( changeEvent.target.value )
}
const updateBirthdate = ( changeEvent ) => {
selectBirthdate( changeEvent.target.value )
const updateIssuer = (e) => selectIssuer(e.target.value);
const updateCompany = (e) => selectCompany(e.target.value);
const updatePhone = (e) => selectPhone(e.target.value);
const updateBirthdate = (e) => selectBirthdate( e.target.value );

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

if (item.issuers && item.name !== "mollie_wc_gateway_creditcard"){
Expand All @@ -218,38 +218,59 @@ const MollieComponent = (props) => {
return <div dangerouslySetInnerHTML={ {__html: item.content} }></div>;
}

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

if (item.name === "mollie_wc_gateway_billie") {
if (isCompanyFieldVisible) {
return;
}
const companyField = item.companyPlaceholder ? item.companyPlaceholder : "Company name";
return fieldMarkup("billing-company","text", companyField, updateCompany, inputCompany);
return (
<>
<div><p>{item.content}</p></div>
{fieldMarkup("billing-company","text", companyField, updateCompany, inputCompany)}
</>
);
}

if (item.name === "mollie_wc_gateway_in3"){
let fields = [];
const birthdateField = item.birthdatePlaceholder ? item.birthdatePlaceholder : "Birthdate";
fields.push(fieldMarkup("billing-birthdate", "date", birthdateField, updateBirthdate, inputBirthdate));
if (isPhoneFieldVisible === false) {
const phoneField = item.phonePlaceholder ? item.phonePlaceholder : "Phone";
fields.push(fieldMarkup("billing-phone-in3", "tel", phoneField, updatePhone, inputPhone));
}
useEffect(() => {
const countryCodes = {
BE: '+32xxxxxxxxx',
NL: '+316xxxxxxxx',
DE: '+49xxxxxxxxx',
AT: '+43xxxxxxxxx',
};
const country = billing.billingData.country;
item.phonePlaceholder = countryCodes[country] || countryCodes['NL'];
}, [billing.billingData.country]);

if (item.name === "mollie_wc_gateway_in3") {
const birthdateField = item.birthdatePlaceholder || "Birthdate";
const phoneField = item.phonePlaceholder || "+316xxxxxxxx";
const phoneLabel = item.phoneLabel || "Phone";
return (
<>
<div><p>{item.content}</p></div>
{fieldMarkup("billing-birthdate", "date", birthdateField, updateBirthdate, inputBirthdate)}
{!isPhoneFieldVisible && fieldMarkup("billing-phone-in3", "tel", phoneLabel, updatePhone, inputPhone, phoneField)}
</>
);
}

return <>{fields}</>;
if (item.name === "mollie_wc_gateway_riverty") {
const birthdateField = item.birthdatePlaceholder || "Birthdate";
const phoneField = item.phonePlaceholder || "+316xxxxxxxx";
const phoneLabel = item.phoneLabel || "Phone";
return (
<>
<div><p>{item.content}</p></div>
{fieldMarkup("billing-birthdate", "date", birthdateField, updateBirthdate, inputBirthdate)}
{!isPhoneFieldVisible && fieldMarkup("billing-phone-riverty", "tel", phoneLabel, updatePhone, inputPhone, phoneField)}
</>
);
}

return <div><p>{item.content}</p></div>
}


const molliePaymentMethod = (useEffect, ajaxUrl, filters, gatewayData, availableGateways, item, jQuery, requiredFields, isCompanyFieldVisible, isPhoneFieldVisible) =>{
let billingCountry = filters.billingCountry
let cartTotal = filters.cartTotal
Expand Down
9 changes: 8 additions & 1 deletion resources/js/mollieBlockIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import molliePaymentMethod from './blocks/molliePaymentMethod'
window.onload = (event) => {
const { registerPaymentMethod } = wc.wcBlocksRegistry;
const { checkoutData, defaultFields } = wc.wcSettings.allSettings;
const { billing_address, shipping_address } = checkoutData;
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"
Expand Down
13 changes: 13 additions & 0 deletions resources/js/rivertyCountryPlaceholder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(
function ({jQuery}) {
jQuery(function ($) {
$('body').on('change', '#billing_country', function () {
if ($('input[name="payment_method"]:checked').val() === 'mollie_wc_gateway_riverty') {
$('body').trigger('update_checkout');
}
});
});
})(window)



15 changes: 11 additions & 4 deletions src/Assets/AssetsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ protected function registerFrontendScripts(string $pluginUrl, string $pluginPath
(string) filemtime($this->getPluginPath($pluginPath, '/public/js/gatewaySurcharge.min.js')),
true
);
wp_register_script(
'mollie-riverty-classic-handles',
$this->getPluginUrl($pluginUrl, '/public/js/rivertyCountryPlaceholder.min.js'),
['jquery'],
(string) filemtime($this->getPluginPath($pluginPath, '/public/js/rivertyCountryPlaceholder.min.js')),
true
);
}

public function registerBlockScripts(string $pluginUrl, string $pluginPath): void
Expand Down Expand Up @@ -310,11 +317,11 @@ public function enqueueFrontendScripts($container)
return;
}
wp_enqueue_style('mollie-gateway-icons');
$isBillieEnabled = mollieWooCommerceIsGatewayEnabled('mollie_wc_gateway_billie_settings', 'enabled');
$allMethodsEnabledAtMollie = $container->get('gateway.paymentMethodsEnabledAtMollie');
$isBillieEnabledAtMollie = in_array('billie', $allMethodsEnabledAtMollie, true);
if ($isBillieEnabled && $isBillieEnabledAtMollie) {
wp_enqueue_script('mollie-billie-classic-handles');
$isRivertyEnabled = mollieWooCommerceIsGatewayEnabled('mollie_wc_gateway_riverty_settings', 'enabled');
$isRivertyEnabledAtMollie = in_array('riverty', $allMethodsEnabledAtMollie, true);
if ($isRivertyEnabled && $isRivertyEnabledAtMollie) {
wp_enqueue_script('mollie-riverty-classic-handles');
}

$applePayGatewayEnabled = mollieWooCommerceIsGatewayEnabled('mollie_wc_gateway_applepay_settings', 'enabled');
Expand Down
11 changes: 10 additions & 1 deletion src/Assets/MollieCheckoutBlocksSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ public static function gatewayDataForWCBlocks(Data $dataService, array $gatewayI
$title = $gateway->paymentMethod()->title();
$labelMarkup = "<span style='margin-right: 1em'>{$title}</span>{$gateway->icon}";
$hasSurcharge = $gateway->paymentMethod()->hasSurcharge();
$countryCodes = [
'BE' => '+32xxxxxxxxx',
'NL' => '+316xxxxxxxx',
'DE' => '+49xxxxxxxxx',
'AT' => '+43xxxxxxxxx',
];
$country = WC()->customer ? WC()->customer->get_billing_country() : '';
$phonePlaceholder = in_array($country, array_keys($countryCodes)) ? $countryCodes[$country] : $countryCodes['NL'];
$gatewayData[] = [
'name' => $gatewayKey,
'label' => $labelMarkup,
Expand All @@ -152,7 +160,8 @@ public static function gatewayDataForWCBlocks(Data $dataService, array $gatewayI
'supports' => self::gatewaySupportsFeatures($gateway->paymentMethod(), $isSepaEnabled),
'errorMessage' => $gateway->paymentMethod()->getProperty('errorMessage'),
'companyPlaceholder' => $gateway->paymentMethod()->getProperty('companyPlaceholder'),
'phonePlaceholder' => $gateway->paymentMethod()->getProperty('phonePlaceholder'),
'phoneLabel' => $gateway->paymentMethod()->getProperty('phoneLabel'),
'phonePlaceholder' => $phonePlaceholder,
'birthdatePlaceholder' => $gateway->paymentMethod()->getProperty('birthdatePlaceholder'),
];
}
Expand Down
9 changes: 2 additions & 7 deletions src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,14 +794,9 @@ private function isPhoneValid($billing_phone)
return preg_match('/^\+[1-9]\d{10,13}$|^[1-9]\d{9,13}$|^06\d{9,13}$/', $billing_phone);
}

private function isBirthValid($billing_birthdate)
private function isBirthValid($billing_birthdate): bool
{
$today = new DateTime();
$birthdate = DateTime::createFromFormat('Y-m-d', $billing_birthdate);
if ($birthdate >= $today) {
return false;
}
return true;
return isMollieBirthValid($billing_birthdate);
}

public function addPhoneWhenRest($arrayContext)
Expand Down
2 changes: 1 addition & 1 deletion src/Gateway/MolliePaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function __construct(
'yes';
$this->enabled = $isEnabledAtWoo;

if ($this->paymentMethod->getProperty('filtersOnBuild')) {
if ($this->enabled && $this->paymentMethod->getProperty('filtersOnBuild')) {
$this->paymentMethod->filtersOnBuild();
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Payment/MollieOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,11 @@ protected function getCustomerBirthdate($order)
if (!$gateway || !isset($gateway->id)) {
return null;
}
$methodId = $gateway->id === 'mollie_wc_gateway_in3';
if (strpos($gateway->id, 'mollie_wc_gateway_') === false) {
return null;
}
$additionalFields = $gateway->paymentMethod()->getProperty('additionalFields');
$methodId = $additionalFields && in_array('birthdate', $additionalFields, true);
if ($methodId) {
//phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$fieldPosted = wc_clean(wp_unslash($_POST["billing_birthdate"] ?? ''));
Expand Down
1 change: 1 addition & 0 deletions src/Payment/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ protected function processAsMollieOrder(
'mollie_wc_gateway_klarna',
'mollie_wc_gateway_billie',
'mollie_wc_gateway_in3',
'mollie_wc_gateway_riverty',
];

if (in_array($order_payment_method, $orderMandatoryPaymentMethods, true)) {
Expand Down
1 change: 1 addition & 0 deletions src/PaymentMethods/In3.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function getConfig(): array
'settingsDescription' => '',
'defaultDescription' => __('Pay in 3 instalments, 0% interest', 'mollie-payments-for-woocommerce'),
'paymentFields' => true,
'additionalFields' => ['birthdate', 'phone'],
'instructions' => false,
'supports' => [
'products',
Expand Down
29 changes: 29 additions & 0 deletions src/PaymentMethods/Payconiq.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;

class Payconiq extends AbstractPaymentMethod implements PaymentMethodI
{
protected function getConfig(): array
{
return [
'id' => 'payconiq',
'defaultTitle' => __('payconiq', 'mollie-payments-for-woocommerce'),
'settingsDescription' => '',
'defaultDescription' => '',
'paymentFields' => false,
'instructions' => false,
'supports' => ['products', 'refunds'],
'filtersOnBuild' => false,
'confirmationDelayed' => false,
'SEPA' => false,
];
}

public function getFormFields($generalFormFields): array
{
return $generalFormFields;
}
}
Loading

0 comments on commit add1dd0

Please sign in to comment.