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 d4486a92 authored by rikterbeek's avatar rikterbeek

Refactor code to get Adyen CC api working

parent c6c22e74
<?php
namespace Adyen\Payment\Controller\Process;
class Redirect extends \Magento\Framework\App\Action\Action
{
/**
* @var \Magento\Quote\Model\Quote
*/
protected $_quote = false;
/**
* @var \Magento\Checkout\Model\Session
*/
protected $_checkoutSession;
protected $checkoutFactory;
/**
* @var \Magento\Customer\Model\Session
*/
protected $_customerSession;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Customer\Model\Session $customerSession
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Customer\Model\Session $customerSession
) {
parent::__construct($context);
$this->_customerSession = $customerSession;
}
/**
* Return checkout session object
*
* @return \Magento\Checkout\Model\Session
*/
protected function _getCheckoutSession()
{
return $this->_checkoutSession;
}
public function execute()
{
$this->_getQuote();
echo 'hier;';die();
$this->_quote->collectTotals();
echo 'hier';die();
$url = "http://www.google.com";
$this->getResponse()->setRedirect($url);
return;
// $this->_view->loadLayout();
// $this->_view->getLayout()->initMessages();
// $this->_view->renderLayout();
}
/**
* Return checkout quote object
*
* @return \Magento\Quote\Model\Quote
*/
protected function _getQuote()
{
if (!$this->_quote) {
$this->_quote = $this->_getCheckoutSession()->getQuote();
}
return $this->_quote;
}
}
\ No newline at end of file
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Adyen\Payment\Model;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Payment\Helper\Data as PaymentHelper;
class AdyenHppConfigProvider implements ConfigProviderInterface
{
/**
* @var Config
*/
protected $config;
/**
* @var string[]
*/
protected $methodCodes = [
'adyen_hpp'
];
/**
* @var \Magento\Payment\Model\Method\AbstractMethod[]
*/
protected $methods = [];
/**
* @var PaymentHelper
*/
protected $paymentHelper;
/**
* @param PaymentHelper $paymentHelper
*/
public function __construct(
PaymentHelper $paymentHelper
) {
$this->paymentHelper = $paymentHelper;
foreach ($this->methodCodes as $code) {
$this->methods[$code] = $this->paymentHelper->getMethodInstance($code);
}
}
public function getConfig()
{
$config = [
'payment' => [
'adyenHpp' => [
]
]
];
foreach ($this->methodCodes as $code) {
if ($this->methods[$code]->isAvailable()) {
$config['payment']['adyenHpp']['redirectUrl'][$code] = $this->getMethodRedirectUrl($code);
}
}
return $config;
}
/**
* Return redirect URL for method
*
* @param string $code
* @return mixed
*/
protected function getMethodRedirectUrl($code)
{
return $this->methods[$code]->getCheckoutRedirectUrl();
}
}
\ No newline at end of file
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
define(
[
'jquery',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/url-builder',
'mage/storage',
'Magento_Checkout/js/model/error-processor',
'Magento_Customer/js/model/customer'
],
function ($, quote, urlBuilder, storage, errorProcessor, customer) {
'use strict';
return function () {
var serviceUrl,
payload,
paymentData = quote.paymentMethod();
/**
* Checkout for guest and registered customer.
*/
if (!customer.isLoggedIn()) {
serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/selected-payment-method', {
cartId: quote.getQuoteId()
});
payload = {
cartId: quote.getQuoteId(),
method: paymentData
};
} else {
serviceUrl = urlBuilder.createUrl('/carts/mine/selected-payment-method', {});
payload = {
cartId: quote.getQuoteId(),
method: paymentData
};
}
return storage.put(
serviceUrl, JSON.stringify(payload)
).done(
function () {
$.mage.redirect(window.checkoutConfig.payment.adyenHpp.redirectUrl[quote.paymentMethod().method]);
}
).fail(
function (response) {
errorProcessor.process(response);
}
);
};
}
);
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