diff --git a/Helper/ChargedCurrency.php b/Helper/ChargedCurrency.php index b15925611..0c74cd6ea 100644 --- a/Helper/ChargedCurrency.php +++ b/Helper/ChargedCurrency.php @@ -17,6 +17,7 @@ use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Invoice; use Magento\Sales\Api\Data\CreditmemoItemInterface; +use Magento\Tax\Block\Item\Price\RendererFactory; class ChargedCurrency { @@ -26,16 +27,10 @@ class ChargedCurrency */ const BASE = "base"; - /** - * @var Config - */ - private $config; - public function __construct( - Config $config - ) { - $this->config = $config; - } + private readonly Config $config, + private readonly RendererFactory $priceRendererFactory + ) { } /** * @param Order $order @@ -44,7 +39,7 @@ public function __construct( * * @return AdyenAmountCurrency */ - public function getOrderAmountCurrency(Order $order, bool $orderPlacement = true) + public function getOrderAmountCurrency(Order $order, bool $orderPlacement = true): AdyenAmountCurrency { $chargedCurrency = $orderPlacement ? $this->config->getChargedCurrency($order->getStoreId()) @@ -71,7 +66,7 @@ public function getOrderAmountCurrency(Order $order, bool $orderPlacement = true * @param Quote $quote * @return AdyenAmountCurrency */ - public function getQuoteAmountCurrency(Quote $quote) + public function getQuoteAmountCurrency(Quote $quote): AdyenAmountCurrency { $chargedCurrency = $this->config->getChargedCurrency($quote->getStoreId()); if ($chargedCurrency == self::BASE) { @@ -83,6 +78,7 @@ public function getQuoteAmountCurrency(Quote $quote) public function getQuoteItemAmountCurrency(Quote\Item $item): AdyenAmountCurrency { $chargedCurrency = $this->config->getChargedCurrency($item->getStoreId()); + $priceRenderer = $this->priceRendererFactory->create(); if ($chargedCurrency == self::BASE) { return new AdyenAmountCurrency( @@ -91,8 +87,7 @@ public function getQuoteItemAmountCurrency(Quote\Item $item): AdyenAmountCurrenc $item->getBaseDiscountAmount() / $item->getQty(), $item->getBaseTaxAmount() / $item->getQty(), null, - $item->getBaseRowTotalInclTax() / $item->getQty(), - $item->getBaseDiscountTaxCompensationAmount() / $item->getQty() + $priceRenderer->getBaseTotalAmount($item) / $item->getQty() ); } @@ -102,14 +97,14 @@ public function getQuoteItemAmountCurrency(Quote\Item $item): AdyenAmountCurrenc $item->getDiscountAmount() / $item->getQty(), $item->getTaxAmount() / $item->getQty(), null, - $item->getRowTotalInclTax() / $item->getQty(), - $item->getDiscountTaxCompensationAmount() / $item->getQty() + $priceRenderer->getTotalAmount($item) / $item->getQty() ); } public function getInvoiceItemAmountCurrency(Invoice\Item $item): AdyenAmountCurrency { $chargedCurrency = $item->getInvoice()->getOrder()->getAdyenChargedCurrency(); + $priceRenderer = $this->priceRendererFactory->create(); if ($chargedCurrency == self::BASE) { return new AdyenAmountCurrency( @@ -118,8 +113,7 @@ public function getInvoiceItemAmountCurrency(Invoice\Item $item): AdyenAmountCur $item->getBaseDiscountAmount() / $item->getQty(), $item->getBaseTaxAmount() / $item->getQty(), null, - $item->getBaseRowTotalInclTax() / $item->getQty(), - $item->getBaseDiscountTaxCompensationAmount() / $item->getQty() + $priceRenderer->getBaseTotalAmount($item) ); } @@ -129,8 +123,7 @@ public function getInvoiceItemAmountCurrency(Invoice\Item $item): AdyenAmountCur $item->getDiscountAmount() / $item->getQty(), $item->getTaxAmount() / $item->getQty(), null, - $item->getRowTotalInclTax() / $item->getQty(), - $item->getDiscountTaxCompensationAmount() / $item->getQty() + $priceRenderer->getTotalAmount($item) ); } @@ -138,7 +131,7 @@ public function getInvoiceItemAmountCurrency(Invoice\Item $item): AdyenAmountCur * @param CreditmemoInterface $creditMemo * @return AdyenAmountCurrency */ - public function getCreditMemoAmountCurrency(CreditmemoInterface $creditMemo) + public function getCreditMemoAmountCurrency(CreditmemoInterface $creditMemo): AdyenAmountCurrency { $chargedCurrency = $creditMemo->getOrder()->getAdyenChargedCurrency(); if ($chargedCurrency == self::BASE) { @@ -162,7 +155,7 @@ public function getCreditMemoAmountCurrency(CreditmemoInterface $creditMemo) * @param CreditmemoInterface $creditMemo * @return AdyenAmountCurrency */ - public function getCreditMemoAdjustmentAmountCurrency(CreditmemoInterface $creditMemo) + public function getCreditMemoAdjustmentAmountCurrency(CreditmemoInterface $creditMemo): AdyenAmountCurrency { $chargedCurrency = $creditMemo->getOrder()->getAdyenChargedCurrency(); if ($chargedCurrency == self::BASE) { @@ -188,8 +181,7 @@ public function getCreditMemoShippingAmountCurrency(CreditmemoInterface $creditM null, $creditMemo->getBaseShippingTaxAmount(), null, - $creditMemo->getBaseShippingInclTax(), - $creditMemo->getBaseShippingDiscountTaxCompensationAmnt() + $creditMemo->getBaseShippingInclTax() ); } return new AdyenAmountCurrency( @@ -198,14 +190,14 @@ public function getCreditMemoShippingAmountCurrency(CreditmemoInterface $creditM null, $creditMemo->getShippingTaxAmount(), null, - $creditMemo->getShippingInclTax(), - $creditMemo->getShippingDiscountTaxCompensationAmount() + $creditMemo->getShippingInclTax() ); } public function getCreditMemoItemAmountCurrency(CreditmemoItemInterface $item): AdyenAmountCurrency { $chargedCurrency = $item->getCreditMemo()->getOrder()->getAdyenChargedCurrency(); + $priceRenderer = $this->priceRendererFactory->create(); if ($chargedCurrency == self::BASE) { return new AdyenAmountCurrency( @@ -214,8 +206,7 @@ public function getCreditMemoItemAmountCurrency(CreditmemoItemInterface $item): $item->getBaseDiscountAmount() / $item->getQty(), $item->getBaseTaxAmount() / $item->getQty(), null, - $item->getBaseRowTotalInclTax() / $item->getQty(), - $item->getBaseDiscountTaxCompensationAmount() / $item->getQty() + $priceRenderer->getBaseTotalAmount($item) ); } return new AdyenAmountCurrency( @@ -224,8 +215,7 @@ public function getCreditMemoItemAmountCurrency(CreditmemoItemInterface $item): $item->getDiscountAmount() / $item->getQty(), $item->getTaxAmount() / $item->getQty(), null, - $item->getRowTotalInclTax() / $item->getQty(), - $item->getDiscountTaxCompensationAmount() / $item->getQty() + $priceRenderer->getTotalAmount($item) ); } @@ -240,8 +230,7 @@ public function getQuoteShippingAmountCurrency(Quote $quote): AdyenAmountCurrenc $quote->getShippingAddress()->getBaseShippingDiscountAmount(), $quote->getShippingAddress()->getBaseShippingTaxAmount(), null, - $quote->getShippingAddress()->getBaseShippingInclTax(), - $quote->getShippingAddress()->getBaseShippingDiscountTaxCompensationAmnt() + $quote->getShippingAddress()->getBaseShippingInclTax() ); } @@ -251,8 +240,7 @@ public function getQuoteShippingAmountCurrency(Quote $quote): AdyenAmountCurrenc $quote->getShippingAddress()->getShippingDiscountAmount(), $quote->getShippingAddress()->getShippingTaxAmount(), null, - $quote->getShippingAddress()->getShippingInclTax(), - $quote->getShippingAddress()->getShippingDiscountTaxCompensationAmount() + $quote->getShippingAddress()->getShippingInclTax() ); } @@ -267,8 +255,7 @@ public function getInvoiceShippingAmountCurrency(Invoice $invoice): AdyenAmountC null, $invoice->getBaseShippingTaxAmount(), null, - $invoice->getBaseShippingInclTax(), - $invoice->getBaseShippingDiscountTaxCompensationAmnt() + $invoice->getBaseShippingInclTax() ); } @@ -278,8 +265,7 @@ public function getInvoiceShippingAmountCurrency(Invoice $invoice): AdyenAmountC null, $invoice->getShippingTaxAmount(), null, - $invoice->getShippingInclTax(), - $invoice->getShippingDiscountTaxCompensationAmount() + $invoice->getShippingInclTax() ); } diff --git a/Helper/OpenInvoice.php b/Helper/OpenInvoice.php index 85558ad24..f0d9439ef 100644 --- a/Helper/OpenInvoice.php +++ b/Helper/OpenInvoice.php @@ -142,29 +142,19 @@ protected function formatShippingLineItem( ): array { $currency = $shippingAmount->getCurrencyCode(); - $formattedPriceExcludingTax = $this->adyenHelper->formatAmount( - $shippingAmount->getAmountWithDiscount(), - $currency - ); $formattedPriceIncludingTax = $this->adyenHelper->formatAmount( - $shippingAmount->getAmountIncludingTaxWithDiscount(), + $shippingAmount->getAmountIncludingTax(), $currency ); $formattedTaxAmount = $this->adyenHelper->formatAmount($shippingAmount->getTaxAmount(), $currency); - $formattedTaxPercentage = $this->adyenHelper->formatAmount( - $shippingAmount->getCalculatedTaxPercentage(), - $currency - ); return [ 'id' => 'shippingCost', - 'amountExcludingTax' => $formattedPriceExcludingTax, 'amountIncludingTax' => $formattedPriceIncludingTax, 'taxAmount' => $formattedTaxAmount, 'description' => $shippingDescription, - 'quantity' => 1, - 'taxPercentage' => $formattedTaxPercentage + 'quantity' => 1 ]; } @@ -172,12 +162,8 @@ protected function formatLineItem(AdyenAmountCurrency $itemAmountCurrency, $item { $currency = $itemAmountCurrency->getCurrencyCode(); - $formattedPriceExcludingTax = $this->adyenHelper->formatAmount( - $itemAmountCurrency->getAmountWithDiscount(), - $currency - ); $formattedPriceIncludingTax = $this->adyenHelper->formatAmount( - $itemAmountCurrency->getAmountIncludingTaxWithDiscount(), + $itemAmountCurrency->getAmountIncludingTax(), $currency ); @@ -188,7 +174,6 @@ protected function formatLineItem(AdyenAmountCurrency $itemAmountCurrency, $item return [ 'id' => $product ? $product->getId() : $item->getProductId(), - 'amountExcludingTax' => $formattedPriceExcludingTax, 'amountIncludingTax' => $formattedPriceIncludingTax, 'taxAmount' => $formattedTaxAmount, 'description' => $item->getName(), @@ -199,6 +184,9 @@ protected function formatLineItem(AdyenAmountCurrency $itemAmountCurrency, $item ]; } + /** + * @deprecated + */ protected function formatInvoiceDiscount( mixed $discountAmount, $shippingDiscountAmount, AdyenAmountCurrency $itemAmountCurrency ): array @@ -210,7 +198,6 @@ protected function formatInvoiceDiscount( return [ 'id' => 'Discount', - 'amountExcludingTax' => $itemAmount, 'amountIncludingTax' => $itemAmount, 'taxAmount' => 0, 'description' => $description, diff --git a/Model/AdyenAmountCurrency.php b/Model/AdyenAmountCurrency.php index c8040e4d2..ca7bfdad6 100644 --- a/Model/AdyenAmountCurrency.php +++ b/Model/AdyenAmountCurrency.php @@ -25,6 +25,9 @@ class AdyenAmountCurrency protected $amountDue; + /** + * @deprecated + */ protected $discountTaxCompensationAmount; public function __construct( @@ -75,11 +78,17 @@ public function getAmountDue() return $this->amountDue; } + /** + * @deprecated + */ public function getDiscountTaxCompensationAmount() { return $this->discountTaxCompensationAmount; } + /** + * @deprecated + */ public function getAmountIncludingTaxWithDiscount() { if ($this->getDiscountTaxCompensationAmount() > 0) { @@ -90,11 +99,17 @@ public function getAmountIncludingTaxWithDiscount() } } + /** + * @deprecated + */ public function getAmountWithDiscount() { return $this->getAmount() - $this->getDiscountAmount() + $this->getDiscountTaxCompensationAmount(); } + /** + * @deprecated + */ public function getCalculatedTaxPercentage() { if ($this->getAmountWithDiscount() > 0) { diff --git a/Test/Unit/Helper/ChargedCurrencyTest.php b/Test/Unit/Helper/ChargedCurrencyTest.php index 8416d9472..7fee185b8 100755 --- a/Test/Unit/Helper/ChargedCurrencyTest.php +++ b/Test/Unit/Helper/ChargedCurrencyTest.php @@ -20,8 +20,9 @@ use Magento\Sales\Api\Data\CreditmemoItemInterface; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Creditmemo\Item; +use Magento\Tax\Block\Item\Price\Renderer; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\TestCase; +use Magento\Tax\Block\Item\Price\RendererFactory; class ChargedCurrencyTest extends AbstractAdyenTestCase { @@ -35,7 +36,8 @@ class ChargedCurrencyTest extends AbstractAdyenTestCase 'taxAmount' => 12.34, 'amountDue' => 56.78, 'amountIncludingTax' => 135.79, - 'discountTaxCompensationAmount' => 0.05 + 'discountTaxCompensationAmount' => 0.05, + 'amountIncludingTaxWithDiscount' => 67.90 ], 'display' => [ @@ -45,7 +47,8 @@ class ChargedCurrencyTest extends AbstractAdyenTestCase 'taxAmount' => 54.32, 'amountDue' => 10.98, 'amountIncludingTax' => 708.64, - 'discountTaxCompensationAmount' => 0.02 + 'discountTaxCompensationAmount' => 0.02, + 'amountIncludingTaxWithDiscount' => 609.88 ] ]; @@ -94,6 +97,16 @@ class ChargedCurrencyTest extends AbstractAdyenTestCase */ private $creditMemo; + /** + * @var RendererFactory + */ + private $priceRendererFactory; + + /** + * @var Renderer + */ + private $priceRenderer; + protected function setUp(): void { $this->order = $this->createMockWithMethods( @@ -361,14 +374,21 @@ protected function setUp(): void ); $this->configHelper = $this->createMock(Config::class); + + $this->priceRenderer = $this->createMock(Renderer::class); + $this->priceRenderer->method('getBaseTotalAmount')->willReturn(self::AMOUNT_CURRENCY['base']['amountIncludingTax']); + $this->priceRenderer->method('getTotalAmount')->willReturn(self::AMOUNT_CURRENCY['display']['amountIncludingTax']); + + $this->priceRendererFactory = $this->createGeneratedMock(RendererFactory::class, ['create']); + $this->priceRendererFactory->method('create')->willReturn($this->priceRenderer); } /** * @dataProvider amountCurrencyProvider * @param $configValue + * @param AdyenAmountCurrency $expectedResult * @param $orderPlacement * @param $getAdyenChargedCurrency - * @param $expectedResult */ public function testGetOrderAmountCurrency( $configValue, @@ -378,7 +398,7 @@ public function testGetOrderAmountCurrency( ) { $this->configHelper->method('getChargedCurrency')->willReturn($configValue); $this->order->method('getAdyenChargedCurrency')->willReturn($getAdyenChargedCurrency); - $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper); + $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper, $this->priceRendererFactory); $result = $this->chargedCurrencyHelper->getOrderAmountCurrency($this->order, $orderPlacement); $this->assertEquals( [ @@ -407,7 +427,7 @@ public function testGetQuoteAmountCurrency( ) { if ($orderPlacement) { $this->configHelper->method('getChargedCurrency')->willReturn($configValue); - $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper); + $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper, $this->priceRendererFactory); $result = $this->chargedCurrencyHelper->getQuoteAmountCurrency($this->quote); $this->assertEquals( [ @@ -438,32 +458,30 @@ public function testGetQuoteItemAmountCurrency( ) { if ($orderPlacement) { $this->configHelper->method('getChargedCurrency')->willReturn($configValue); - $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper); + $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper, $this->priceRendererFactory); $result = $this->chargedCurrencyHelper->getQuoteItemAmountCurrency($this->quoteItem); - $this->assertEquals( - [ - $expectedResult->getAmount(), - $expectedResult->getCurrencyCode(), - $expectedResult->getDiscountAmount(), - $expectedResult->getTaxAmount(), - $expectedResult->getAmountIncludingTax(), - $expectedResult->getDiscountTaxCompensationAmount(), - $expectedResult->getAmountWithDiscount(), - $expectedResult->getCalculatedTaxPercentage(), - $expectedResult->getAmountIncludingTaxWithDiscount() - ], - [ - $result->getAmount(), - $result->getCurrencyCode(), - $result->getDiscountAmount(), - number_format($result->getTaxAmount(), 2, '.', ','), - $result->getAmountIncludingTax(), - $result->getDiscountTaxCompensationAmount(), - $result->getAmountWithDiscount(), - $result->getCalculatedTaxPercentage(), - $result->getAmountIncludingTaxWithDiscount() - ] - ); + + $expected = [ + $expectedResult->getAmount(), + $expectedResult->getCurrencyCode(), + $expectedResult->getDiscountAmount(), + $expectedResult->getTaxAmount(), + $expectedResult->getAmountIncludingTax() + ]; + + $actual = [ + $result->getAmount(), + $result->getCurrencyCode(), + $result->getDiscountAmount(), + $result->getTaxAmount(), + $result->getAmountIncludingTax() + ]; + + $this->assertEquals($expected[0], $actual[0], 'Amount mismatch'); + $this->assertEquals($expected[1], $actual[1], 'Currency code mismatch'); + $this->assertEquals($expected[2], $actual[2], 'Discount amount mismatch'); + $this->assertEquals($expected[3], $actual[3], 'Tax amount mismatch'); + $this->assertEquals($expected[4], $actual[4], 'Amount including tax mismatch'); } else { // Quote items are not evaluated after being saved, only during order placement $this->assertTrue(true); @@ -484,7 +502,7 @@ public function testGetInvoiceItemAmountCurrency( $getAdyenChargedCurrency ) { $this->order->method('getAdyenChargedCurrency')->willReturn($orderPlacement ? $configValue : $getAdyenChargedCurrency); - $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper); + $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper, $this->priceRendererFactory); $result = $this->chargedCurrencyHelper->getInvoiceItemAmountCurrency($this->invoiceItem); $this->assertEquals( [ @@ -515,7 +533,7 @@ public function testGetCreditMemoAmountCurrency( $getAdyenChargedCurrency ) { $this->order->method('getAdyenChargedCurrency')->willReturn($getAdyenChargedCurrency); - $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper); + $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper, $this->priceRendererFactory); $result = $this->chargedCurrencyHelper->getCreditMemoAmountCurrency($this->creditMemo); $this->assertEquals( @@ -546,7 +564,7 @@ public function testGetCreditMemoAdjustmentAmountCurrency( $getAdyenChargedCurrency ) { $this->order->method('getAdyenChargedCurrency')->willReturn($getAdyenChargedCurrency); - $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper); + $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper, $this->priceRendererFactory); $result = $this->chargedCurrencyHelper->getCreditMemoAdjustmentAmountCurrency($this->creditMemo); $this->assertEquals( @@ -575,7 +593,7 @@ public function testGetCreditMemoShippingAmountCurrency( $getAdyenChargedCurrency ) { $this->order->method('getAdyenChargedCurrency')->willReturn($getAdyenChargedCurrency); - $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper); + $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper, $this->priceRendererFactory); $result = $this->chargedCurrencyHelper->getCreditMemoShippingAmountCurrency($this->creditMemo); $this->assertEquals( @@ -606,7 +624,7 @@ public function testGetCreditMemoItemAmountCurrency( $getAdyenChargedCurrency ) { $this->order->method('getAdyenChargedCurrency')->willReturn($getAdyenChargedCurrency); - $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper); + $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper, $this->priceRendererFactory); $result = $this->chargedCurrencyHelper->getCreditMemoItemAmountCurrency($this->creditMemoItem); $this->assertEquals( @@ -637,7 +655,7 @@ public function testGetQuoteShippingAmountCurrency( $getAdyenChargedCurrency ) { $this->configHelper->method('getChargedCurrency')->willReturn($orderPlacement ? $configValue : $getAdyenChargedCurrency); - $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper); + $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper, $this->priceRendererFactory); $result = $this->chargedCurrencyHelper->getQuoteShippingAmountCurrency($this->quote); $this->assertEquals( [ @@ -672,7 +690,7 @@ public function testGetInvoiceShippingAmountCurrency( $getAdyenChargedCurrency ) { $this->order->method('getAdyenChargedCurrency')->willReturn($getAdyenChargedCurrency); - $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper); + $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper, $this->priceRendererFactory); $result = $this->chargedCurrencyHelper->getInvoiceShippingAmountCurrency($this->invoice); $this->assertEquals( [ @@ -702,7 +720,7 @@ public function testGetInvoiceAmountCurrency( $getAdyenChargedCurrency ) { $this->order->method('getAdyenChargedCurrency')->willReturn($getAdyenChargedCurrency); - $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper); + $this->chargedCurrencyHelper = new ChargedCurrency($this->configHelper, $this->priceRendererFactory); $result = $this->chargedCurrencyHelper->getInvoiceAmountCurrency($this->invoice); $this->assertEquals( [ diff --git a/Test/Unit/Helper/OpenInvoiceTest.php b/Test/Unit/Helper/OpenInvoiceTest.php index 5bfbcd04b..cef2f8912 100644 --- a/Test/Unit/Helper/OpenInvoiceTest.php +++ b/Test/Unit/Helper/OpenInvoiceTest.php @@ -71,8 +71,7 @@ public function testGetOpenInvoiceDataFomOrder(): void ); $itemAmountCurrencyMock = $this->createMock(AdyenAmountCurrency::class); - $itemAmountCurrencyMock->method('getAmountWithDiscount')->willReturn(100.00); - $itemAmountCurrencyMock->method('getAmountIncludingTaxWithDiscount')->willReturn(100.00); + $itemAmountCurrencyMock->method('getAmountIncludingTax')->willReturn(100.00); $itemAmountCurrencyMock->method('getTaxAmount')->willReturn(0.00); $itemAmountCurrencyMock->method('getCurrencyCode')->willReturn('EUR'); @@ -102,26 +101,22 @@ public function getUrl() $this->imageHelperMock->method('setImageFile')->willReturnSelf(); $this->imageHelperMock->method('getUrl')->willReturn('https://localhost.store/media/catalog/product/cache/3d0891988c4d57b25ce48fde378871d2/w/b/wb04-blue-0.jpg'); - $this->shippingAmountCurrencyMock->method('getAmountWithDiscount')->willReturn(500); - $this->shippingAmountCurrencyMock->method('getAmountIncludingTaxWithDiscount')->willReturn(550); + $this->shippingAmountCurrencyMock->method('getAmountIncludingTax')->willReturn(550); $this->shippingAmountCurrencyMock->method('getTaxAmount')->willReturn(50); - $this->shippingAmountCurrencyMock->method('getCalculatedTaxPercentage')->willReturn(10); $this->chargedCurrencyMock->method('getQuoteShippingAmountCurrency')->willReturn($this->shippingAmountCurrencyMock); $this->shippingAddressMock->method('__call')->willReturnMap([ ['getShippingAmount', [], 500.0], - ['getShippingTaxAmount', [], 0.0], + ['getShippingTaxAmount', [], 50.0], ['getShippingDescription', [], 'Flat Rate - Fixed'], ['getShippingAmountCurrency', [], 'EUR'], - ['getShippingAmountCurrency', [], 'EUR'], ]); $expectedResult = [ 'lineItems' => [ [ 'id' => '14', - 'amountExcludingTax' => 10000, 'amountIncludingTax' => 10000, 'taxAmount' => 0, 'description' => 'Push It Messenger Bag', @@ -132,28 +127,23 @@ public function getUrl() ], [ 'id' => 'shippingCost', - 'amountExcludingTax' => 50000, 'amountIncludingTax' => 55000, 'taxAmount' => 5000, 'description' => 'Flat Rate - Fixed', - 'quantity' => 1, - 'taxPercentage' => 1000 + 'quantity' => 1 ] ] ]; - // Act: Call the method with the mocked parameters $result = $openInvoice->getOpenInvoiceDataForOrder($this->orderMock); - // Assert: Verify that the output matches your expectations $this->assertEquals($expectedResult, $result); } public function testGetOpenInvoiceDataForLastInvoice(): void { $itemAmountCurrencyMock = $this->createMock(AdyenAmountCurrency::class); - $itemAmountCurrencyMock->method('getAmountWithDiscount')->willReturn(100.00); - $itemAmountCurrencyMock->method('getAmountIncludingTaxWithDiscount')->willReturn(121.00); + $itemAmountCurrencyMock->method('getAmountIncludingTax')->willReturn(121.00); $itemAmountCurrencyMock->method('getTaxAmount')->willReturn(21.00); $this->productMock->method('getId')->willReturn('14'); @@ -180,10 +170,8 @@ public function getUrl() $this->orderMock->method('getShippingDescription')->willReturn('Flat Rate - Fixed'); - $this->shippingAmountCurrencyMock->method('getAmountWithDiscount')->willReturn(500); - $this->shippingAmountCurrencyMock->method('getAmountIncludingTaxWithDiscount')->willReturn(550); + $this->shippingAmountCurrencyMock->method('getAmountIncludingTax')->willReturn(550); $this->shippingAmountCurrencyMock->method('getTaxAmount')->willReturn(50); - $this->shippingAmountCurrencyMock->method('getCalculatedTaxPercentage')->willReturn(10); $openInvoice = new OpenInvoice( $this->adyenHelperMock, @@ -197,7 +185,6 @@ public function getUrl() 'lineItems' => [ [ 'id' => '14', - 'amountExcludingTax' => 10000, 'amountIncludingTax' => 12100, 'taxAmount' => 2100, 'description' => 'Push It Messenger Bag', @@ -208,12 +195,10 @@ public function getUrl() ], [ 'id' => 'shippingCost', - 'amountExcludingTax' => 50000, 'amountIncludingTax' => 55000, 'taxAmount' => 5000, 'description' => 'Flat Rate - Fixed', 'quantity' => 1, - 'taxPercentage' => 1000 ] ] ]; @@ -237,17 +222,14 @@ public function testGetOpenInvoiceDataForCreditMemo(): void $this->orderItemMock->method('getTaxPercent')->willReturn(0); $itemAmountCurrencyMock = $this->createMock(AdyenAmountCurrency::class); - $itemAmountCurrencyMock->method('getAmountWithDiscount')->willReturn(45); - $itemAmountCurrencyMock->method('getAmountIncludingTaxWithDiscount')->willReturn(45); + $itemAmountCurrencyMock->method('getAmountIncludingTax')->willReturn(45); $itemAmountCurrencyMock->method('getTaxAmount')->willReturn(0); $itemAmountCurrencyMock->method('getCurrencyCode')->willReturn('EUR'); $this->chargedCurrencyMock->method('getCreditMemoItemAmountCurrency')->willReturn($itemAmountCurrencyMock); - $this->shippingAmountCurrencyMock->method('getAmountWithDiscount')->willReturn(500); - $this->shippingAmountCurrencyMock->method('getAmountIncludingTaxWithDiscount')->willReturn(550); + $this->shippingAmountCurrencyMock->method('getAmountIncludingTax')->willReturn(550); $this->shippingAmountCurrencyMock->method('getTaxAmount')->willReturn(50); - $this->shippingAmountCurrencyMock->method('getCalculatedTaxPercentage')->willReturn(10); $this->chargedCurrencyMock->method('getCreditMemoShippingAmountCurrency')->willReturn($this->shippingAmountCurrencyMock); @@ -273,7 +255,6 @@ public function getUrl() 'lineItems' => [ [ 'id' => '14', - 'amountExcludingTax' => 4500, 'amountIncludingTax' => 4500, 'taxAmount' => 0, 'description' => 'Push It Messenger Bag', @@ -284,12 +265,10 @@ public function getUrl() ], [ 'id' => 'shippingCost', - 'amountExcludingTax' => 50000, 'amountIncludingTax' => 55000, 'taxAmount' => 5000, 'description' => 'Flat Rate - Fixed', - 'quantity' => 1, - 'taxPercentage' => 1000 + 'quantity' => 1 ] ] ]; diff --git a/Test/Unit/Helper/WebhookTest.php b/Test/Unit/Helper/WebhookTest.php index fc832031d..a0bfa9d12 100644 --- a/Test/Unit/Helper/WebhookTest.php +++ b/Test/Unit/Helper/WebhookTest.php @@ -3,6 +3,7 @@ use Adyen\Payment\Helper\Webhook; use Adyen\Payment\Helper\Webhook\WebhookHandlerInterface; +use Adyen\Payment\Model\AdyenAmountCurrency; use Adyen\Payment\Model\Notification; use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; use Magento\Framework\Serialize\Serializer\Json; @@ -414,14 +415,10 @@ public function testAddNotificationDetailsHistoryCommentWithFullRefund() ->disableOriginalConstructor() ->getMock(); - $orderAmountCurrencyObject = new class { - public function getAmount() { - return 100; - } - public function getCurrencyCode() { - return 'EUR'; - } - }; + $orderAmountCurrencyObject = $this->createConfiguredMock(AdyenAmountCurrency::class, [ + 'getAmount' => 100, + 'getCurrencyCode' => 'EUR' + ]); $chargedCurrencyMock = $this->createMock(ChargedCurrency::class); $chargedCurrencyMock->method('getOrderAmountCurrency') diff --git a/Test/Unit/Model/Resolver/StoreConfig/StoreLocaleTest.php b/Test/Unit/Model/Resolver/StoreConfig/StoreLocaleTest.php index 45c17388e..46fffedf9 100644 --- a/Test/Unit/Model/Resolver/StoreConfig/StoreLocaleTest.php +++ b/Test/Unit/Model/Resolver/StoreConfig/StoreLocaleTest.php @@ -27,11 +27,11 @@ */ class StoreLocaleTest extends AbstractAdyenTestCase { - private MockObject&Context $contextMock; - private MockObject&Field $fieldMock; - private MockObject&ResolveInfo $infoMock; - private MockObject&Data $dataHelperMock; - private MockObject&ContextExtensionInterface $contextExtensionMock; + private MockObject|Context $contextMock; + private MockObject|Field $fieldMock; + private MockObject|ResolveInfo $infoMock; + private MockObject|Data $dataHelperMock; + private MockObject|ContextExtensionInterface $contextExtensionMock; private StoreLocale $storeLocale; protected function setUp(): void