-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrderController.php
107 lines (87 loc) · 3.19 KB
/
OrderController.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace OxidEsales\MonduPayment\Controller;
use OxidEsales\Eshop\Application\Model\Basket;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Request;
use OxidEsales\Eshop\Core\UtilsView;
use OxidEsales\MonduPayment\Core\Http\MonduClient;
use OxidEsales\MonduPayment\Core\Utils\MonduHelper;
use Symfony\Component\Config\Definition\Exception\Exception;
class OrderController extends OrderController_parent
{
private MonduClient $_client;
private User|null|false $_oUser;
public function __construct()
{
parent::__construct();
$this->_client = oxNew(MonduClient::class);
$this->_oUser = $this->getUser();
}
public function isMonduPayment()
{
$session = Registry::getSession();
$paymentId = $session->getVariable('paymentid');
return MonduHelper::isMonduPayment($paymentId);
}
public function getPaymentPageUrl()
{
$shopUrl = \OxidEsales\Eshop\Core\Registry::getConfig()->getShopSecureHomeURL();
return $shopUrl . '&cl=payment&payerror=2';
}
/**
* @throws \Exception
*/
public function execute()
{
if($this->isMonduPayment()){
$orderUuid = Registry::get(Request::class)->getRequestEscapedParameter('order_uuid');
if (!$orderUuid) {
throw new \Exception('Mondu: Not found');
}
$monduOrder = $this->_client->getMonduOrder($orderUuid);
$response = $this->_client->confirmOrder($orderUuid);
if (isset($response['state']) && $response['state'] == 'confirmed') {
try {
$iSuccess = $this->monduExecute($this->getBasket());
return $this->_getNextStep($iSuccess);
} catch (Exception $e) {
throw new \Exception('Mondu: Error during the order process');
}
}
}
// if user is not logged in set the user
if(!$this->getUser() && isset($this->_oUser)){
$this->setUser($this->_oUser);
}
return parent::execute();
}
/**
* Save order to database, delete order_id from session and redirect to thank you page
*
* @param Basket $oBasket
*
* @return bool|int|mixed
*/
protected function monduExecute(Basket $oBasket)
{
if (!Registry::getSession()->getVariable('sess_challenge')) {
Registry::getSession()->setVariable('sess_challenge', Registry::getUtilsObject()->generateUID());
}
$iSuccess = 0;
$oBasket->calculateBasket(true);
$oOrder = oxNew(Order::class);
try {
$iSuccess = $oOrder->finalizeOrder($oBasket, $oBasket->getUser());
} catch (StandardException $e) {
Registry::get(UtilsView::class)->addErrorToDisplay($e);
}
if ($iSuccess === 1) {
// performing special actions after user finishes order (assignment to special user groups)
$this->_oUser->onOrderExecute($oBasket, $iSuccess);
}
return $iSuccess;
}
}