Skip to content

Commit

Permalink
Merge pull request #60 from paynl/feature/DOB
Browse files Browse the repository at this point in the history
Add DOB field to Billink
  • Loading branch information
woutse authored Apr 28, 2020
2 parents ef56ab1 + 452b25c commit 46e7016
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 8 deletions.
43 changes: 43 additions & 0 deletions Model/Config/Source/showDobOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright © 2020 Pay.nl All rights reserved.
*/

namespace Paynl\Payment\Model\Config\Source;

use \Magento\Framework\Option\ArrayInterface;

class showDobOptions implements ArrayInterface
{

/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
$arrOptions = $this->toArray();

$arrResult = [];
foreach ($arrOptions as $value => $label) {
$arrResult[] = ['value' => $value, 'label' => $label];
}
return $arrResult;
}

/**
* Get options in "key-value" format
*
* @return array
*/
public function toArray()
{
return [
'0' => __('No'),
'1' => __('Yes, as optional'),
'2' => __('Yes, as required'),
];
}

}
8 changes: 7 additions & 1 deletion Model/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2020 PAY. All rights reserved.
* Copyright © 2015 Pay.nl All rights reserved.
*/

namespace Paynl\Payment\Model;
Expand Down Expand Up @@ -111,6 +111,7 @@ public function getConfig()
$config['payment']['banks'][$code] = $this->getBanks($code);
$config['payment']['icon'][$code] = $this->getIcon($code);
$config['payment']['showkvk'][$code] = $this->getKVK($code);
$config['payment']['showdob'][$code] = $this->getDOB($code);
}
}

Expand Down Expand Up @@ -139,6 +140,11 @@ protected function getKVK($code)
return $this->methods[$code]->getKVK();
}

protected function getDOB($code)
{
return $this->methods[$code]->getDOB();
}

/**
* Get payment method icon
*
Expand Down
12 changes: 11 additions & 1 deletion Model/Paymentmethod/Billink.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2020 PAY. All rights reserved.
* Copyright © 2020 Pay.nl All rights reserved.
*/

namespace Paynl\Payment\Model\Paymentmethod;
Expand All @@ -26,13 +26,19 @@ public function getKVK()
return $this->_scopeConfig->getValue('payment/paynl_payment_billink/showkvk', 'store');
}

public function getDOB()
{
return $this->_scopeConfig->getValue('payment/paynl_payment_billink/showdob', 'store');
}

public function assignData(\Magento\Framework\DataObject $data)
{
parent::assignData($data);

if (is_array($data))
{
$this->getInfoInstance()->setAdditionalInformation('kvknummer', $data['kvknummer']);
$this->getInfoInstance()->setAdditionalInformation('dob', $data['dob']);
} elseif ($data instanceof \Magento\Framework\DataObject)
{

Expand All @@ -46,6 +52,10 @@ public function assignData(\Magento\Framework\DataObject $data)
$this->getInfoInstance()->setAdditionalInformation('billink_agree', $additional_data['billink_agree']);
}

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

}
return $this;
}
Expand Down
13 changes: 12 additions & 1 deletion Model/Paymentmethod/PaymentMethod.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © 2020 PAY. All rights reserved.
* Copyright © 2015 Pay.nl All rights reserved.
*/

namespace Paynl\Payment\Model\Paymentmethod;
Expand Down Expand Up @@ -116,6 +116,11 @@ public function getKVK()
return [];
}

public function getDOB()
{
return [];
}

public function initialize($paymentAction, $stateObject)
{
$status = $this->getConfigData('order_status');
Expand Down Expand Up @@ -194,6 +199,7 @@ protected function doStartTransaction(Order $order)
$additionalData = $order->getPayment()->getAdditionalInformation();
$bankId = null;
$expireDate = null;

if (isset($additionalData['kvknummer']) && is_numeric($additionalData['kvknummer'])) {
$kvknummer = $additionalData['kvknummer'];
}
Expand Down Expand Up @@ -244,6 +250,9 @@ protected function doStartTransaction(Order $order)
'phoneNumber' => $arrBillingAddress['telephone'],
'emailAddress' => $arrBillingAddress['email'],
);
if (isset($additionalData['dob'])) {
$enduser['dob'] = $additionalData['dob'];
}

if (isset($arrBillingAddress['company']) && !empty($arrBillingAddress['company'])) {
$enduser['company']['name'] = $arrBillingAddress['company'];
Expand Down Expand Up @@ -423,6 +432,8 @@ protected function doStartTransaction(Order $order)
}
$data['ipaddress'] = $ipAddress;



$transaction = \Paynl\Transaction::start($data);

return $transaction;
Expand Down
9 changes: 9 additions & 0 deletions etc/adminhtml/paymentmethods/billink.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
<config_path>payment/paynl_payment_billink/showkvk</config_path>
<comment><![CDATA[When choosen for Billink the customer can additionally enter his KVK/COC before continuing to Billink.]]></comment>
</field>
<field id="showdob" translate="label" type="select" sortOrder="66" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show Date of birth field</label>
<source_model>Paynl\Payment\Model\Config\Source\showDobOptions</source_model>
<depends>
<field id="active">1</field>
</depends>
<config_path>payment/paynl_payment_billink/showdob</config_path>
<comment><![CDATA[When choosen for Billink the customer can additionally enter his Date of Birth before continuing to Billink.]]></comment>
</field>
<field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Title</label>
Expand Down
39 changes: 37 additions & 2 deletions view/frontend/web/js/view/payment/method-renderer/billink.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,51 @@ define(
template: 'Paynl_Payment/payment/billink'
},
kvknummer: null,
dateofbirth: null,
billink_agree: null,
showKVK: function () {
showKVK: function () {
return this.getKVK() > 0;
},
getKVK: function () {
return window.checkoutConfig.payment.showkvk[this.item.method];
},
showDOB: function () {
return this.getDOB() > 0;
},
getDOB: function () {
return window.checkoutConfig.payment.showdob[this.item.method];
},
showKVKDOB: function () {
return this.getDOB() > 0;
},
getKVKDOB: function () {
return (this.getDOB() > 0 && this.getKVK() > 0);
},
/**
* Get payment method data
*/
getData: function () {

var dob = new Date(this.dateofbirth);

var dd = dob.getDate();
var mm = dob.getMonth() + 1;

var yyyy = dob.getFullYear();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
var dob_format = dd + '-' + mm + '-' + yyyy;

return {
'method': this.item.method,
'po_number': null,
'additional_data': {
"kvknummer": this.kvknummer,
"dob": dob_format,
"billink_agree": this.billink_agree
}
};
Expand All @@ -43,7 +72,7 @@ define(
placeOrder: function (data, event) {
var placeOrder;
var showingKVK = this.getKVK() == 2;

var showingDOB = this.getDOB() == 2;
if (showingKVK) {
if (this.billink_agree != true) {
alert('U dient eerst akkoord te gaan met de betalingsvoorwaarden van Billink.');
Expand All @@ -54,6 +83,12 @@ define(
return false;
}
}
if (showingDOB) {
if (this.dateofbirth == null || this.dateofbirth.length < 1) {
alert('Voer een geldig geboortedatum in.');
return false;
}
}

if (event) {
event.preventDefault();
Expand Down
13 changes: 10 additions & 3 deletions view/frontend/web/template/payment/billink.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@
<!--/ko-->
</div>
<p data-bind="html: getInstructions();"></p>
<div data-bind="visible: showDOB()" class="field-select-billing">
<label for="dob">Geboortedatum</label>
<input type="date" data-bind="optionsValue: 'id', name: 'dateofbirth', value: dateofbirth" name="dateofbirth" placeholder="mm/dd/yyyy"/>
</div>
<div data-bind="visible: showKVKDOB()" class="field-select-billing">
<br/>
</div>
<div data-bind="visible: showKVK()" class="field-select-billing">
<label for="kvknummer">KVK nummer</label>
<input data-bind="optionsValue: 'id', name: 'kvknummer', value: kvknummer" name="kvknummer"/>

<div style="padding-top:10px">
<input data-bind="optionsValue: 'id', name: 'kvknummer', value: kvknummer" name="kvknummer"/>
<div style="padding-top:10px; padding-bottom:10px">
<input type="checkbox" data-bind="checked: billink_agree"/>
<label for="billink_agree">U dient akkoord te gaan met de</label> <a target="_blank" href="https://billink.nl/voorwaarden/gebruikersvoorwaarden.pdf">betalingsvoorwaarden</a>
</div>
</div>

<div class="actions-toolbar">
<div class="primary">
<button class="action primary checkout"
Expand Down

0 comments on commit 46e7016

Please sign in to comment.