Skip to content

Commit

Permalink
BP-3027 Remove BIC/IBAN fields for Giropay
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivascu Madalin committed Oct 18, 2023
1 parent 849a1fc commit 98e2774
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 169 deletions.
56 changes: 1 addition & 55 deletions Model/Method/Giropay.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* NOTICE OF LICENSE
*
Expand All @@ -20,9 +21,6 @@

namespace Buckaroo\Magento2\Model\Method;

use Magento\Framework\Validator\Exception;
use Magento\Sales\Model\Order\Payment;

class Giropay extends AbstractMethod
{
/**
Expand All @@ -42,24 +40,6 @@ class Giropay extends AbstractMethod
*/
protected $_code = self::PAYMENT_METHOD_CODE;

/**
* {@inheritdoc}
*/
public function assignData(\Magento\Framework\DataObject $data)
{
parent::assignData($data);
$data = $this->assignDataConvertToArray($data);

if (isset($data['additional_data']['customer_bic'])) {
$this->getInfoInstance()->setAdditionalInformation(
'customer_bic',
$data['additional_data']['customer_bic']
);
}

return $this;
}

/**
* {@inheritdoc}
*/
Expand All @@ -71,12 +51,6 @@ public function getOrderTransactionBuilder($payment)
'Name' => 'giropay',
'Action' => 'Pay',
'Version' => 2,
'RequestParameter' => [
[
'_' => $payment->getAdditionalInformation('customer_bic'),
'Name' => 'bic',
],
],
];

/**
Expand Down Expand Up @@ -118,34 +92,6 @@ public function getVoidTransactionBuilder($payment)
return true;
}

/**
* Validate the extra input fields.
*
* @return $this
* @throws Exception
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function validate()
{
parent::validate();

$paymentInfo = $this->getInfoInstance();

$skipValidation = $paymentInfo->getAdditionalInformation('buckaroo_skip_validation');
if ($skipValidation) {
return $this;
}

$customerBicNumber = $paymentInfo->getAdditionalInformation('customer_bic');

if (!preg_match(static::BIC_NUMBER_REGEX, $customerBicNumber)) {
//phpcs:ignore:Magento2.Exceptions.DirectThrow
throw new Exception(__('Please enter a valid BIC number'));
}

return $this;
}

/**
* @param \Magento\Sales\Api\Data\OrderPaymentInterface|\Magento\Payment\Model\InfoInterface $payment
*
Expand Down
80 changes: 6 additions & 74 deletions view/frontend/web/js/view/payment/method-renderer/giropay.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,10 @@ define(
) {
'use strict';

/**
* Add validation methods
* */

$.validator.addMethod(
'bic',
function (value) {
var patternBIC = new RegExp('^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$');
return patternBIC.test(value);
},
$.mage.__('Enter Valid BIC number')
);

return Component.extend(
{
defaults: {
template: 'Buckaroo_Magento2/payment/buckaroo_magento2_giropay',
bicNumber: '',
validationState: {}
template: 'Buckaroo_Magento2/payment/buckaroo_magento2_giropay'
},
paymentFeeLabel : window.checkoutConfig.payment.buckaroo.giropay.paymentFeeLabel,
subtext : window.checkoutConfig.payment.buckaroo.giropay.subtext,
Expand All @@ -78,55 +63,12 @@ define(
return this._super(options);
},

initObservable: function () {
this._super().observe(['bicNumber', 'validationState']);

/** Check used to see form is valid **/
this.buttoncheck = ko.computed(
function () {
const state = this.validationState();
const valid = [
'bicnumber',
].map((field) => {
if(state[field] !== undefined) {
return state[field];
}
return false;
}).reduce(
function(prev, cur) {
return prev && cur
},
true
)
return valid;
},
this
);

return this;
},

/**
* Run function
*/

validate: function () {
return $('.' + this.getCode() + ' .payment-method-second-col form').valid();
},

validateField(data, event) {
const isValid = $(event.target).valid();
let state = this.validationState();
state[event.target.id] = isValid;
this.validationState(state);
},

/**
* Place order.
*
* placeOrderAction has been changed from Magento_Checkout/js/action/place-order to our own version
* (Buckaroo_Magento2/js/action/place-order) to prevent redirect and handle the response.
*/
* Place order.
*
* placeOrderAction has been changed from Magento_Checkout/js/action/place-order to our own version
* (Buckaroo_Magento2/js/action/place-order) to prevent redirect and handle the response.
*/
placeOrder: function (data, event) {
var self = this,
placeOrder;
Expand Down Expand Up @@ -163,16 +105,6 @@ define(
return true;
},

getData: function () {
return {
"method": this.item.method,
"po_number": null,
"additional_data": {
"customer_bic": this.bicNumber()
}
};
},

payWithBaseCurrency: function () {
var allowedCurrencies = window.checkoutConfig.payment.buckaroo.giropay.allowedCurrencies;

Expand Down
48 changes: 8 additions & 40 deletions view/frontend/web/template/payment/buckaroo_magento2_giropay.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,13 @@
</div>

<div class="payment-method-content">
<!-- ko foreach: getRegion('messages') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->

<div class="payment-method-billing-address">
<!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>

<div class="payment-method-second-col billing-address-form">
<form data-bind="mageInit: { 'validation': [] },
attr: {'data-hasrequired': $t('* Required Fields')}">
<fieldset class="fieldset payment">

<div class="field required">
<label for="bicnumber" class="label">
<span data-bind="i18n: 'BIC Number'"> </span>

</label>
<div class="control">
<input id="bicnumber" class="input-text field _error" type="text"
placeholder="AAAABBCCDDD"
data-bind="
value: bicNumber,
valueUpdate: 'keyup',
attr: {
'data-validate': JSON.stringify({ 'required': true, 'bic':true })
},
event: { blur: validateField }
"
name="payment[buckaroo_magento2_giropay][customer_bic]">
</div>
</div>


</fieldset>
</form>
</div>

<div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>

<div class="actions-toolbar">
<div class="primary">
<button id="button-action-checkout-giropay"
Expand All @@ -75,7 +36,7 @@
click: placeOrder,
attr: {title: $t('Place Order')},
enable: (getCode() == isChecked()),
css: {disabled: !isPlaceOrderActionAllowed() || !buttoncheck()}
css: {disabled: !isPlaceOrderActionAllowed() }
"
disabled>
<span data-bind="i18n: 'Place Order'"></span>
Expand All @@ -88,5 +49,12 @@
<span data-bind="text: getPayWithBaseCurrencyText()"></span>
</div>
<!--/ko-->

<div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>

</div>
</div>

0 comments on commit 98e2774

Please sign in to comment.