/** * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { /** * @var $clientOrderHelper \Orba\Payupl\Model\Client\OrderInterface */ $resultRedirect = $this->resultRedirectFactory->create(); $redirectUrl = '/'; try { if ($this->successValidator->isValid()) { $redirectUrl = 'orba_payupl/payment/error'; $this->session->setLastOrderId(null); $clientOrderHelper = $this->getClientOrderHelper(); if ($this->orderHelper->paymentSuccessCheck() && $clientOrderHelper->paymentSuccessCheck()) { $redirectUrl = 'checkout/onepage/success'; } } else { if ($this->session->getLastOrderId()) { $redirectUrl = 'orba_payupl/payment/repeat_error'; $clientOrderHelper = $this->getClientOrderHelper(); if ($this->orderHelper->paymentSuccessCheck() && $clientOrderHelper->paymentSuccessCheck()) { $redirectUrl = 'orba_payupl/payment/repeat_success'; } } } } catch (LocalizedException $e) { $this->logger->critical($e); } $resultRedirect->setPath($redirectUrl); return $resultRedirect; }
/** * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { /** * @var $clientOrderHelper \Orba\Payupl\Model\Client\OrderInterface */ $resultRedirect = $this->resultRedirectFactory->create(); $orderId = $this->session->getLastOrderId(); $redirectParams = []; if ($orderId) { try { $client = $this->clientFactory->create(); $clientOrderHelper = $client->getOrderHelper(); $order = $this->orderHelper->loadOrderById($orderId); $orderData = $clientOrderHelper->getDataForOrderCreate($order); $result = $client->orderCreate($orderData); $this->orderHelper->addNewOrderTransaction($order, $result['orderId'], $result['extOrderId'], $clientOrderHelper->getNewStatus()); $this->orderHelper->setNewOrderStatus($order); $redirectUrl = $result['redirectUri']; } catch (LocalizedException $e) { $redirectUrl = 'orba_payupl/payment/end'; $redirectParams = ['exception' => '1']; } } else { $redirectUrl = 'orba_payupl/payment/repeat_error'; } $resultRedirect->setPath($redirectUrl, $redirectParams); return $resultRedirect; }
/** * @param int $orderId * @return string|false */ public function getRepeatPaymentUrl($orderId) { $order = $this->orderHelper->loadOrderById($orderId); if ($order && $this->orderHelper->canRepeatPayment($order)) { return $this->_urlBuilder->getUrl('orba_payupl/payment/repeat', ['id' => $this->transactionResource->getLastPayuplOrderIdByOrderId($orderId)]); } return false; }
/** * @param string $payuplOrderId * @return \Orba\Payupl\Model\Sales\Order * @throws LocalizedException */ protected function loadOrderByPayuplOrderId($payuplOrderId) { $order = $this->orderHelper->loadOrderByPayuplOrderId($payuplOrderId); if (!$order) { throw new LocalizedException(new Phrase('Order not found.')); } return $order; }
/** * @return \Magento\Framework\Controller\Result\Redirect */ public function execute() { /** * @var $clientOrderHelper \Orba\Payupl\Model\Client\OrderInterface * @var $resultRedirect \Magento\Framework\Controller\Result\Redirect */ $resultRedirect = $this->resultRedirectFactory->create(); $redirectUrl = 'checkout/cart'; $redirectParams = []; $orderId = $this->orderHelper->getOrderIdForPaymentStart(); if ($orderId) { $order = $this->orderHelper->loadOrderById($orderId); if ($this->orderHelper->canStartFirstPayment($order)) { try { $client = $this->clientFactory->create(); $clientOrderHelper = $client->getOrderHelper(); $orderData = $clientOrderHelper->getDataForOrderCreate($order); $result = $client->orderCreate($orderData); $this->orderHelper->addNewOrderTransaction($order, $result['orderId'], $result['extOrderId'], $clientOrderHelper->getNewStatus()); $this->orderHelper->setNewOrderStatus($order); $redirectUrl = $result['redirectUri']; } catch (LocalizedException $e) { $this->logger->critical($e); $redirectUrl = 'orba_payupl/payment/end'; $redirectParams = ['exception' => '1']; } $this->session->setLastOrderId($orderId); } } $resultRedirect->setPath($redirectUrl, $redirectParams); return $resultRedirect; }
public function testAddNewOrderTransaction() { $payuplOrderId = 'ABC'; $payuplExternalOrderId = '123'; $status = 'NEW'; $orderId = 1; $try = 2; $order = $this->getOrderMock(); $order->expects($this->once())->method('getId')->willReturn($orderId); $this->transactionResource->expects($this->once())->method('getLastTryByOrderId')->willReturn($try); $payment = $this->getMockBuilder(\Magento\Sales\Model\Order\Payment::class)->disableOriginalConstructor()->getMock(); $payment->expects($this->once())->method('setTransactionId')->with($this->equalTo($payuplOrderId)); $payment->expects($this->once())->method('setTransactionAdditionalInfo')->with($this->equalTo(\Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS), $this->equalTo(['order_id' => $payuplExternalOrderId, 'try' => $try + 1, 'status' => $status])); $payment->expects($this->once())->method('setIsTransactionClosed')->with($this->equalTo(0)); $transaction = $this->getMockBuilder(\Magento\Sales\Model\Order\Payment\Transaction::class)->disableOriginalConstructor()->getMock(); $transaction->expects($this->once())->method('save'); $payment->expects($this->once())->method('addTransaction')->with($this->equalTo('order'))->willReturn($transaction); $payment->expects($this->once())->method('save'); $order->expects($this->once())->method('getPayment')->willReturn($payment); $this->model->addNewOrderTransaction($order, $payuplOrderId, $payuplExternalOrderId, $status); }