We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit 46c6758b authored by Rik ter Beek's avatar Rik ter Beek

#61 add gender,dob and telephone number iput fields for openinvoice

parent 1d9aaa5d
......@@ -27,6 +27,10 @@ use Symfony\Component\Config\Definition\Exception\Exception;
class Pos extends \Magento\Payment\Block\Form
{
/**
* quest prefix
*/
const GUEST_ID = 'customer_';
protected $_orderFactory;
/**
......
......@@ -28,6 +28,11 @@ use Symfony\Component\Config\Definition\Exception\Exception;
class Redirect extends \Magento\Payment\Block\Form
{
/**
* quest prefix
*/
const GUEST_ID = 'customer_';
/**
* @var \Magento\Sales\Model\OrderFactory
*/
......@@ -118,7 +123,9 @@ class Redirect extends \Magento\Payment\Block\Form
if ($this->getPaymentMethodSelectionOnAdyen()) {
$url = 'https://test.adyen.com/hpp/select.shtml';
} else {
if ($this->_order->getPayment()->getAdditionalInformation('brand_code') == 'klarna') {
if ($this->_adyenHelper->isPaymentMethodOpenInvoiceMethod(
$this->_order->getPayment()->getAdditionalInformation('brand_code')
)) {
$url = "https://test.adyen.com/hpp/skipDetails.shtml";
} else {
$url = "https://test.adyen.com/hpp/details.shtml";
......@@ -133,7 +140,9 @@ class Redirect extends \Magento\Payment\Block\Form
if ($this->getPaymentMethodSelectionOnAdyen()) {
$url = 'https://live.adyen.com/hpp/select.shtml';
} else {
if ($this->_order->getPayment()->getAdditionalInformation('brand_code') == 'klarna') {
if ($this->_adyenHelper->isPaymentMethodOpenInvoiceMethod(
$this->_order->getPayment()->getAdditionalInformation('brand_code')
)) {
$url = "https://live.adyen.com/hpp/skipDetails.shtml";
} else {
$url = "https://live.adyen.com/hpp/details.shtml";
......@@ -194,6 +203,7 @@ class Redirect extends \Magento\Payment\Block\Form
}
$formFields = [];
$formFields['merchantAccount'] = $merchantAccount;
$formFields['merchantReference'] = $realOrderId;
$formFields['paymentAmount'] = (int)$amount;
......@@ -261,6 +271,10 @@ class Redirect extends \Magento\Payment\Block\Form
if ($this->_order->getPayment()->getAdditionalInformation(
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE) == "klarna"
) {
// // needed for DE and AT
$formFields['klarna.acceptPrivacyPolicy'] = 'true';
// don't allow editable shipping/delivery address
$formFields['billingAddressType'] = "1";
$formFields['deliveryAddressType'] = "1";
......
......@@ -54,7 +54,24 @@ class HppCommand implements CommandInterface
// do not send email
$payment = $payment->getPayment();
$payment->getOrder()->setCanSendNewEmailFlag(false);
$order = $payment->getOrder();
$order->setCanSendNewEmailFlag(false);
// update customer based on additionalFields
if ($payment->getAdditionalInformation("gender")) {
$order->setCustomerGender(\Adyen\Payment\Model\Gender::getMagentoGenderFromAdyenGender(
$payment->getAdditionalInformation("gender"))
);
}
if ($payment->getAdditionalInformation("dob")) {
$order->setCustomerDob($payment->getAdditionalInformation("dob"));
}
if ($payment->getAdditionalInformation("telephone")) {
$order->getBillingAddress()->setTelephone($payment->getAdditionalInformation("telephone"));
}
// update status and state
$stateObject->setState(\Magento\Sales\Model\Order::STATE_NEW);
......
......@@ -29,6 +29,11 @@ use Magento\Payment\Gateway\CommandInterface;
class PayByMailCommand implements CommandInterface
{
/**
* quest prefix
*/
const GUEST_ID = 'customer_';
/**
* @var \Adyen\Payment\Helper\Data
*/
......
......@@ -768,6 +768,22 @@ class Data extends AbstractHelper
return $billingAgreements;
}
/**
* @param $paymentMethod
* @return bool
*/
public function isPaymentMethodOpenInvoiceMethod($paymentMethod)
{
if (strlen($paymentMethod) >= 9 && substr($paymentMethod, 0, 9) == 'afterpay_') {
return true;
} else if($paymentMethod == 'klarna') {
return true;
} else {
return false;
}
}
/**
* @return bool
*/
......
......@@ -201,6 +201,11 @@ class PaymentMethods extends AbstractHelper
$paymentMethodCode = $paymentMethod['brandCode'];
$paymentMethod = $this->_fieldMapPaymentMethod($paymentMethod);
// check if payment method is an openinvoice method
$paymentMethod['isPaymentMethodOpenInvoiceMethod'] =
$this->_adyenHelper->isPaymentMethodOpenInvoiceMethod($paymentMethodCode);
// add icon location in result
if ($this->_adyenHelper->showLogos()) {
......
......@@ -1074,10 +1074,8 @@ class Cron
// if auto capture mode for openinvoice is turned on then use auto capture
if ($captureModeOpenInvoice == true &&
(strcmp($this->_paymentMethod, 'openinvoice') === 0 ||
strcmp($this->_paymentMethod, 'afterpay_default') === 0 ||
strcmp($this->_paymentMethod, 'klarna') === 0)) {
$this->_adyenHelper->isPaymentMethodOpenInvoiceMethod($this->_paymentMethod)
) {
$this->_adyenLogger->addAdyenNotificationCronjob(
'This payment method is configured to be working as auto capture '
);
......@@ -1106,10 +1104,7 @@ class Cron
* online capture after delivery, use Magento backend to online invoice
* (if the option auto capture mode for openinvoice is not set)
*/
if (strcmp($this->_paymentMethod, 'openinvoice') === 0 ||
strcmp($this->_paymentMethod, 'afterpay_default') === 0 ||
strcmp($this->_paymentMethod, 'klarna') === 0) {
if ($this->_adyenHelper->isPaymentMethodOpenInvoiceMethod($this->_paymentMethod)) {
$this->_adyenLogger->addAdyenNotificationCronjob('Capture mode for klarna is by default set to manual');
return false;
}
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model;
class Gender
{
const MALE = '1';
const FEMALE = '2';
const MALE_VALUE = 'MALE';
const FEMALE_VALUE = 'FEMALE';
/**
* @return array
*/
public static function getGenderTypes()
{
return [
self::MALE_VALUE => __('Male'),
self::FEMALE_VALUE => __('Female')
];
}
/**
* Get Magento Gender Value from Adyen Gender Value
*
* @param string $genderValue
* @return null|string
*/
public static function getMagentoGenderFromAdyenGender($genderValue)
{
$gender = null;
if ($genderValue == self::MALE_VALUE) {
$gender = self::MALE;
} elseif ($genderValue == self::FEMALE_VALUE) {
$gender = self::FEMALE;
}
return $gender;
}
/**
* @param string $genderValue
* @return null|string
*/
public static function getAdyenGenderFromMagentoGender($genderValue)
{
$gender = null;
if ($genderValue == self::MALE) {
$gender = self::MALE_VALUE;
} elseif ($genderValue == self::FEMALE) {
$gender = self::FEMALE_VALUE;
}
return $gender;
}
}
\ No newline at end of file
......@@ -54,22 +54,33 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
*/
protected $_urlBuilder;
/**
* @var \Magento\Customer\Model\Session
*/
protected $_customerSession;
/**
* AdyenHppConfigProvider constructor.
*
* @param PaymentHelper $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Magento\Customer\Model\Session $customerSession
*/
public function __construct(
PaymentHelper $paymentHelper,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\UrlInterface $urlBuilder
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Customer\Model\Session $customerSession
) {
$this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper;
$this->_request = $request;
$this->_urlBuilder = $urlBuilder;
$this->_customerSession = $customerSession;
}
/**
......@@ -90,9 +101,40 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
]
];
// get customer
if ($this->_customerSession->isLoggedIn()) {
$gender = \Adyen\Payment\Model\Gender::getAdyenGenderFromMagentoGender(
$this->_customerSession->getCustomerData()->getGender()
);
// format to calendar date
$dob = $this->_customerSession->getCustomerData()->getDob();
$dob = strtotime($dob);
$dob = date('m/d/Y', $dob);
} else {
$gender = "";
$dob = "";
}
// add to config
$config['payment'] ['adyenHpp']['gender'] = $gender;
$config['payment'] ['adyenHpp']['dob'] = $dob;
// gender types
$config['payment'] ['adyenHpp']['genderTypes'] = \Adyen\Payment\Model\Gender::getGenderTypes();
$paymentMethodSelectionOnAdyen =
$this->_adyenHelper->getAdyenHppConfigDataFlag('payment_selection_on_adyen');
$config['payment'] ['adyenHpp']['isPaymentMethodSelectionOnAdyen'] = $paymentMethodSelectionOnAdyen;
$config['payment'] ['adyenHpp']['showGender'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_gender');
$config['payment'] ['adyenHpp']['showDob'] = $this->_adyenHelper->getAdyenHppConfigDataFlag('show_dob');
$config['payment'] ['adyenHpp']['showTelephone'] = $this->_adyenHelper->getAdyenHppConfigDataFlag(
'show_telephone'
);
return $config;
}
......
......@@ -33,13 +33,20 @@ class AdyenHppDataAssignObserver extends AbstractDataAssignObserver
{
const BRAND_CODE = 'brand_code';
const ISSUER_ID = 'issuer_id';
const GENDER = 'gender';
const DOB = 'dob';
const TELEPHONE = 'telephone';
/**
* @var array
*/
protected $additionalInformationList = [
self::BRAND_CODE,
self::ISSUER_ID
self::ISSUER_ID,
self::GENDER,
self::DOB,
self::TELEPHONE
];
/**
......
......@@ -55,19 +55,44 @@
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<config_path>payment/adyen_hpp/hmac_live</config_path>
</field>
<group id="adyen_hpp_advanced_settings" translate="label" showInDefault="1" showInWebsite="1" sortOrder="200">
<label>Advanced Settings</label>
<frontend_model>Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
<group id="adyen_hpp_openinvoice_settings" translate="label" showInDefault="1" showInWebsite="1" sortOrder="100">
<label>Klarna\Afterpay Settings</label>
<frontend_model>Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
<field id="show_gender" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show Gender</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_hpp/show_gender</config_path>
</field>
<field id="show_dob" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show Date of Birth</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_hpp/show_dob</config_path>
</field>
<field id="show_telephone" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show Telephone</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_hpp/show_telephone</config_path>
</field>
<field id="ignore_second_address_field" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Ignore the second address line field</label>
<tooltip>If you do not want to send the second line address field to Klarna set this setting to 'Yes'</tooltip>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_hpp/ignore_second_address_field</config_path>
</field>
</group>
<group id="adyen_hpp_advanced_settings" translate="label" showInDefault="1" showInWebsite="1" sortOrder="200">
<label>Advanced Settings</label>
<frontend_model>Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
<field id="title" translate="label" type="text" sortOrder="65" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Title</label>
<config_path>payment/adyen_hpp/title</config_path>
</field>
<field id="delivery_days" translate="label" type="text" sortOrder="68" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Days to Delivery</label>
<tooltip>How many days to be added to the current date for delivery. ONLY whole numbers allowed.</tooltip>
<frontend_class>validate-number</frontend_class>
<config_path>payment/adyen_hpp/delivery_days</config_path>
</field>
<field id="delivery_days" translate="label" type="text" sortOrder="68" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Days to Delivery</label>
<tooltip>How many days to be added to the current date for delivery. ONLY whole numbers allowed.</tooltip>
<frontend_class>validate-number</frontend_class>
<config_path>payment/adyen_hpp/delivery_days</config_path>
</field>
<field id="payment_selection_on_adyen" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Payment method selection on Adyen Hosted Payment Page (HPP)</label>
<tooltip>If you set this to 'Yes', payment methods in the checkout won't be displayed and you will be redirected to the Adyen HPP to make the selection.</tooltip>
......
......@@ -61,6 +61,11 @@
background-position: 0 -272px;
}
.checkout-payment-method .input-text._has-datepicker {
width:20%;
margin-right:10px;
}
......@@ -52,7 +52,10 @@ define(
this._super()
.observe([
'brandCode',
'issuerId'
'issuerId',
'gender',
'dob',
'telephone'
]);
return this;
},
......@@ -100,37 +103,43 @@ define(
var paymentList = _.map(paymentMethods, function(value) {
if(value.brandCode == "ideal") {
return {
'value': value.brandCode,
'name': value,
'method': self.item.method,
'issuerIds': value.issuers,
'issuerId': ko.observable(null),
getCode: function() {
return self.item.method;
},
validate: function () {
return self.validate();
}
}
} else {
return {
'value': value.brandCode,
'name': value,
'method': self.item.method,
getCode: function() {
return self.item.method;
},
validate: function () {
return self.validate();
}
}
}
var result = {};
result.value = value.brandCode;
result.name = value;
result.method = self.item.method;
result.getCode = function() {
return self.item.method;
};
result.validate = function () {
return self.validate();
}
);
if(value.brandCode == "ideal") {
result.issuerIds = value.issuers;
result.issuerId = ko.observable(null);
} else if(value.isPaymentMethodOpenInvoiceMethod) {
result.telephone = ko.observable(quote.shippingAddress().telephone);
result.gender = ko.observable(window.checkoutConfig.payment.adyenHpp.gender);
result.dob = ko.observable(window.checkoutConfig.payment.adyenHpp.dob);
result.datepickerValue = ko.observable(); // needed ??
}
result.isPaymentMethodOpenInvoiceMethod = function() {
return value.isPaymentMethodOpenInvoiceMethod;
}
return result;
});
return paymentList;
},
getGenderTypes: function() {
// return window.checkoutConfig.payment.adyenHpp.genderTypes;
return _.map(window.checkoutConfig.payment.adyenHpp.genderTypes, function(value, key) {
return {
'key': key,
'value': value
}
});
},
/** Redirect to adyen */
continueToAdyen: function () {
if (this.validate() && additionalValidators.validate()) {
......@@ -146,26 +155,24 @@ define(
if (this.validate() && additionalValidators.validate()) {
// for ideal add brand_code in request
var data = {};
data.method = self.method;
data.po_number = null;
var additionalData = {};
additionalData.brand_code = self.value;
if(brandCode() == "ideal") {
var data = {
"method": self.method,
"po_number": null,
"additional_data": {
issuer_id: this.issuerId(),
brand_code: self.value
}
};
} else {
var data = {
"method": self.method,
"po_number": null,
"additional_data": {
brand_code: self.value
}
};
additionalData.issuer_id = this.issuerId();
} else if(brandCode() == "klarna") {
additionalData.gender = this.gender();
additionalData.dob = this.dob();
additionalData.telephone = this.telephone();
}
data.additional_data = additionalData;
selectPaymentMethodAction(data);
setPaymentMethodAction();
}
......@@ -212,6 +219,15 @@ define(
isIconEnabled: function() {
return window.checkoutConfig.payment.adyen.showLogo;
},
showGender: function() {
return window.checkoutConfig.payment.adyenHpp.showGender;
},
showDob: function() {
return window.checkoutConfig.payment.adyenHpp.showDob;
},
showTelephone: function() {
return window.checkoutConfig.payment.adyenHpp.showTelephone;
},
validate: function () {
return true;
}
......
......@@ -53,13 +53,11 @@
</div>
<fieldset class="fieldset" data-bind='attr: {id: "payment_form_" + $parent.getCode() + "_" + value}'>
<div class="payment-method-note">
<!-- ko if: value == 'ideal' -->
<label data-bind="attr: {'for': 'issuerId'}" class="label">
<span><!-- ko text: $t('Select Your Bank') --><!-- /ko --></span>
</label>
<!-- ko if: value == 'ideal' -->
<label data-bind="attr: {'for': 'issuerId'}" class="label">
<span><!-- ko text: $t('Select Your Bank') --><!-- /ko --></span>
</label>
<select name="payment[issuer_id]" data-bind="
options: name.issuers,
......@@ -68,11 +66,72 @@
value: issuerId,
optionsCaption: $t('Choose Your Bank')">
</select>
<!--/ko-->
<!-- ko if: isPaymentMethodOpenInvoiceMethod() -->
<!-- ko if: $parent.showGender() -->
<div class="field gender_type type required">
<label data-bind="attr: {for: getCode() + '_gender_type'}" class="label">
<span><!-- ko text: $t('Gender')--><!-- /ko --></span>
</label>
<div class="control">
<select class="select select-gender-type"
name="payment[gender]"
data-bind="attr: {id: getCode() + '_gender_type', 'data-container': getCode() + '-gender-type', 'data-validate': JSON.stringify({required:true})},
options: $parent.getGenderTypes(),
optionsValue: 'key',
optionsText: 'value',
optionsCaption: $t('-Please select-'),
value: gender"
data-validate="{required:true}">
</select>
</div>
</div>
<!--/ko-->
<!-- ko if: $parent.showDob() -->
<div class="field required">
<label data-bind="attr: {for: getCode() + '_dob'}" class="label">
<span><!-- ko text: $t('Date of Birth')--><!-- /ko --></span>
</label>
<div class="control">
<input type="text" class="input-text"
name="payment[dob]"
data-bind="
datepicker: { storage: datepickerValue, options: { showOn: 'both' } },
attr: {
title: $t('Date of Birth'),
'data-container': getCode() + '-dob',
'data-validate': JSON.stringify({'required':true })
},
value: dob"
/>
</div>
</div>
<!--/ko-->
</div>
<!-- ko if: $parent.showTelephone() -->
<div class="field required">
<label data-bind="attr: {for: getCode() + '_telephone'}" class="label">
<span><!-- ko text: $t('Telephone')--><!-- /ko --></span>
</label>
<div class="control">
<input type="number" class="input-text"
name="payment[telephone]"
data-bind="
attr: {
id: getCode() + '_telephone',
title: $t('Telephone'),
'data-container': getCode() + '-telephone',
'data-validate': JSON.stringify({'required-number':true })
},
value: telephone"
/>
</div>
</div>
<!--/ko-->
<!--/ko-->
</fieldset>
<div class="checkout-agreements-block">
<!-- ko foreach: $parents[1].getRegion('before-place-order') -->
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment