Skip to content

Commit

Permalink
Rollback tax calculation fix from the other day
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Jun 21, 2023
1 parent 03840b4 commit 2900872
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/Tax/Standard/TaxEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function calculateForLineItem(Order $order, LineItem $lineItem): TaxCalcu
}
}

$taxAmount = $lineItem->total() * ($taxRate->rate() / 100);
$itemTax = (int) round($taxAmount);
$taxAmount = ($lineItem->total() / 100) * ($taxRate->rate() / (100 + $taxRate->rate()));
$itemTax = (int) round($taxAmount * 100);

return new TaxCalculation($itemTax, $taxRate->rate(), $taxRate->includeInPrice());
}
Expand Down Expand Up @@ -111,8 +111,8 @@ public function calculateForShipping(Order $order, ShippingMethod $shippingMetho
}
}

$taxAmount = $order->shippingTotal() * ($taxRate->rate() / 100);
$itemTax = (int) round($taxAmount);
$taxAmount = ($order->shippingTotal() / 100) * ($taxRate->rate() / (100 + $taxRate->rate()));
$itemTax = (int) round($taxAmount * 100);

return new TaxCalculation($itemTax, $taxRate->rate(), $taxRate->includeInPrice());
}
Expand Down
20 changes: 10 additions & 10 deletions tests/Tax/StandardTaxEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@

// Ensure tax on line items are right
$this->assertSame($recalculate->lineItems()->first()->tax(), [
'amount' => 200,
'amount' => 167,
'rate' => 20,
'price_includes_tax' => false,
]);

// Ensure global order tax is right
expect(200)->toBe($recalculate->taxTotal());
expect(167)->toBe($recalculate->taxTotal());
});

test('can correctly calculate line item tax rate based on region', function () {
Expand Down Expand Up @@ -162,13 +162,13 @@

// Ensure tax on line items are right
$this->assertSame($recalculate->lineItems()->first()->tax(), [
'amount' => 150,
'amount' => 130,
'rate' => 15,
'price_includes_tax' => false,
]);

// Ensure global order tax is right
expect(150)->toBe($recalculate->taxTotal());
expect(130)->toBe($recalculate->taxTotal());
});

test('can calculate line item tax rate when included in price', function () {
Expand Down Expand Up @@ -229,13 +229,13 @@

// Ensure tax on line items are right
$this->assertSame($recalculate->lineItems()->first()->tax(), [
'amount' => 200,
'amount' => 167,
'rate' => 20,
'price_includes_tax' => true,
]);

// Ensure global order tax is right
expect(200)->toBe($recalculate->taxTotal());
expect(167)->toBe($recalculate->taxTotal());
});

test('can use default line item tax rate if no rate available', function () {
Expand Down Expand Up @@ -289,7 +289,7 @@
expect(12)->toBe($recalculate->lineItems()->first()->tax()['rate']);

// Ensure global order tax is right
expect(120)->toBe($recalculate->taxTotal());
expect(107)->toBe($recalculate->taxTotal());
});

test('throws prevent checkout exception if no rate available', function () {
Expand Down Expand Up @@ -400,7 +400,7 @@
expect(99)->toBe($recalculate->lineItems()->first()->tax()['rate']);

// Ensure global order tax is right
expect(990)->toBe($recalculate->taxTotal());
expect(497)->toBe($recalculate->taxTotal());
});

test('throws prevent checkout exception if no address provided', function () {
Expand Down Expand Up @@ -525,8 +525,8 @@
$recalculate = $order->recalculate();

// Ensure 10% is deducted from shipping_total (500 -> 450)
expect($recalculate->shippingTotal())->toBe(450);
expect($recalculate->shippingTotal())->toBe(455);

// Ensure tax total is 50
expect($recalculate->taxTotal())->toBe(50);
expect($recalculate->taxTotal())->toBe(45);
});

0 comments on commit 2900872

Please sign in to comment.