55use OxidEsales \Eshop \Application \Model \Basket ;
66use OxidEsales \Eshop \Application \Model \Order ;
77use 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 ;
811use OxidEsales \Eshop \Core \Exception \StandardException ;
912use OxidEsales \Eshop \Core \Registry ;
1013use 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}
0 commit comments