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
fc46d74a
Commit
fc46d74a
authored
Dec 20, 2017
by
Rik ter Beek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
oneclick based on the listRecurringDetails api call for demo purposes
parent
331edac8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
123 additions
and
3 deletions
+123
-3
Helper/PaymentMethods.php
Helper/PaymentMethods.php
+113
-1
Model/Ui/AdyenOneclickConfigProvider.php
Model/Ui/AdyenOneclickConfigProvider.php
+10
-2
No files found.
Helper/PaymentMethods.php
View file @
fc46d74a
...
...
@@ -90,6 +90,11 @@ class PaymentMethods extends AbstractHelper
*/
protected
$_themeProvider
;
/**
* @var \Adyen\Payment\Model\Api\PaymentRequest
*/
protected
$_adyenPaymentRequest
;
/**
* PaymentMethods constructor.
*
...
...
@@ -118,7 +123,8 @@ class PaymentMethods extends AbstractHelper
\Magento\Framework\App\RequestInterface
$request
,
\Magento\Framework\View\Asset\Source
$assetSource
,
\Magento\Framework\View\DesignInterface
$design
,
\Magento\Framework\View\Design\Theme\ThemeProviderInterface
$themeProvider
\Magento\Framework\View\Design\Theme\ThemeProviderInterface
$themeProvider
,
\Adyen\Payment\Model\Api\PaymentRequest
$paymentRequest
)
{
$this
->
_quoteRepository
=
$quoteRepository
;
$this
->
_quoteIdMaskFactory
=
$quoteIdMaskFactory
;
...
...
@@ -132,6 +138,7 @@ class PaymentMethods extends AbstractHelper
$this
->
_assetSource
=
$assetSource
;
$this
->
_design
=
$design
;
$this
->
_themeProvider
=
$themeProvider
;
$this
->
_adyenPaymentRequest
=
$paymentRequest
;
}
/**
...
...
@@ -454,4 +461,109 @@ class PaymentMethods extends AbstractHelper
{
return
$this
->
_session
->
getQuote
();
}
/**
* Get payment methods from the listRecurringDetails API
*
* @param $customerId
* @param $storeId
* @param $grandTotal
* @param $recurringType
* @return array
* @throws \Exception
*/
public
function
getOneClickPaymentMethods
(
$customerId
,
$storeId
,
$grandTotal
,
$recurringType
)
{
$billingAgreements
=
[];
// get the billing agreements from the listRecurringDetails call
$recurringContracts
=
$this
->
_adyenPaymentRequest
->
getRecurringContractsForShopper
(
$customerId
,
$storeId
);
// print_r($recurringContracts);
foreach
(
$recurringContracts
as
$recurringDetailReference
=>
$agreementData
)
{
// $agreementData = $billingAgreement->getAgreementData();
// no agreementData and contractType then ignore
if
((
!
is_array
(
$agreementData
))
||
(
!
isset
(
$agreementData
[
'contractTypes'
])))
{
continue
;
}
// check if contractType is supporting the selected contractType for OneClick payments
$allowedContractTypes
=
$agreementData
[
'contractTypes'
];
if
(
in_array
(
$recurringType
,
$allowedContractTypes
))
{
// allow only cards
if
(
isset
(
$agreementData
[
'card'
][
'number'
]))
{
// only cards
$label
=
__
(
'%1, %2, **** %3'
,
$agreementData
[
'variant'
],
$agreementData
[
'card'
][
'holderName'
],
$agreementData
[
'card'
][
'number'
],
$agreementData
[
'card'
][
'expiryMonth'
],
$agreementData
[
'card'
][
'expiryYear'
]
);
$data
=
[
'reference_id'
=>
$recurringDetailReference
,
'agreement_label'
=>
$label
,
'agreement_data'
=>
$agreementData
];
if
(
$this
->
_adyenHelper
->
showLogos
())
{
$logoName
=
$agreementData
[
'variant'
];
$asset
=
$this
->
_adyenHelper
->
createAsset
(
'Adyen_Payment::images/logos/'
.
$logoName
.
'.png'
);
$icon
=
null
;
$placeholder
=
$this
->
_assetSource
->
findSource
(
$asset
);
if
(
$placeholder
)
{
list
(
$width
,
$height
)
=
getimagesize
(
$asset
->
getSourceFile
());
$icon
=
[
'url'
=>
$asset
->
getUrl
(),
'width'
=>
$width
,
'height'
=>
$height
];
}
$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
;
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
;
}
}
}
return
$billingAgreements
;
}
}
\ No newline at end of file
Model/Ui/AdyenOneclickConfigProvider.php
View file @
fc46d74a
...
...
@@ -36,12 +36,16 @@ class AdyenOneclickConfigProvider implements ConfigProviderInterface
*/
protected
$config
;
/**
* @var \Adyen\Payment\Helper\Data
*/
protected
$_adyenHelper
;
/**
* @var \Adyen\Payment\Helper\PaymentMethods
*/
protected
$_adyenPaymentMethodsHelper
;
/**
* @var \Magento\Framework\App\RequestInterface
*/
...
...
@@ -76,14 +80,17 @@ class AdyenOneclickConfigProvider implements ConfigProviderInterface
* AdyenOneclickConfigProvider constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Helper\PaymentMethods $adyenPaymentMethodsHelper
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Checkout\Model\Session $session
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Magento\Payment\Model\CcConfig $ccConfig
*/
public
function
__construct
(
\Adyen\Payment\Helper\Data
$adyenHelper
,
\Adyen\Payment\Helper\PaymentMethods
$adyenPaymentMethodsHelper
,
\Magento\Framework\App\RequestInterface
$request
,
\Magento\Customer\Model\Session
$customerSession
,
\Magento\Checkout\Model\Session
$session
,
...
...
@@ -98,6 +105,7 @@ class AdyenOneclickConfigProvider implements ConfigProviderInterface
$this
->
_storeManager
=
$storeManager
;
$this
->
_urlBuilder
=
$urlBuilder
;
$this
->
ccConfig
=
$ccConfig
;
$this
->
_adyenPaymentMethodsHelper
=
$adyenPaymentMethodsHelper
;
}
/**
...
...
@@ -177,7 +185,7 @@ class AdyenOneclickConfigProvider implements ConfigProviderInterface
$grandTotal
=
$this
->
_getQuote
()
->
getGrandTotal
();
$recurringType
=
$this
->
_getRecurringContractType
();
$billingAgreements
=
$this
->
_adyenHelper
->
getOneClickPaymentMethods
(
$billingAgreements
=
$this
->
_adyen
PaymentMethods
Helper
->
getOneClickPaymentMethods
(
$customerId
,
$storeId
,
$grandTotal
,
...
...
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