/** * @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; }
/** * @param int $orderId * @return string|false */ public function getStartPaymentUrl($orderId) { $order = $this->orderHelper->loadOrderById($orderId); if ($order && $this->orderHelper->canStartFirstPayment($order)) { return $this->_urlBuilder->getUrl('orba_payupl/payment/start', ['id' => $orderId]); } return false; }
public function testCanStartFirstPaymentSuccess() { $order = $this->getOrderMock(); $this->orderValidator->expects($this->once())->method('validateCustomer')->with($this->equalTo($order))->willReturn(true); $this->orderValidator->expects($this->once())->method('validateNoTransactions')->with($this->equalTo($order))->willReturn(true); $this->orderValidator->expects($this->once())->method('validatePaymentMethod')->with($this->equalTo($order))->willReturn(true); $this->orderValidator->expects($this->once())->method('validateState')->with($this->equalTo($order))->willReturn(true); $this->assertTrue($this->model->canStartFirstPayment($order)); }