Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT-1573 added a service that allows buyer_fee_cents to be overwritten #50

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
use JTL\Events\Dispatcher;
use JTL\Link\LinkInterface;
use JTL\Plugin\Bootstrapper;
use JTL\Shop;
use JTL\Smarty\JTLSmarty;
use Plugin\MonduPayment\Src\Services\InstallService;
use Plugin\MonduPayment\Src\Services\OrderServices\AbstractOrderAdditionalCostsService;
use Plugin\MonduPayment\Src\Services\OrderServices\OrderAdditionalCostsService;
use Plugin\MonduPayment\Src\Services\RoutesService;

/**
Expand All @@ -23,6 +26,8 @@ class Bootstrap extends Bootstrapper
public function boot(Dispatcher $dispatcher)
{
parent::boot($dispatcher);

$this->registerServices();
}

/**
Expand Down Expand Up @@ -77,4 +82,16 @@ public function prepareFrontend(LinkInterface $link, JTLSmarty $smarty): bool

return true;
}

protected function registerServices(): void
{
$container = Shop::Container();
try {
$container->setSingleton(AbstractOrderAdditionalCostsService::class, function () {
return new OrderAdditionalCostsService();
});
} catch (\Exception $e) {
// Silence
}
}
}
18 changes: 16 additions & 2 deletions Src/Services/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,35 @@
namespace Plugin\MonduPayment\Src\Services;

use Plugin\MonduPayment\Src\Helpers\BasketHelper;
use Plugin\MonduPayment\Src\Services\OrderServices\AbstractOrderAdditionalCostsService;
use Plugin\MonduPayment\Src\Support\HttpClients\MonduClient;
use JTL\Shop;
use JTL\Session\Frontend;
use JTL\DB\ReturnType;
use Plugin\MonduPayment\Src\Helpers\OrderHashHelper;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class OrderService
{
private MonduClient $monduClient;
private ConfigService $configService;


private ?AbstractOrderAdditionalCostsService $orderAdditionalCostsService;

public function __construct()
{
$this->monduClient = new MonduClient();
$this->configService = new ConfigService();

try {
/**
* @var $orderAdditionalCostsService AbstractOrderAdditionalCostsService
*/
$this->orderAdditionalCostsService = Shop::Container()->get(AbstractOrderAdditionalCostsService::class);
} catch (NotFoundExceptionInterface | ContainerExceptionInterface $e) {
$this->orderAdditionalCostsService = null;
}
}

public function token($paymentMethod)
Expand Down Expand Up @@ -105,7 +119,7 @@ public function getOrderData($paymentMethod)
],
'lines' => [
[
'buyer_fee_cents' => round($basket->surcharge[0] * 100),
'buyer_fee_cents' => (int) $this->orderAdditionalCostsService?->getAdditionalCostsCentsFromOrder($basket),
'discount_cents' => round($basket->discount[0] * 100),
'shipping_price_cents' => round($basket->shipping[0] * 100),
'tax_cents' => round(($basket->total[1] - $basket->total[0]) * 100),
Expand Down
14 changes: 14 additions & 0 deletions Src/Services/OrderServices/AbstractOrderAdditionalCostsService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Plugin\MonduPayment\Src\Services\OrderServices;

abstract class AbstractOrderAdditionalCostsService
{
/**
* Additional costs associated with order in cents from basket (in admin panel)
*
* @param mixed $basket
* @return int
*/
abstract public function getAdditionalCostsCentsFromOrder(mixed $basket): int;
}
14 changes: 14 additions & 0 deletions Src/Services/OrderServices/OrderAdditionalCostsService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Plugin\MonduPayment\Src\Services\OrderServices;

class OrderAdditionalCostsService extends AbstractOrderAdditionalCostsService {

/**
* @inheritDoc
*/
public function getAdditionalCostsCentsFromOrder(mixed $basket): int
{
return round($basket->surcharge[0] * 100);
}
}
2 changes: 1 addition & 1 deletion info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PluginID>MonduPayment</PluginID>
<XMLVersion>100</XMLVersion>
<ShopVersion>5.0.0</ShopVersion>
<Version>3.0.4</Version>
<Version>3.0.5</Version>
<CreateDate>2022-06-07</CreateDate>
<Install>
<Hooks>
Expand Down
Loading