This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Start.php
93 lines (85 loc) · 3.05 KB
/
Start.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* @copyright Copyright (c) 2015 Orba Sp. z o.o. (http://orba.pl)
*/
namespace Orba\Payupl\Controller\Payment;
use Magento\Framework\Exception\LocalizedException;
class Start extends \Magento\Framework\App\Action\Action
{
/**
* @var \Orba\Payupl\Model\ClientFactory
*/
protected $clientFactory;
/**
* @var \Orba\Payupl\Model\Order
*/
protected $orderHelper;
/**
* @var \Orba\Payupl\Model\Session
*/
protected $session;
/**
* @var \Orba\Payupl\Logger\Logger
*/
protected $logger;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Orba\Payupl\Model\ClientFactory $clientFactory
* @param \Orba\Payupl\Model\Order $orderHelper
* @param \Orba\Payupl\Model\Session $session
* @param \Orba\Payupl\Logger\Logger $logger
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Orba\Payupl\Model\ClientFactory $clientFactory,
\Orba\Payupl\Model\Order $orderHelper,
\Orba\Payupl\Model\Session $session,
\Orba\Payupl\Logger\Logger $logger
) {
parent::__construct($context);
$this->clientFactory = $clientFactory;
$this->orderHelper = $orderHelper;
$this->session = $session;
$this->logger = $logger;
}
/**
* @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;
}
}