Skip to content

Commit bfb3109

Browse files
2 parents 2d312cd + 8d66dd9 commit bfb3109

7 files changed

+78
-20
lines changed

Core/Mappers/MonduAdjustmentMapper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function getMappedOrderData($order)
1414

1515
$data = [
1616
"currency" => $order->getOrderCurrency()->name,
17-
"external_reference_id" => $order->getId(),
17+
"external_reference_id" => $order->getFieldData('oxorder__oxordernr') ? (string) $order->getFieldData('oxorder__oxordernr') : $order->getId(),
1818
"amount" => [
1919
"net_price_cents" => round($order->getOrderNetSum() * 100),
2020
"tax_cents" => round($tax * 100),

Core/Mappers/MonduInvoiceMapper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function getMappedInvoiceData($order)
1111
$invoiceLineItems = $this->getInvoiceLineItems($order);
1212

1313
return MonduHelper::removeEmptyElementsFromArray([
14-
'external_reference_id' => $order->getId(),
14+
'external_reference_id' => $order->getFieldData('oxorder__oxordernr') ? (string) $order->getFieldData('oxorder__oxordernr') : $order->getId(),
1515
'invoice_url' => 'http://localhost',
1616
'gross_amount_cents' => round($order->getFieldData('oxtotalordersum') * 100),
1717
'line_items' => $invoiceLineItems

Core/OrderShippingProcessor.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,20 @@ protected function createMonduInvoice()
5252
$invoiceDataMapper = oxNew(MonduInvoiceMapper::class);
5353
$invoiceData = $invoiceDataMapper->getMappedInvoiceData($this->_oOrder);
5454

55-
$response = $this->client->createInvoice($this->_oMonduOrder->getFieldData('order_uuid'), $invoiceData);
56-
57-
return $response;
55+
return $this->client->createInvoice($this->_oMonduOrder->getFieldData('order_uuid'), $invoiceData);
5856
}
5957

6058
protected function cancelMonduInvoice()
6159
{
62-
$monduInvoice = array_values($this->_oOrder->getMonduInvoices()->getArray())[0];
60+
if ($this->_oOrder->getMonduInvoices()) {
61+
$monduInvoice = array_values($this->_oOrder->getMonduInvoices()->getArray())[0];
6362

64-
if ($monduInvoice) {
65-
$response = $this->client->cancelInvoice($this->_oMonduOrder->getFieldData('order_uuid'), $monduInvoice->getFieldData('invoice_uuid'));
66-
return $response;
63+
if ($monduInvoice) {
64+
return $this->client->cancelInvoice(
65+
$this->_oMonduOrder->getFieldData('order_uuid'),
66+
$monduInvoice->getFieldData('invoice_uuid')
67+
);
68+
}
6769
}
6870
}
6971

Core/PaymentHandler/MonduInvoiceHandler.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@ public function execute(Order $oOrder): bool
2525
return false;
2626
}
2727

28-
$updatedOrder = $this->_client->updateOrderExternalInfo(
29-
$monduOrderUuid,
30-
['external_reference_id' => $oOrder->getId()]
31-
);
28+
$monduOrder = $this->_client->getMonduOrder($monduOrderUuid);
3229

33-
$monduOrder = $this->_client->getMonduOrder($updatedOrder['uuid']);
34-
35-
if (!$updatedOrder || !$monduOrder) {
30+
if (!$monduOrder) {
3631
return false;
3732
}
3833

Model/Order.php

+63-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@
33
namespace OxidEsales\MonduPayment\Model;
44

55
use OxidEsales\Eshop\Core\Model\ListModel;
6+
use OxidEsales\Eshop\Core\Registry;
7+
use OxidEsales\MonduPayment\Core\Http\MonduClient;
68
use OxidEsales\MonduPayment\Core\Utils\MonduHelper;
79
use OxidEsales\MonduPayment\Model\MonduOrder;
810
use OxidEsales\MonduPayment\Model\MonduInvoice;
911

1012
class Order extends Order_parent
1113
{
14+
/**
15+
* @var mixed|\oxdeliveryset|\oxField|\OxidEsales\Eshop\Core\Field|\OxidEsales\EshopCommunity\Application\Model\oxDeliverySet|MonduClient
16+
*/
17+
private mixed $client;
18+
19+
public function __construct()
20+
{
21+
parent::__construct();
22+
$this->client = oxNew(MonduClient::class);
23+
}
24+
1225
public function getMonduOrders()
1326
{
1427
if ($this->isMonduPayment()) {
@@ -27,11 +40,16 @@ public function getMonduOrders()
2740
public function getMonduInvoices()
2841
{
2942
if ($this->isMonduPayment()) {
30-
$sQuery = 'SELECT * FROM `oemondu_invoices` WHERE `invoice_id`=:oxorderid ORDER BY created_at DESC';
43+
$sQuery = 'SELECT * FROM `oemondu_invoices` WHERE `invoice_id` IN (:oxorderid, :oxordernr) ORDER BY created_at DESC';
3144

3245
$oMonduInvoices = oxNew(ListModel::class);
3346
$oMonduInvoices->init(MonduInvoice::class);
34-
$oMonduInvoices->selectString($sQuery, [':oxorderid' => $this->getId()]);
47+
$oMonduInvoices->selectString(
48+
$sQuery, [
49+
':oxorderid' => $this->getId(),
50+
':oxordernr' => $this->getFieldData('oxorder__oxordernr')
51+
]
52+
);
3553

3654
return $oMonduInvoices;
3755
}
@@ -54,4 +72,47 @@ public function deleteAllArticles()
5472

5573
$this->recalculateOrder();
5674
}
75+
76+
/**
77+
* Order checking, processing and saving method.
78+
* Before saving performed checking if order is still not executed (checks in
79+
* database oxorder table for order with know ID), if yes - returns error code 3,
80+
* if not - loads payment data, assigns all info from basket to new Order object
81+
* and saves full order with error status. Then executes payment. On failure -
82+
* deletes order and returns error code 2. On success - saves order (\OxidEsales\Eshop\Application\Model\Order::save()),
83+
* removes article from wishlist (\OxidEsales\Eshop\Application\Model\Order::_updateWishlist()), updates voucher data
84+
* (\OxidEsales\Eshop\Application\Model\Order::_markVouchers()). Finally sends order confirmation email to customer
85+
* (\OxidEsales\Eshop\Core\Email::SendOrderEMailToUser()) and shop owner (\OxidEsales\Eshop\Core\Email::SendOrderEMailToOwner()).
86+
* If this is order recalculation, skipping payment execution, marking vouchers as used
87+
* and sending order by email to shop owner and user
88+
* Mailing status (1 if OK, 0 on error) is returned.
89+
*
90+
* @param \OxidEsales\Eshop\Application\Model\Basket $oBasket Basket object
91+
* @param object $oUser Current User object
92+
* @param bool $blRecalculatingOrder Order recalculation
93+
*
94+
* @return integer
95+
*/
96+
public function finalizeOrder(\OxidEsales\Eshop\Application\Model\Basket $oBasket, $oUser, $blRecalculatingOrder = false)
97+
{
98+
$result = parent::finalizeOrder($oBasket, $oUser, $blRecalculatingOrder);
99+
100+
if (
101+
$this->isMonduPayment() &&
102+
$this->getMonduOrders()
103+
) {
104+
$monduOrderUuid = array_values($this->getMonduOrders()->getArray())[0]->getFieldData( 'order_uuid' );
105+
106+
if (!$monduOrderUuid || !$this->getFieldData( 'oxorder__oxordernr')) {
107+
return $result;
108+
}
109+
110+
$this->client->updateOrderExternalInfo(
111+
$monduOrderUuid,
112+
['external_reference_id' => (string) $this->getFieldData('oxorder__oxordernr')]
113+
);
114+
}
115+
116+
return $result;
117+
}
57118
}

composer.json

+1-1
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.0.0",
5+
"version": "1.0.2",
66
"license": [
77
"OSL-3.0",
88
"AFL-3.0"

metadata.php

+1-1
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.0.0',
13+
'version' => '1.0.2',
1414
'author' => 'Mondu GmbH',
1515
'url' => 'https://www.mondu.ai',
1616
'email' => '[email protected]',

0 commit comments

Comments
 (0)