Skip to content

Commit be68462

Browse files
PT-2291: Temp order ID visible in the order confirmation email (#27)
1 parent 0e7c115 commit be68462

File tree

3 files changed

+62
-22
lines changed

3 files changed

+62
-22
lines changed

Controller/OrderController.php

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
use OxidEsales\Eshop\Application\Model\Basket;
66
use OxidEsales\Eshop\Application\Model\Order;
77
use OxidEsales\Eshop\Application\Model\User;
8+
use OxidEsales\Eshop\Core\DatabaseProvider;
9+
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
10+
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
811
use OxidEsales\Eshop\Core\Exception\StandardException;
912
use OxidEsales\Eshop\Core\Registry;
1013
use OxidEsales\Eshop\Core\Request;
@@ -39,7 +42,7 @@ public function isMonduPayment()
3942

4043
public function getPaymentPageUrl()
4144
{
42-
$shopUrl = \OxidEsales\Eshop\Core\Registry::getConfig()->getShopSecureHomeURL();
45+
$shopUrl = Registry::getConfig()->getShopSecureHomeURL();
4346
return $shopUrl . '&cl=payment&payerror=2';
4447
}
4548

@@ -56,23 +59,13 @@ public function execute()
5659
}
5760

5861
$oBasket = $this->getBasket();
59-
$data = [];
60-
if ($oBasket->getOrderId()) {
61-
$data['external_reference_id'] = $oBasket->getOrderId();
62-
}
63-
$response = $this->_client->confirmOrder($orderUuid, $data);
64-
$this->_logger->debug('MonduOrderController [execute $response]: ' . print_r($response, true));
65-
66-
if (isset($response['state']) && ($response['state'] == 'confirmed' || $response['state'] == 'pending')) {
67-
$isPending = $response['state'] == 'pending';
6862

69-
try {
70-
$iSuccess = $this->monduExecute($oBasket, $isPending);
63+
try {
64+
$iSuccess = $this->monduExecute($oBasket, $orderUuid);
7165

72-
return $this->getNextStep($iSuccess);
73-
} catch (Exception $e) {
74-
throw new \Exception('Mondu: Error during the order process');
75-
}
66+
return $this->_getNextStep($iSuccess);
67+
} catch (Exception $e) {
68+
throw new \Exception('Mondu: Error during the order process');
7669
}
7770
}
7871

@@ -88,10 +81,12 @@ public function execute()
8881
* Save order to database, delete order_id from session and redirect to thank you page
8982
*
9083
* @param Basket $oBasket
91-
* @param bool $isPending
92-
* @return bool|int|mixed
84+
* @param $orderUuid
85+
* @return string
86+
* @throws DatabaseConnectionException
87+
* @throws DatabaseErrorException
9388
*/
94-
protected function monduExecute(Basket $oBasket, bool $isPending)
89+
protected function monduExecute(Basket $oBasket, $orderUuid)
9590
{
9691
if (!Registry::getSession()->getVariable('sess_challenge')) {
9792
Registry::getSession()->setVariable('sess_challenge', Registry::getUtilsObject()->generateUID());
@@ -102,7 +97,7 @@ protected function monduExecute(Basket $oBasket, bool $isPending)
10297
$oOrder = oxNew(Order::class);
10398

10499
try {
105-
$iSuccess = $oOrder->finalizeOrder($oBasket, $oBasket->getUser(), false, $isPending);
100+
$iSuccess = $oOrder->finalizeOrder($oBasket, $oBasket->getUser(), false);
106101
} catch (StandardException $e) {
107102
Registry::get(UtilsView::class)->addErrorToDisplay($e);
108103
}
@@ -112,6 +107,51 @@ protected function monduExecute(Basket $oBasket, bool $isPending)
112107
$this->_oUser->onOrderExecute($oBasket, $iSuccess);
113108
}
114109

110+
$this->confirmOrder($oBasket, $orderUuid);
111+
115112
return $iSuccess;
116113
}
114+
115+
/**
116+
* @param $oBasket
117+
* @param $orderUuid
118+
* @return void
119+
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
120+
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseErrorException
121+
*/
122+
protected function confirmOrder($oBasket, $orderUuid)
123+
{
124+
if (!$oBasket->getOrderId()) {
125+
return;
126+
}
127+
128+
$data = [];
129+
$order = oxNew(Order::class);
130+
$order->load($oBasket->getOrderId());
131+
$data['external_reference_id'] = $order->getFieldData('oxorder__oxordernr');
132+
133+
$response = $this->_client->confirmOrder($orderUuid, $data);
134+
$this->_logger->debug('MonduOrderController [execute $response]: ' . print_r($response, true));
135+
136+
if (isset($response['state']) && ($response['state'] == 'confirmed' || $response['state'] == 'pending')) {
137+
$isPending = $response['state'] == 'pending';
138+
139+
if ($isPending) {
140+
$sQuery = "
141+
UPDATE
142+
oxorder
143+
SET
144+
oxfolder = 'ORDERFOLDER_PROBLEMS',
145+
oxtransstatus = 'PENDING'
146+
WHERE
147+
OXORDERNR = '{$order->getFieldData('oxorder__oxordernr')}'
148+
";
149+
DatabaseProvider::getDb()->execute($sQuery);
150+
}
151+
152+
$this->_logger->debug(
153+
'MonduOrderController [execute $response]: ' . print_r($response, true)
154+
);
155+
}
156+
}
117157
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "mondu/bnpl-checkout-oxid",
33
"description": "Mondu payment method for the OXID eShop.",
44
"type": "oxideshop-module",
5-
"version": "1.1.7",
5+
"version": "1.1.8",
66
"license": [
77
"OSL-3.0",
88
"AFL-3.0"

metadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'en' => 'Module for Mondu payment.',
1111
),
1212
'thumbnail' => 'out/src/images/logo.png',
13-
'version' => '1.1.7',
13+
'version' => '1.1.8',
1414
'author' => 'Mondu GmbH',
1515
'url' => 'https://www.mondu.ai',
1616
'email' => '[email protected]',

0 commit comments

Comments
 (0)