-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonduCheckoutController.php
68 lines (52 loc) · 1.91 KB
/
MonduCheckoutController.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
<?php
namespace OxidEsales\MonduPayment\Controller;
use OxidEsales\MonduPayment\Core\Http\MonduClient;
use OxidEsales\MonduPayment\Core\Mappers\MonduOrderMapper;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\MonduPayment\Model\MonduPayment;
use OxidEsales\Eshop\Application\Model\Order;
class MonduCheckoutController extends \OxidEsales\Eshop\Application\Controller\FrontendController
{
protected MonduClient $_client;
protected MonduOrderMapper $_orderMapper;
public function __construct()
{
parent::__construct();
$this->_client = oxNew(MonduClient::class);
$this->_orderMapper = oxNew(MonduOrderMapper::class);
}
public function createOrder()
{
$this->_orderMapper->setBasket($this->getBasket());
$this->_orderMapper->setDeliveryAddress($this->getDelAddress());
$paymentMethod = $this->getPaymentMethod();
$orderData = $this->_orderMapper->getMappedOrderData($paymentMethod);
$response = $this->_client->createOrder($orderData);
$token = $response['uuid'] ?? 'error';
if ($token !== 'error') {
$session = Registry::getSession();
$session->setVariable('mondu_order_uuid', $token);
}
echo json_encode([
'token' => $token,
'hostedCheckoutUrl' => $response['hosted_checkout_url'] ?? false
]);
exit();
}
protected function getBasket()
{
return Registry::getSession()->getBasket();
}
protected function getDelAddress()
{
$order = oxNew(Order::class);
return $order->getDelAddressInfo();
}
protected function getPaymentMethod()
{
$session = Registry::getSession();
$paymentId = $session->getVariable("paymentid");
$payment = MonduPayment::getMonduPaymentMethodFromPaymentId($paymentId);
return $payment ? $payment['mondu_payment_method'] : 'invoice';
}
}