Index.php (3242B)
1 <?php 2 /** 3 * 4 * This file is part of TALER 5 * Copyright (C) 2024 Taler Systems SA 6 * 7 * TALER is free software; you can redistribute it and/or modify it under the 8 * terms of the GNU General Public License as published by the Free Software 9 * Foundation; either version 3, or (at your option) any later version. 10 *checkoutConfig.payment.taler_gateway) 11 * TALER is distributed in the hope that it will be useful, but WITHOUT ANY 12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 13 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along with 16 * TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 17 * 18 * @author Nicola Eigel 19 */ 20 21 namespace GNU\Taler\Controller\Service; 22 23 use Magento\Checkout\Model\Session; 24 use Magento\Framework\App\ActionInterface; 25 use Magento\Framework\Controller\Result\RedirectFactory; 26 use Magento\Payment\Model\Method\Logger; 27 use Magento\Framework\App\Bootstrap; 28 29 class Index implements ActionInterface 30 { 31 32 /** 33 * @var Logger 34 */ 35 private $_logger; 36 37 /** 38 * @var Session 39 */ 40 private $_session; 41 42 /** 43 * @var mixed 44 */ 45 private $objectManager; 46 47 /** 48 * @var mixed 49 */ 50 private $_resultRedirectFactory; 51 52 /** 53 * @param Logger $_logger 54 * @param Session $_session 55 * @param RedirectFactory $resultRedirectFactory 56 */ 57 58 /** 59 * @param Logger $_logger 60 * @param Session $_session 61 * @param RedirectFactory $resultRedirectFactory 62 */ 63 public function __construct( 64 Logger $_logger, 65 Session $_session, 66 RedirectFactory $resultRedirectFactory 67 ) 68 { 69 $bootstrap = Bootstrap::create(BP, $_SERVER); 70 $this->objectManager = $bootstrap->getObjectManager(); 71 $state = $this->objectManager->get('Magento\Framework\App\State'); 72 $state->setAreaCode('frontend'); 73 $this->_logger = $_logger; 74 $this->_session = $_session; 75 $this->_resultRedirectFactory = $resultRedirectFactory; 76 } 77 78 /** 79 * Fulfillment action, triggered by redirect after Taler payment 80 * @return void 81 */ 82 public function execute() 83 { 84 $quoteId = $this->_session->getQuoteId(); 85 $cartManagement = $this->objectManager->get(\Magento\Quote\Api\CartManagementInterface::class); 86 87 try { 88 $orderId = $cartManagement->placeOrder($quoteId); 89 90 $log = [ 91 'result' => "Successfully placed order: " . $orderId 92 ]; 93 $this->_logger->debug($log); 94 $resultRedirect = $this->_resultRedirectFactory->create(); 95 $resultRedirect->setPath('checkout/onepage/success'); 96 97 return $resultRedirect; 98 } catch (\Exception $e) { 99 $log = [ 100 'result' => "Error placing order: " . $e->getMessage() 101 ]; 102 $this->_logger->debug($log); 103 $resultRedirect = $this->_resultRedirectFactory->create(); 104 $resultRedirect->setPath('checkout', ['_fragment' => 'payment', '_messages' => $e->getMessage()]); 105 106 return $resultRedirect; 107 } 108 } 109 }