Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Adyen Magento2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shared Libs
Adyen Magento2
Commits
cddb1830
Commit
cddb1830
authored
Jun 27, 2016
by
Rik ter Beek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#58 added installments for creditcard and oneclick and minor oneclick sepa payment fix
parent
8a723268
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
759 additions
and
97 deletions
+759
-97
Block/Adminhtml/System/Config/Field/Cctypes.php
Block/Adminhtml/System/Config/Field/Cctypes.php
+98
-0
Block/Adminhtml/System/Config/Field/Installment.php
Block/Adminhtml/System/Config/Field/Installment.php
+57
-0
Block/Adminhtml/System/Config/Field/Installments.php
Block/Adminhtml/System/Config/Field/Installments.php
+133
-0
Model/AdyenCcConfigProvider.php
Model/AdyenCcConfigProvider.php
+39
-22
Model/AdyenOneclickConfigProvider.php
Model/AdyenOneclickConfigProvider.php
+43
-5
Model/Api/PaymentRequest.php
Model/Api/PaymentRequest.php
+11
-0
Model/Config/Backend/Installments.php
Model/Config/Backend/Installments.php
+145
-0
Model/Method/Cc.php
Model/Method/Cc.php
+5
-0
Model/Method/Oneclick.php
Model/Method/Oneclick.php
+6
-1
etc/adminhtml/system/adyen_cc.xml
etc/adminhtml/system/adyen_cc.xml
+7
-0
view/adminhtml/templates/info/adyen_cc.phtml
view/adminhtml/templates/info/adyen_cc.phtml
+4
-0
view/frontend/web/js/model/installments.js
view/frontend/web/js/model/installments.js
+39
-0
view/frontend/web/js/view/payment/method-renderer/adyen-cc-method.js
...nd/web/js/view/payment/method-renderer/adyen-cc-method.js
+55
-4
view/frontend/web/js/view/payment/method-renderer/adyen-oneclick-method.js
.../js/view/payment/method-renderer/adyen-oneclick-method.js
+67
-65
view/frontend/web/template/payment/cc-form.html
view/frontend/web/template/payment/cc-form.html
+26
-0
view/frontend/web/template/payment/oneclick-form.html
view/frontend/web/template/payment/oneclick-form.html
+24
-0
No files found.
Block/Adminhtml/System/Config/Field/Cctypes.php
0 → 100644
View file @
cddb1830
<?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
.
'[]'
);
}
}
Block/Adminhtml/System/Config/Field/Installment.php
0 → 100644
View file @
cddb1830
<?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
);
}
}
Block/Adminhtml/System/Config/Field/Installments.php
0 → 100644
View file @
cddb1830
<?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
;
}
}
Model/AdyenCcConfigProvider.php
View file @
cddb1830
...
...
@@ -87,35 +87,52 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
{
$config
=
parent
::
getConfig
();
$demoMode
=
$this
->
_adyenHelper
->
getAdyenAbstractConfigDataFlag
(
'demo_mode'
);
foreach
(
$this
->
_methodCodes
as
$code
)
{
if
(
$this
->
methods
[
$code
]
->
isAvailable
())
{
if
(
$demoMode
)
{
$cseKey
=
$this
->
_adyenHelper
->
getAdyenCcConfigData
(
'cse_publickey_test'
);
}
else
{
$cseKey
=
$this
->
_adyenHelper
->
getAdyenCcConfigData
(
'cse_publickey_live'
);
}
$demoMode
=
$this
->
_adyenHelper
->
getAdyenAbstractConfigDataFlag
(
'demo_mode'
);
$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'
);
$canCreateBillingAgreement
=
false
;
if
(
$recurringType
==
"ONECLICK"
||
$recurringType
==
"ONECLICK,RECURRING"
)
{
$canCreateBillingAgreement
=
true
;
}
$cseEnabled
=
$this
->
_adyenHelper
->
getAdyenCcConfigDataFlag
(
'cse_enabled'
);
$config
[
'payment'
]
[
'adyenCc'
][
'cseKey'
]
=
$cseKey
;
$config
[
'payment'
]
[
'adyenCc'
][
'cseEnabled'
]
=
$cseEnabled
;
$config
[
'payment'
]
[
'adyenCc'
][
'cseEnabled'
]
=
$cseEnabled
;
$config
[
'payment'
][
'adyenCc'
][
'generationTime'
]
=
date
(
"c"
)
;
$config
[
'payment'
][
'adyenCc'
][
'canCreateBillingAgreement'
]
=
$canCreateBillingAgreement
;
$recurringType
=
$this
->
_adyenHelper
->
getAdyenAbstractConfigData
(
'recurring_type'
)
;
$canCreateBillingAgreement
=
false
;
if
(
$recurringType
==
"ONECLICK"
||
$recurringType
==
"ONECLICK,RECURRING"
)
{
$canCreateBillingAgreement
=
true
;
}
// show logos turned on by default
if
(
$this
->
_genericConfig
->
showLogos
())
{
$config
[
'payment'
][
'adyenCc'
][
'creditCardPaymentMethodIcon'
]
=
$this
->
_getCreditCardPaymentMethodIcon
();
}
$config
[
'payment'
]
[
'adyenCc'
][
'cseKey'
]
=
$cseKey
;
$config
[
'payment'
]
[
'adyenCc'
][
'cseEnabled'
]
=
$cseEnabled
;
$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
;
}
...
...
Model/AdyenOneclickConfigProvider.php
View file @
cddb1830
...
...
@@ -179,7 +179,7 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
// is admin?
if
(
$this
->
_appState
->
getAreaCode
()
===
\Magento\Backend\App\Area\FrontNameResolver
::
AREA_CODE
)
{
//retrieve storeId from quote
$store
=
$this
->
_
session
->
getQuote
()
->
getStore
();
$store
=
$this
->
_getQuote
()
->
getStore
();
}
else
{
$store
=
$this
->
_storeManager
->
getStore
();
}
...
...
@@ -206,6 +206,12 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
if
(
in_array
(
$recurringPaymentType
,
$allowedContractTypes
))
{
// check if AgreementLabel is set and if contract has an recurringType
if
(
$billingAgreement
->
getAgreementLabel
())
{
// for Ideal use sepadirectdebit because it is
if
(
$agreementData
[
'variant'
]
==
'ideal'
)
{
$agreementData
[
'variant'
]
=
'sepadirectdebit'
;
}
$data
=
[
'reference_id'
=>
$billingAgreement
->
getReferenceId
(),
'agreement_label'
=>
$billingAgreement
->
getAgreementLabel
(),
'agreement_data'
=>
$agreementData
...
...
@@ -213,10 +219,6 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
if
(
$this
->
_genericConfig
->
showLogos
())
{
$logoName
=
$agreementData
[
'variant'
];
// for Ideal use sepadirectdebit because it is
if
(
$agreementData
[
'variant'
]
==
'ideal'
)
{
$logoName
=
"sepadirectdebit"
;
}
$asset
=
$this
->
_genericConfig
->
createAsset
(
'Adyen_Payment::images/logos/'
.
$logoName
.
'.png'
...
...
@@ -235,6 +237,34 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
}
$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
;
}
}
...
...
@@ -250,4 +280,12 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
{
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
Model/Api/PaymentRequest.php
View file @
cddb1830
...
...
@@ -259,6 +259,11 @@ class PaymentRequest extends DataObject
$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
||
$paymentMethodCode
==
\Adyen\Payment\Model\Method\Oneclick
::
METHOD_CODE
)
{
// If cse is enabled add encrypted card date into request
...
...
@@ -291,6 +296,12 @@ class PaymentRequest extends DataObject
$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
);
return
$result
;
}
...
...
Model/Config/Backend/Installments.php
0 → 100644
View file @
cddb1830
<?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
;
}
}
Model/Method/Cc.php
View file @
cddb1830
...
...
@@ -207,6 +207,11 @@ class Cc extends \Magento\Payment\Model\Method\Cc
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
if
(
isset
(
$additionalData
[
'store_cc'
]))
{
...
...
Model/Method/Oneclick.php
View file @
cddb1830
...
...
@@ -78,7 +78,7 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc
$variant
=
$additionalData
[
'variant'
];
$ccType
=
$this
->
_adyenHelper
->
getMagentoCreditCartType
(
$variant
);
$infoInstance
->
setCcType
(
$ccType
);
// save value remember details checkbox
$infoInstance
->
setAdditionalInformation
(
'recurring_detail_reference'
,
$additionalData
[
'recurring_detail_reference'
]);
...
...
@@ -92,6 +92,11 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc
$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
;
}
...
...
etc/adminhtml/system/adyen_cc.xml
View file @
cddb1830
...
...
@@ -72,6 +72,13 @@
<source_model>
Magento\Config\Model\Config\Source\Yesno
</source_model>
<config_path>
payment/adyen_cc/enable_moto
</config_path>
</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
id=
"adyen_cc_country_specific"
translate=
"label"
showInDefault=
"1"
showInWebsite=
"1"
sortOrder=
"200"
>
...
...
view/adminhtml/templates/info/adyen_cc.phtml
View file @
cddb1830
...
...
@@ -55,6 +55,10 @@ $_isDemoMode = $block->isDemoMode();
<?php
echo
__
(
'Credit Card Number: xxxx-%1'
,
$this
->
getInfo
()
->
getCcLast4
())
?>
<br/>
<?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
echo
__
(
'Avs result: %1'
,
$_info
->
getAdditionalInformation
(
'adyen_avs_result'
))
?>
<br/>
...
...
view/frontend/web/js/model/installments.js
0 → 100644
View file @
cddb1830
/**
* 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
;
}
};
}
);
view/frontend/web/js/view/payment/method-renderer/adyen-cc-method.js
View file @
cddb1830
...
...
@@ -30,9 +30,13 @@ define(
'
mage/translate
'
,
'
Magento_Checkout/js/model/payment/additional-validators
'
,
'
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
'
],
function
(
_
,
$
,
Component
,
placeOrderAction
,
$t
,
additionalValidators
,
customer
,
adyenEncrypt
)
{
function
(
_
,
$
,
Component
,
placeOrderAction
,
$t
,
additionalValidators
,
customer
,
creditCardData
,
quote
,
ko
,
installments
,
adyenEncrypt
)
{
'
use strict
'
;
return
Component
.
extend
({
...
...
@@ -40,7 +44,8 @@ define(
template
:
'
Adyen_Payment/payment/cc-form
'
,
creditCardOwner
:
''
,
encryptedData
:
''
,
setStoreCc
:
true
setStoreCc
:
true
,
installment
:
''
},
initObservable
:
function
()
{
this
.
_super
()
...
...
@@ -56,10 +61,49 @@ define(
'
creditCardOwner
'
,
'
encryptedData
'
,
'
generationtime
'
,
'
setStoreCc
'
'
setStoreCc
'
,
'
installment
'
]);
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
)
{
this
.
placeOrderHandler
=
handler
;
},
...
...
@@ -76,7 +120,8 @@ define(
'
cc_type
'
:
this
.
creditCardType
(),
'
encrypted_data
'
:
this
.
encryptedData
(),
'
generationtime
'
:
this
.
generationtime
(),
'
store_cc
'
:
this
.
setStoreCc
()
'
store_cc
'
:
this
.
setStoreCc
(),
'
number_of_installments
'
:
this
.
installment
()
}
};
},
...
...
@@ -175,6 +220,12 @@ define(
?
window
.
checkoutConfig
.
payment
.
adyenCc
.
icons
[
type
]
:
false
},
hasInstallments
:
function
()
{
return
window
.
checkoutConfig
.
payment
.
adyenCc
.
hasInstallments
;
},
getAllInstallments
:
function
()
{
return
window
.
checkoutConfig
.
payment
.
adyenCc
.
installments
;
}
});
}
);
...
...
view/frontend/web/js/view/payment/method-renderer/adyen-oneclick-method.js
View file @
cddb1830
...
...
@@ -66,16 +66,6 @@ define(
getCode
:
function
()
{
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
()
{
return
true
;
},
...
...
@@ -112,7 +102,8 @@ define(
"
additional_data
"
:
{
encrypted_data
:
encryptedData
,
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(
// convert to list so you can iterate
var
paymentList
=
_
.
map
(
window
.
checkoutConfig
.
payment
.
adyenOneclick
.
billingAgreements
,
function
(
value
)
{
var
creditCardExpMonth
,
creditCardExpYear
=
false
;
if
(
value
.
agreement_data
.
card
)
{
creditCardExpMonth
=
value
.
agreement_data
.
card
.
expiryMonth
creditCardExpYear
=
value
.
agreement_data
.
card
.
expiryYear
;
var
creditCardExpMonth
,
creditCardExpYear
=
false
;
if
(
value
.
agreement_data
.
card
)
{
creditCardExpMonth
=
value
.
agreement_data
.
card
.
expiryMonth
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
{
'
expiry
'
:
ko
.
observable
(
false
),
'
test
'
:
true
,
'
test2
'
:
true
,
'
label
'
:
value
.
agreement_label
,
'
value
'
:
value
.
reference_id
,
'
agreement_data
'
:
value
.
agreement_data
,
'
logo
'
:
value
.
logo
,
'
method
'
:
self
.
item
.
method
,
getCode
:
function
()
{
return
self
.
item
.
method
;
},
creditCardVerificationNumber
:
''
,
creditCardExpMonth
:
ko
.
observable
(
creditCardExpMonth
),
creditCardExpYear
:
ko
.
observable
(
creditCardExpYear
),
getCSEKey
:
function
()
{
return
window
.
checkoutConfig
.
payment
.
adyenCc
.
cseKey
;
},
getGenerationTime
:
function
()
{
return
window
.
checkoutConfig
.
payment
.
adyenCc
.
generationTime
;
},
validate
:
function
()
{
return
{
'
expiry
'
:
ko
.
observable
(
false
),
'
label
'
:
value
.
agreement_label
,
'
value
'
:
value
.
reference_id
,
'
agreement_data
'
:
value
.
agreement_data
,
'
logo
'
:
value
.
logo
,
'
installment
'
:
''
,
'
number_of_installments
'
:
value
.
number_of_installments
,
getInstallments
:
ko
.
observableArray
(
installments
),
'
method
'
:
self
.
item
.
method
,
getCode
:
function
()
{
return
self
.
item
.
method
;
},
creditCardVerificationNumber
:
''
,
creditCardExpMonth
:
ko
.
observable
(
creditCardExpMonth
),
creditCardExpYear
:
ko
.
observable
(
creditCardExpYear
),
getCSEKey
:
function
()
{
return
window
.
checkoutConfig
.
payment
.
adyenCc
.
cseKey
;
},
getGenerationTime
:
function
()
{
return
window
.
checkoutConfig
.
payment
.
adyenCc
.
generationTime
;
},
validate
:
function
()
{
var
code
=
self
.
item
.
method
;
var
value
=
this
.
value
;
var
codeValue
=
code
+
'
_
'
+
value
;
var
code
=
self
.
item
.
method
;
var
value
=
this
.
value
;
var
codeValue
=
code
+
'
_
'
+
value
;
var
form
=
'
form[data-role=
'
+
codeValue
+
'
]
'
;
var
formObject
=
$
(
form
);
var
form
=
'
form[data-role=
'
+
codeValue
+
'
]
'
;
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
(
this
.
agreement_data
.
card
)
{
// add extra validation because jqeury validation will not work on non name attributes
var
expiration
=
Boolean
(
$
(
form
+
'
#
'
+
codeValue
+
'
_expiration
'
).
valid
());
var
expiration_yr
=
Boolean
(
$
(
form
+
'
#
'
+
codeValue
+
'
_expiration_yr
'
).
valid
());
}
else
{
var
expiration
=
true
;
var
expiration_yr
=
true
;
}
// if oneclick or recurring is a card do validation on expiration date
if
(
this
.
agreement_data
.
card
)
{
// add extra validation because jqeury validation will not work on non name attributes
var
expiration
=
Boolean
(
$
(
form
+
'
#
'
+
codeValue
+
'
_expiration
'
).
valid
());
var
expiration_yr
=
Boolean
(
$
(
form
+
'
#
'
+
codeValue
+
'
_expiration_yr
'
).
valid
());
// only check if recurring type is set to oneclick
var
cid
=
true
;
if
(
self
.
hasVerification
())
{
var
cid
=
Boolean
(
$
(
form
+
'
#
'
+
codeValue
+
'
_cc_cid
'
).
valid
());
}
if
(
!
validate
||
!
expiration
||
!
expiration_yr
||
!
cid
)
{
return
false
;
}
return
true
;
},
selectExpiry
:
function
()
{
var
self
=
this
;
self
.
expiry
(
true
);
return
true
;
}
else
{
var
expiration
=
true
;
var
expiration_yr
=
true
;
var
cid
=
true
;
}
if
(
!
validate
||
!
expiration
||
!
expiration_yr
||
!
cid
)
{
return
false
;
}
return
true
;
},
selectExpiry
:
function
()
{
var
self
=
this
;
self
.
expiry
(
true
);
return
true
;
}
}
);
}
);
return
paymentList
;
},
selectBillingAgreement
:
function
()
{
var
self
=
this
;
// set payment method
to adyen_hpp
// set payment method
data
var
data
=
{
"
method
"
:
self
.
method
,
"
po_number
"
:
null
,
...
...
view/frontend/web/template/payment/cc-form.html
View file @
cddb1830
...
...
@@ -202,6 +202,32 @@
</div>
<!-- /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())-->
<div
class=
"field choice"
>
...
...
view/frontend/web/template/payment/oneclick-form.html
View file @
cddb1830
...
...
@@ -196,6 +196,30 @@
<!--/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 -->
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment