Skip to content

Commit

Permalink
Fix mall pay order item discount
Browse files Browse the repository at this point in the history
  • Loading branch information
Daaarkling authored and janlanger committed Feb 14, 2022
1 parent 22376c1 commit 6a9565e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
2 changes: 0 additions & 2 deletions src/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public function __construct(
Currency $currency
)
{
Validator::checkNumberPositiveOrZero($amount);

$this->amount = $amount;
$this->currency = $currency;
}
Expand Down
43 changes: 42 additions & 1 deletion tests/unit/MallPay/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand All @@ -46,6 +63,11 @@ public function testEncode(): void
'currency' => 'EUR',
'vatRate' => 20,
],
[
'amount' => 0,
'currency' => 'EUR',
'vatRate' => 0,
],
],
'addresses' => [
[
Expand Down Expand Up @@ -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',
Expand Down
11 changes: 0 additions & 11 deletions tests/unit/PriceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SlevomatCsobGateway;

use InvalidArgumentException;
use PHPUnit\Framework\TestCase;

class PriceTest extends TestCase
Expand All @@ -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());
}
}

}

0 comments on commit 6a9565e

Please sign in to comment.