/** * Show payment page * @return \Magento\Framework\View\Result\PageFactory */ public function execute() { $resultPage = $this->_resultPageFactory->create(); $resultPage->getLayout()->getBlock('pagseguro.direct.payment')->setData('order', $this->_checkoutSession->getLastRealOrder()->getId()); try { $this->_library->setEnvironment(); $resultPage->getLayout()->getBlock('pagseguro.direct.payment')->setData('sessionCode', $this->_library->getSession()); $resultPage->getLayout()->getBlock('pagseguro.direct.payment')->setData('paymentUrl', $this->_library->getDirectPaymentUrl()); } catch (\Exception $exc) { /** @var \Magento\Sales\Model\Order $order */ $order = $this->_objectManager->create('\\Magento\\Sales\\Model\\Order')->load($this->_checkoutSession->getLastRealOrder()->getId()); /** change payment status in magento */ $order->addStatusToHistory('pagseguro_cancelada', null, true); /** save order */ $order->save(); return $this->_redirect('pagseguro/payment/failure'); } return $resultPage; }
/** * Update status in Magento2 Order * * @return bool */ private function updateOrderStatus() { $this->_library->setEnvironment(); $this->_library->setCharset(); $this->_library->setLog(); $transaction = $this->getTransaction(); $order = $this->_order->get($this->_helperData->getReferenceDecryptOrderID($transaction->getReference())); $status = $this->_helperData->getStatusFromKey($transaction->getStatus()); if (!$this->compareStatus($status, $order->getStatus())) { $history = array('status' => $this->_history->setStatus($status), 'comment' => $this->_history->setComment('PagSeguro Notification')); $transactionCode = $transaction->getCode(); $orderId = $order->getId(); $order->setStatus($status); $order->setStatusHistories($history); $order->save(); $this->updateSalesOrderGridTransactionCode($orderId, $transactionCode); $this->updatePagSeguroOrdersTransactionCode($orderId, $transactionCode); } return true; }
/** * Request all PagSeguroTransaction in this _date interval * * @param $page * @return string * @throws \Exception */ protected function requestPagSeguroAbandoned($page) { $date = $this->getDates(); $options = ['initial_date' => $date['initial'], 'final_date' => $date['final'], 'page' => $page, 'max_per_page' => 1000]; try { $this->_library->setEnvironment(); $this->_library->setCharset(); $this->_library->setLog(); return \PagSeguro\Services\Transactions\Search\Abandoned::search($this->_library->getPagSeguroCredentials(), $options); } catch (Exception $exception) { throw $exception; } }