Skip to content

Commit 5bc7034

Browse files
authored
Ignore taxes and fees for free orders (#754)
1 parent aa9a107 commit 5bc7034

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

backend/app/DomainObjects/ProductPriceDomainObject.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,9 @@ public function getOffSaleReason(): ?string
113113
{
114114
return $this->offSaleReason;
115115
}
116+
117+
public function isFree(): bool
118+
{
119+
return $this->getPrice() === 0.00;
120+
}
116121
}

backend/app/Services/Domain/Order/OrderItemProcessingService.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
use Illuminate\Support\Collection;
2020
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
2121

22-
readonly class OrderItemProcessingService
22+
class OrderItemProcessingService
2323
{
2424
public function __construct(
25-
private OrderRepositoryInterface $orderRepository,
26-
private ProductRepositoryInterface $productRepository,
27-
private TaxAndFeeCalculationService $taxCalculationService,
28-
private ProductPriceService $productPriceService,
25+
private readonly OrderRepositoryInterface $orderRepository,
26+
private readonly ProductRepositoryInterface $productRepository,
27+
private readonly TaxAndFeeCalculationService $taxCalculationService,
28+
private readonly ProductPriceService $productPriceService,
2929
)
3030
{
3131
}

backend/app/Services/Domain/Product/ProductFilterService.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,15 @@ private function filterProduct(
162162

163163
private function processProductPrice(ProductDomainObject $product, ProductPriceDomainObject $price): void
164164
{
165-
$taxAndFees = $this->taxCalculationService
166-
->calculateTaxAndFeesForProductPrice($product, $price);
167-
168-
$price
169-
->setTaxTotal(Currency::round($taxAndFees->taxTotal))
170-
->setFeeTotal(Currency::round($taxAndFees->feeTotal));
165+
// If the product is free of charge, we don't charge service fees or taxes
166+
if (!$price->isFree()) {
167+
$taxAndFees = $this->taxCalculationService
168+
->calculateTaxAndFeesForProductPrice($product, $price);
169+
170+
$price
171+
->setTaxTotal(Currency::round($taxAndFees->taxTotal))
172+
->setFeeTotal(Currency::round($taxAndFees->feeTotal));
173+
}
171174

172175
$price->setIsAvailable($this->getPriceAvailability($price, $product));
173176
}

backend/app/Services/Domain/Tax/TaxAndFeeCalculationService.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace HiEvents\Services\Domain\Tax;
44

55
use HiEvents\DomainObjects\Enums\TaxCalculationType;
6-
use HiEvents\DomainObjects\TaxAndFeesDomainObject;
76
use HiEvents\DomainObjects\ProductDomainObject;
87
use HiEvents\DomainObjects\ProductPriceDomainObject;
8+
use HiEvents\DomainObjects\TaxAndFeesDomainObject;
99
use HiEvents\Services\Domain\Tax\DTO\TaxCalculationResponse;
1010
use InvalidArgumentException;
1111

@@ -49,6 +49,13 @@ public function calculateTaxAndFeesForProduct(
4949

5050
private function calculateFee(TaxAndFeesDomainObject $taxOrFee, float $price, int $quantity): float
5151
{
52+
// We do not charge a tax or fee on items which are free of charge
53+
if ($price === 0.00) {
54+
$this->taxRollupService->addToRollUp($taxOrFee, 0);
55+
56+
return 0.00;
57+
}
58+
5259
$amount = match ($taxOrFee->getCalculationType()) {
5360
TaxCalculationType::FIXED->name => $taxOrFee->getRate(),
5461
TaxCalculationType::PERCENTAGE->name => ($price * $taxOrFee->getRate()) / 100,

0 commit comments

Comments
 (0)