From 6a9565e12c1601c0be8e1cbb11603264359033dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Va=C5=88ura?= Date: Wed, 15 Dec 2021 09:04:03 +0100 Subject: [PATCH] Fix mall pay order item discount --- src/Price.php | 2 -- tests/unit/MallPay/OrderTest.php | 43 +++++++++++++++++++++++++++++++- tests/unit/PriceTest.php | 11 -------- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/Price.php b/src/Price.php index 902a410..24f3ae8 100644 --- a/src/Price.php +++ b/src/Price.php @@ -16,8 +16,6 @@ public function __construct( Currency $currency ) { - Validator::checkNumberPositiveOrZero($amount); - $this->amount = $amount; $this->currency = $currency; } diff --git a/tests/unit/MallPay/OrderTest.php b/tests/unit/MallPay/OrderTest.php index b534073..b281c19 100644 --- a/tests/unit/MallPay/OrderTest.php +++ b/tests/unit/MallPay/OrderTest.php @@ -33,11 +33,28 @@ public function testEncode(): void 20, 'https://obchod.cz/produkt/123-345' ); + $order->addItem( + 'discount', + null, + 'Sleva', + OrderItemType::get(OrderItemType::DISCOUNT), + 2, + null, + null, + null, + null, + -50, + -100, + null, + 0, + 0, + null + ); $order->addAddress('Slevomat', Country::get(Country::CZE), 'Praha 8', 'Pernerova 691/42', 'xxx', '186 00', AddressType::get(AddressType::BILLING)); $expected = [ 'totalPrice' => [ - 'amount' => 200, + 'amount' => 100, 'currency' => 'EUR', ], 'totalVat' => [ @@ -46,6 +63,11 @@ public function testEncode(): void 'currency' => 'EUR', 'vatRate' => 20, ], + [ + 'amount' => 0, + 'currency' => 'EUR', + 'vatRate' => 0, + ], ], 'addresses' => [ [ @@ -89,6 +111,25 @@ public function testEncode(): void ], 'productUrl' => 'https://obchod.cz/produkt/123-345', ], + [ + 'code' => 'discount', + 'name' => 'Sleva', + 'totalPrice' => [ + 'amount' => -100, + 'currency' => 'EUR', + ], + 'totalVat' => [ + 'amount' => 0, + 'currency' => 'EUR', + 'vatRate' => 0, + ], + 'type' => 'DISCOUNT', + 'quantity' => 2, + 'unitPrice' => [ + 'amount' => -50, + 'currency' => 'EUR', + ], + ], ], 'deliveryType' => 'DELIVERY_CARRIER', 'carrierId' => 'TNT', diff --git a/tests/unit/PriceTest.php b/tests/unit/PriceTest.php index 0bc3e17..8f436c2 100644 --- a/tests/unit/PriceTest.php +++ b/tests/unit/PriceTest.php @@ -2,7 +2,6 @@ namespace SlevomatCsobGateway; -use InvalidArgumentException; use PHPUnit\Framework\TestCase; class PriceTest extends TestCase @@ -23,14 +22,4 @@ public function testEncode(): void self::assertSame(['amount' => 123, 'currency' => 'USD'], $price->encode()); } - public function testValidation(): void - { - try { - new Price(-123, Currency::get(Currency::USD)); - self::fail(); - } catch (InvalidArgumentException $e) { - self::assertSame('Value is negative.', $e->getMessage()); - } - } - }