We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit cd6ecf87 authored by Rik ter Beek's avatar Rik ter Beek

Fixes #60 added oneclick as backend payment option

parent ab470b0d
...@@ -29,4 +29,56 @@ class Oneclick extends \Adyen\Payment\Block\Form\Cc ...@@ -29,4 +29,56 @@ class Oneclick extends \Adyen\Payment\Block\Form\Cc
* @var string * @var string
*/ */
protected $_template = 'Adyen_Payment::form/oneclick.phtml'; protected $_template = 'Adyen_Payment::form/oneclick.phtml';
/**
* @var \Adyen\Payment\Model\AdyenOneclickConfigProvider
*/
protected $_oneclickConfig;
/**
* @var \Magento\Backend\Model\Session\Quote
*/
protected $_sessionQuote;
/**
* Cc constructor.
*
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Payment\Model\Config $paymentConfig
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Payment\Model\Config $paymentConfig,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Checkout\Model\Session $checkoutSession,
\Adyen\Payment\Model\AdyenOneclickConfigProvider $oneclickConfigProvider,
\Magento\Backend\Model\Session\Quote $sessionQuote,
array $data = []
) {
parent::__construct($context, $paymentConfig, $adyenHelper, $checkoutSession, $data);
$this->_oneclickConfig = $oneclickConfigProvider;
$this->_sessionQuote = $sessionQuote;
}
/**
* @return array
*/
public function getOneClickCards()
{
$customerId = $this->_sessionQuote->getCustomerId();
$storeId = $this->_sessionQuote->getStoreId();
$grandTotal = $this->_sessionQuote->getQuote()->getGrandTotal();
// For backend only allow recurring payments
$recurringType = \Adyen\Payment\Model\RecurringType::RECURRING;
$cards = $this->_adyenHelper->getOneClickPaymentMethods($customerId, $storeId, $grandTotal, $recurringType);
return $cards;
}
} }
\ No newline at end of file
...@@ -51,25 +51,51 @@ class Data extends AbstractHelper ...@@ -51,25 +51,51 @@ class Data extends AbstractHelper
*/ */
protected $_moduleList; protected $_moduleList;
/**
* @var \Adyen\Payment\Model\Resource\Billing\Agreement\CollectionFactory
*/
protected $_billingAgreementCollectionFactory;
/**
* @var Repository
*/
protected $_assetRepo;
/**
* @var \Magento\Framework\View\Asset\Source
*/
protected $_assetSource;
/** /**
* Data constructor. * Data constructor.
* *
* @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @param \Magento\Framework\Config\DataInterface $dataStorage * @param \Magento\Framework\Config\DataInterface $dataStorage
* @param \Magento\Directory\Model\Config\Source\Country $country
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
* @param \Adyen\Payment\Model\Resource\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory
* @param \Magento\Framework\View\Asset\Repository $assetRepo
* @param \Magento\Framework\View\Asset\Source $assetSource
*/ */
public function __construct( public function __construct(
\Magento\Framework\App\Helper\Context $context, \Magento\Framework\App\Helper\Context $context,
\Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Magento\Framework\Config\DataInterface $dataStorage, \Magento\Framework\Config\DataInterface $dataStorage,
\Magento\Directory\Model\Config\Source\Country $country, \Magento\Directory\Model\Config\Source\Country $country,
\Magento\Framework\Module\ModuleListInterface $moduleList \Magento\Framework\Module\ModuleListInterface $moduleList,
\Adyen\Payment\Model\Resource\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory,
\Magento\Framework\View\Asset\Repository $assetRepo,
\Magento\Framework\View\Asset\Source $assetSource
) { ) {
parent::__construct($context); parent::__construct($context);
$this->_encryptor = $encryptor; $this->_encryptor = $encryptor;
$this->_dataStorage = $dataStorage; $this->_dataStorage = $dataStorage;
$this->_country = $country; $this->_country = $country;
$this->_moduleList = $moduleList; $this->_moduleList = $moduleList;
$this->_billingAgreementCollectionFactory = $billingAgreementCollectionFactory;
$this->_assetRepo = $assetRepo;
$this->_assetSource = $assetSource;
} }
/** /**
...@@ -633,4 +659,136 @@ class Data extends AbstractHelper ...@@ -633,4 +659,136 @@ class Data extends AbstractHelper
], ],
]; ];
} }
/**
* @param $customerId
* @param $storeId
* @param $grandTotal
* @param $recurringType
* @return array
*/
public function getOneClickPaymentMethods($customerId, $storeId, $grandTotal, $recurringType)
{
$billingAgreements = [];
$baCollection = $this->_billingAgreementCollectionFactory->create();
$baCollection->addFieldToFilter('customer_id', $customerId);
$baCollection->addFieldToFilter('store_id', $storeId);
$baCollection->addFieldToFilter('method_code', 'adyen_oneclick');
$baCollection->addActiveFilter();
foreach ($baCollection as $billingAgreement) {
$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)) {
// 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
];
if ($this->showLogos()) {
$logoName = $agreementData['variant'];
$asset = $this->createAsset(
'Adyen_Payment::images/logos/' . $logoName . '.png'
);
$placeholder = $this->findRelativeSourceFilePath($asset);
$icon = null;
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->getMagentoCreditCartType($agreementData['variant']);
$installments = null;
$installmentsValue = $this->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;
}
/**
* @return bool
*/
public function showLogos()
{
$showLogos = $this->getAdyenAbstractConfigData('title_renderer');
if ($showLogos == \Adyen\Payment\Model\Config\Source\RenderMode::MODE_TITLE_IMAGE) {
return true;
}
return false;
}
/**
* Create a file asset that's subject of fallback system
*
* @param string $fileId
* @param array $params
* @return \Magento\Framework\View\Asset\File
*/
public function createAsset($fileId, array $params = [])
{
$params = array_merge(['_secure' => $this->_request->isSecure()], $params);
return $this->_assetRepo->createAsset($fileId, $params);
}
/**
* @param $asset
* @return bool|string
*/
public function findRelativeSourceFilePath($asset)
{
return $this->_assetSource->findRelativeSourceFilePath($asset);
}
} }
\ No newline at end of file
...@@ -47,11 +47,6 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -47,11 +47,6 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
*/ */
protected $_adyenHelper; protected $_adyenHelper;
/**
* @var AdyenGenericConfig
*/
protected $_genericConfig;
/** /**
* @var Source * @var Source
*/ */
...@@ -63,20 +58,17 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -63,20 +58,17 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
* @param \Magento\Payment\Model\CcConfig $ccConfig * @param \Magento\Payment\Model\CcConfig $ccConfig
* @param PaymentHelper $paymentHelper * @param PaymentHelper $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param AdyenGenericConfig $genericConfig
* @param Source $assetSource * @param Source $assetSource
*/ */
public function __construct( public function __construct(
\Magento\Payment\Model\CcConfig $ccConfig, \Magento\Payment\Model\CcConfig $ccConfig,
PaymentHelper $paymentHelper, PaymentHelper $paymentHelper,
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Model\AdyenGenericConfig $genericConfig,
Source $assetSource Source $assetSource
) { ) {
parent::__construct($ccConfig, $paymentHelper, $this->_methodCodes); parent::__construct($ccConfig, $paymentHelper, $this->_methodCodes);
$this->_paymentHelper = $paymentHelper; $this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper; $this->_adyenHelper = $adyenHelper;
$this->_genericConfig = $genericConfig;
$this->_assetSource = $assetSource; $this->_assetSource = $assetSource;
} }
...@@ -113,7 +105,7 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -113,7 +105,7 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
$config['payment']['adyenCc']['canCreateBillingAgreement'] = $canCreateBillingAgreement; $config['payment']['adyenCc']['canCreateBillingAgreement'] = $canCreateBillingAgreement;
// show logos turned on by default // show logos turned on by default
if ($this->_genericConfig->showLogos()) { if ($this->_adyenHelper->showLogos()) {
$config['payment']['adyenCc']['creditCardPaymentMethodIcon'] = $this->_getCreditCardPaymentMethodIcon(); $config['payment']['adyenCc']['creditCardPaymentMethodIcon'] = $this->_getCreditCardPaymentMethodIcon();
} }
...@@ -142,8 +134,8 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -142,8 +134,8 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
*/ */
protected function _getCreditCardPaymentMethodIcon() protected function _getCreditCardPaymentMethodIcon()
{ {
$asset = $this->_genericConfig->createAsset('Adyen_Payment::images/logos/img_trans.gif'); $asset = $this->_adyenHelper->createAsset('Adyen_Payment::images/logos/img_trans.gif');
$placeholder = $this->_genericConfig->findRelativeSourceFilePath($asset); $placeholder = $this->_adyenHelper->findRelativeSourceFilePath($asset);
$icon = null; $icon = null;
if ($placeholder) { if ($placeholder) {
......
...@@ -39,9 +39,9 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface ...@@ -39,9 +39,9 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface
protected $_paymentHelper; protected $_paymentHelper;
/** /**
* @var AdyenGenericConfig * @var \Adyen\Payment\Helper\Data
*/ */
protected $_genericConfig; protected $_adyenHelper;
/** /**
* @var string[] * @var string[]
...@@ -59,14 +59,14 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface ...@@ -59,14 +59,14 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface
* AdyenGenericConfigProvider constructor. * AdyenGenericConfigProvider constructor.
* *
* @param PaymentHelper $paymentHelper * @param PaymentHelper $paymentHelper
* @param AdyenGenericConfig $genericConfig * @param \Adyen\Payment\Helper\Data $adyenHelper
*/ */
public function __construct( public function __construct(
PaymentHelper $paymentHelper, PaymentHelper $paymentHelper,
\Adyen\Payment\Model\AdyenGenericConfig $genericConfig \Adyen\Payment\Helper\Data $adyenHelper
) { ) {
$this->_paymentHelper = $paymentHelper; $this->_paymentHelper = $paymentHelper;
$this->_genericConfig = $genericConfig; $this->_adyenHelper = $adyenHelper;
foreach ($this->_methodCodes as $code) { foreach ($this->_methodCodes as $code) {
$this->_methods[$code] = $this->_paymentHelper->getMethodInstance($code); $this->_methods[$code] = $this->_paymentHelper->getMethodInstance($code);
...@@ -94,7 +94,7 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface ...@@ -94,7 +94,7 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface
} }
// show logos turned on by default // show logos turned on by default
if ($this->_genericConfig->showLogos()) { if ($this->_adyenHelper->showLogos()) {
$config['payment']['adyen']['showLogo'] = true; $config['payment']['adyen']['showLogo'] = true;
} else { } else {
$config['payment']['adyen']['showLogo'] = false; $config['payment']['adyen']['showLogo'] = false;
......
...@@ -56,11 +56,6 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -56,11 +56,6 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
*/ */
protected $_adyenHelper; protected $_adyenHelper;
/**
* @var Resource\Billing\Agreement\CollectionFactory
*/
protected $_billingAgreementCollectionFactory;
/** /**
* @var \Magento\Customer\Model\Session * @var \Magento\Customer\Model\Session
*/ */
...@@ -81,44 +76,33 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -81,44 +76,33 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
*/ */
protected $_storeManager; protected $_storeManager;
/**
* @var AdyenGenericConfig
*/
protected $_genericConfig;
/** /**
* AdyenOneclickConfigProvider constructor. * AdyenOneclickConfigProvider constructor.
* *
* @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Model\Context $context
* @param \Magento\Payment\Model\CcConfig $ccConfig * @param \Magento\Payment\Model\CcConfig $ccConfig
* @param PaymentHelper $paymentHelper * @param PaymentHelper $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param Resource\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory
* @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Checkout\Model\Session $session * @param \Magento\Checkout\Model\Session $session
* @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param AdyenGenericConfig $genericConfig
*/ */
public function __construct( public function __construct(
\Magento\Framework\Model\Context $context, \Magento\Framework\Model\Context $context,
\Magento\Payment\Model\CcConfig $ccConfig, \Magento\Payment\Model\CcConfig $ccConfig,
PaymentHelper $paymentHelper, PaymentHelper $paymentHelper,
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Model\Resource\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory,
\Magento\Customer\Model\Session $customerSession, \Magento\Customer\Model\Session $customerSession,
\Magento\Checkout\Model\Session $session, \Magento\Checkout\Model\Session $session,
\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Store\Model\StoreManagerInterface $storeManager
\Adyen\Payment\Model\AdyenGenericConfig $genericConfig
) { ) {
parent::__construct($ccConfig, $paymentHelper, $this->_methodCodes); parent::__construct($ccConfig, $paymentHelper, $this->_methodCodes);
$this->_paymentHelper = $paymentHelper; $this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper; $this->_adyenHelper = $adyenHelper;
$this->_billingAgreementCollectionFactory = $billingAgreementCollectionFactory;
$this->_customerSession = $customerSession; $this->_customerSession = $customerSession;
$this->_session = $session; $this->_session = $session;
$this->_appState = $context->getAppState(); $this->_appState = $context->getAppState();
$this->_storeManager = $storeManager; $this->_storeManager = $storeManager;
$this->_genericConfig = $genericConfig;
} }
/** /**
...@@ -156,7 +140,6 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -156,7 +140,6 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
$recurringContractType = $this->_getRecurringContractType(); $recurringContractType = $this->_getRecurringContractType();
$config['payment'] ['adyenOneclick']['billingAgreements'] = $this->getAdyenOneclickPaymentMethods(); $config['payment'] ['adyenOneclick']['billingAgreements'] = $this->getAdyenOneclickPaymentMethods();
$config['payment'] ['adyenOneclick']['recurringContractType'] = $recurringContractType;
if ($recurringContractType == \Adyen\Payment\Model\RecurringType::ONECLICK) { if ($recurringContractType == \Adyen\Payment\Model\RecurringType::ONECLICK) {
$config['payment'] ['adyenOneclick']['hasCustomerInteraction'] = true; $config['payment'] ['adyenOneclick']['hasCustomerInteraction'] = true;
} else { } else {
...@@ -176,99 +159,11 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -176,99 +159,11 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
$billingAgreements = []; $billingAgreements = [];
if ($this->_customerSession->isLoggedIn()) { if ($this->_customerSession->isLoggedIn()) {
$customerId = $this->_customerSession->getCustomerId(); $customerId = $this->_customerSession->getCustomerId();
// is admin? $storeId = $this->_storeManager->getStore()->getId();
if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { $grandTotal = $this->_getQuote()->getGrandTotal();
//retrieve storeId from quote $recurringType = $this->_getRecurringContractType();
$store = $this->_getQuote()->getStore();
} else {
$store = $this->_storeManager->getStore();
}
$baCollection = $this->_billingAgreementCollectionFactory->create();
$baCollection->addFieldToFilter('customer_id', $customerId);
$baCollection->addFieldToFilter('store_id', $store->getId());
$baCollection->addFieldToFilter('method_code', 'adyen_oneclick');
$baCollection->addActiveFilter();
$recurringPaymentType = $this->_getRecurringContractType();
foreach ($baCollection as $billingAgreement) { $billingAgreements = $this->_adyenHelper->getOneClickPaymentMethods($customerId, $storeId, $grandTotal, $recurringType);
$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($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
];
if ($this->_genericConfig->showLogos()) {
$logoName = $agreementData['variant'];
$asset = $this->_genericConfig->createAsset(
'Adyen_Payment::images/logos/' . $logoName . '.png'
);
$placeholder = $this->_genericConfig->findRelativeSourceFilePath($asset);
$icon = null;
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;
$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;
}
}
}
} }
return $billingAgreements; return $billingAgreements;
} }
......
...@@ -48,14 +48,7 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc ...@@ -48,14 +48,7 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc
* @var string * @var string
*/ */
protected $_infoBlockType = 'Adyen\Payment\Block\Info\Oneclick'; protected $_infoBlockType = 'Adyen\Payment\Block\Info\Oneclick';
/**
* Payment Method not ready for internal use
*
* @var bool
*/
protected $_canUseInternal = false;
/** /**
* Assign data to info model instance * Assign data to info model instance
* *
...@@ -65,7 +58,6 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc ...@@ -65,7 +58,6 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc
*/ */
public function assignData(\Magento\Framework\DataObject $data) public function assignData(\Magento\Framework\DataObject $data)
{ {
parent::assignData($data);
if (!$data instanceof \Magento\Framework\DataObject) { if (!$data instanceof \Magento\Framework\DataObject) {
$data = new \Magento\Framework\DataObject($data); $data = new \Magento\Framework\DataObject($data);
...@@ -74,6 +66,7 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc ...@@ -74,6 +66,7 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc
$additionalData = $data->getAdditionalData(); $additionalData = $data->getAdditionalData();
$infoInstance = $this->getInfoInstance(); $infoInstance = $this->getInfoInstance();
// get from variant magento code for creditcard type and set this in ccType // get from variant magento code for creditcard type and set this in ccType
$variant = $additionalData['variant']; $variant = $additionalData['variant'];
$ccType = $this->_adyenHelper->getMagentoCreditCartType($variant); $ccType = $this->_adyenHelper->getMagentoCreditCartType($variant);
...@@ -83,9 +76,18 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc ...@@ -83,9 +76,18 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc
$infoInstance->setAdditionalInformation('recurring_detail_reference', $infoInstance->setAdditionalInformation('recurring_detail_reference',
$additionalData['recurring_detail_reference']); $additionalData['recurring_detail_reference']);
$recurringPaymentType = $this->_adyenHelper->getAdyenOneclickConfigData('recurring_payment_type'); $recurringPaymentType = $this->getRecurringPaymentType();
if ($recurringPaymentType == \Adyen\Payment\Model\RecurringType::ONECLICK) { if ($recurringPaymentType == \Adyen\Payment\Model\RecurringType::ONECLICK) {
$customerInteraction = true; $customerInteraction = true;
// retrieve cse key
if ($this->_adyenHelper->getAdyenCcConfigDataFlag('cse_enabled')) {
if (isset($additionalData['encrypted_data'])) {
$infoInstance->setAdditionalInformation('encrypted_data', $additionalData['encrypted_data']);
} else {
throw new \Magento\Framework\Exception\LocalizedException(__('Card encryption failed'));
}
}
} else { } else {
$customerInteraction = false; $customerInteraction = false;
} }
...@@ -94,12 +96,29 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc ...@@ -94,12 +96,29 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc
// set number of installements // set number of installements
if (isset($additionalData['number_of_installments'])) { if (isset($additionalData['number_of_installments'])) {
$infoInstance->setAdditionalInformation('number_of_installments', $additionalData['number_of_installments']); $infoInstance->setAdditionalInformation('number_of_installments',
$additionalData['number_of_installments']);
} }
return $this; return $this;
} }
/**
* For admin use RECURRING contract for front-end get it from configuration
*
* @return mixed|string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getRecurringPaymentType()
{
// For admin always use Recurring
if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
return \Adyen\Payment\Model\RecurringType::RECURRING;
} else {
return $this->_adyenHelper->getAdyenOneclickConfigData('recurring_payment_type');
}
}
/** /**
* @param \Adyen\Payment\Model\Billing\Agreement $agreement * @param \Adyen\Payment\Model\Billing\Agreement $agreement
* @return $this * @return $this
......
...@@ -20,88 +20,36 @@ ...@@ -20,88 +20,36 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
namespace Adyen\Payment\Model;
use Magento\Framework\App\RequestInterface; // @codingStandardsIgnoreFile
use Magento\Framework\UrlInterface; /**
use Magento\Framework\View\Asset\Repository; * @var \Magento\Payment\Block\Adminhtml\Transparent\Form $block
use Psr\Log\LoggerInterface; */
use Magento\Payment\Model\Config as PaymentConfig; $code = $block->escapeHtml($block->getMethodCode());
use Magento\Framework\View\Asset\Source; $currentCountry = $block->getInfoData('country');
?>
class AdyenGenericConfig
{
/**
* @var Repository
*/
protected $_assetRepo;
/** <fieldset class="admin__fieldset payment-method" id="payment_form_<?php /* @noEscape */ echo $code; ?>"
* @var RequestInterface style="display:none">
*/
protected $_request;
/**
* @var \Magento\Framework\View\Asset\Source
*/
protected $_assetSource;
/** <input type="hidden" id="adyen_oneclick_variant" name="payment[variant]" value="" />
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/** <dl style="margin: 0 0 10px 10px;">
* AdyenGenericConfig constructor. <?php if( !empty($block->getOneClickCards())): ?>
* <?php foreach($block->getOneClickCards() as $card): ?>
* @param Repository $assetRepo <?php if($card['agreement_label'] != ""):?>
* @param RequestInterface $request <dt class="admin__field-option">
* @param Source $assetSource <input id="p_method_adyen_oneclick_<?php echo $card['reference_id']?>" value="<?php echo $card['reference_id']; ?>" type="radio" name="payment[recurring_detail_reference]" title="Adyen OneClick" onclick="document.getElementById('adyen_oneclick_variant').value = '<?php echo $card['agreement_data']['variant']; ?>';" class="admin__control-radio">
* @param \Adyen\Payment\Helper\Data $adyenHelper <label class="admin__field-label" for="p_method_adyen_oneclick_<?php echo $card['reference_id']?>"><?php echo $card['agreement_label']; ?></label>
*/ </dt>
public function __construct( <?php endif; ?>
Repository $assetRepo, <?php endforeach; ?>
RequestInterface $request, <?php else: ?>
Source $assetSource, <dt><?php echo $block->escapeHtml(__('Customer has no saved recurring cards')); ?></dt>
\Adyen\Payment\Helper\Data $adyenHelper <?php endif; ?>
) { </dl>
$this->_assetRepo = $assetRepo;
$this->_request = $request;
$this->_assetSource = $assetSource;
$this->_adyenHelper = $adyenHelper;
}
/**
* Create a file asset that's subject of fallback system
*
* @param string $fileId
* @param array $params
* @return \Magento\Framework\View\Asset\File
*/
public function createAsset($fileId, array $params = [])
{
$params = array_merge(['_secure' => $this->_request->isSecure()], $params);
return $this->_assetRepo->createAsset($fileId, $params);
}
/**
* @param $asset
* @return bool|string
*/
public function findRelativeSourceFilePath($asset)
{
return $this->_assetSource->findRelativeSourceFilePath($asset);
}
/** </fieldset>
* @return bool
*/
public function showLogos()
{
$showLogos = $this->_adyenHelper->getAdyenAbstractConfigData('title_renderer');
if ($showLogos == \Adyen\Payment\Model\Config\Source\RenderMode::MODE_TITLE_IMAGE) {
return true;
}
return false;
}
}
\ No newline at end of file
...@@ -253,9 +253,6 @@ define( ...@@ -253,9 +253,6 @@ define(
} }
return null; return null;
}), }),
getRecurringContractType: function() {
return window.checkoutConfig.payment.adyenOneClick.recurringContractType;
},
hasVerification: function() { hasVerification: function() {
return window.checkoutConfig.payment.adyenOneclick.hasCustomerInteraction; return window.checkoutConfig.payment.adyenOneclick.hasCustomerInteraction;
}, },
......
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