From fc4663e12e4313c3753b7bcf56698f3a2a5cb830 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 22 May 2019 11:08:27 +0200 Subject: [PATCH 1/9] [change] (PHPLIB-70) Update changelog. --- CHANGELOG.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a90b75a..909ff42c 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,6 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [X.X.X.X][X.X.X.X] - -### Changed -* Enabled fetching the payment via orderId if its id is not set. - ## [1.1.1.1][1.1.1.1] ### Added @@ -19,9 +14,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Fixed * Added missing parameter `invoiceId` to `payment::ship` method. -### Change +### Changed * Change key pair for SAQ-A integration test. * Refactored implementation examples. +* Enabled fetching the payment via orderId if its id is not set. ## [1.1.1.0][1.1.1.0] From f182fa737e1cd386123c7b7f1c4c1e53e477fd4e Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 29 May 2019 14:28:41 +0200 Subject: [PATCH 2/9] [bugfix] (PHPLIB-162) Fix a problem which resulted in an error when setting amount per unit of basket item to 0.0. --- src/Resources/AbstractHeidelpayResource.php | 7 +--- src/Resources/Basket.php | 24 +++++------ .../EmbeddedResources/BasketItem.php | 40 +++++++++---------- test/integration/BasketTest.php | 5 ++- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/Resources/AbstractHeidelpayResource.php b/src/Resources/AbstractHeidelpayResource.php index 2364d183..f77fe340 100755 --- a/src/Resources/AbstractHeidelpayResource.php +++ b/src/Resources/AbstractHeidelpayResource.php @@ -35,7 +35,6 @@ use function is_array; use function is_callable; use function is_object; -use function is_string; use ReflectionException; use ReflectionProperty; use RuntimeException; @@ -164,10 +163,8 @@ public function getUri($appendId = true): string private static function updateValues($object, stdClass $response) { foreach ($response as $key => $value) { - $newValue = $value; - if ($value !== false && (!is_string($value) || $value === '')) { - $newValue = $value ?: null; - } + // set empty string to null (workaround) + $newValue = $value === '' ? null : $value; // handle nested object if (is_object($value)) { diff --git a/src/Resources/Basket.php b/src/Resources/Basket.php index b1275524..bdc7dc14 100755 --- a/src/Resources/Basket.php +++ b/src/Resources/Basket.php @@ -35,10 +35,10 @@ class Basket extends AbstractHeidelpayResource protected $amountTotal = 0.0; /** @var float $amountTotalDiscount */ - protected $amountTotalDiscount; + protected $amountTotalDiscount = 0.0; /** @var float $amountTotalVat */ - protected $amountTotalVat; + protected $amountTotalVat = 0.0; /** @var string $currencyCode */ protected $currencyCode; @@ -75,9 +75,9 @@ public function __construct( // /** - * @return float|null + * @return float */ - public function getAmountTotal() + public function getAmountTotal(): float { return $this->amountTotal; } @@ -94,38 +94,38 @@ public function setAmountTotal(float $amountTotal): Basket } /** - * @return float|null + * @return float */ - public function getAmountTotalDiscount() + public function getAmountTotalDiscount(): float { return $this->amountTotalDiscount; } /** - * @param float|null $amountTotalDiscount + * @param float $amountTotalDiscount * * @return Basket */ - public function setAmountTotalDiscount($amountTotalDiscount): Basket + public function setAmountTotalDiscount(float $amountTotalDiscount): Basket { $this->amountTotalDiscount = $amountTotalDiscount; return $this; } /** - * @return float|null + * @return float */ - public function getAmountTotalVat() + public function getAmountTotalVat(): float { return $this->amountTotalVat; } /** - * @param float|null $amountTotalVat + * @param float $amountTotalVat * * @return Basket */ - public function setAmountTotalVat($amountTotalVat): Basket + public function setAmountTotalVat(float $amountTotalVat): Basket { $this->amountTotalVat = $amountTotalVat; return $this; diff --git a/src/Resources/EmbeddedResources/BasketItem.php b/src/Resources/EmbeddedResources/BasketItem.php index f3fa35d7..ce163a69 100755 --- a/src/Resources/EmbeddedResources/BasketItem.php +++ b/src/Resources/EmbeddedResources/BasketItem.php @@ -34,17 +34,17 @@ class BasketItem extends AbstractHeidelpayResource /** @var int $quantity */ protected $quantity = 1; - /** @var int $vat */ - protected $vat; + /** @var float $vat */ + protected $vat = 0.0; /** @var float $amountDiscount */ - protected $amountDiscount; + protected $amountDiscount = 0.0; /** @var float $amountGross */ - protected $amountGross; + protected $amountGross = 0.0; /** @var float $amountVat */ - protected $amountVat; + protected $amountVat = 0.0; /** @var float $amountPerUnit */ protected $amountPerUnit = 0.0; @@ -119,47 +119,47 @@ public function setQuantity(int $quantity): BasketItem } /** - * @return int|null + * @return float */ - public function getVat() + public function getVat(): float { return $this->vat; } /** - * @param int|null $vat + * @param float $vat * * @return BasketItem */ - public function setVat($vat): BasketItem + public function setVat(float $vat): BasketItem { $this->vat = $vat; return $this; } /** - * @return float|null + * @return float */ - public function getAmountDiscount() + public function getAmountDiscount(): float { return $this->amountDiscount; } /** - * @param float|null $amountDiscount + * @param float $amountDiscount * * @return BasketItem */ - public function setAmountDiscount($amountDiscount): BasketItem + public function setAmountDiscount(float $amountDiscount): BasketItem { $this->amountDiscount = $amountDiscount; return $this; } /** - * @return float|null + * @return float */ - public function getAmountGross() + public function getAmountGross(): float { return $this->amountGross; } @@ -169,26 +169,26 @@ public function getAmountGross() * * @return BasketItem */ - public function setAmountGross($amountGross): BasketItem + public function setAmountGross(float $amountGross): BasketItem { $this->amountGross = $amountGross; return $this; } /** - * @return float|null + * @return float */ - public function getAmountVat() + public function getAmountVat(): float { return $this->amountVat; } /** - * @param float|null $amountVat + * @param float $amountVat * * @return BasketItem */ - public function setAmountVat($amountVat): BasketItem + public function setAmountVat(float $amountVat): BasketItem { $this->amountVat = $amountVat; return $this; diff --git a/test/integration/BasketTest.php b/test/integration/BasketTest.php index 9e02a79c..a36670a5 100755 --- a/test/integration/BasketTest.php +++ b/test/integration/BasketTest.php @@ -47,7 +47,10 @@ public function minBasketShouldBeCreatableAndFetchable() $orderId = microtime(true); $basket = new Basket($orderId, 123.4, 'EUR', []); $basket->setNote('This basket is creatable!'); - $basket->addBasketItem(new BasketItem('myItem', 1234, 2345, 12)); + $basketItem = new BasketItem('myItem', 1234, 2345, 12); + $basket->addBasketItem($basketItem); + $basketItem = new BasketItem('title'); + $basket->addBasketItem($basketItem); $this->assertEmpty($basket->getId()); $this->heidelpay->createBasket($basket); From cbc619a883e7ee38133287d66164ecae46836be6 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 29 May 2019 14:29:56 +0200 Subject: [PATCH 3/9] [bugfix] (PHPLIB-162) Fix a problem which resulted in a discrepancy of the type of field basketItemReferenceId. --- src/Resources/Basket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/Basket.php b/src/Resources/Basket.php index bdc7dc14..3ddf0e62 100755 --- a/src/Resources/Basket.php +++ b/src/Resources/Basket.php @@ -231,7 +231,7 @@ public function addBasketItem(BasketItem $basketItem): Basket { $this->basketItems[] = $basketItem; if ($basketItem->getBasketItemReferenceId() === null) { - $basketItem->setBasketItemReferenceId($this->getKeyOfLastBasketItemAdded()); + $basketItem->setBasketItemReferenceId((string)$this->getKeyOfLastBasketItemAdded()); } return $this; } From 6f55522b647549ac90c43f32af84ee98c5f97e93 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 29 May 2019 15:57:35 +0200 Subject: [PATCH 4/9] [change] (PHPLIB-162) Update changelog and version. --- CHANGELOG.md | 7 +++++-- src/Heidelpay.php | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6321991f..9f9b2088 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [1.1.2.0][1.1.2.0] +## [1.2.0.0][1.2.0.0] ### Added * Added 3ds flag to card payment type. @@ -14,11 +14,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Fixed * Added missing parameter `invoiceId` to `payment::ship` method. +* A problem which resulted in an error when the property BasketItem::AmountPerUnit is set to 0.0. ### Changed -* Change key pair for SAQ-A integration test. * Refactored implementation examples. * Enabled fetching the payment via orderId if its id is not set. +* Changed the default values of Basket and BasketItem. +* Refactored updating resource properties. * Adapt to small API changes. ## [1.1.1.0][1.1.1.0] @@ -170,3 +172,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [1.1.0.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.0.2.0..1.1.0.0 [1.1.1.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.0.0..1.1.1.0 [1.1.2.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.1.0..1.1.2.0 +[1.2.0.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.1.0..1.2.0.0 diff --git a/src/Heidelpay.php b/src/Heidelpay.php index a3ac9c6e..c28b880f 100755 --- a/src/Heidelpay.php +++ b/src/Heidelpay.php @@ -53,7 +53,7 @@ class Heidelpay implements HeidelpayParentInterface const BASE_URL = 'https://api.heidelpay.com/'; const API_VERSION = 'v1'; const SDK_TYPE = 'HeidelpayPHP'; - const SDK_VERSION = '1.1.2.0'; + const SDK_VERSION = '1.2.0.0'; /** @var string $key */ private $key; From faa87567e4efeb060081fb629f3d13ac35869e79 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 29 May 2019 16:01:01 +0200 Subject: [PATCH 5/9] [change] (PHPLIB-162) Update basket test. --- test/integration/BasketTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/BasketTest.php b/test/integration/BasketTest.php index a36670a5..96f50b10 100755 --- a/test/integration/BasketTest.php +++ b/test/integration/BasketTest.php @@ -49,7 +49,7 @@ public function minBasketShouldBeCreatableAndFetchable() $basket->setNote('This basket is creatable!'); $basketItem = new BasketItem('myItem', 1234, 2345, 12); $basket->addBasketItem($basketItem); - $basketItem = new BasketItem('title'); + $basketItem = (new BasketItem('title'))->setAmountPerUnit(0.0); $basket->addBasketItem($basketItem); $this->assertEmpty($basket->getId()); From 47010f2c595a94a563aff503845d2b9d914941da Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 29 May 2019 16:51:42 +0200 Subject: [PATCH 6/9] [change] Customer: Add test to verify fetching customer via customerId. --- test/integration/CustomerTest.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/integration/CustomerTest.php b/test/integration/CustomerTest.php index b92fa99c..419db5e5 100755 --- a/test/integration/CustomerTest.php +++ b/test/integration/CustomerTest.php @@ -102,6 +102,22 @@ public function customerCanBeFetchedById(Customer $customer) $this->assertEquals($customer->getId(), $fetchedCustomer->getId()); } + /** + * @throws HeidelpayApiException + * @throws RuntimeException + * @depends maxCustomerCanBeCreatedAndFetched + * @test + */ + public function customerCanBeFetchedByCustomerId() + { + $customerId = str_replace([' ', '.'], '', microtime()); + $customer = $this->getMaximumCustomer()->setCustomerId($customerId); + $this->heidelpay->createCustomer($customer); + + $fetchedCustomer = $this->heidelpay->fetchCustomer($customer->getCustomerId()); + $this->assertEquals($customer->expose(), $fetchedCustomer->expose()); + } + /** * @param Customer $customer * @@ -316,11 +332,9 @@ public function customerShouldBeFetchedByCustomerIdAndUpdatedIfItAlreadyExists() { $customerId = str_replace(' ', '', microtime()); - $customer = $this->getMaximumCustomer()->setCustomerId($customerId); - try { // fetch non-existing customer by customerId - $this->heidelpay->fetchCustomer($customer); + $this->heidelpay->fetchCustomerByExtCustomerId($customerId); } catch (HeidelpayApiException $e) { $this->assertEquals($e->getCode(), ApiResponseCodes::API_ERROR_CUSTOMER_CAN_NOT_BE_FOUND); } From 0fcc313503835bcc18254a9d9d7c5c2fbb4928a5 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 29 May 2019 16:52:53 +0200 Subject: [PATCH 7/9] [change] Customer: Add test to verify fetching customer via customerId #2. --- test/integration/CustomerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/CustomerTest.php b/test/integration/CustomerTest.php index 419db5e5..c8a1b5be 100755 --- a/test/integration/CustomerTest.php +++ b/test/integration/CustomerTest.php @@ -114,7 +114,7 @@ public function customerCanBeFetchedByCustomerId() $customer = $this->getMaximumCustomer()->setCustomerId($customerId); $this->heidelpay->createCustomer($customer); - $fetchedCustomer = $this->heidelpay->fetchCustomer($customer->getCustomerId()); + $fetchedCustomer = $this->heidelpay->fetchCustomerByExtCustomerId($customer->getCustomerId()); $this->assertEquals($customer->expose(), $fetchedCustomer->expose()); } From 4648e5a246eb56dc30213381ee71a922faed0d97 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 5 Jun 2019 09:12:40 +0200 Subject: [PATCH 8/9] [change] (PHPLIB-162) Change version. --- CHANGELOG.md | 3 +-- src/Heidelpay.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f9b2088..6341a11a 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [1.2.0.0][1.2.0.0] +## [1.1.2.0][1.1.2.0] ### Added * Added 3ds flag to card payment type. @@ -172,4 +172,3 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [1.1.0.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.0.2.0..1.1.0.0 [1.1.1.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.0.0..1.1.1.0 [1.1.2.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.1.0..1.1.2.0 -[1.2.0.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.1.0..1.2.0.0 diff --git a/src/Heidelpay.php b/src/Heidelpay.php index c28b880f..a3ac9c6e 100755 --- a/src/Heidelpay.php +++ b/src/Heidelpay.php @@ -53,7 +53,7 @@ class Heidelpay implements HeidelpayParentInterface const BASE_URL = 'https://api.heidelpay.com/'; const API_VERSION = 'v1'; const SDK_TYPE = 'HeidelpayPHP'; - const SDK_VERSION = '1.2.0.0'; + const SDK_VERSION = '1.1.2.0'; /** @var string $key */ private $key; From 75ef46f998551648aa426ce05a05a9c74ed5a1b9 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 6 Jun 2019 10:24:08 +0200 Subject: [PATCH 9/9] Update test/integration/CustomerTest.php Co-Authored-By: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> --- test/integration/CustomerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/CustomerTest.php b/test/integration/CustomerTest.php index c8a1b5be..e31ecdb9 100755 --- a/test/integration/CustomerTest.php +++ b/test/integration/CustomerTest.php @@ -335,6 +335,7 @@ public function customerShouldBeFetchedByCustomerIdAndUpdatedIfItAlreadyExists() try { // fetch non-existing customer by customerId $this->heidelpay->fetchCustomerByExtCustomerId($customerId); + $this->assertTrue(false, 'Exception should be thrown here.'); } catch (HeidelpayApiException $e) { $this->assertEquals($e->getCode(), ApiResponseCodes::API_ERROR_CUSTOMER_CAN_NOT_BE_FOUND); }