Skip to content

Commit

Permalink
PIWOO-414 Add bancomat and fix in3, billie
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Mar 6, 2024
1 parent c9d52ea commit f3aa7b1
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 52 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.6.0
* 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.
32 changes: 0 additions & 32 deletions resources/js/mollieBillie.js

This file was deleted.

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
91 changes: 89 additions & 2 deletions src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ static function () {
11,
2
);
add_action(
'woocommerce_checkout_posted_data',
[$this, 'switchFields'],
11
);
}
$isIn3Enabled = mollieWooCommerceIsGatewayEnabled('mollie_wc_gateway_in3_settings', 'enabled');
if ($isIn3Enabled) {
Expand All @@ -263,6 +268,30 @@ static function () {
[$this, 'in3FieldsMandatoryPayForOrder'],
11
);
add_action(
'woocommerce_checkout_posted_data',
[$this, 'switchFields'],
11
);
}
$isBancomatPayEnabled = mollieWooCommerceIsGatewayEnabled('mollie_wc_gateway_bancomatpay_settings', 'enabled');
if ($isBancomatPayEnabled) {
add_filter(
'woocommerce_after_checkout_validation',
[$this, 'bancomatpayFieldsMandatory'],
11,
2
);
add_action(
'woocommerce_before_pay_action',
[$this, 'bancomatpayFieldsMandatoryPayForOrder'],
11
);
add_action(
'woocommerce_checkout_posted_data',
[$this, 'switchFields'],
11
);
}
// Set order to paid and processed when eventually completed without Mollie
add_action('woocommerce_payment_complete', [$this, 'setOrderPaidByOtherGateway'], 10, 1);
Expand Down Expand Up @@ -621,22 +650,31 @@ protected function instantiatePaymentMethods($container): array
public function BillieFieldsMandatory($fields, $errors)
{
$gatewayName = "mollie_wc_gateway_billie";
$field = 'billing_company';
$field = 'billing_company_billie';
$companyLabel = __('Company', 'mollie-payments-for-woocommerce');
return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $field, $companyLabel, $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);
return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $birthdateField, $birthDateLabel, $errors);
}

public function bancomatpayFieldsMandatory($fields, $errors)
{
$gatewayName = "mollie_wc_gateway_bancomatpay";
$phoneField = 'billing_phone_bancomatpay';
$phoneLabel = __('Phone', 'mollie-payments-for-woocommerce');
return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $phoneField, $phoneLabel, $errors);
}


/**
* @param $order
*/
Expand All @@ -662,6 +700,31 @@ public function in3FieldsMandatoryPayForOrder($order)
}
}

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

if ($paymentMethod !== 'mollie_wc_gateway_bancomatpay') {
return;
}

$phoneValue = filter_input(INPUT_POST, 'billing_phone_bancomatpay', FILTER_SANITIZE_SPECIAL_CHARS) ?? false;
$phoneLabel = __('Phone', 'mollie-payments-for-woocommerce');

if (!$phoneValue) {
wc_add_notice(
sprintf(
__('%s is a required field.', 'woocommerce'),
"<strong>$phoneLabel</strong>"
),
'error'
);
}
}

/**
* @param string $id
* @param IconFactory $iconFactory
Expand Down Expand Up @@ -722,4 +785,28 @@ public function addPaymentMethodMandatoryFields($fields, string $gatewayName, st

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_bancomatpay') {
$fieldPosted = filter_input(INPUT_POST, 'billing_phone_bancomatpay', 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;
}
}
36 changes: 36 additions & 0 deletions src/PaymentMethods/Bancomatpay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods;

class Bancomatpay extends AbstractPaymentMethod implements PaymentMethodI
{
public function getConfig(): array
{
return [
'id' => 'bancomatpay',
'defaultTitle' => __('Bancomat Pay', 'mollie-payments-for-woocommerce'),
'settingsDescription' => '',
'defaultDescription' => '',
'paymentFields' => true,
'instructions' => false,
'supports' => [
'products',
'refunds',
],
'filtersOnBuild' => false,
'confirmationDelayed' => false,
'errorMessage' => __(
'Required field is empty. Phone field is required.',
'mollie-payments-for-woocommerce'
),
'phonePlaceholder' => __('Please enter your phone here. +00..', 'mollie-payments-for-woocommerce'),
];
}

public function getFormFields($generalFormFields): array
{
return $generalFormFields;
}
}
2 changes: 1 addition & 1 deletion src/PaymentMethods/Billie.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected function getConfig(): array
'mollie-payments-for-woocommerce'
),
'defaultDescription' => '',
'paymentFields' => false,
'paymentFields' => true,
'instructions' => false,
'supports' => [
'products',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods\PaymentFieldsStrategies;

class BancomatpayFieldsStrategy implements PaymentFieldsStrategyI
{
const FIELD_PHONE = "billing_phone_bancomatpay";

public function execute($gateway, $dataHelper)
{
$showPhoneField = false;

if (is_checkout_pay_page()) {
$order = $this->getOrderIdOnPayForOrderPage();
$showPhoneField = empty($order->get_billing_phone());
}

if (is_checkout() && !is_checkout_pay_page()) {
$showPhoneField = true;
}

if ($showPhoneField) {
$this->phoneNumber();
}
}

protected function getOrderIdOnPayForOrderPage()
{
global $wp;
$orderId = absint($wp->query_vars['order-pay']);
return wc_get_order($orderId);
}

protected function phoneNumber()
{
?>
<p class="form-row form-row-wide" id="billing_phone_field">
<label for="<?= esc_attr(self::FIELD_PHONE); ?>" class=""><?= esc_html__('Phone', 'mollie-payments-for-woocommerce'); ?>
<abbr class="required" title="required">*</abbr>
</label>
<span class="woocommerce-input-wrapper">
<input type="tel" class="input-text " name="<?= esc_attr(self::FIELD_PHONE); ?>" id="<?= esc_attr(self::FIELD_PHONE); ?>"
placeholder="+00000000000"
value="" autocomplete="phone">
</span>
</p>
<?php
}

public function getFieldMarkup($gateway, $dataHelper)
{
return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace Mollie\WooCommerce\PaymentMethods\PaymentFieldsStrategies;

class BillieFieldsStrategy implements PaymentFieldsStrategyI
{
const FIELD_COMPANY = "billing_company_billie";

public function execute($gateway, $dataHelper)
{
$showCompanyField = false;

if (is_checkout_pay_page()) {
$order = $this->getOrderIdOnPayForOrderPage();
$showCompanyField = empty($order->get_billing_company());
}

if (is_checkout() && !is_checkout_pay_page()) {
$showCompanyField = true;
}

if ($showCompanyField) {
$this->company();
}
}

protected function getOrderIdOnPayForOrderPage()
{
global $wp;
$orderId = absint($wp->query_vars['order-pay']);
return wc_get_order($orderId);
}

protected function company()
{
?>
<p class="form-row form-row-wide" id="billing_company_field">
<label for="<?= esc_attr(self::FIELD_COMPANY); ?>" class=""><?= esc_html__('Company', 'mollie-payments-for-woocommerce'); ?>
<abbr class="required" title="required">*</abbr>
</label>
<span class="woocommerce-input-wrapper">
<input type="tel" class="input-text " name="<?= esc_attr(self::FIELD_COMPANY); ?>" id="<?= esc_attr(self::FIELD_COMPANY); ?>"
placeholder="Company name"
value="" autocomplete="organization">
</span>
</p>
<?php
}

public function getFieldMarkup($gateway, $dataHelper)
{
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class In3FieldsStrategy implements PaymentFieldsStrategyI
{
const FIELD_BIRTHDATE = "billing_birthdate";
const FIELD_PHONE = "billing_phone";
const FIELD_PHONE = "billing_phone_in3";

public function execute($gateway, $dataHelper)
{
Expand All @@ -21,15 +21,8 @@ public function execute($gateway, $dataHelper)
}

if (is_checkout() && !is_checkout_pay_page()) {
$checkoutFields = WC()->checkout()->get_checkout_fields();

if (!isset($checkoutFields["billing"][self::FIELD_PHONE])) {
$showPhoneField = true;
}

if (!isset($checkoutFields["billing"][self::FIELD_BIRTHDATE])) {
$showBirthdateField = true;
}
}

if ($showPhoneField) {
Expand Down
1 change: 1 addition & 0 deletions src/Shared/SharedDataDictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SharedDataDictionary
'Mollie_WC_Gateway_Directdebit',
'Mollie_WC_Gateway_Blik',
'Mollie_WC_Gateway_Twint',
'Mollie_WC_Gateway_Bancomatpay',
];

public const MOLLIE_OPTIONS_NAMES = [
Expand Down
Loading

0 comments on commit f3aa7b1

Please sign in to comment.