Skip to content

Commit

Permalink
Bugfix: fix PaymentFactory passing EET (#23)
Browse files Browse the repository at this point in the history
* create test that fails on issue #22
* fix #22
* create test that fails on #21
* Revert "create test that fails on #21"
* create test that fails on #21
* better way to do it
* fix21
* code style
  • Loading branch information
haltuf authored and f3l1x committed Feb 28, 2017
1 parent c19f4c2 commit 1325ae9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Api/Entity/PaymentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public static function create($data, $validators = [])
'name' => 'name',
'amount' => 'amount',
'count' => 'count',
'vat_rate' => 'vatRate',
'type' => 'type',
], $param);
$payment->addItem($item);
}
Expand Down Expand Up @@ -191,6 +193,8 @@ public static function create($data, $validators = [])
throw new ValidationException(sprintf('EET sum (%s) and order sum (%s) do not match', $eetSum, $orderPrice));
}
}

$payment->setEet($eet);
}

return $payment;
Expand Down
17 changes: 16 additions & 1 deletion tests/cases/unit/Api/Entity/PaymentFactory.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/
use Markette\GopayInline\Api\Entity\Payment;
use Markette\GopayInline\Api\Entity\PaymentFactory;
use Markette\GopayInline\Api\Lists\PaymentType;
use Markette\GopayInline\Api\Lists\TargetType;
use Markette\GopayInline\Api\Objects\Eet;
use Markette\GopayInline\Exception\ValidationException;
use Tester\Assert;

Expand Down Expand Up @@ -40,6 +42,13 @@ test(function () {

// Simple payment
test(function () {
$eet = [
'celk_trzba' => 550,
'zakl_dan1' => 100,
'dan1' => 50,
'zakl_dan2' => 300,
'dan2' => 100,
];
$data = [
'payer' => [
'default_payment_instrument' => 'BANK_ACCOUNT',
Expand All @@ -61,14 +70,17 @@ test(function () {
'goid' => 123456,
'type' => TargetType::ACCOUNT,
],
'amount' => 200,
'amount' => 550,
'currency' => 'CZK',
'order_number' => '001',
'order_description' => 'pojisteni01',
'items' => [
['name' => 'item01', 'amount' => 50, 'count' => 2],
['name' => 'item02', 'amount' => 100],
['name' => 'item03', 'amount' => 150, 'vat_rate' => 21],
['name' => 'item04', 'amount' => 200, 'type' => PaymentType::ITEM],
],
'eet' => $eet,
'additional_params' => [
['name' => 'invoicenumber', 'value' => '2015001003'],
],
Expand All @@ -79,6 +91,9 @@ test(function () {

$payment = PaymentFactory::create($data);
Assert::type(Payment::class, $payment);
Assert::equal(21, $payment->getItems()[2]->getVatRate());
Assert::equal(PaymentType::ITEM, $payment->getItems()[3]->getType());
Assert::type(Eet::class, $payment->getEet());
});

// Validate order price and items price
Expand Down

0 comments on commit 1325ae9

Please sign in to comment.