Skip to content

Commit 65381c2

Browse files
Include changes from 2.1.4 release
1 parent 53c38b4 commit 65381c2

File tree

9 files changed

+173
-14
lines changed

9 files changed

+173
-14
lines changed

Components/MonduApi/Service/MonduClient.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,26 @@ public function __construct(
3737
/**
3838
* @throws RequestException
3939
*/
40-
public function createOrder($order, $returnUrl, $cancelUrl, $declineUrl, $paymentMethod) {
40+
public function createOrder($order, $returnUrl, $cancelUrl, $declineUrl, $paymentMethod, $userData) {
41+
$user = $userData['additional']['user'];
42+
$billing = $userData['billingaddress'];
43+
4144
$order['payment_method'] = $paymentMethod;
4245
$order['success_url'] = $returnUrl;
4346
$order['cancel_url'] = $cancelUrl;
4447
$order['declined_url'] = $declineUrl;
48+
$order['buyer'] = [
49+
'email' => $user['email'],
50+
'first_name' => $user['firstname'],
51+
'last_name' => $user['lastname'],
52+
'company_name' => $billing['company'],
53+
'phone' => !$billing['phone'] ? null : (trim($billing['phone']) ?: null),
54+
'is_registered' => (bool)$user['userID'],
55+
'salutation' => $billing['salutation'],
56+
'created_at' => $user['firstlogin'] . ' 00:00:00',
57+
'updated_at' => $user['changed'],
58+
'address_line1' => $billing['street']
59+
];
4560

4661
$body = json_encode($order);
4762

Helpers/OrderHelper.php

+20-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Mond1SWR5\Components\PluginConfig\Service\ConfigService;
66
use Mond1SWR5\Enum\PaymentMethods;
7+
use Mond1SWR5\Services\OrderServices\AbstractOrderAdditionalCostsService;
78
use Monolog\Logger;
89
use Shopware\Components\HttpClient\RequestException;
910
use Shopware\Components\Model\ModelManager;
@@ -43,20 +44,27 @@ class OrderHelper
4344
*/
4445
private $customerHelper;
4546

47+
/**
48+
* @var AbstractOrderAdditionalCostsService
49+
*/
50+
private $orderAdditionalCostsService;
51+
4652
public function __construct(
4753
ModelManager $modelManager,
4854
DocumentHelper $documentHelper,
4955
Logger $logger,
5056
ConfigService $configService,
5157
CartHelper $cartHelper,
52-
CustomerHelper $customerHelper
58+
CustomerHelper $customerHelper,
59+
AbstractOrderAdditionalCostsService $orderAdditionalCostsService
5360
) {
5461
$this->modelManager = $modelManager;
5562
$this->documentHelper = $documentHelper;
5663
$this->logger = $logger;
5764
$this->configService = $configService;
5865
$this->cartHelper = $cartHelper;
5966
$this->customerHelper = $customerHelper;
67+
$this->orderAdditionalCostsService = $orderAdditionalCostsService;
6068
}
6169

6270
public function canShipOrder($order): bool
@@ -72,7 +80,7 @@ public function canShipOrder($order): bool
7280
*/
7381
public function shipOrder($order) {
7482
/**
75-
* @var MonduClient
83+
* @var $client MonduClient
7684
*/
7785
$client = Shopware()->Container()->get(MonduClient::class);
7886

@@ -195,6 +203,7 @@ public function getOrderFromOrderVariables($orderVariables) {
195203
'lines' => [
196204
[
197205
'discount_cents' => $this->getTotalDiscount($content, $chargeVat),
206+
'buyer_fee_cents' => $this->orderAdditionalCostsService->getAdditionalCostsCentsFromOrderVariables($orderVariables),
198207
'shipping_price_cents' => round($shippingAmount * 100),
199208
'line_items' => $this->removeDuplicateSwReferenceIds($this->getLineItems($content, $chargeVat))
200209
]
@@ -238,6 +247,7 @@ public function getOrderAdjustment($order) {
238247
'lines' => [
239248
[
240249
'discount_cents' => $totalDiscountGross,
250+
'buyer_fee_cents' => $this->orderAdditionalCostsService->getAdditionalCostsCentsFromOrder($order),
241251
'shipping_price_cents' => round($order->getInvoiceShipping() * 100),
242252
'line_items' => $this->removeDuplicateSwReferenceIds($lineitems)
243253
]
@@ -336,18 +346,19 @@ public function getInvoiceCreateState()
336346
}
337347

338348
private function getBuyerParams($userData) {
339-
$params = $userData['additional']['user'];
349+
$user = $userData['additional']['user'];
340350
$billing = $userData['billingaddress'];
341351

342-
$phone = !$billing['phone'] ? null : (trim($billing['phone']) ?: null);
343-
344352
return [
345-
'email' => $params['email'],
346-
'phone' => $phone,
353+
'email' => $user['email'],
354+
'first_name' => $user['firstname'],
355+
'last_name' => $user['lastname'],
347356
'company_name' => $billing['company'],
348-
'first_name' => $billing['firstname'],
349-
'last_name' => $billing['lastname'],
357+
'phone' => !$billing['phone'] ? null : (trim($billing['phone']) ?: null),
358+
'is_registered' => (bool)$user['userID'],
350359
'salutation' => $billing['salutation'],
360+
'created_at' => $user['firstlogin'] . ' 00:00:00',
361+
'updated_at' => $user['changed'],
351362
'address_line1' => $billing['street']
352363
];
353364
}

Resources/services.xml

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
<service id="Mond1SWR5\Components\PluginConfig\Service\ConfigService" public="true">
2727
<argument key="$router" id="router" type="service"/>
2828
</service>
29+
30+
<service
31+
id="Mond1SWR5\Services\OrderServices\AbstractOrderAdditionalCostsService"
32+
class="Mond1SWR5\Services\OrderServices\OrderAdditionalCostsService"
33+
/>
34+
2935
<service id="Mond1SWR5\Services\PaymentService" public="true"/>
3036
<service id="Mond1SWR5\Services\Webhook\WebhookService" public="true"/>
3137
<service id="Mond1SWR5\Services\PaymentStatusService" public="true"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Mond1SWR5\Services\OrderServices;
4+
5+
use Shopware\Models\Order\Order;
6+
7+
abstract class AbstractOrderAdditionalCostsService {
8+
9+
/**
10+
* Additional costs associated with order in cents from sOrderVariables (during checkout)
11+
*
12+
* @param $sOrderVariables mixed
13+
* @return int
14+
*/
15+
abstract public function getAdditionalCostsCentsFromOrderVariables($sOrderVariables): int;
16+
17+
/**
18+
* Additional costs associated with order in cents from order (in admin panel)
19+
*
20+
* @param null|mixed|Order $order
21+
* @return int
22+
*/
23+
abstract public function getAdditionalCostsCentsFromOrder($order): int;
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Mond1SWR5\Services\OrderServices;
4+
5+
class OrderAdditionalCostsService extends AbstractOrderAdditionalCostsService {
6+
/**
7+
* {@inheritDoc}
8+
*/
9+
public function getAdditionalCostsCentsFromOrderVariables($sOrderVariables): int
10+
{
11+
return 0;
12+
}
13+
14+
/**
15+
* {@inheritDoc}
16+
*/
17+
public function getAdditionalCostsCentsFromOrder($order): int
18+
{
19+
/**
20+
* Check if $order instanceof Order and get the additional costs associated with the order
21+
*/
22+
return 0;
23+
}
24+
}

Services/OrderServices/README.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
## Services
2+
3+
### How to decorate a service
4+
5+
1. Create a class that extends the abstract class of the service you want to decorate
6+
7+
```php
8+
<?php
9+
10+
namespace MonduExtendBuyerFees\Services;
11+
12+
use Mond1SWR5\Services\OrderServices\AbstractOrderAdditionalCostsService;
13+
14+
class OrderAdditionalCostsDecorator extends AbstractOrderAdditionalCostsService {
15+
/**
16+
* @var AbstractOrderAdditionalCostsService
17+
*/
18+
protected $orderAdditionalCostsService;
19+
20+
public function __construct(AbstractOrderAdditionalCostsService $orderAdditionalCostsService) {
21+
$this->orderAdditionalCostsService = $orderAdditionalCostsService;
22+
}
23+
24+
/**
25+
* Get the additional costs associated with the order (during the checkout)
26+
*
27+
* @param $sOrderVariables
28+
* @return int
29+
*/
30+
public function getAdditionalCostsCentsFromOrderVariables($sOrderVariables): int
31+
{
32+
// $original = $this->orderAdditionalCostsService->getAdditionalCostsCentsFromOrderVariables($sOrderVariables);
33+
return 0;
34+
}
35+
36+
37+
/**
38+
* Check if $order instanceof Order and get the additional costs associated with the order (in admin panels)
39+
*/
40+
public function getAdditionalCostsCentsFromOrder($order): int
41+
{
42+
// $original = $this->orderAdditionalCostsService->getAdditionalCostsCentsFromOrder($order);
43+
return 0;
44+
}
45+
}
46+
```
47+
48+
2. Map the decorator class in services.xml
49+
50+
```xml
51+
<?xml version="1.0" ?>
52+
53+
<container xmlns="http://symfony.com/schema/dic/services"
54+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
56+
<services>
57+
<service
58+
id="MonduExtendBuyerFees\Services\OrderAdditionalCostsDecorator"
59+
decorates="Mond1SWR5\Services\OrderServices\AbstractOrderAdditionalCostsService">
60+
<argument type="service" id="MonduExtendBuyerFees\Services\OrderAdditionalCostsDecorator.inner" />
61+
</service>
62+
</services>
63+
</container>
64+
65+
```
66+
67+
You can get the boilerplate plugin for the quickstart [here](https://github.com/tikohov20/MonduSWR5Extension).

Services/SessionService.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ public function createCheckoutSession($returnUrl, $cancelUrl, $declineUrl, $paym
2323
{
2424
try {
2525
$this->reserveOrderNumber();
26+
$userData = $this->session->get('sOrderVariables')['sUserData'];
2627
$monduOrder = $this->monduClient->createOrder(
2728
$this->getOrder(),
2829
$returnUrl,
2930
$cancelUrl,
3031
$declineUrl,
31-
$paymentMethod
32+
$paymentMethod,
33+
$userData
3234
);
3335

3436
$checkoutUrl = $monduOrder['hosted_checkout_url'];

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mondu/bnpl-checkout-shopware5",
33
"description": "Mondu payment method for shopware 5",
4-
"version": "1.0.13",
4+
"version": "2.1.4",
55
"license": "MIT",
66
"authors": [
77
{
@@ -14,6 +14,6 @@
1414
"installer-name": "Mond1SWR5"
1515
},
1616
"require": {
17-
"php": "^7.0 || ^8.0"
17+
"php": "^7.1 || ^8.0"
1818
}
1919
}

plugin.xml

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<label lang="en">Mondu Payment</label>
66
<label lang="de">Mondu Payment</label>
77

8-
<version>2.1.2</version>
8+
<version>2.1.4</version>
99
<copyright>(c) Mondu GmbH</copyright>
1010
<author>Mondu GmbH</author>
1111
<link>https://mondu.ai</link>
@@ -15,6 +15,16 @@
1515
<description lang="en">This module offers you Mondu as a checkout option</description>
1616
<description lang="de">This module offers you Mondu as a checkout option</description>
1717

18+
<changelog version="2.1.4">
19+
<changes lang="en">Bugfixes and improvements</changes>
20+
<changes lang="de">Bugfixes and improvements</changes>
21+
</changelog>
22+
23+
<changelog version="2.1.3">
24+
<changes lang="en">Added OrderAdditionalCostsService that can be overwritten to include additional fees associated with order</changes>
25+
<changes lang="de">Added OrderAdditionalCostsService that can be overwritten to include additional fees associated with order</changes>
26+
</changelog>
27+
1828
<changelog version="2.1.2">
1929
<changes lang="en">Bugfixes and improvements</changes>
2030
<changes lang="de">Bugfixes and improvements</changes>

0 commit comments

Comments
 (0)