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 cddb1830 authored by Rik ter Beek's avatar Rik ter Beek

#58 added installments for creditcard and oneclick and minor oneclick sepa payment fix

parent 8a723268
<?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\Block\Adminhtml\System\Config\Field;
class Cctypes extends \Magento\Framework\View\Element\Html\Select
{
/**
* All possible credit card types
*
* @var array
*/
protected $ccTypes = [];
/**
* @var \Magento\Braintree\Model\Source\CcType
*/
protected $ccTypeSource;
/**
* Cctypes constructor.
*
* @param \Magento\Framework\View\Element\Context $context
* @param \Adyen\Payment\Model\Config\Source\CcType $ccTypeSource
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Adyen\Payment\Model\Config\Source\CcType $ccTypeSource,
array $data = []
) {
parent::__construct($context, $data);
$this->ccTypeSource = $ccTypeSource;
}
/**
* Render block HTML
*
* @return string
*/
public function _toHtml()
{
if (!$this->getOptions()) {
foreach ($this->_getCcTypes() as $country) {
if (isset($country['value']) && $country['value'] && isset($country['label']) && $country['label']) {
$this->addOption($country['value'], $country['label']);
}
}
}
$this->setClass('cc-type-select');
$this->setExtraParams('multiple="multiple"');
return parent::_toHtml();
}
/**
* All possible credit card types
*
* @return array
*/
protected function _getCcTypes()
{
if (!$this->ccTypes) {
$this->ccTypes = $this->ccTypeSource->toOptionArray();
}
return $this->ccTypes;
}
/**
* Sets name for input element
*
* @param string $value
* @return $this
*/
public function setInputName($value)
{
return $this->setName($value . '[]');
}
}
<?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\Block\Adminhtml\System\Config\Field;
class Installment extends \Magento\Framework\View\Element\Html\Select
{
/**
* Options
*
* @var array
*/
protected $_options = [ '1' => '1x',
'2' => '2x',
'3' => '3x',
'4' => '4x',
'5' => '5x',
'6' => '6x',
'7' => '7x',
'8' => '8x',
'9' => '9x',
'10' => '10x',
'11' => '11x',
'12' => '12x'
];
/**
* Sets name for input element
*
* @param string $value
* @return $this
*/
public function setInputName($value)
{
return $this->setName($value);
}
}
<?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\Block\Adminhtml\System\Config\Field;
class Installments extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{
/**
* @var \Adyen\Payment\Block\Adminhtml\System\Config\Field\Installment
*/
protected $_installmentRenderer = null;
/**
* @var \Magento\Braintree\Block\Adminhtml\Form\Field\CcTypes
*/
protected $_ccTypesRenderer = null;
/**
* Return renderer for installments
*
* @return Installment|\Magento\Framework\View\Element\BlockInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function getNumberOfInstallmentsRenderer()
{
if (!$this->_installmentRenderer) {
$this->_installmentRenderer = $this->getLayout()->createBlock(
'\Adyen\Payment\Block\Adminhtml\System\Config\Field\Installment',
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_installmentRenderer;
}
/**
* Returns renderer for country element
*
* @return \Magento\Braintree\Block\Adminhtml\Form\Field\Cctypes
*/
protected function getCcTypesRenderer()
{
if (!$this->_ccTypesRenderer) {
$this->_ccTypesRenderer = $this->getLayout()->createBlock(
'\Adyen\Payment\Block\Adminhtml\System\Config\Field\Cctypes',
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_ccTypesRenderer;
}
/**
* Prepare to render
* @return void
*/
protected function _prepareToRender()
{
$this->addColumn(
'amount',
[
'label' => __('Amount Range (minor units)'),
'renderer' => false,
]
);
$this->addColumn(
'installments',
[
'label' => __('Max Number Of Installments'),
'renderer' => $this->getNumberOfInstallmentsRenderer(),
]
);
$this->addColumn(
'cc_types',
[
'label' => __('Allowed Credit Card Types'),
'renderer' => $this->getCcTypesRenderer(),
]
);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add Rule');
}
/**
* Prepare existing row data object
*
* @param \Magento\Framework\DataObject $row
* @return void
*/
protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
{
$installlments = $row->getInstallments();
$options = [];
if ($installlments) {
$options['option_' . $this->getNumberOfInstallmentsRenderer()->calcOptionHash($installlments)]
= 'selected="selected"';
$ccTypes = $row->getCcTypes();
if (!is_array($ccTypes)) {
$ccTypes = [$ccTypes];
}
foreach ($ccTypes as $cardType) {
$options['option_' . $this->getCcTypesRenderer()->calcOptionHash($cardType)]
= 'selected="selected"';
}
}
$row->setData('option_extra_attrs', $options);
return;
}
}
...@@ -87,35 +87,52 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -87,35 +87,52 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
{ {
$config = parent::getConfig(); $config = parent::getConfig();
$demoMode = $this->_adyenHelper->getAdyenAbstractConfigDataFlag('demo_mode'); foreach ($this->_methodCodes as $code) {
if ($this->methods[$code]->isAvailable()) {
if ($demoMode) { $demoMode = $this->_adyenHelper->getAdyenAbstractConfigDataFlag('demo_mode');
$cseKey = $this->_adyenHelper->getAdyenCcConfigData('cse_publickey_test');
} else {
$cseKey = $this->_adyenHelper->getAdyenCcConfigData('cse_publickey_live');
}
$cseEnabled = $this->_adyenHelper->getAdyenCcConfigDataFlag('cse_enabled'); if ($demoMode) {
$cseKey = $this->_adyenHelper->getAdyenCcConfigData('cse_publickey_test');
} else {
$cseKey = $this->_adyenHelper->getAdyenCcConfigData('cse_publickey_live');
}
$recurringType = $this->_adyenHelper->getAdyenAbstractConfigData('recurring_type'); $cseEnabled = $this->_adyenHelper->getAdyenCcConfigDataFlag('cse_enabled');
$canCreateBillingAgreement = false;
if ($recurringType == "ONECLICK" || $recurringType == "ONECLICK,RECURRING") {
$canCreateBillingAgreement = true;
}
$config['payment'] ['adyenCc']['cseKey'] = $cseKey; $recurringType = $this->_adyenHelper->getAdyenAbstractConfigData('recurring_type');
$config['payment'] ['adyenCc']['cseEnabled'] = $cseEnabled; $canCreateBillingAgreement = false;
$config['payment'] ['adyenCc']['cseEnabled'] = $cseEnabled; if ($recurringType == "ONECLICK" || $recurringType == "ONECLICK,RECURRING") {
$config['payment']['adyenCc']['generationTime'] = date("c"); $canCreateBillingAgreement = true;
$config['payment']['adyenCc']['canCreateBillingAgreement'] = $canCreateBillingAgreement; }
// show logos turned on by default $config['payment'] ['adyenCc']['cseKey'] = $cseKey;
if ($this->_genericConfig->showLogos()) { $config['payment'] ['adyenCc']['cseEnabled'] = $cseEnabled;
$config['payment']['adyenCc']['creditCardPaymentMethodIcon'] = $this->_getCreditCardPaymentMethodIcon(); $config['payment'] ['adyenCc']['cseEnabled'] = $cseEnabled;
} $config['payment']['adyenCc']['generationTime'] = date("c");
$config['payment']['adyenCc']['canCreateBillingAgreement'] = $canCreateBillingAgreement;
$config['payment']['adyenCc']['icons'] = $this->getIcons(); // show logos turned on by default
if ($this->_genericConfig->showLogos()) {
$config['payment']['adyenCc']['creditCardPaymentMethodIcon'] = $this->_getCreditCardPaymentMethodIcon();
}
$config['payment']['adyenCc']['icons'] = $this->getIcons();
// has installments by default false
$config['payment']['adyenCc']['hasInstallments'] = false;
// get Installments
$installments = $this->_adyenHelper->getAdyenCcConfigData('installments');
if ($installments) {
$config['payment']['adyenCc']['installments'] = unserialize($installments);
$config['payment']['adyenCc']['hasInstallments'] = true;
} else {
$config['payment']['adyenCc']['installments'] = [];
}
}
}
return $config; return $config;
} }
......
...@@ -179,7 +179,7 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -179,7 +179,7 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
// is admin? // is admin?
if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
//retrieve storeId from quote //retrieve storeId from quote
$store = $this->_session->getQuote()->getStore(); $store = $this->_getQuote()->getStore();
} else { } else {
$store = $this->_storeManager->getStore(); $store = $this->_storeManager->getStore();
} }
...@@ -206,6 +206,12 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -206,6 +206,12 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
if (in_array($recurringPaymentType, $allowedContractTypes)) { if (in_array($recurringPaymentType, $allowedContractTypes)) {
// check if AgreementLabel is set and if contract has an recurringType // check if AgreementLabel is set and if contract has an recurringType
if ($billingAgreement->getAgreementLabel()) { if ($billingAgreement->getAgreementLabel()) {
// for Ideal use sepadirectdebit because it is
if ($agreementData['variant'] == 'ideal') {
$agreementData['variant'] = 'sepadirectdebit';
}
$data = ['reference_id' => $billingAgreement->getReferenceId(), $data = ['reference_id' => $billingAgreement->getReferenceId(),
'agreement_label' => $billingAgreement->getAgreementLabel(), 'agreement_label' => $billingAgreement->getAgreementLabel(),
'agreement_data' => $agreementData 'agreement_data' => $agreementData
...@@ -213,10 +219,6 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -213,10 +219,6 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
if ($this->_genericConfig->showLogos()) { if ($this->_genericConfig->showLogos()) {
$logoName = $agreementData['variant']; $logoName = $agreementData['variant'];
// for Ideal use sepadirectdebit because it is
if ($agreementData['variant'] == 'ideal') {
$logoName = "sepadirectdebit";
}
$asset = $this->_genericConfig->createAsset( $asset = $this->_genericConfig->createAsset(
'Adyen_Payment::images/logos/' . $logoName . '.png' 'Adyen_Payment::images/logos/' . $logoName . '.png'
...@@ -235,6 +237,34 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -235,6 +237,34 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
} }
$data['logo'] = $icon; $data['logo'] = $icon;
} }
/**
* Check if there are installments for this creditcard type defined
*/
$data['number_of_installments'] = 0;
$ccType = $this->_adyenHelper->getMagentoCreditCartType($agreementData['variant']);
$installments = null;
$installmentsValue = $this->_adyenHelper->getAdyenCcConfigData('installments');
if ($installmentsValue) {
$installments = unserialize($installmentsValue);
}
if ($installments) {
$numberOfInstallments = null;
$grandTotal = $this->_getQuote()->getGrandTotal();
foreach ($installments as $ccTypeInstallment => $installment) {
if ($ccTypeInstallment == $ccType) {
foreach ($installment as $amount => $installments) {
if ($grandTotal <= $amount) {
$numberOfInstallments = $installments;
}
}
}
}
if ($numberOfInstallments) {
$data['number_of_installments'] = $numberOfInstallments;
}
}
$billingAgreements[] = $data; $billingAgreements[] = $data;
} }
} }
...@@ -250,4 +280,12 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -250,4 +280,12 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
{ {
return $this->_adyenHelper->getAdyenOneclickConfigData('recurring_payment_type'); return $this->_adyenHelper->getAdyenOneclickConfigData('recurring_payment_type');
} }
/**
* @return \Magento\Quote\Model\Quote
*/
protected function _getQuote()
{
return $this->_session->getQuote();
}
} }
\ No newline at end of file
...@@ -259,6 +259,11 @@ class PaymentRequest extends DataObject ...@@ -259,6 +259,11 @@ class PaymentRequest extends DataObject
$request['selectedRecurringDetailReference'] = $recurringDetailReference; $request['selectedRecurringDetailReference'] = $recurringDetailReference;
} }
// if it is a sepadirectdebit set selectedBrand to sepadirectdebit in the case of oneclick
if ($payment->getCcType() == "sepadirectdebit") {
$request['selectedBrand'] = "sepadirectdebit";
}
if ($paymentMethodCode == \Adyen\Payment\Model\Method\Cc::METHOD_CODE || if ($paymentMethodCode == \Adyen\Payment\Model\Method\Cc::METHOD_CODE ||
$paymentMethodCode == \Adyen\Payment\Model\Method\Oneclick::METHOD_CODE) { $paymentMethodCode == \Adyen\Payment\Model\Method\Oneclick::METHOD_CODE) {
// If cse is enabled add encrypted card date into request // If cse is enabled add encrypted card date into request
...@@ -291,6 +296,12 @@ class PaymentRequest extends DataObject ...@@ -291,6 +296,12 @@ class PaymentRequest extends DataObject
$request['bankAccount'] = $bankAccount; $request['bankAccount'] = $bankAccount;
} }
// if installments is set add it into the request
if ($payment->getAdditionalInformation('number_of_installments') &&
$payment->getAdditionalInformation('number_of_installments') > 0) {
$request['installments']['value'] = $payment->getAdditionalInformation('number_of_installments');
}
$result = $service->authorise($request); $result = $service->authorise($request);
return $result; return $result;
} }
......
<?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\Config\Backend;
class Installments extends \Magento\Framework\App\Config\Value
{
/**
* @var \Magento\Framework\Math\Random
*/
protected $mathRandom;
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
* @param \Magento\Framework\Math\Random $mathRandom
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
*/
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\App\Config\ScopeConfigInterface $config,
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
\Magento\Framework\Math\Random $mathRandom,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
$this->mathRandom = $mathRandom;
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
}
/**
* Prepare data before save
*
* @return $this
*/
public function beforeSave()
{
$value = $this->getValue();
$result = [];
foreach ($value as $data) {
if (!$data) {
continue;
}
if (!is_array($data)) {
continue;
}
if (count($data) < 2) {
continue;
}
$amount = $data['amount'];
$installments = $data['installments'];
$ccTypes = $data['cc_types'];
foreach($ccTypes as $ccType) {
$result[$ccType][$amount] = $installments;
}
}
$this->setValue(serialize($result));
return $this;
}
/**
* Process data after load
*
* @return $this
*/
protected function _afterLoad()
{
$value = $this->getValue();
$value = unserialize($value);
if (is_array($value)) {
$value = $this->encodeArrayFieldValue($value);
$this->setValue($value);
}
return $this;
}
/**
* Encode value to be used in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
*
* @param array $value
* @return array
*/
protected function encodeArrayFieldValue(array $value)
{
$result = [];
// first combine the ccTypes together
$list = [];
foreach ($value as $ccType => $items) {
// sort on amount
ksort($items);
foreach ($items as $amount => $installment) {
if (!isset($list[$installment][$amount])) {
$list[$installment][$amount] = [$ccType];
} else {
$ccTypes = $list[$installment][$amount];
$ccTypes[] = $ccType;
$list[$installment][$amount] = $ccTypes;
}
}
}
// loop through combined ccTypes configuration and pre fill the items
foreach ($list as $installment => $amounts) {
foreach ($amounts as $amount => $ccTypes) {
$resultId = $this->mathRandom->getUniqueHash('_');
$result[$resultId] = ['amount' => $amount, 'cc_types' => $ccTypes, 'installments' => $installment];
}
}
return $result;
}
}
...@@ -207,6 +207,11 @@ class Cc extends \Magento\Payment\Model\Method\Cc ...@@ -207,6 +207,11 @@ class Cc extends \Magento\Payment\Model\Method\Cc
throw new \Magento\Framework\Exception\LocalizedException(__('Card encryption failed')); throw new \Magento\Framework\Exception\LocalizedException(__('Card encryption failed'));
} }
} }
// set number of installements
if (isset($additionalData['number_of_installments'])) {
$infoInstance->setAdditionalInformation('number_of_installments', $additionalData['number_of_installments']);
}
// save value remember details checkbox // save value remember details checkbox
if (isset($additionalData['store_cc'])) { if (isset($additionalData['store_cc'])) {
......
...@@ -78,7 +78,7 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc ...@@ -78,7 +78,7 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc
$variant = $additionalData['variant']; $variant = $additionalData['variant'];
$ccType = $this->_adyenHelper->getMagentoCreditCartType($variant); $ccType = $this->_adyenHelper->getMagentoCreditCartType($variant);
$infoInstance->setCcType($ccType); $infoInstance->setCcType($ccType);
// save value remember details checkbox // save value remember details checkbox
$infoInstance->setAdditionalInformation('recurring_detail_reference', $infoInstance->setAdditionalInformation('recurring_detail_reference',
$additionalData['recurring_detail_reference']); $additionalData['recurring_detail_reference']);
...@@ -92,6 +92,11 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc ...@@ -92,6 +92,11 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc
$infoInstance->setAdditionalInformation('customer_interaction', $customerInteraction); $infoInstance->setAdditionalInformation('customer_interaction', $customerInteraction);
// set number of installements
if (isset($additionalData['number_of_installments'])) {
$infoInstance->setAdditionalInformation('number_of_installments', $additionalData['number_of_installments']);
}
return $this; return $this;
} }
......
...@@ -72,6 +72,13 @@ ...@@ -72,6 +72,13 @@
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_cc/enable_moto</config_path> <config_path>payment/adyen_cc/enable_moto</config_path>
</field> </field>
<field id="installments" translate="label" sortOrder="220" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Installments</label>
<tooltip>Configure your installment foreach creditcard type.</tooltip>
<frontend_model>Adyen\Payment\Block\Adminhtml\System\Config\Field\Installments</frontend_model>
<backend_model>Adyen\Payment\Model\Config\Backend\Installments</backend_model>
<config_path>payment/adyen_cc/installments</config_path>
</field>
</group> </group>
<group id="adyen_cc_country_specific" translate="label" showInDefault="1" showInWebsite="1" sortOrder="200"> <group id="adyen_cc_country_specific" translate="label" showInDefault="1" showInWebsite="1" sortOrder="200">
......
...@@ -55,6 +55,10 @@ $_isDemoMode = $block->isDemoMode(); ...@@ -55,6 +55,10 @@ $_isDemoMode = $block->isDemoMode();
<?php echo __('Credit Card Number: xxxx-%1', $this->getInfo()->getCcLast4()) ?><br/> <?php echo __('Credit Card Number: xxxx-%1', $this->getInfo()->getCcLast4()) ?><br/>
<?php endif;?> <?php endif;?>
<?php if($_info->getAdditionalInformation('number_of_installments') != ""): ?>
<?php echo __('Number of installments: %1', $_info->getAdditionalInformation('number_of_installments')) ?><br/>
<?php endif; ?>
<?php if($_info->getAdditionalInformation('adyen_avs_result') != ""): ?> <?php if($_info->getAdditionalInformation('adyen_avs_result') != ""): ?>
<?php echo __('Avs result: %1', $_info->getAdditionalInformation('adyen_avs_result')) ?><br/> <?php echo __('Avs result: %1', $_info->getAdditionalInformation('adyen_avs_result')) ?><br/>
......
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
define(
[
'ko',
],
function (ko) {
'use strict';
var installments = ko.observableArray([]);
return {
/**
* Populate the list of installments
* @param {Array} methods
*/
setInstallments: function (installmentData) {
// remove everything from the current list
installments.removeAll();
// populate installments
var i;
for (i = 1; i <= installmentData; i++) {
installments.push({
key: i,
value: i
});
}
},
/**
* Get the list of available installments.
* @returns {Array}
*/
getInstallments: function () {
return installments;
}
};
}
);
...@@ -30,9 +30,13 @@ define( ...@@ -30,9 +30,13 @@ define(
'mage/translate', 'mage/translate',
'Magento_Checkout/js/model/payment/additional-validators', 'Magento_Checkout/js/model/payment/additional-validators',
'Magento_Customer/js/model/customer', 'Magento_Customer/js/model/customer',
'Magento_Payment/js/model/credit-card-validation/credit-card-data',
'Magento_Checkout/js/model/quote',
'ko',
'Adyen_Payment/js/model/installments',
'adyen/encrypt' 'adyen/encrypt'
], ],
function (_, $, Component, placeOrderAction, $t, additionalValidators, customer, adyenEncrypt) { function (_, $, Component, placeOrderAction, $t, additionalValidators, customer, creditCardData, quote, ko, installments, adyenEncrypt) {
'use strict'; 'use strict';
return Component.extend({ return Component.extend({
...@@ -40,7 +44,8 @@ define( ...@@ -40,7 +44,8 @@ define(
template: 'Adyen_Payment/payment/cc-form', template: 'Adyen_Payment/payment/cc-form',
creditCardOwner: '', creditCardOwner: '',
encryptedData: '', encryptedData: '',
setStoreCc: true setStoreCc: true,
installment: ''
}, },
initObservable: function () { initObservable: function () {
this._super() this._super()
...@@ -56,10 +61,49 @@ define( ...@@ -56,10 +61,49 @@ define(
'creditCardOwner', 'creditCardOwner',
'encryptedData', 'encryptedData',
'generationtime', 'generationtime',
'setStoreCc' 'setStoreCc',
'installment'
]); ]);
return this; return this;
}, },
getInstallments: installments.getInstallments(),
initialize: function() {
var self = this;
this._super();
//Set credit card number to credit card data object
this.creditCardNumber.subscribe(function(value) {
// installments enabled ??
var allInstallments = self.getAllInstallments();
// what card is this ??
var creditcardType = creditCardData.creditCard.type;
if(creditcardType) {
if (creditcardType in allInstallments) {
// get for the creditcard the installments
var installmentCreditcard = allInstallments[creditcardType];
var grandTotal = quote.totals().grand_total;
var numberOfInstallments = 0;
$.each(installmentCreditcard, function (amount, installment) {
if(grandTotal <= amount) {
numberOfInstallments = installment;
return false;
}
});
if(numberOfInstallments > 0) {
installments.setInstallments(numberOfInstallments);
}
} else {
installments.setInstallments(0);
}
}
});
},
setPlaceOrderHandler: function(handler) { setPlaceOrderHandler: function(handler) {
this.placeOrderHandler = handler; this.placeOrderHandler = handler;
}, },
...@@ -76,7 +120,8 @@ define( ...@@ -76,7 +120,8 @@ define(
'cc_type': this.creditCardType(), 'cc_type': this.creditCardType(),
'encrypted_data': this.encryptedData(), 'encrypted_data': this.encryptedData(),
'generationtime': this.generationtime(), 'generationtime': this.generationtime(),
'store_cc': this.setStoreCc() 'store_cc': this.setStoreCc(),
'number_of_installments': this.installment()
} }
}; };
}, },
...@@ -175,6 +220,12 @@ define( ...@@ -175,6 +220,12 @@ define(
? window.checkoutConfig.payment.adyenCc.icons[type] ? window.checkoutConfig.payment.adyenCc.icons[type]
: false : false
}, },
hasInstallments: function() {
return window.checkoutConfig.payment.adyenCc.hasInstallments;
},
getAllInstallments: function() {
return window.checkoutConfig.payment.adyenCc.installments;
}
}); });
} }
); );
......
...@@ -66,16 +66,6 @@ define( ...@@ -66,16 +66,6 @@ define(
getCode: function() { getCode: function() {
return 'adyen_oneclick'; return 'adyen_oneclick';
}, },
getData: function() {
return {
'method': this.item.method,
additional_data: {
'cc_type': this.creditCardType(),
'cc_cid': this.creditCardVerificationNumber(),
'encrypted_data': this.encryptedData()
}
};
},
isActive: function() { isActive: function() {
return true; return true;
}, },
...@@ -112,7 +102,8 @@ define( ...@@ -112,7 +102,8 @@ define(
"additional_data": { "additional_data": {
encrypted_data: encryptedData, encrypted_data: encryptedData,
recurring_detail_reference: self.value, recurring_detail_reference: self.value,
variant: self.agreement_data.variant variant: self.agreement_data.variant,
number_of_installments: self.installment
} }
}; };
...@@ -147,80 +138,91 @@ define( ...@@ -147,80 +138,91 @@ define(
// convert to list so you can iterate // convert to list so you can iterate
var paymentList = _.map(window.checkoutConfig.payment.adyenOneclick.billingAgreements, function(value) { var paymentList = _.map(window.checkoutConfig.payment.adyenOneclick.billingAgreements, function(value) {
var creditCardExpMonth, creditCardExpYear = false; var creditCardExpMonth, creditCardExpYear = false;
if(value.agreement_data.card) { if(value.agreement_data.card) {
creditCardExpMonth = value.agreement_data.card.expiryMonth creditCardExpMonth = value.agreement_data.card.expiryMonth
creditCardExpYear = value.agreement_data.card.expiryYear; creditCardExpYear = value.agreement_data.card.expiryYear;
}
// pre-define installments if they are set
var i, installments = [];
if(value.number_of_installments > 0) {
for (i = 1; i <= value.number_of_installments; i++) {
installments.push({
key: i,
value: i
});
} }
}
return { return {
'expiry': ko.observable(false), 'expiry': ko.observable(false),
'test': true, 'label': value.agreement_label,
'test2': true, 'value': value.reference_id,
'label': value.agreement_label, 'agreement_data': value.agreement_data,
'value': value.reference_id, 'logo': value.logo,
'agreement_data': value.agreement_data, 'installment': '',
'logo': value.logo, 'number_of_installments': value.number_of_installments,
'method': self.item.method, getInstallments: ko.observableArray(installments),
getCode: function() { 'method': self.item.method,
return self.item.method; getCode: function() {
}, return self.item.method;
creditCardVerificationNumber: '', },
creditCardExpMonth: ko.observable(creditCardExpMonth), creditCardVerificationNumber: '',
creditCardExpYear: ko.observable(creditCardExpYear), creditCardExpMonth: ko.observable(creditCardExpMonth),
getCSEKey: function() { creditCardExpYear: ko.observable(creditCardExpYear),
return window.checkoutConfig.payment.adyenCc.cseKey; getCSEKey: function() {
}, return window.checkoutConfig.payment.adyenCc.cseKey;
getGenerationTime: function() { },
return window.checkoutConfig.payment.adyenCc.generationTime; getGenerationTime: function() {
}, return window.checkoutConfig.payment.adyenCc.generationTime;
validate: function () { },
validate: function () {
var code = self.item.method; var code = self.item.method;
var value = this.value; var value = this.value;
var codeValue = code + '_' + value; var codeValue = code + '_' + value;
var form = 'form[data-role=' + codeValue + ']'; var form = 'form[data-role=' + codeValue + ']';
var formObject = $(form);
var validate = $(form).validation() && $(form).validation('isValid'); var validate = $(form).validation() && $(form).validation('isValid');
// if oneclick or recurring is a card do validation on expiration date // if oneclick or recurring is a card do validation on expiration date
if(this.agreement_data.card) { if(this.agreement_data.card) {
// add extra validation because jqeury validation will not work on non name attributes // add extra validation because jqeury validation will not work on non name attributes
var expiration = Boolean($(form + ' #' + codeValue + '_expiration').valid()); var expiration = Boolean($(form + ' #' + codeValue + '_expiration').valid());
var expiration_yr = Boolean($(form + ' #' + codeValue + '_expiration_yr').valid()); var expiration_yr = Boolean($(form + ' #' + codeValue + '_expiration_yr').valid());
} else {
var expiration = true;
var expiration_yr = true;
}
// only check if recurring type is set to oneclick // only check if recurring type is set to oneclick
var cid = true; var cid = true;
if(self.hasVerification()) { if(self.hasVerification()) {
var cid = Boolean($(form + ' #' + codeValue + '_cc_cid').valid()); var cid = Boolean($(form + ' #' + codeValue + '_cc_cid').valid());
} }
} else {
if(!validate || !expiration || !expiration_yr || !cid) { var expiration = true;
return false; var expiration_yr = true;
} var cid = true;
return true;
},
selectExpiry: function() {
var self = this;
self.expiry(true);
return true;
} }
if(!validate || !expiration || !expiration_yr || !cid) {
return false;
}
return true;
},
selectExpiry: function() {
var self = this;
self.expiry(true);
return true;
} }
} }
); });
return paymentList; return paymentList;
}, },
selectBillingAgreement: function() { selectBillingAgreement: function() {
var self = this; var self = this;
// set payment method to adyen_hpp // set payment method data
var data = { var data = {
"method": self.method, "method": self.method,
"po_number": null, "po_number": null,
......
...@@ -202,6 +202,32 @@ ...@@ -202,6 +202,32 @@
</div> </div>
<!-- /ko --> <!-- /ko -->
<!-- ko if: (hasInstallments())-->
<div class="field required" data-bind="attr: {id: getCode() + '_installments_div'}, visible: getInstallments().length > 0">
<label data-bind="attr: {for: getCode() + '_installments'}" class="label">
<span><!-- ko text: $t('Installments')--><!-- /ko --></span>
</label>
<div class="control">
<select class="select"
name="payment[number_of_installments]"
data-bind="attr: {id: getCode() + '_installments', 'data-container': getCode() + '-installments', 'data-validate': JSON.stringify({required:true})},
enable: isActive($parents),
options: getInstallments,
optionsValue: 'value',
optionsText: 'key',
optionsCaption: $t('Installments'),
value: installment"
data-validate="{required:true}">
</select>
</div>
</div>
<!-- /ko -->
<!-- ko if: (canCreateBillingAgreement())--> <!-- ko if: (canCreateBillingAgreement())-->
<div class="field choice"> <div class="field choice">
......
...@@ -196,6 +196,30 @@ ...@@ -196,6 +196,30 @@
<!--/ko--> <!--/ko-->
<!-- ko if: number_of_installments > 0 -->
<div class="field required" data-bind="attr: {id: getCode() + '_installments_div'}, visible: getInstallments().length > 0">
<label data-bind="attr: {for: getCode() + '_installments'}" class="label">
<span><!-- ko text: $t('Installments')--><!-- /ko --></span>
</label>
<div class="control">
<select class="select"
name="payment[number_of_installments]"
data-bind="attr: {id: getCode() + '_installments', 'data-container': getCode() + '-installments', 'data-validate': JSON.stringify({required:true})},
enable: $parent.isActive($parents),
options: getInstallments,
optionsValue: 'value',
optionsText: 'key',
optionsCaption: $t('Installments'),
value: installment"
data-validate="{required:true}">
</select>
</div>
</div>
<!-- /ko -->
......
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