-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from cashfree/bugfix/session-related-issue
bugfix for session in latest magento version
- Loading branch information
Showing
13 changed files
with
899 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,168 +1,204 @@ | ||
<?php | ||
namespace Cashfree\Cfcheckout\Controller; | ||
|
||
abstract class CfAbstract extends \Magento\Framework\App\Action\Action | ||
{ | ||
/** | ||
* @var \Magento\Checkout\Model\Session | ||
*/ | ||
protected $_checkoutSession; | ||
|
||
/** | ||
* @var \Magento\Sales\Model\OrderFactory | ||
*/ | ||
protected $_orderFactory; | ||
|
||
/** | ||
* @var \Magento\Customer\Model\Session | ||
*/ | ||
protected $_customerSession; | ||
|
||
/** | ||
* @var \Magento\Quote\Api\CartRepositoryInterface | ||
*/ | ||
protected $quoteRepository; | ||
|
||
/** | ||
* @var \Psr\Log\LoggerInterface | ||
*/ | ||
protected $_logger; | ||
|
||
/** | ||
* @var \Magento\Quote\Model\Quote | ||
*/ | ||
protected $_quote; | ||
|
||
/** | ||
* @var \Tco\Checkout\Model\Checkout | ||
*/ | ||
protected $_paymentMethod; | ||
|
||
/** | ||
* @var \Tco\Checkout\Helper\Checkout | ||
*/ | ||
protected $_checkoutHelper; | ||
|
||
/** | ||
* @var \Magento\Quote\Api\CartManagementInterface | ||
*/ | ||
protected $cartManagement; | ||
|
||
/** | ||
* @var \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory | ||
*/ | ||
protected $resultJsonFactory; | ||
|
||
|
||
|
||
public function __construct( | ||
\Magento\Framework\App\Action\Context $context, | ||
\Magento\Customer\Model\Session $customerSession, | ||
\Magento\Checkout\Model\Session $checkoutSession, | ||
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository, | ||
\Magento\Sales\Model\OrderFactory $orderFactory, | ||
\Psr\Log\LoggerInterface $logger, | ||
\Cashfree\Cfcheckout\Model\Cfcheckout $paymentMethod, | ||
\Cashfree\Cfcheckout\Helper\Cfcheckout $checkoutHelper, | ||
\Magento\Quote\Api\CartManagementInterface $cartManagement, | ||
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory | ||
) { | ||
$this->_customerSession = $customerSession; | ||
$this->_checkoutSession = $checkoutSession; | ||
$this->quoteRepository = $quoteRepository; | ||
$this->_orderFactory = $orderFactory; | ||
$this->_paymentMethod = $paymentMethod; | ||
$this->_checkoutHelper = $checkoutHelper; | ||
$this->cartManagement = $cartManagement; | ||
$this->resultJsonFactory = $resultJsonFactory; | ||
$this->_logger = $logger; | ||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* Instantiate quote and checkout | ||
* | ||
* @return void | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
protected function initCheckout() | ||
{ | ||
$quote = $this->getQuote(); | ||
if (!$quote->hasItems() || $quote->getHasError()) { | ||
$this->getResponse()->setStatusHeader(403, '1.1', 'Forbidden'); | ||
throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t initialize checkout.')); | ||
} | ||
} | ||
|
||
/** | ||
* Cancel order, return quote to customer | ||
* | ||
* @param string $errorMsg | ||
* @return false|string | ||
*/ | ||
protected function _cancelPayment($errorMsg = '') | ||
{ | ||
$gotoSection = false; | ||
$this->_checkoutHelper->cancelCurrentOrder($errorMsg); | ||
if ($this->_checkoutSession->restoreQuote()) { | ||
//Redirect to payment step | ||
$gotoSection = 'paymentMethod'; | ||
} | ||
|
||
return $gotoSection; | ||
} | ||
|
||
/** | ||
* Get order object | ||
* | ||
* @return \Magento\Sales\Model\Order | ||
*/ | ||
protected function getOrderById($order_id) | ||
{ | ||
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); | ||
$order = $objectManager->get('Magento\Sales\Model\Order'); | ||
$order_info = $order->load($order_id); | ||
return $order_info; | ||
} | ||
|
||
/** | ||
* Get order object | ||
* | ||
* @return \Magento\Sales\Model\Order | ||
*/ | ||
protected function getOrder() | ||
{ | ||
return $this->_orderFactory->create()->loadByIncrementId( | ||
$this->_checkoutSession->getLastRealOrderId() | ||
); | ||
} | ||
|
||
protected function getQuote() | ||
{ | ||
if (!$this->_quote) { | ||
$this->_quote = $this->getCheckoutSession()->getQuote(); | ||
} | ||
return $this->_quote; | ||
} | ||
|
||
protected function getCheckoutSession() | ||
{ | ||
return $this->_checkoutSession; | ||
} | ||
|
||
public function getCustomerSession() | ||
{ | ||
return $this->_customerSession; | ||
} | ||
|
||
public function getPaymentMethod() | ||
{ | ||
return $this->_paymentMethod; | ||
} | ||
|
||
protected function getCheckoutHelper() | ||
{ | ||
return $this->_checkoutHelper; | ||
} | ||
|
||
} | ||
<?php | ||
namespace Cashfree\Cfcheckout\Controller; | ||
|
||
use Magento\Framework\App\Action\Action; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\App\CsrfAwareActionInterface; | ||
use Magento\Framework\App\Request\InvalidRequestException; | ||
|
||
abstract class CfAbstract extends Action implements CsrfAwareActionInterface | ||
{ | ||
/** | ||
* @var \Magento\Checkout\Model\Session | ||
*/ | ||
protected $_checkoutSession; | ||
|
||
/** | ||
* @var \Magento\Sales\Model\OrderFactory | ||
*/ | ||
protected $_orderFactory; | ||
|
||
/** | ||
* @var \Magento\Customer\Model\Session | ||
*/ | ||
protected $_customerSession; | ||
|
||
/** | ||
* @var \Magento\Quote\Model\Quote | ||
*/ | ||
protected $_quote; | ||
|
||
/** | ||
* @var \Tco\Checkout\Model\Checkout | ||
*/ | ||
protected $_paymentMethod; | ||
|
||
/** | ||
* @var \Tco\Checkout\Helper\Checkout | ||
*/ | ||
protected $_checkoutHelper; | ||
|
||
/** | ||
* @var \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory | ||
*/ | ||
protected $resultJsonFactory; | ||
|
||
/** | ||
* __construct | ||
* | ||
* @return void | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\App\Action\Context $context, | ||
\Magento\Customer\Model\Session $customerSession, | ||
\Magento\Checkout\Model\Session $checkoutSession, | ||
\Magento\Sales\Model\OrderFactory $orderFactory, | ||
\Cashfree\Cfcheckout\Model\Cfcheckout $paymentMethod, | ||
\Cashfree\Cfcheckout\Helper\Cfcheckout $checkoutHelper, | ||
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, | ||
\Magento\Framework\App\CacheInterface $cache, | ||
\Magento\Sales\Api\Data\OrderInterface $order, | ||
\Magento\Quote\Model\QuoteManagement $quoteManagement, | ||
\Magento\Store\Model\StoreManagerInterface $storeManagement | ||
) { | ||
$this->_customerSession = $customerSession; | ||
$this->_checkoutSession = $checkoutSession; | ||
$this->_orderFactory = $orderFactory; | ||
$this->_paymentMethod = $paymentMethod; | ||
$this->_checkoutHelper = $checkoutHelper; | ||
$this->resultJsonFactory = $resultJsonFactory; | ||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* Instantiate quote and checkout | ||
* | ||
* @return void | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
protected function initCheckout() | ||
{ | ||
$quote = $this->getQuote(); | ||
if (!$quote->hasItems() || $quote->getHasError()) { | ||
$this->getResponse()->setStatusHeader(403, '1.1', 'Forbidden'); | ||
throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t initialize checkout.')); | ||
} | ||
} | ||
|
||
/** | ||
* Cancel order, return quote to customer | ||
* | ||
* @param string $errorMsg | ||
* @return false|string | ||
*/ | ||
protected function _cancelPayment($errorMsg = '') | ||
{ | ||
$gotoSection = false; | ||
$this->_checkoutHelper->cancelCurrentOrder($errorMsg); | ||
if ($this->_checkoutSession->restoreQuote()) { | ||
//Redirect to payment step | ||
$gotoSection = 'paymentMethod'; | ||
} | ||
|
||
return $gotoSection; | ||
} | ||
|
||
/** | ||
* Get order object | ||
* | ||
* @return \Magento\Sales\Model\Order | ||
*/ | ||
protected function getOrderById($order_id) | ||
{ | ||
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); | ||
$order = $objectManager->get('Magento\Sales\Model\Order'); | ||
$order_info = $order->load($order_id); | ||
return $order_info; | ||
} | ||
|
||
/** | ||
* Get order object | ||
* | ||
* @return \Magento\Sales\Model\Order | ||
*/ | ||
protected function getOrder() | ||
{ | ||
return $this->_orderFactory->create()->loadByIncrementId( | ||
$this->_checkoutSession->getLastRealOrderId() | ||
); | ||
} | ||
|
||
/** | ||
* Get Quote Object | ||
* | ||
* @return void | ||
*/ | ||
protected function getQuote() | ||
{ | ||
if (!$this->_quote) { | ||
$this->_quote = $this->getCheckoutSession()->getQuote(); | ||
} | ||
return $this->_quote; | ||
} | ||
|
||
/** | ||
* Get CheckoutSession | ||
* | ||
* @return void | ||
*/ | ||
protected function getCheckoutSession() | ||
{ | ||
return $this->_checkoutSession; | ||
} | ||
|
||
/** | ||
* Get CustomerSession | ||
* | ||
* @return void | ||
*/ | ||
public function getCustomerSession() | ||
{ | ||
return $this->_customerSession; | ||
} | ||
|
||
/** | ||
* Get PaymentMethod | ||
* | ||
* @return void | ||
*/ | ||
public function getPaymentMethod() | ||
{ | ||
return $this->_paymentMethod; | ||
} | ||
|
||
/** | ||
* Get CheckoutHelper | ||
* | ||
* @return void | ||
*/ | ||
protected function getCheckoutHelper() | ||
{ | ||
return $this->_checkoutHelper; | ||
} | ||
|
||
/** | ||
* Create Csrf validation exception | ||
* | ||
* @param mixed $request | ||
* @return InvalidRequestException | ||
*/ | ||
public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException | ||
{ | ||
return null; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function validateForCsrf(RequestInterface $request): ?bool | ||
{ | ||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.