Skip to content

Commit

Permalink
Merge pull request #1003 from buckaroo-it/BP-3678-Billink-is-always-B2B
Browse files Browse the repository at this point in the history
BP-3678-Billink-is-always-B2B
  • Loading branch information
vegimcarkaxhija authored Aug 8, 2024
2 parents c1b1a0a + cf49b05 commit 4375b45
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 75 deletions.
28 changes: 15 additions & 13 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,20 +463,8 @@ public function checkCustomerGroup(string $paymentMethod, bool $forceB2C = false
$configProvider = $this->configProviderMethodFactory->get($paymentMethodCode);
$configCustomerGroup = $configProvider->getSpecificCustomerGroup();

if (!$forceB2C
&& (
($paymentMethodCode == 'billink')
|| (
(($paymentMethodCode == 'afterpay') || ($paymentMethodCode == 'afterpay2'))
&& ($configProvider->getBusiness() == Business::BUSINESS_B2B)
)
|| (
($paymentMethodCode == 'payperemail') && ($configProvider->getEnabledB2B())
)
)
) {
if (!$forceB2C && $this->isBusinessCustomer($paymentMethodCode, $configProvider)) {
$configCustomerGroup = $configProvider->getSpecificCustomerGroupB2B();

}

if ($configCustomerGroup === null) {
Expand All @@ -503,6 +491,20 @@ public function checkCustomerGroup(string $paymentMethod, bool $forceB2C = false
return true;
}

private function isBusinessCustomer(string $paymentMethodCode, $configProvider): bool
{
return (
($paymentMethodCode == 'billink') ||
(
(($paymentMethodCode == 'afterpay') || ($paymentMethodCode == 'afterpay2')) &&
($configProvider->getBusiness() == Business::BUSINESS_B2B)
) ||
(
($paymentMethodCode == 'payperemail') && ($configProvider->getEnabledB2B())
)
);
}

private function checkCustomerGroupAdminArea(array $configCustomerGroupArr): bool
{
if (($customerId = $this->_getRequest()->getParam('customer_id')) && ($customerId > 0)) {
Expand Down
16 changes: 8 additions & 8 deletions Model/Method/Billink.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ public function assignData(\Magento\Framework\DataObject $data)

$additionalData = $data['additional_data'];

if (isset($additionalData['customer_billingName'])) {
$this->getInfoInstance()->setAdditionalInformation(
'customer_billingName',
$additionalData['customer_billingName']
);
}
// if (isset($additionalData['customer_billingName'])) {
// $this->getInfoInstance()->setAdditionalInformation(
// 'customer_billingName',
// $additionalData['customer_billingName']
// );
// }

if (isset($additionalData['customer_gender'])) {
$this->getInfoInstance()->setAdditionalInformation('customer_gender', $additionalData['customer_gender']);
}

if (isset($additionalData['customer_chamberOfCommerce'])) {
if (isset($additionalData['customer_chamberOfCommerce']) && !empty($additionalData['customer_chamberOfCommerce'])) {
$this->getInfoInstance()->setAdditionalInformation(
'customer_chamberOfCommerce',
$additionalData['customer_chamberOfCommerce']
Expand Down Expand Up @@ -681,7 +681,7 @@ public function getRequestBillingData($payment)
$telephone = $payment->getAdditionalInformation('customer_telephone');
$telephone = (empty($telephone) ? $billingAddress->getTelephone() : $telephone);

$category = $this->helper->checkCustomerGroup('buckaroo_magento2_billink') ? 'B2B' : 'B2C'; //1
$category = !empty($billingAddress->getCompany()) ? 'B2B' : 'B2C';

switch ($payment->getAdditionalInformation('customer_gender')) {
case 'male':
Expand Down
81 changes: 44 additions & 37 deletions view/frontend/web/js/view/payment/method-renderer/billink.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ define(
'buckaroo/checkout/common',
'buckaroo/checkout/datepicker',
'Magento_Ui/js/lib/knockout/bindings/datepicker'
/*,
'jquery/validate'*/
],
function (
$,
Expand All @@ -49,23 +47,23 @@ define(
'use strict';

$.validator.addMethod('validateAge', function (value) {
if (value && (value.length > 0)) {
var dateReg = /^\d{2}[./-]\d{2}[./-]\d{4}$/;
if (value.match(dateReg)) {
var birthday = +new Date(
value.substr(6, 4),
value.substr(3, 2) - 1,
value.substr(0, 2),
0, 0, 0
);
return ~~((Date.now() - birthday) / (31557600000)) >= 18;
if (value && (value.length > 0)) {
var dateReg = /^\d{2}[./-]\d{2}[./-]\d{4}$/;
if (value.match(dateReg)) {
var birthday = +new Date(
value.substr(6, 4),
value.substr(3, 2) - 1,
value.substr(0, 2),
0, 0, 0
);
return ~~((Date.now() - birthday) / (31557600000)) >= 18;
}
}
}
return false;
},
$.mage.__('You should be at least 18 years old.')
return false;
},
$.mage.__('You should be at least 18 years old.')
);

const validPhone = function (value) {
if (quote.billingAddress() === null) {
return false;
Expand Down Expand Up @@ -115,7 +113,6 @@ define(
$.mage.__('Phone number should be correct.')
);


return Component.extend(
{
defaults : {
Expand Down Expand Up @@ -144,7 +141,6 @@ define(
currentCustomerAddressId : null,
genderList: window.checkoutConfig.payment.buckaroo.billink.genderList,
dp: datePicker,
isB2B: window.checkoutConfig.payment.buckaroo.billink.b2b == true,

/**
* @override
Expand Down Expand Up @@ -175,14 +171,14 @@ define(
this.showFinancialWarning = ko.computed(
function () {
return quote.billingAddress() !== null &&
quote.billingAddress().countryId == 'NL' &&
window.checkoutConfig.payment.buckaroo.billink.showFinancialWarning
quote.billingAddress().countryId == 'NL' &&
window.checkoutConfig.payment.buckaroo.billink.showFinancialWarning
},
this
);
this.billingName = ko.computed(
function () {
if(this.isB2B && quote.billingAddress() !== null) {
if(this.isB2B() && quote.billingAddress() !== null) {
return quote.billingAddress().company;
}
if(quote.billingAddress() !== null) {
Expand All @@ -204,18 +200,18 @@ define(
return (
quote.billingAddress() === null ||
!validPhone(quote.billingAddress().telephone)
) && !this.isB2B;
) && !this.isB2B();
},
this
);

this.dob.subscribe(function() {
const dobId = 'buckaroo_magento2_billink_DoB';
const isValid = $(`#${dobId}`).valid();
let state = this.validationState();
state[dobId] = isValid;
this.validationState(state);
}, this);
}, this);

this.buttoncheck = ko.computed(
function () {
Expand Down Expand Up @@ -251,10 +247,10 @@ define(
];
if(this.showPhone()) {
fields.push('buckaroo_magento2_billink_Telephone')
}
if(this.isB2B) {
fields.push('buckaroo_magento2_billink_chamberOfCommerce')
}

if(this.isB2B()) {
fields.push('buckaroo_magento2_billink_chamberOfCommerce')
} else {
fields = fields.concat([
'buckaroo_magento2_billink_DoB',
Expand Down Expand Up @@ -313,25 +309,36 @@ define(
return true;
},

isB2B: function () {
const billingAddress = quote.billingAddress();
return billingAddress && billingAddress.company;
},

getData: function () {
let phone = this.phone();
if(!this.showPhone() && quote.billingAddress() !== null) {
phone = quote.billingAddress().telephone;
}

let additionalData = {
"customer_telephone": phone,
"customer_gender": this.selectedGender(),
"customer_DoB": this.dob(),
"termsCondition": this.tos(),
};

if (this.isB2B()) {
additionalData["customer_chamberOfCommerce"] = this.cocNumber();
additionalData["customer_VATNumber"] = this.vatNumber();
}

return {
"method": this.item.method,
"po_number": null,
"additional_data": {
"customer_telephone" : phone,
"customer_gender" : this.selectedGender(),
"customer_chamberOfCommerce" : this.cocNumber(),
"customer_VATNumber" : this.vatNumber(),
"customer_DoB" : this.dob(),
"termsCondition": this.tos(),
}
"additional_data": additionalData
};
}

}
);
}
Expand Down
35 changes: 18 additions & 17 deletions view/frontend/web/template/payment/buckaroo_magento2_billink.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
name="payment[method]"
class="radio"
data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>
<label class="label" data-bind="attr: {'for': getCode()}" >
<!-- ko text: getTitle() --><!-- /ko -->
<!-- ko if: subtext !== null && subtext.length > 0 -->
<p class="bk-description" data-bind="text: subtext, style: subTextStyle"></p>
<!-- /ko -->
<label class="label" data-bind="attr: {'for': getCode()}">
<!-- ko text: getTitle() --><!-- /ko -->
<!-- ko if: subtext !== null && subtext.length > 0 -->
<p class="bk-description" data-bind="text: subtext, style: subTextStyle"></p>
<!-- /ko -->
</label>
</div>
<div class="bk-img-wrap">
Expand All @@ -32,12 +32,12 @@
attr: {'data-hasrequired': $t('* Required Fields')}">
<fieldset class="fieldset payment">

<!-- ko if: !isB2B -->
<!-- ko if: !isB2B() -->
<div class="field required">
<label class="label" for="buckaroo_magento2_payperemail_genderSelect"> <span data-bind="i18n: 'Salutation:'"> </span> </label>
<label class="label" for="buckaroo_magento2_bilink_genderSelect"> <span data-bind="i18n: 'Salutation:'"> </span> </label>
<div class="control">
<select id="buckaroo_magento2_bilink_genderSelect" name="payment[buckaroo_magento2_bilink][customer_gender]" class="select"
data-bind="options: genderList,
<select id="buckaroo_magento2_bilink_genderSelect" name="payment[buckaroo_magento2_bilink][customer_gender]" class="select"
data-bind="options: genderList,
optionsText: $t('genderTitle'),
optionsValue: 'genderType',
optionsCaption: $t('-- Please Select Your Gender--'),
Expand All @@ -48,7 +48,8 @@
</div>
<!-- /ko -->

<div class="field required">
<!-- Commented out the Billing Name Field -->
<!-- <div class="field required">
<label class="label" for="buckaroo_magento2_billink_BillingName"> <span data-bind="i18n: 'Billing Name:'"> </span> </label>
<div class="control">
<input id="buckaroo_magento2_billink_BillingName"
Expand All @@ -60,9 +61,9 @@
name="payment[buckaroo_magento2_billink][customer_billingName]"
disabled >
</div>
</div>
</div> -->

<!-- ko if: showPhone -->
<!-- ko if: showPhone() -->
<div class="field required" >
<label class="label" for="buckaroo_magento2_billink_Telephone"> <span data-bind="i18n: 'Telephone:'"> </span> </label>
<div class="control">
Expand All @@ -79,7 +80,7 @@
</div>
<!-- /ko -->

<!-- ko if: !isB2B -->
<!-- ko if: !isB2B() -->
<div class="field required">
<label class="label" for="buckaroo_magento2_billink_DoB"> <span data-bind="i18n: 'Date of Birth:'"> </span> </label>
<div class="control addon">
Expand Down Expand Up @@ -109,7 +110,7 @@
</div>
<!-- /ko -->

<!-- ko if: isB2B -->
<!-- ko if: isB2B() -->
<div class="field required">
<legend class="label"> <span data-bind="i18n: 'Chamber of Commerce number:'"> </span> </legend>
<div class="control">
Expand All @@ -125,7 +126,7 @@
">
</div>
</div>

<div class="field">
<legend class="label"> <span data-bind="i18n: 'VAT number:'"> </span> </legend>
<div class="control">
Expand Down Expand Up @@ -166,9 +167,9 @@
</div>

<!-- ko if: showFinancialWarning -->
<span data-bind="i18n: `Je moet minimaal 18+ zijn om deze dienst te gebruiken. Als je op tijd betaalt, voorkom je extra kosten en zorg je dat je in de toekomst nogmaals gebruik kunt maken van de diensten van ${getTitle()}. Door verder te gaan, accepteer je de Algemene Voorwaarden en bevestig je dat je de Privacyverklaring en Cookieverklaring hebt gelezen.`"> </span>
<span data-bind="i18n: `Je moet minimaal 18+ zijn om deze dienst te gebruiken. Als je op tijd betaalt, voorkom je extra kosten en zorg je dat je in de toekomst nogmaals gebruik kunt maken van de diensten van ${getTitle()}. Door verder te gaan, accepteer je de Algemene Voorwaarden en bevestig je dat je de Privacyverklaring en Cookieverklaring hebt gelezen.`"> </span>
<!-- /ko -->

<div class="field">
<span data-bind="i18n: 'Please make sure all fields are filled in correctly before proceeding.' "> </span>
</div>
Expand Down

0 comments on commit 4375b45

Please sign in to comment.