From e073f7e55937282b807f5d02d0b44dcfc5a7b4bf Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Thu, 1 Sep 2022 13:52:43 +0300 Subject: [PATCH 01/90] Add possible query parameters to URL on CurlClient --- src/Util/CurlClient.php | 19 ++++++++++++++++++- tests/ClientTest.php | 7 +++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Util/CurlClient.php b/src/Util/CurlClient.php index ce7bc16..4f3dce8 100644 --- a/src/Util/CurlClient.php +++ b/src/Util/CurlClient.php @@ -27,7 +27,7 @@ public function __construct(string $baseUrl, int $timeout) public function request(string $method, string $uri, array $options) { $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $this->baseUrl . $uri); + curl_setopt($curl, CURLOPT_URL, $this->buildUrl($uri, $options)); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, true); @@ -55,6 +55,23 @@ public function request(string $method, string $uri, array $options) return $curlResponse; } + /** + * Build URL by prefixing endpoint with base URL and possible query parameters. + * + * @param string $uri + * @param array $options + * @return string + */ + private function buildUrl(string $uri, array $options): string + { + $query = ''; + if (isset($options['query'])) { + $uri .= '?' . http_build_query($options['query']); + } + + return $this->baseUrl . $uri . $query; + } + /** * Parse Key => Value headers as Key: Value array for curl. * @param $options diff --git a/tests/ClientTest.php b/tests/ClientTest.php index fc05b0a..98064f6 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -562,4 +562,11 @@ public function testGetSettlementsWithInvalidDateThrowsException() $this->expectException(ValidationException::class); $this->client->getSettlements('30.5.2022'); } + + public function testGetGroupedPaymentProvidersAcceptsLanguageParameters() + { + $providers = $this->client->getGroupedPaymentProviders(100, 'EN'); + $this->assertIsArray($providers); + $this->assertEquals('Mobile payment methods', $providers['groups'][0]['name']); + } } From efdfa9e63e1b6a00a3b1e1637cf0095c96b16991 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Thu, 1 Sep 2022 14:34:36 +0300 Subject: [PATCH 02/90] Add companyName to Customer model Remove unnecessary whitespace, fix typehints --- src/Interfaces/CustomerInterface.php | 26 +++++++++--- src/Model/Customer.php | 60 ++++++++++++++++++---------- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/src/Interfaces/CustomerInterface.php b/src/Interfaces/CustomerInterface.php index 6e27ad2..9ecdf3d 100644 --- a/src/Interfaces/CustomerInterface.php +++ b/src/Interfaces/CustomerInterface.php @@ -35,7 +35,7 @@ public function getEmail(): ?string; /** * Set email. * - * @param string $email + * @param string|null $email * * @return self Return self to enable chaining. */ @@ -51,7 +51,7 @@ public function getFirstName(): ?string; /** * Set first name. * - * @param string $firstName + * @param string|null $firstName * * @return self Return self to enable chaining. */ @@ -67,7 +67,7 @@ public function getLastName(): ?string; /** * Set last name. * - * @param string $lastName + * @param string|null $lastName * * @return self Return self to enable chaining. */ @@ -83,7 +83,7 @@ public function getPhone(): ?string; /** * Set phone. * - * @param string $phone + * @param string|null $phone * * @return self Return self to enable chaining. */ @@ -99,9 +99,25 @@ public function getVatId(): ?string; /** * Set VAT id. * - * @param string $vatId + * @param string|null $vatId * * @return self Return self to enable chaining. */ public function setVatId(?string $vatId) : CustomerInterface; + + /** + * Get Company name. + * + * @return string + */ + public function getCompanyName(): ?string; + + /** + * Set Company Name. + * + * @param string|null $companyName + * + * @return self Return self to enable chaining. + */ + public function setCompanyName(?string $companyName) : CustomerInterface; } \ No newline at end of file diff --git a/src/Model/Customer.php b/src/Model/Customer.php index 96630bc..d1f65c1 100644 --- a/src/Model/Customer.php +++ b/src/Model/Customer.php @@ -29,7 +29,7 @@ class Customer implements \JsonSerializable, CustomerInterface * * @throws ValidationException */ - public function validate() + public function validate(): bool { $props = get_object_vars($this); @@ -79,6 +79,13 @@ public function validate() */ protected $vatId; + /** + * The Company name + * + * @var string + */ + protected $companyName; + /** * Get email. * @@ -86,21 +93,19 @@ public function validate() */ public function getEmail(): ?string { - return $this->email; } /** * Set email. * - * @param string $email + * @param string|null $email * * @return self Return self to enable chaining. */ - public function setEmail(?string $email) : CustomerInterface + public function setEmail(?string $email): CustomerInterface { $this->email = $email; - return $this; } @@ -111,21 +116,19 @@ public function setEmail(?string $email) : CustomerInterface */ public function getFirstName(): ?string { - return $this->firstName; } /** * Set first name. * - * @param string $firstName + * @param string|null $firstName * * @return self Return self to enable chaining. */ - public function setFirstName(?string $firstName) : CustomerInterface + public function setFirstName(?string $firstName): CustomerInterface { $this->firstName = $firstName; - return $this; } @@ -136,21 +139,19 @@ public function setFirstName(?string $firstName) : CustomerInterface */ public function getLastName(): ?string { - return $this->lastName; } /** * Set last name. * - * @param string $lastName + * @param string|null $lastName * * @return self Return self to enable chaining. */ - public function setLastName(?string $lastName) : CustomerInterface + public function setLastName(?string $lastName): CustomerInterface { $this->lastName = $lastName; - return $this; } @@ -161,21 +162,19 @@ public function setLastName(?string $lastName) : CustomerInterface */ public function getPhone(): ?string { - return $this->phone; } /** * Set phone. * - * @param string $phone + * @param string|null $phone * * @return self Return self to enable chaining. */ - public function setPhone(?string $phone) : CustomerInterface + public function setPhone(?string $phone): CustomerInterface { $this->phone = $phone; - return $this; } @@ -186,21 +185,42 @@ public function setPhone(?string $phone) : CustomerInterface */ public function getVatId(): ?string { - return $this->vatId; } /** * Set VAT id. * - * @param string $vatId + * @param string|null $vatId * * @return self Return self to enable chaining. */ - public function setVatId(?string $vatId) : CustomerInterface + public function setVatId(?string $vatId): CustomerInterface { $this->vatId = $vatId; + return $this; + } + + /** + * Get Company name. + * + * @return string + */ + public function getCompanyName(): ?string + { + return $this->companyName; + } + /** + * Set Company Name. + * + * @param string|null $companyName + * + * @return self Return self to enable chaining. + */ + public function setCompanyName(?string $companyName): CustomerInterface + { + $this->companyName = $companyName; return $this; } } From f43e2b015c6926e48f1ffc656dd0d5b060453557 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 22 Jun 2022 14:42:54 +0300 Subject: [PATCH 03/90] Add report request --- src/Client.php | 16 +++++ src/Request/ReportRequest.php | 108 ++++++++++++++++++++++++++++++++++ tests/ClientTest.php | 1 + 3 files changed, 125 insertions(+) create mode 100644 src/Request/ReportRequest.php diff --git a/src/Client.php b/src/Client.php index 607a2d5..65ec4a4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -13,6 +13,7 @@ use Paytrail\SDK\Request\GetTokenRequest; use Paytrail\SDK\Request\MitPaymentRequest; use Paytrail\SDK\Request\PaymentRequest; +use Paytrail\SDK\Request\ReportRequest; use Paytrail\SDK\Request\ShopInShopPaymentRequest; use Paytrail\SDK\Request\PaymentStatusRequest; use Paytrail\SDK\Request\RefundRequest; @@ -656,6 +657,21 @@ function ($decoded) { }); } + /** + * Request payment report. + * Report is sent to callbackUrl defined in ReportRequest. + * + * @param ReportRequest $reportRequest + * @return mixed + * @throws HmacException + * @throws ValidationException + */ + public function requestPaymentReport(ReportRequest $reportRequest) { + $this->validateRequestItem($reportRequest); + $uri = '/payments/report'; + return $this->post($uri, $reportRequest); + } + /** * A proxy for the Signature class' static method * to be used via a client instance. diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php new file mode 100644 index 0000000..ad207c7 --- /dev/null +++ b/src/Request/ReportRequest.php @@ -0,0 +1,108 @@ +createFromFormat('Y-m-d', $startDate) == false) { + throw new ValidationException('startDate must be in Y-m-d format'); + } + } + + if ($props['endDate']) { + if ((new \DateTime())->createFromFormat('Y-m-d', $endDate) == false) { + throw new ValidationException('startDate must be in Y-m-d format'); + } + } + + if ($props['limit'] > 50000) { + throw new ValidationException('Limit exceeds maximum value of 50000'); + } + + return true; + } + + public function setRequestType(string $requestType): self + { + $this->requestType = $requestType; + return $this; + } + + public function setCallbackUrl(string $callbackUrl): self + { + $this->callbackUrl = $callbackUrl; + return $this; + } + + public function setPaymentStatus(string $paymentStatus): self + { + $this->paymentStatus = $paymentStatus; + return $this; + } + + public function setStartDate(string $startDate): self + { + $this->startDate = $startDate; + return $this; + } + + public function setEndDate(string $endDate): self + { + $this->endDate = $endDate; + return $this; + } + + public function setLimit(int $limit): self + { + $this->limit = $limit; + return $this; + } + + public function setReportFields(string $reportFields): self + { + $this->reportFields = $reportFields; + return $this; + } + + public function setSubMerchant(int $subMerchant): self + { + $this->subMerchant = $subMerchant; + return $this; + } + + public function jsonSerialize(): array + { + $dataArray = json_encode(get_object_vars($this)); + return array_filter(json_decode($dataArray, true)); + } +} diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 98064f6..e0aa179 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -19,6 +19,7 @@ use Paytrail\SDK\Request\MitPaymentRequest; use Paytrail\SDK\Request\PaymentRequest; use Paytrail\SDK\Request\PaymentStatusRequest; +use Paytrail\SDK\Request\ReportRequest; use Paytrail\SDK\Request\RevertPaymentAuthHoldRequest; use Paytrail\SDK\Request\ShopInShopPaymentRequest; use PHPUnit\Framework\TestCase; From d8d30e531d42cc4703eef05240cd7bb45cab3297 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 22 Jun 2022 14:43:51 +0300 Subject: [PATCH 04/90] Filter out empty parameters from settlement request --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 65ec4a4..658903e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -644,7 +644,7 @@ public function getSettlements(?string $startDate = null, ?string $endDate = nul 'submerchant' => $subMerchant, ]; - $query = http_build_query($parameters); + $query = http_build_query(array_filter($parameters)); if (!empty($query)) { $uri .= '?' . $query; From 068d0918fd2992668c23925c934beb7f59abb296 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 22 Jun 2022 14:48:17 +0300 Subject: [PATCH 05/90] Update readme --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bed4f74..97f0d03 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,13 @@ To use the payment service, you need to sign up for a Paytrail account. Transact ### General requirements - PHP version >= 7.3 -- [Guzzle](https://github.com/guzzle/guzzle) 7 or 6 - PHP HTTP client for performing HTTP request. +- ext-curl PHP cURL extension +- ext-json PHP JSON extension ### Development requirements - [PHPUnit](https://github.com/sebastianbergmann/phpunit) - A programmer-oriented testing framework for running unit tests in PHP. +- [Guzzle](https://github.com/guzzle/guzzle) 7 or 6 - PHP HTTP client for performing HTTP request. ## Installation @@ -76,6 +78,10 @@ Some of the key features are: - [Requesting merchant settlements](https://docs.paytrail.com/#/?id=settlements) +### Reports + +- [Request payment report](https://docs.paytrail.com/#/?id=payment-report-request) + ## Methods List of `Client::class` methods @@ -99,3 +105,4 @@ List of `Client::class` methods | createMitPaymentCommit() | Commit MiT authorization hold | | revertPaymentAuthorizationHold() | Revert existing Mit or CiT authorization hold | | getSettlements() | Request settlements | +| requestPaymentReport() | Request payment report | From 5558fa9014b625cf1a9658eee6e65ad322911e0b Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 22 Jun 2022 15:00:52 +0300 Subject: [PATCH 06/90] Add extra validation --- src/Request/ReportRequest.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index ad207c7..c522831 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -9,6 +9,13 @@ class ReportRequest implements \JsonSerializable { + const PAYMENT_STATUSES = [ + 'default', + 'paid', + 'all', + 'settled' + ]; + private $requestType; private $callbackUrl; private $paymentStatus; @@ -18,7 +25,6 @@ class ReportRequest implements \JsonSerializable private $reportFields; private $subMerchant; - use ObjectPropertyConverter; public function validate() @@ -29,10 +35,20 @@ public function validate() throw new ValidationException('RequestType can not be empty'); } + if (!in_array($props['requestType'], ['json', 'csv'])) { + throw new ValidationException('RequestType must be either "json" or "csv"'); + } + if (empty($props['callbackUrl'])) { throw new ValidationException('CallbackUrl can not be empty'); } + if ($props['paymentStatus']) { + if (!in_array($props['paymentStatus'], self::PAYMENT_STATUSES)) { + throw new ValidationException('Invalid paymentStatus value'); + } + } + if ($props['startDate']) { if ((new \DateTime())->createFromFormat('Y-m-d', $startDate) == false) { throw new ValidationException('startDate must be in Y-m-d format'); @@ -49,6 +65,12 @@ public function validate() throw new ValidationException('Limit exceeds maximum value of 50000'); } + if ($props['reportFields']) { + if (!is_array($props['reportFields'])) { + throw new ValidationException('ReportFields must be type of array'); + } + } + return true; } From a55effb839cac1ea549ff874bce25366605d2632 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Tue, 28 Jun 2022 10:07:04 +0300 Subject: [PATCH 07/90] Clean ReportRequest validation, add dockblocks --- src/Request/ReportRequest.php | 72 +++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index c522831..fc8f63b 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -43,79 +43,119 @@ public function validate() throw new ValidationException('CallbackUrl can not be empty'); } - if ($props['paymentStatus']) { - if (!in_array($props['paymentStatus'], self::PAYMENT_STATUSES)) { - throw new ValidationException('Invalid paymentStatus value'); - } + if ($props['paymentStatus'] && !in_array($props['paymentStatus'], self::PAYMENT_STATUSES)) { + throw new ValidationException('Invalid paymentStatus value'); } - if ($props['startDate']) { - if ((new \DateTime())->createFromFormat('Y-m-d', $startDate) == false) { - throw new ValidationException('startDate must be in Y-m-d format'); - } + if ($props['startDate'] && !(new \DateTime())->createFromFormat('Y-m-d', $props['startDate'])) { + throw new ValidationException('startDate must be in Y-m-d format'); } - if ($props['endDate']) { - if ((new \DateTime())->createFromFormat('Y-m-d', $endDate) == false) { - throw new ValidationException('startDate must be in Y-m-d format'); - } + if ($props['endDate'] && (new \DateTime())->createFromFormat('Y-m-d', $props['endDate'])) { + throw new ValidationException('startDate must be in Y-m-d format'); } if ($props['limit'] > 50000) { throw new ValidationException('Limit exceeds maximum value of 50000'); } - if ($props['reportFields']) { - if (!is_array($props['reportFields'])) { - throw new ValidationException('ReportFields must be type of array'); - } + if ($props['reportFields'] && is_array($props['reportFields'])) { + throw new ValidationException('ReportFields must be type of array'); } return true; } + /** + * Set request type. + * + * @param string $requestType + * @return $this + */ public function setRequestType(string $requestType): self { $this->requestType = $requestType; return $this; } + /** + * Set callback url. + * + * @param string $callbackUrl + * @return $this + */ public function setCallbackUrl(string $callbackUrl): self { $this->callbackUrl = $callbackUrl; return $this; } + /** + * Set payment statuses. + * + * @param string $paymentStatus + * @return $this + */ public function setPaymentStatus(string $paymentStatus): self { $this->paymentStatus = $paymentStatus; return $this; } + /** + * Set start date. + * + * @param string $startDate + * @return $this + */ public function setStartDate(string $startDate): self { $this->startDate = $startDate; return $this; } + /** + * Set end date. + * + * @param string $endDate + * @return $this + */ public function setEndDate(string $endDate): self { $this->endDate = $endDate; return $this; } + /** + * Set limit. + * + * @param int $limit + * @return $this + */ public function setLimit(int $limit): self { $this->limit = $limit; return $this; } + /** + * Set report fields. + * + * @param string $reportFields + * @return $this + */ public function setReportFields(string $reportFields): self { $this->reportFields = $reportFields; return $this; } + /** + * Set submerchant. + * + * @param int $subMerchant + * @return $this + */ public function setSubMerchant(int $subMerchant): self { $this->subMerchant = $subMerchant; From bd78dffa5d2c4e72782fc483904ee187b25b4ded Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Tue, 28 Jun 2022 10:40:36 +0300 Subject: [PATCH 08/90] Add tests for validation, remove date validations Dates are required in ISO format, and validating that would be more complicated compared to beneffits for validating field. --- src/Request/ReportRequest.php | 8 -------- tests/ClientTest.php | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index fc8f63b..4014002 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -47,14 +47,6 @@ public function validate() throw new ValidationException('Invalid paymentStatus value'); } - if ($props['startDate'] && !(new \DateTime())->createFromFormat('Y-m-d', $props['startDate'])) { - throw new ValidationException('startDate must be in Y-m-d format'); - } - - if ($props['endDate'] && (new \DateTime())->createFromFormat('Y-m-d', $props['endDate'])) { - throw new ValidationException('startDate must be in Y-m-d format'); - } - if ($props['limit'] > 50000) { throw new ValidationException('Limit exceeds maximum value of 50000'); } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index e0aa179..6aa4bbd 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -570,4 +570,40 @@ public function testGetGroupedPaymentProvidersAcceptsLanguageParameters() $this->assertIsArray($providers); $this->assertEquals('Mobile payment methods', $providers['groups'][0]['name']); } + + public function testRequestPaymentReportThrowsExceptionWhenRequestTypeIsEmpty() + { + $this->expectException(ValidationException::class); + $reportRequest = (new ReportRequest()) + ->setCallbackUrl('https://nourl.test'); + $this->client->requestPaymentReport($reportRequest); + } + + public function testRequestPaymentReportThrowsExceptionWhenCallbackUrlIsEmpty() + { + $this->expectException(ValidationException::class); + $reportRequest = (new ReportRequest()) + ->setRequestType('json'); + $this->client->requestPaymentReport($reportRequest); + } + + public function testRequestPaymentReportThrowsExceptionWithInvalidPaymentStatus() + { + $this->expectException(ValidationException::class); + $reportRequest = (new ReportRequest()) + ->setRequestType('json') + ->setCallbackUrl('https://nourl.test') + ->setPaymentStatus('Foobar'); + $this->client->requestPaymentReport($reportRequest); + } + + public function testRequestPaymentReportThrowsExceptionWhenLimitExceeds() + { + $this->expectException(ValidationException::class); + $reportRequest = (new ReportRequest()) + ->setRequestType('json') + ->setCallbackUrl('https://nourl.test') + ->setLimit(99999999); + $this->client->requestPaymentReport($reportRequest); + } } From e0bcae070f4a0251e4548ee1e0b75f72dd5cbaeb Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 10 Aug 2022 12:57:14 +0300 Subject: [PATCH 09/90] Add Guzzle recommendation to README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 97f0d03..a9a25da 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,11 @@ To use the payment service, you need to sign up for a Paytrail account. Transact - [PHPUnit](https://github.com/sebastianbergmann/phpunit) - A programmer-oriented testing framework for running unit tests in PHP. - [Guzzle](https://github.com/guzzle/guzzle) 7 or 6 - PHP HTTP client for performing HTTP request. +### Guzzle +PHP-SDK will use Guzzle 6 or 7, if in present application, otherwise it will fall back to cURL. Guzzle is still used as dev dependency to make testing easier. + +Using Guzzle is recommended on applications using PHP-SDK. + ## Installation Install with Composer: From b811e098b3bc49d508b33a0a7d74ef92b8219a73 Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Tue, 30 Aug 2022 13:41:11 +0300 Subject: [PATCH 10/90] Fix ReportRequest ReportFields validation --- src/Request/ReportRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index 4014002..d50e4b0 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -51,7 +51,7 @@ public function validate() throw new ValidationException('Limit exceeds maximum value of 50000'); } - if ($props['reportFields'] && is_array($props['reportFields'])) { + if ($props['reportFields'] && !is_array($props['reportFields'])) { throw new ValidationException('ReportFields must be type of array'); } From 5a0d15fe67019da061eaf5ed748e8c88771f06b5 Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Tue, 30 Aug 2022 13:50:25 +0300 Subject: [PATCH 11/90] Add validation and tests for API requirement limit >= 0 --- src/Request/ReportRequest.php | 4 ++++ tests/ClientTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index d50e4b0..1c0d1d0 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -51,6 +51,10 @@ public function validate() throw new ValidationException('Limit exceeds maximum value of 50000'); } + if ($props['limit'] < 0) { + throw new ValidationException('Limit must have a minimum value of 0'); + } + if ($props['reportFields'] && !is_array($props['reportFields'])) { throw new ValidationException('ReportFields must be type of array'); } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 6aa4bbd..289cec4 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -606,4 +606,14 @@ public function testRequestPaymentReportThrowsExceptionWhenLimitExceeds() ->setLimit(99999999); $this->client->requestPaymentReport($reportRequest); } + + public function testRequestPaymentReportThrowsExceptionWhenLimitIsNegative() + { + $this->expectException(ValidationException::class); + $reportRequest = (new ReportRequest()) + ->setRequestType('json') + ->setCallbackUrl('https://nourl.test') + ->setLimit(-500); + $this->client->requestPaymentReport($reportRequest); + } } From 9aa976b3b15eae0f3c1a93ea52c44d79b6f300ae Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Tue, 30 Aug 2022 13:54:03 +0300 Subject: [PATCH 12/90] Fix ReportRequest setReportFields input type --- src/Request/ReportRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index 1c0d1d0..c7c47a2 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -137,10 +137,10 @@ public function setLimit(int $limit): self /** * Set report fields. * - * @param string $reportFields + * @param string[] $reportFields * @return $this */ - public function setReportFields(string $reportFields): self + public function setReportFields(array $reportFields): self { $this->reportFields = $reportFields; return $this; From 68117c3389eb481ee505be3110ab3a843759bb92 Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Tue, 30 Aug 2022 14:00:01 +0300 Subject: [PATCH 13/90] Add documentation for payment request dates --- src/Request/ReportRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index c7c47a2..2b791f3 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -101,7 +101,7 @@ public function setPaymentStatus(string $paymentStatus): self /** * Set start date. * - * @param string $startDate + * @param string $startDate Start date as ISO format. * @return $this */ public function setStartDate(string $startDate): self @@ -113,7 +113,7 @@ public function setStartDate(string $startDate): self /** * Set end date. * - * @param string $endDate + * @param string $endDate End date as ISO format. * @return $this */ public function setEndDate(string $endDate): self From 4e0359b70a7916a26097a37335f29be47875a5f1 Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Tue, 30 Aug 2022 14:58:09 +0300 Subject: [PATCH 14/90] Add report request response and tests --- src/Client.php | 21 ++++++++++- src/Response/ReportRequestResponse.php | 51 ++++++++++++++++++++++++++ tests/ClientTest.php | 21 +++++++++++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/Response/ReportRequestResponse.php diff --git a/src/Client.php b/src/Client.php index 658903e..2efc6e3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -26,6 +26,7 @@ use Paytrail\SDK\Response\PaymentStatusResponse; use Paytrail\SDK\Response\RefundResponse; use Paytrail\SDK\Response\EmailRefundResponse; +use Paytrail\SDK\Response\ReportRequestResponse; use Paytrail\SDK\Response\RevertPaymentAuthHoldResponse; use Paytrail\SDK\Response\SettlementResponse; use Paytrail\SDK\Util\Signature; @@ -662,14 +663,30 @@ function ($decoded) { * Report is sent to callbackUrl defined in ReportRequest. * * @param ReportRequest $reportRequest - * @return mixed + * @return ReportRequestResponse * @throws HmacException * @throws ValidationException */ public function requestPaymentReport(ReportRequest $reportRequest) { $this->validateRequestItem($reportRequest); $uri = '/payments/report'; - return $this->post($uri, $reportRequest); + + $reportRequestResponse = $this->post( + $uri, + $reportRequest, + /** + * Create the response instance. + * + * @param mixed $decoded The decoded body. + * @return ReportRequestResponse + */ + function ($decoded) { + return (new ReportRequestResponse()) + ->setRequestId($decoded->requestId ?? null); + }, + ); + + return $reportRequestResponse; } /** diff --git a/src/Response/ReportRequestResponse.php b/src/Response/ReportRequestResponse.php new file mode 100644 index 0000000..9c33d7e --- /dev/null +++ b/src/Response/ReportRequestResponse.php @@ -0,0 +1,51 @@ +requestId = $requestId; + + return $this; + } + + /** + * Get the request id. + * + * @return string + */ + public function getRequestId(): ?string + { + return $this->requestId; + } +} diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 289cec4..03d7f32 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -564,6 +564,7 @@ public function testGetSettlementsWithInvalidDateThrowsException() $this->client->getSettlements('30.5.2022'); } + public function testGetGroupedPaymentProvidersAcceptsLanguageParameters() { $providers = $this->client->getGroupedPaymentProviders(100, 'EN'); @@ -571,6 +572,17 @@ public function testGetGroupedPaymentProvidersAcceptsLanguageParameters() $this->assertEquals('Mobile payment methods', $providers['groups'][0]['name']); } + public function testRequestPaymentReportReturnsRequestId() + { + $reportRequest = (new ReportRequest()) + ->setRequestType('json') + ->setCallbackUrl('https://nourl.test'); + $response = $this->client->requestPaymentReport($reportRequest); + + $this->assertNotNull($response->getRequestId()); + $this->assertNotEmpty($response->getRequestId()); + } + public function testRequestPaymentReportThrowsExceptionWhenRequestTypeIsEmpty() { $this->expectException(ValidationException::class); @@ -616,4 +628,13 @@ public function testRequestPaymentReportThrowsExceptionWhenLimitIsNegative() ->setLimit(-500); $this->client->requestPaymentReport($reportRequest); } + + public function testRequestPaymentReportThrowsExceptionWhenUrlInvalid() + { + $this->expectException(ClientException::class); + $reportRequest = (new ReportRequest()) + ->setRequestType('json') + ->setCallbackUrl('invalid-url'); + $this->client->requestPaymentReport($reportRequest); + } } From a6f1d5b377689b61d536c951a445beacaf8994e3 Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Tue, 30 Aug 2022 15:03:21 +0300 Subject: [PATCH 15/90] Fix typo --- src/Response/ReportRequestResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Response/ReportRequestResponse.php b/src/Response/ReportRequestResponse.php index 9c33d7e..acb38ea 100644 --- a/src/Response/ReportRequestResponse.php +++ b/src/Response/ReportRequestResponse.php @@ -26,7 +26,7 @@ class ReportRequestResponse implements ResponseInterface protected $requestId; /** - * Set the transaction id. + * Set the request id. * * @param string|null $requestId * From cc5500223d755ae2dee4ca9134a1803da2fa84fd Mon Sep 17 00:00:00 2001 From: Joonas Loueranta Date: Mon, 5 Sep 2022 11:54:39 +0300 Subject: [PATCH 16/90] Preparing for 2.3.0 release --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1da40be..901d2cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.3.0] - 2022-09-05 +### Added +- Payment report endpoint added +- companyName added to Customer model +### Fixed +- Fixed cUrlClient query parameters + ## [2.2.0] - 2022-06-15 ### Added - Added PHPUnit test workflow From 2aa4f4f6c0a5a1a0c4ca724f0e7b230626564049 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 7 Sep 2022 09:40:11 +0300 Subject: [PATCH 17/90] Add missing properties to RefundRequest --- src/Request/RefundRequest.php | 84 +++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/src/Request/RefundRequest.php b/src/Request/RefundRequest.php index c632f99..df9b75d 100644 --- a/src/Request/RefundRequest.php +++ b/src/Request/RefundRequest.php @@ -93,6 +93,27 @@ public function validate() */ protected $callbackUrls; + /** + * Refund recipient email address. + * + * @var $mail + */ + protected $email; + + /** + * Merchant unique identifier for the refund. + * + * @var $refundStamp + */ + protected $refundStamp; + + /** + * Refund reference. + * + * @var $refundReference + */ + protected $refundReference; + /** * Get the amount. * @@ -164,4 +185,67 @@ public function setCallbackUrls(?CallbackUrl $callbackUrls) : RefundRequest return $this; } + + /** + * Get customer email. + * + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * Set customer email + * + * @param string|null $email + * @return void + */ + public function setEmail(?string $email): void + { + $this->email = $email; + } + + /** + * Get refund stamp. + * + * @return string + */ + public function getRefundStamp(): string + { + return $this->refundStamp; + } + + /** + * Set refund stamp. + * + * @param string $refundStamp + * @return void + */ + public function setRefundStamp(string $refundStamp): void + { + $this->refundStamp = $refundStamp; + } + + /** + * Get refund reference. + * + * @return string + */ + public function getRefundReference(): string + { + return $this->refundReference; + } + + /** + * Set refund reference. + * + * @param string $refundReference + * @return void + */ + public function setRefundReference(string $refundReference): void + { + $this->refundReference = $refundReference; + } } From c2a3d999227b4ed586cb8e786ac8183fe3b869d1 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 7 Sep 2022 10:10:08 +0300 Subject: [PATCH 18/90] Fix RefundRequest return types --- src/Request/EmailRefundRequest.php | 10 ++---- src/Request/RefundRequest.php | 52 +++++++++++++++--------------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/Request/EmailRefundRequest.php b/src/Request/EmailRefundRequest.php index 1ea639d..e1ed11c 100644 --- a/src/Request/EmailRefundRequest.php +++ b/src/Request/EmailRefundRequest.php @@ -6,9 +6,6 @@ namespace Paytrail\SDK\Request; use Paytrail\SDK\Exception\ValidationException; -use Paytrail\SDK\Model\CallbackUrl; -use Paytrail\SDK\Model\RefundItem; -use Paytrail\SDK\Util\JsonSerializable; /** * Class EmailRefund @@ -53,7 +50,7 @@ public function validate() * * @return string */ - public function getEmail() : string + public function getEmail(): string { return $this->email; } @@ -61,14 +58,13 @@ public function getEmail() : string /** * Set the email. * - * @param string $email + * @param string|null $email * * @return EmailRefundRequest Return self to enable chaining. */ - public function setEmail(?string $email) : EmailRefundRequest + public function setEmail(?string $email): RefundRequest { $this->email = $email; - return $this; } } diff --git a/src/Request/RefundRequest.php b/src/Request/RefundRequest.php index df9b75d..f393652 100644 --- a/src/Request/RefundRequest.php +++ b/src/Request/RefundRequest.php @@ -117,9 +117,9 @@ public function validate() /** * Get the amount. * - * @return int + * @return int|null */ - public function getAmount() : int + public function getAmount(): ?int { return $this->amount; } @@ -127,14 +127,13 @@ public function getAmount() : int /** * Set the amount. * - * @param int $amount + * @param int|null $amount * * @return RefundRequest Return self to enable chaining. */ - public function setAmount(?int $amount) : RefundRequest + public function setAmount(?int $amount): RefundRequest { $this->amount = $amount; - return $this; } @@ -143,7 +142,7 @@ public function setAmount(?int $amount) : RefundRequest * * @return RefundItem[] */ - public function getItems() : array + public function getItems(): array { return $this->items ?? []; } @@ -155,19 +154,18 @@ public function getItems() : array * * @return RefundRequest Return self to enable chaining. */ - public function setItems(?array $items) : RefundRequest + public function setItems(?array $items): RefundRequest { $this->items = $items; - return $this; } /** * Get the callback urls. * - * @return CallbackUrl + * @return CallbackUrl|null */ - public function getCallbackUrls() : CallbackUrl + public function getCallbackUrls(): ?CallbackUrl { return $this->callbackUrls; } @@ -175,23 +173,22 @@ public function getCallbackUrls() : CallbackUrl /** * Set the callback urls. * - * @param CallbackUrl $callbackUrls The callback url instance holding success and cancel urls. + * @param CallbackUrl|null $callbackUrls The callback url instance holding success and cancel urls. * * @return RefundRequest Return self to enable chaining. */ public function setCallbackUrls(?CallbackUrl $callbackUrls) : RefundRequest { $this->callbackUrls = $callbackUrls; - return $this; } /** * Get customer email. * - * @return string + * @return string|null */ - public function getEmail(): string + public function getEmail(): ?string { return $this->email; } @@ -200,19 +197,20 @@ public function getEmail(): string * Set customer email * * @param string|null $email - * @return void + * @return RefundRequest */ - public function setEmail(?string $email): void + public function setEmail(?string $email): RefundRequest { $this->email = $email; + return $this; } /** * Get refund stamp. * - * @return string + * @return string|null */ - public function getRefundStamp(): string + public function getRefundStamp(): ?string { return $this->refundStamp; } @@ -220,20 +218,21 @@ public function getRefundStamp(): string /** * Set refund stamp. * - * @param string $refundStamp - * @return void + * @param string|null $refundStamp + * @return RefundRequest */ - public function setRefundStamp(string $refundStamp): void + public function setRefundStamp(?string $refundStamp): RefundRequest { $this->refundStamp = $refundStamp; + return $this; } /** * Get refund reference. * - * @return string + * @return string|null */ - public function getRefundReference(): string + public function getRefundReference(): ?string { return $this->refundReference; } @@ -241,11 +240,12 @@ public function getRefundReference(): string /** * Set refund reference. * - * @param string $refundReference - * @return void + * @param string|null $refundReference + * @return RefundRequest */ - public function setRefundReference(string $refundReference): void + public function setRefundReference(?string $refundReference): RefundRequest { $this->refundReference = $refundReference; + return $this; } } From 06547b606182320e29fc28cf4665f515eca436f6 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 7 Sep 2022 10:15:08 +0300 Subject: [PATCH 19/90] Add refundStamp and reference to unit tests --- tests/Request/EmailRefundRequestTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Request/EmailRefundRequestTest.php b/tests/Request/EmailRefundRequestTest.php index 6093564..37666fb 100644 --- a/tests/Request/EmailRefundRequestTest.php +++ b/tests/Request/EmailRefundRequestTest.php @@ -34,6 +34,9 @@ public function testEmailRefundRequest() $er->setCallbackUrls($cb); + $er->setRefundReference('ref-1234') + ->setRefundStamp('c7557cd5d5f548daa5332ccc4abb264f'); + $this->assertEquals(true, $er->validate()); } From 998b817907179589dcf68a353bf949e30dc76b2a Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 14 Sep 2022 10:07:45 +0300 Subject: [PATCH 20/90] Add meethod for activate-invoice endpoint --- src/Client.php | 28 +++++++++++++ src/PaytrailClient.php | 4 +- src/Response/InvoiceActivationResponse.php | 49 ++++++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/Response/InvoiceActivationResponse.php diff --git a/src/Client.php b/src/Client.php index 2efc6e3..488887f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -29,6 +29,7 @@ use Paytrail\SDK\Response\ReportRequestResponse; use Paytrail\SDK\Response\RevertPaymentAuthHoldResponse; use Paytrail\SDK\Response\SettlementResponse; +use Paytrail\SDK\Response\InvoiceActivationResponse; use Paytrail\SDK\Util\Signature; use Paytrail\SDK\Exception\HmacException; use Paytrail\SDK\Exception\ValidationException; @@ -689,6 +690,33 @@ function ($decoded) { return $reportRequestResponse; } + /** + * Activate invoice created with manualInvoiceActivation set to true + * + * @param string $transactionId + * @return InvoiceActivationResponse + * @throws HmacException + */ + public function activateInvoice(string $transactionId) + { + $uri = "/payments/{$transactionId}/activate-invoice"; + + return $this->post( + $uri, + null, + /** + * Create the response instance. + * + * @param mixed $decoded The decoded body. + * @return InvoiceActivationResponse + */ + function ($decoded) { + return (new InvoiceActivationResponse()) + ->setStatus($decoded->status); + } + ); + } + /** * A proxy for the Signature class' static method * to be used via a client instance. diff --git a/src/PaytrailClient.php b/src/PaytrailClient.php index 5a1e6c4..a61c62f 100644 --- a/src/PaytrailClient.php +++ b/src/PaytrailClient.php @@ -47,7 +47,7 @@ protected function createHttpClient() * A wrapper for post requests. * * @param string $uri The uri for the request. - * @param \JsonSerializable $data The request payload. + * @param \JsonSerializable|null $data The request payload. * @param callable|null $callback The callback method to run for the decoded response. If left empty, the response is returned. * @param string|null $transactionId Paytrail transaction ID when accessing single transaction not required for a new payment request. * @param bool $signatureInHeader Checks if signature is calculated from header/body parameters @@ -56,7 +56,7 @@ protected function createHttpClient() * @return mixed * @throws HmacException */ - protected function post(string $uri, \JsonSerializable $data, callable $callback = null, string $transactionId = null, bool $signatureInHeader = true, string $paytrailTokenizationId = null) + protected function post(string $uri, \JsonSerializable $data = null, callable $callback = null, string $transactionId = null, bool $signatureInHeader = true, string $paytrailTokenizationId = null) { $body = json_encode($data, JSON_UNESCAPED_SLASHES); diff --git a/src/Response/InvoiceActivationResponse.php b/src/Response/InvoiceActivationResponse.php new file mode 100644 index 0000000..8e4597e --- /dev/null +++ b/src/Response/InvoiceActivationResponse.php @@ -0,0 +1,49 @@ +status; + } + + /** + * Set the status. + * + * @param string $status + * + * @return InvoiceActivationResponse Return self to enable chaining. + */ + public function setStatus(string $status): InvoiceActivationResponse + { + $this->status = $status; + return $this; + } +} From 63b7007b5c520145c87ba388fc8f6f07f3e11fbd Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Thu, 15 Sep 2022 14:26:13 +0300 Subject: [PATCH 21/90] Allow null for some response setters, fix dockblock type hints --- src/Response/CitPaymentResponse.php | 2 +- src/Response/PaymentResponse.php | 8 +++--- src/Response/PaymentStatusResponse.php | 36 ++++++++++---------------- src/Response/RefundResponse.php | 6 ++--- 4 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/Response/CitPaymentResponse.php b/src/Response/CitPaymentResponse.php index 9fba630..3c63319 100644 --- a/src/Response/CitPaymentResponse.php +++ b/src/Response/CitPaymentResponse.php @@ -53,7 +53,7 @@ public function getTransactionId(): ?string } /** - * @param string $threeDSecureUrl + * @param string|null $threeDSecureUrl * @return CitPaymentResponse */ public function setThreeDSecureUrl(?string $threeDSecureUrl): CitPaymentResponse diff --git a/src/Response/PaymentResponse.php b/src/Response/PaymentResponse.php index 04ec97c..4e9dcb4 100644 --- a/src/Response/PaymentResponse.php +++ b/src/Response/PaymentResponse.php @@ -54,11 +54,11 @@ public function getTransactionId() : ?string /** * Set the transaction id. * - * @param string $transactionId + * @param string|null $transactionId * * @return PaymentResponse Return self to enable chaining. */ - public function setTransactionId(string $transactionId) : PaymentResponse + public function setTransactionId(?string $transactionId) : PaymentResponse { $this->transactionId = $transactionId; @@ -78,11 +78,11 @@ public function getHref() : ?string /** * Set the href. * - * @param string $href + * @param string|null $href * * @return PaymentResponse Return self to enable chaining. */ - public function setHref(string $href) : PaymentResponse + public function setHref(?string $href) : PaymentResponse { $this->href = $href; diff --git a/src/Response/PaymentStatusResponse.php b/src/Response/PaymentStatusResponse.php index 0dab874..3ce9291 100644 --- a/src/Response/PaymentStatusResponse.php +++ b/src/Response/PaymentStatusResponse.php @@ -35,7 +35,7 @@ class PaymentStatusResponse implements ResponseInterface /** * Total amount of the payment in currency's minor units, - * eg. for Euros means cents. + * e.g. for Euros means cents. * * @var integer */ @@ -137,7 +137,7 @@ public function getStatus(): ?string /** * Set the payment status. * - * @param string $status Possible values: new, ok, fail, + * @param string|null $status Possible values: new, ok, fail, * pending, or delayed * * @return PaymentStatusResponse Return self to enable chaining. @@ -145,7 +145,6 @@ public function getStatus(): ?string public function setStatus(?string $status): PaymentStatusResponse { $this->status = $status; - return $this; } @@ -161,16 +160,15 @@ public function getAmount(): ?int /** * Set the total amount of the payment in currency's minor units, - * eg. for Euros means cents. + * e.g. for Euros means cents. * - * @param integer $amount + * @param integer|null $amount * * @return PaymentStatusResponse Return self to enable chaining. */ public function setAmount(?int $amount): PaymentStatusResponse { $this->amount = $amount; - return $this; } @@ -187,14 +185,13 @@ public function getCurrency(): ?string /** * Set currency. * - * @param string $currency + * @param string|null $currency * * @return PaymentStatusResponse Return self to enable chaining. */ public function setCurrency(?string $currency): PaymentStatusResponse { $this->currency = $currency; - return $this; } @@ -211,14 +208,13 @@ public function getStamp(): ?string /** * Set merchant unique identifier for the order. * - * @param string $stamp + * @param string|null $stamp * * @return PaymentStatusResponse Return self to enable chaining. */ public function setStamp(?string $stamp): PaymentStatusResponse { $this->stamp = $stamp; - return $this; } @@ -227,7 +223,7 @@ public function setStamp(?string $stamp): PaymentStatusResponse * * @return string */ - public function getReference() + public function getReference(): string { return $this->reference; } @@ -235,14 +231,13 @@ public function getReference() /** * Set the order reference. * - * @param string $reference + * @param string|null $reference * * @return PaymentStatusResponse Return self to enable chaining. */ public function setReference(?string $reference): PaymentStatusResponse { $this->reference = $reference; - return $this; } @@ -259,14 +254,13 @@ public function getCreatedAt(): ?string /** * Set the transaction creation timestamp. * - * @param string $createdAt + * @param string|null $createdAt * * @return PaymentStatusResponse Return self to enable chaining. */ public function setCreatedAt(?string $createdAt): PaymentStatusResponse { $this->createdAt = $createdAt; - return $this; } @@ -283,14 +277,13 @@ public function getHref(): ?string /** * Set payment API url. * - * @param string $href + * @param string|null $href * * @return PaymentStatusResponse Return self to enable chaining. */ public function setHref(?string $href): PaymentStatusResponse { $this->href = $href; - return $this; } @@ -307,14 +300,13 @@ public function getProvider() /** * Set provider name. * - * @param string $provider If processed, the name of the payment method provider + * @param string|null $provider If processed, the name of the payment method provider * * @return PaymentStatusResponse Return self to enable chaining. */ public function setProvider(?string $provider): PaymentStatusResponse { $this->provider = $provider; - return $this; } @@ -331,14 +323,13 @@ public function getFilingCode(): ?string /** * Set filing code. * - * @param string $filingCode + * @param string|null $filingCode * * @return PaymentStatusResponse Return self to enable chaining. */ public function setFilingCode(?string $filingCode): PaymentStatusResponse { $this->filingCode = $filingCode; - return $this; } @@ -355,14 +346,13 @@ public function getPaidAt(): ?string /** * Set timestamp when the transaction was paid * - * @param string $paidAt + * @param string|null $paidAt * * @return PaymentStatusResponse Return self to enable chaining. */ public function setPaidAt(?string $paidAt): PaymentStatusResponse { $this->paidAt = $paidAt; - return $this; } } diff --git a/src/Response/RefundResponse.php b/src/Response/RefundResponse.php index 82d0ce4..cd3301a 100644 --- a/src/Response/RefundResponse.php +++ b/src/Response/RefundResponse.php @@ -52,7 +52,7 @@ public function getProvider(): string /** * Set the provider. * - * @param string $provider + * @param string|null $provider * * @return RefundResponse Return self to enable chaining. */ @@ -78,7 +78,7 @@ public function getStatus(): string /** * Set the status. * - * @param string $status + * @param string|null $status * * @return RefundResponse Return self to enable chaining. */ @@ -104,7 +104,7 @@ public function getTransactionId(): string /** * Set the transactionId. * - * @param string $transactionId + * @param string|null $transactionId * * @return RefundResponse Return self to enable chaining. */ From 6d8a9347839b5f5b31013f377781cec18e9833e1 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Tue, 27 Sep 2022 12:15:16 +0300 Subject: [PATCH 22/90] Allow null in CIT/MIT response transactionId setters --- src/Response/CitPaymentResponse.php | 5 ++--- src/Response/MitPaymentResponse.php | 5 ++--- src/Response/RevertPaymentAuthHoldResponse.php | 9 ++++----- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Response/CitPaymentResponse.php b/src/Response/CitPaymentResponse.php index 3c63319..fe0688b 100644 --- a/src/Response/CitPaymentResponse.php +++ b/src/Response/CitPaymentResponse.php @@ -31,14 +31,13 @@ class CitPaymentResponse implements ResponseInterface /** * Set the transaction id. * - * @param string $transactionId + * @param string|null $transactionId * * @return CitPaymentResponse Return self to enable chaining. */ - public function setTransactionId(string $transactionId): CitPaymentResponse + public function setTransactionId(?string $transactionId): CitPaymentResponse { $this->transactionId = $transactionId; - return $this; } diff --git a/src/Response/MitPaymentResponse.php b/src/Response/MitPaymentResponse.php index b611547..cf5ed6a 100644 --- a/src/Response/MitPaymentResponse.php +++ b/src/Response/MitPaymentResponse.php @@ -28,14 +28,13 @@ class MitPaymentResponse implements ResponseInterface /** * Set the transaction id. * - * @param string $transactionId + * @param string|null $transactionId * * @return MitPaymentResponse Return self to enable chaining. */ - public function setTransactionId(string $transactionId): MitPaymentResponse + public function setTransactionId(?string $transactionId): MitPaymentResponse { $this->transactionId = $transactionId; - return $this; } diff --git a/src/Response/RevertPaymentAuthHoldResponse.php b/src/Response/RevertPaymentAuthHoldResponse.php index ecb37ba..3360cdd 100644 --- a/src/Response/RevertPaymentAuthHoldResponse.php +++ b/src/Response/RevertPaymentAuthHoldResponse.php @@ -28,14 +28,13 @@ class RevertPaymentAuthHoldResponse implements ResponseInterface /** * Set the transaction id. * - * @param string $transactionId + * @param string|null $transactionId * - * @return CitPaymentResponse Return self to enable chaining. + * @return RevertPaymentAuthHoldResponse Return self to enable chaining. */ - public function setTransactionId(string $transactionId): RevertPaymentAuthHoldResponse + public function setTransactionId(?string $transactionId): RevertPaymentAuthHoldResponse { $this->transactionId = $transactionId; - return $this; } @@ -44,7 +43,7 @@ public function setTransactionId(string $transactionId): RevertPaymentAuthHoldRe * * @return string */ - public function getTransactionId(): string + public function getTransactionId(): ?string { return $this->transactionId; } From 3b45537649a69ed66698ecf71d6c5afbcbb5b984 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 28 Sep 2022 07:51:42 +0300 Subject: [PATCH 23/90] Add manualInvoiceActivation option to payment request Default as false, so it needs to be set explicitly on. --- src/Request/AbstractPaymentRequest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Request/AbstractPaymentRequest.php b/src/Request/AbstractPaymentRequest.php index bdcee43..7d542cf 100644 --- a/src/Request/AbstractPaymentRequest.php +++ b/src/Request/AbstractPaymentRequest.php @@ -210,6 +210,13 @@ public function validate() */ protected $groups; + /** + * Activate invoices manually + * + * @var boolean + */ + protected $manualInvoiceActivation = false; + /** * Get the stamp. * @@ -535,4 +542,15 @@ public function getGroups(): array { return $this->groups; } + + public function setManualInvoiceActivation($value = false): PaymentRequestInterface + { + $this->manualInvoiceActivation = $value; + return $this; + } + + public function getManualInvoiceActivation(): bool + { + return $this->manualInvoiceActivation; + } } From c3cf9f60abd6fdd9421b93f59cc6926322106bac Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 28 Sep 2022 09:16:47 +0300 Subject: [PATCH 24/90] Remove default value from manualInvoiceActivation --- src/Request/AbstractPaymentRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Request/AbstractPaymentRequest.php b/src/Request/AbstractPaymentRequest.php index 7d542cf..be91917 100644 --- a/src/Request/AbstractPaymentRequest.php +++ b/src/Request/AbstractPaymentRequest.php @@ -215,7 +215,7 @@ public function validate() * * @var boolean */ - protected $manualInvoiceActivation = false; + protected $manualInvoiceActivation; /** * Get the stamp. From b30f0cfd544d3fa31084971df577ccd4930f6fc7 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Thu, 6 Oct 2022 10:05:17 +0300 Subject: [PATCH 25/90] Add missing dockblocks and type casting --- src/Request/AbstractPaymentRequest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Request/AbstractPaymentRequest.php b/src/Request/AbstractPaymentRequest.php index be91917..38f81cd 100644 --- a/src/Request/AbstractPaymentRequest.php +++ b/src/Request/AbstractPaymentRequest.php @@ -543,12 +543,19 @@ public function getGroups(): array return $this->groups; } - public function setManualInvoiceActivation($value = false): PaymentRequestInterface + /** + * @param bool $value + * @return PaymentRequestInterface + */ + public function setManualInvoiceActivation(bool $value = false): PaymentRequestInterface { $this->manualInvoiceActivation = $value; return $this; } + /** + * @return bool + */ public function getManualInvoiceActivation(): bool { return $this->manualInvoiceActivation; From b60b74d0386ed560b30c392e7571e3c72db7d753 Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Mon, 24 Oct 2022 20:41:56 +0300 Subject: [PATCH 26/90] Fix payment response function and docs types --- src/Client.php | 4 ++-- src/Response/PaymentResponse.php | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Client.php b/src/Client.php index 2efc6e3..eb0649f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -217,7 +217,7 @@ function ($decoded) { return (new PaymentResponse()) ->setTransactionId($decoded->transactionId ?? null) ->setHref($decoded->href ?? null) - ->setProviders($decoded->providers ?? null); + ->setProviders($decoded->providers ?? []); } ); @@ -252,7 +252,7 @@ function ($decoded) { return (new PaymentResponse()) ->setTransactionId($decoded->transactionId ?? null) ->setHref($decoded->href ?? null) - ->setProviders($decoded->providers ?? null); + ->setProviders($decoded->providers ?? []); } ); diff --git a/src/Response/PaymentResponse.php b/src/Response/PaymentResponse.php index 04ec97c..7c270f1 100644 --- a/src/Response/PaymentResponse.php +++ b/src/Response/PaymentResponse.php @@ -23,14 +23,14 @@ class PaymentResponse implements ResponseInterface /** * The transaction id. * - * @var string + * @var string|null */ protected $transactionId; /** * Payment API url. * - * @var string + * @var string|null */ protected $href; @@ -44,7 +44,7 @@ class PaymentResponse implements ResponseInterface /** * Get the transaction id. * - * @return string + * @return string|null */ public function getTransactionId() : ?string { @@ -54,11 +54,11 @@ public function getTransactionId() : ?string /** * Set the transaction id. * - * @param string $transactionId + * @param string|null $transactionId * * @return PaymentResponse Return self to enable chaining. */ - public function setTransactionId(string $transactionId) : PaymentResponse + public function setTransactionId(?string $transactionId) : PaymentResponse { $this->transactionId = $transactionId; @@ -68,7 +68,7 @@ public function setTransactionId(string $transactionId) : PaymentResponse /** * Get the href. * - * @return string + * @return string|null */ public function getHref() : ?string { @@ -78,11 +78,11 @@ public function getHref() : ?string /** * Set the href. * - * @param string $href + * @param string|null $href * * @return PaymentResponse Return self to enable chaining. */ - public function setHref(string $href) : PaymentResponse + public function setHref(?string $href) : PaymentResponse { $this->href = $href; @@ -92,11 +92,10 @@ public function setHref(string $href) : PaymentResponse /** * Get providers. * - * @return Provider[] + * @return Provider[]|null */ public function getProviders() : ?array { - return $this->providers; } @@ -111,7 +110,7 @@ public function getProviders() : ?array * * @return PaymentResponse Return self to enable chaining. */ - public function setProviders(?array $providers) : PaymentResponse + public function setProviders(array $providers) : PaymentResponse { if (empty($providers)) { return $this; From 6ad6471c9b4e564f067d46104bbab7adb33f271c Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Mon, 24 Oct 2022 21:07:10 +0300 Subject: [PATCH 27/90] Add payment method group model --- src/Model/PaymentMethodGroup.php | 144 +++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 src/Model/PaymentMethodGroup.php diff --git a/src/Model/PaymentMethodGroup.php b/src/Model/PaymentMethodGroup.php new file mode 100644 index 0000000..4e2ca1d --- /dev/null +++ b/src/Model/PaymentMethodGroup.php @@ -0,0 +1,144 @@ +id; + } + + /** + * Set payment method group id. + * + * @param string|null $id + * @return self + */ + public function setId(?string $id) : self + { + $this->id = $id; + + return $this; + } + + /** + * Get payment method group name. + * + * @return string|null + */ + public function getName() : ?string + { + return $this->name; + } + + /** + * Set payment method group name. + * + * @param string|null $name + * @return self + */ + public function setName(?string $name) : self + { + $this->name = $name; + + return $this; + } + + /** + * Get payment method group svg url. + * + * @return string|null + */ + public function getSvg() : ?string + { + return $this->svg; + } + + /** + * Set payment method group svg url. + * + * @param string|null $svg + * @return self + */ + public function setSvg(?string $svg) : self + { + $this->svg = $svg; + + return $this; + } + + /** + * Get payment method group icon url. + * + * @return string|null + */ + public function getIcon() : ?string + { + return $this->icon; + } + + /** + * Set payment method group icon url. + * + * @param string|null $icon + * @return self + */ + public function setIcon(?string $icon) : self + { + $this->icon = $icon; + + return $this; + } +} From 51e0aeeb92a66de10d8b2e774c7cd9d4707c75f9 Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Mon, 24 Oct 2022 21:17:44 +0300 Subject: [PATCH 28/90] Update payment response model --- src/Response/PaymentResponse.php | 89 +++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/src/Response/PaymentResponse.php b/src/Response/PaymentResponse.php index 7c270f1..c7faa08 100644 --- a/src/Response/PaymentResponse.php +++ b/src/Response/PaymentResponse.php @@ -7,6 +7,7 @@ namespace Paytrail\SDK\Response; +use Paytrail\SDK\Model\PaymentMethodGroup; use Paytrail\SDK\Model\Provider; use Paytrail\SDK\Interfaces\ResponseInterface; @@ -21,19 +22,40 @@ class PaymentResponse implements ResponseInterface { /** - * The transaction id. + * Assigned transaction ID for the payment. * * @var string|null */ protected $transactionId; /** - * Payment API url. + * URL to hosted payment gateway. * * @var string|null */ protected $href; + /** + * Localized text with a link to the terms of payment. + * + * @var string|null + */ + protected $terms; + + /** + * Array of payment method group data with localized names and URLs to icons. + * + * @var PaymentMethodGroup[] + */ + protected $groups = []; + + /** + * The bank reference used for the payments. + * + * @var string|null + */ + protected $reference; + /** * Payment providers. * @@ -89,6 +111,69 @@ public function setHref(?string $href) : PaymentResponse return $this; } + /** + * @return string|null + */ + public function getTerms(): ?string + { + return $this->terms; + } + + /** + * @param string|null $terms + * @return PaymentResponse + */ + public function setTerms(?string $terms): PaymentResponse + { + $this->terms = $terms; + + return $this; + } + + /** + * @return PaymentMethodGroup[] + */ + public function getGroups(): array + { + return $this->groups; + } + + /** + * @param PaymentMethodGroup[]|array $groups + * @return PaymentResponse + */ + public function setGroups(array $groups): PaymentResponse + { + $this->groups = array_map(function ($group) { + if (! $group instanceof Provider) { + return (new Provider())->bindProperties($group); + } + + return $group; + }, $groups); + + return $this; + } + + /** + * @return string|null + */ + public function getReference(): ?string + { + return $this->reference; + } + + /** + * @param string|null $reference + * @return PaymentResponse + */ + public function setReference(?string $reference): PaymentResponse + { + $this->reference = $reference; + + return $this; + } + /** * Get providers. * From 5872a034a52f86d9b2110a70dbbebac1c8efa033 Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Mon, 24 Oct 2022 21:19:53 +0300 Subject: [PATCH 29/90] Simplify payment response provider setter --- src/Response/PaymentResponse.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Response/PaymentResponse.php b/src/Response/PaymentResponse.php index c7faa08..25ba4fe 100644 --- a/src/Response/PaymentResponse.php +++ b/src/Response/PaymentResponse.php @@ -197,19 +197,13 @@ public function getProviders() : ?array */ public function setProviders(array $providers) : PaymentResponse { - if (empty($providers)) { - return $this; - } - - array_walk($providers, function ($provider) { - if (! $provider instanceof Provider) { - $instance = new Provider(); - $instance->bindProperties($provider); - $this->providers[] = $instance; - } else { - $this->providers[] = $provider; + $this->providers = array_map(function ($provider) { + if (! $provider instanceof Provider) { + return (new Provider())->bindProperties($provider); } - }); + + return $provider; + }, $providers); return $this; } From ff711a9b8f5f729e242bcd88eb5fe6bbdf95ce5c Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Mon, 24 Oct 2022 21:29:31 +0300 Subject: [PATCH 30/90] Map payment reponse fields --- src/Client.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Client.php b/src/Client.php index eb0649f..f02d7ec 100644 --- a/src/Client.php +++ b/src/Client.php @@ -217,6 +217,9 @@ function ($decoded) { return (new PaymentResponse()) ->setTransactionId($decoded->transactionId ?? null) ->setHref($decoded->href ?? null) + ->setTerms($decoded->terms ?? null) + ->setGroups($decoded->groups ?? []) + ->setReference($decoded->reference ?? null) ->setProviders($decoded->providers ?? []); } ); @@ -252,6 +255,9 @@ function ($decoded) { return (new PaymentResponse()) ->setTransactionId($decoded->transactionId ?? null) ->setHref($decoded->href ?? null) + ->setTerms($decoded->terms ?? null) + ->setGroups($decoded->groups ?? []) + ->setReference($decoded->reference ?? null) ->setProviders($decoded->providers ?? []); } ); From 6b5ac388f2ad8f6dad0cd443166784842922fac5 Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Mon, 24 Oct 2022 22:24:15 +0300 Subject: [PATCH 31/90] Add base test case for payment request tests and tests for payment response --- tests/ClientTest.php | 100 +++++-------------------------- tests/PaymentRequestTestCase.php | 97 ++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 84 deletions(-) create mode 100644 tests/PaymentRequestTestCase.php diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 03d7f32..0bc9537 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -6,7 +6,6 @@ use Paytrail\SDK\Client; use Paytrail\SDK\Exception\ClientException; use Paytrail\SDK\Exception\HmacException; -use Paytrail\SDK\Exception\RequestException; use Paytrail\SDK\Exception\ValidationException; use Paytrail\SDK\Model\Address; use Paytrail\SDK\Model\CallbackUrl; @@ -22,24 +21,9 @@ use Paytrail\SDK\Request\ReportRequest; use Paytrail\SDK\Request\RevertPaymentAuthHoldRequest; use Paytrail\SDK\Request\ShopInShopPaymentRequest; -use PHPUnit\Framework\TestCase; -class ClientTest extends TestCase +class ClientTest extends PaymentRequestTestCase { - const SECRET = 'SAIPPUAKAUPPIAS'; - - const MERCHANT_ID = 375917; - - const SHOP_IN_SHOP_SECRET = 'MONISAIPPUAKAUPPIAS'; - - const SHOP_IN_SHOP_AGGREGATE_MERCHANT_ID = 695861; - - const SHOP_IN_SHOP_SUB_MERCHANT_ID = '695874'; - - const COF_PLUGIN_VERSION = 'phpunit-test'; - - protected $client; - protected $item; protected $item2; @@ -62,7 +46,7 @@ class ClientTest extends TestCase protected function setUp(): void { - $this->client = new Client(self::MERCHANT_ID, self::SECRET, self::COF_PLUGIN_VERSION); + parent::setUp(); $this->item = (new Item()) ->setDeliveryDate('2020-12-12') @@ -172,93 +156,41 @@ protected function setUp(): void public function testPaymentRequest() { - $client = $this->client; - $paymentRequest = $this->paymentRequest; - - $transactionId = ''; - - if ($paymentRequest->validate()) { - try { - $response = $client->createPayment($paymentRequest); - - $this->assertObjectHasAttribute('transactionId', $response); - $this->assertObjectHasAttribute('href', $response); - $this->assertObjectHasAttribute('providers', $response); - $this->assertIsArray($response->getProviders()); - - $transactionId = $response->getTransactionId(); + $response = $this->createPayment($this->paymentRequest); + $this->assertPaymentResponseIsValid($response); - } catch (HmacException $e) { - var_dump($e->getMessage()); - } catch (ValidationException $e) { - var_dump($e->getMessage()); - } catch (RequestException $e) { - var_dump(json_decode($e->getResponse()->getBody())); - } - - } else { - echo 'PaymentRequest is not valid'; - } + $transactionId = $response->getTransactionId(); // Test payment status request with the transactionId we got from the PaymentRequest $psr = new PaymentStatusRequest(); $psr->setTransactionId($transactionId); - $client = new Client(self::MERCHANT_ID, self::SECRET, self::COF_PLUGIN_VERSION); - try { - $res = $client->getPaymentStatus($psr); + $res = $this->client->getPaymentStatus($psr); $this->assertEquals('new', $res->getStatus()); - $this->assertEquals($res->getTransactionId(), $transactionId); - } catch (HmacException $e) { - var_dump('hmac error'); - } catch (ValidationException $e) { - var_dump('validation error'); + $this->assertEquals($transactionId, $res->getTransactionId()); + } catch (HmacException|ValidationException $e) { + $this->fail($e->getMessage()); } } public function testShopInShopPaymentRequest() { - $client = new Client(self::SHOP_IN_SHOP_AGGREGATE_MERCHANT_ID, self::SHOP_IN_SHOP_SECRET, self::COF_PLUGIN_VERSION); - $paymentRequest = $this->shopInShopPaymentRequest; - - $transactionId = ''; + $response = $this->createShopInShopPayment($this->shopInShopPaymentRequest); + $this->assertPaymentResponseIsValid($response); - if ($paymentRequest->validate()) { - try { - $response = $client->createShopInShopPayment($paymentRequest); - - $this->assertObjectHasAttribute('transactionId', $response); - $this->assertObjectHasAttribute('href', $response); - $this->assertObjectHasAttribute('providers', $response); - $this->assertIsArray($response->getProviders()); - - $transactionId = $response->getTransactionId(); - - } catch (HmacException $e) { - var_dump($e->getMessage()); - } catch (ValidationException $e) { - var_dump($e->getMessage()); - } catch (RequestException $e) { - var_dump(json_decode($e->getResponse()->getBody())); - } - - } else { - echo 'ShopInShopPaymentRequest is not valid'; - } + $transactionId = $response->getTransactionId(); // Test payment status request with the transactionId we got from the PaymentRequest $psr = new PaymentStatusRequest(); $psr->setTransactionId($transactionId); try { - $res = $client->getPaymentStatus($psr); + $res = $this->sisClient->getPaymentStatus($psr); $this->assertEquals('new', $res->getStatus()); - $this->assertEquals($res->getTransactionId(), $transactionId); - } catch (HmacException $e) { - var_dump('hmac error'); - } catch (ValidationException $e) { - var_dump('validation error'); + $this->assertEquals($transactionId, $res->getTransactionId()); + } catch (HmacException|ValidationException $e) { + $this->fail($e->getMessage()); } } diff --git a/tests/PaymentRequestTestCase.php b/tests/PaymentRequestTestCase.php new file mode 100644 index 0000000..e7dcdcb --- /dev/null +++ b/tests/PaymentRequestTestCase.php @@ -0,0 +1,97 @@ +client = new Client(self::MERCHANT_ID, self::SECRET, self::COF_PLUGIN_VERSION); + $this->sisClient = new Client(self::SHOP_IN_SHOP_AGGREGATE_MERCHANT_ID, self::SHOP_IN_SHOP_SECRET, + self::COF_PLUGIN_VERSION); + } + + /** + * Create a payment request. + * + * @param PaymentRequest|PaymentRequestInterface $paymentRequest + * @return PaymentResponse + */ + protected function createPayment(PaymentRequestInterface $paymentRequest): PaymentResponse + { + try { + $paymentRequest->validate(); + return $this->client->createPayment($paymentRequest); + } catch (HmacException|ValidationException $e) { + $this->fail($e->getMessage()); + } + } + + /** + * Create a shop-in-shop payment request. + * + * @param ShopInShopPaymentRequest|PaymentRequestInterface $paymentRequest + * @return PaymentResponse + */ + protected function createShopInShopPayment(PaymentRequestInterface $paymentRequest): PaymentResponse + { + try { + $paymentRequest->validate(); + return $this->sisClient->createShopInShopPayment($paymentRequest); + } catch (HmacException|ValidationException $e) { + $this->fail($e->getMessage()); + } + } + + /** + * Asserts that a payment response is valid and has all the required fields. + * + * @param PaymentResponse $paymentResponse + * @return void + */ + public static function assertPaymentResponseIsValid(PaymentResponse $paymentResponse): void + { + foreach (['transactionId', 'href', 'terms', 'groups', 'reference', 'providers'] as $field) { + static::assertObjectHasAttribute($field, $paymentResponse); + } + + static::assertNotEmpty($paymentResponse->getTransactionId()); + static::assertNotEmpty($paymentResponse->getHref()); + static::assertNotEmpty($paymentResponse->getTerms()); + static::assertNotEmpty($paymentResponse->getReference()); + static::assertIsArray($paymentResponse->getGroups()); + static::assertIsArray($paymentResponse->getProviders()); + } +} From 9601a46566c145d90d89f4955846e2efbcb257e6 Mon Sep 17 00:00:00 2001 From: Sakri Koskimies Date: Mon, 24 Oct 2022 22:42:11 +0300 Subject: [PATCH 32/90] Add phpcs fixes --- src/Model/PaymentMethodGroup.php | 22 +++++++++------------- src/Response/PaymentResponse.php | 18 +++++++----------- tests/ClientTest.php | 5 +++-- tests/PaymentRequestTestCase.php | 26 ++++++++++++++++---------- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/Model/PaymentMethodGroup.php b/src/Model/PaymentMethodGroup.php index 4e2ca1d..921a8e5 100644 --- a/src/Model/PaymentMethodGroup.php +++ b/src/Model/PaymentMethodGroup.php @@ -1,9 +1,6 @@ id; } @@ -66,7 +62,7 @@ public function getId() : ?string * @param string|null $id * @return self */ - public function setId(?string $id) : self + public function setId(?string $id): self { $this->id = $id; @@ -78,7 +74,7 @@ public function setId(?string $id) : self * * @return string|null */ - public function getName() : ?string + public function getName(): ?string { return $this->name; } @@ -89,7 +85,7 @@ public function getName() : ?string * @param string|null $name * @return self */ - public function setName(?string $name) : self + public function setName(?string $name): self { $this->name = $name; @@ -101,7 +97,7 @@ public function setName(?string $name) : self * * @return string|null */ - public function getSvg() : ?string + public function getSvg(): ?string { return $this->svg; } @@ -112,7 +108,7 @@ public function getSvg() : ?string * @param string|null $svg * @return self */ - public function setSvg(?string $svg) : self + public function setSvg(?string $svg): self { $this->svg = $svg; @@ -124,7 +120,7 @@ public function setSvg(?string $svg) : self * * @return string|null */ - public function getIcon() : ?string + public function getIcon(): ?string { return $this->icon; } @@ -135,7 +131,7 @@ public function getIcon() : ?string * @param string|null $icon * @return self */ - public function setIcon(?string $icon) : self + public function setIcon(?string $icon): self { $this->icon = $icon; diff --git a/src/Response/PaymentResponse.php b/src/Response/PaymentResponse.php index 25ba4fe..d280ab4 100644 --- a/src/Response/PaymentResponse.php +++ b/src/Response/PaymentResponse.php @@ -1,9 +1,6 @@ transactionId; } @@ -80,7 +76,7 @@ public function getTransactionId() : ?string * * @return PaymentResponse Return self to enable chaining. */ - public function setTransactionId(?string $transactionId) : PaymentResponse + public function setTransactionId(?string $transactionId): PaymentResponse { $this->transactionId = $transactionId; @@ -92,7 +88,7 @@ public function setTransactionId(?string $transactionId) : PaymentResponse * * @return string|null */ - public function getHref() : ?string + public function getHref(): ?string { return $this->href; } @@ -104,7 +100,7 @@ public function getHref() : ?string * * @return PaymentResponse Return self to enable chaining. */ - public function setHref(?string $href) : PaymentResponse + public function setHref(?string $href): PaymentResponse { $this->href = $href; @@ -179,7 +175,7 @@ public function setReference(?string $reference): PaymentResponse * * @return Provider[]|null */ - public function getProviders() : ?array + public function getProviders(): ?array { return $this->providers; } @@ -195,7 +191,7 @@ public function getProviders() : ?array * * @return PaymentResponse Return self to enable chaining. */ - public function setProviders(array $providers) : PaymentResponse + public function setProviders(array $providers): PaymentResponse { $this->providers = array_map(function ($provider) { if (! $provider instanceof Provider) { diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 0bc9537..adf23a5 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -1,4 +1,5 @@ client->getPaymentStatus($psr); $this->assertEquals('new', $res->getStatus()); $this->assertEquals($transactionId, $res->getTransactionId()); - } catch (HmacException|ValidationException $e) { + } catch (HmacException | ValidationException $e) { $this->fail($e->getMessage()); } } @@ -189,7 +190,7 @@ public function testShopInShopPaymentRequest() $res = $this->sisClient->getPaymentStatus($psr); $this->assertEquals('new', $res->getStatus()); $this->assertEquals($transactionId, $res->getTransactionId()); - } catch (HmacException|ValidationException $e) { + } catch (HmacException | ValidationException $e) { $this->fail($e->getMessage()); } } diff --git a/tests/PaymentRequestTestCase.php b/tests/PaymentRequestTestCase.php index e7dcdcb..730ba87 100644 --- a/tests/PaymentRequestTestCase.php +++ b/tests/PaymentRequestTestCase.php @@ -1,4 +1,5 @@ client = new Client(self::MERCHANT_ID, self::SECRET, self::COF_PLUGIN_VERSION); - $this->sisClient = new Client(self::SHOP_IN_SHOP_AGGREGATE_MERCHANT_ID, self::SHOP_IN_SHOP_SECRET, - self::COF_PLUGIN_VERSION); + $this->sisClient = new Client( + self::SHOP_IN_SHOP_AGGREGATE_MERCHANT_ID, + self::SHOP_IN_SHOP_SECRET, + self::COF_PLUGIN_VERSION + ); } /** @@ -53,8 +57,9 @@ protected function createPayment(PaymentRequestInterface $paymentRequest): Payme { try { $paymentRequest->validate(); + return $this->client->createPayment($paymentRequest); - } catch (HmacException|ValidationException $e) { + } catch (HmacException | ValidationException $e) { $this->fail($e->getMessage()); } } @@ -69,8 +74,9 @@ protected function createShopInShopPayment(PaymentRequestInterface $paymentReque { try { $paymentRequest->validate(); + return $this->sisClient->createShopInShopPayment($paymentRequest); - } catch (HmacException|ValidationException $e) { + } catch (HmacException | ValidationException $e) { $this->fail($e->getMessage()); } } From 61ca027eab085719c8e469f33a58398ee0e2ca8f Mon Sep 17 00:00:00 2001 From: Joonas Loueranta Date: Tue, 15 Nov 2022 12:20:56 +0200 Subject: [PATCH 33/90] Preparing for 2.4.0 release --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 901d2cd..1bb5181 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.4.0] - 2022-11-15 +### Added +- Add missing properties to RefundRequest +- Add missing fields to PaymentResponse model +- Add method for activate-invoice endpoint +### Fixed +- Fix function parameter types + ## [2.3.0] - 2022-09-05 ### Added - Payment report endpoint added From 04ad625ff90c53bd09b399ede953a7a53c632e32 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Tue, 15 Nov 2022 15:56:23 +0200 Subject: [PATCH 34/90] Fix PSR-12 stadard errors --- .gitignore | 4 +- src/Client.php | 112 ++++++------ src/Exception/ClientException.php | 3 +- src/Exception/HmacException.php | 4 +- src/Exception/RequestException.php | 1 + src/Exception/ValidationException.php | 9 +- src/Interfaces/AddressInterface.php | 13 +- src/Interfaces/CallbackUrlInterface.php | 3 +- src/Interfaces/CommissionInterface.php | 75 ++++---- src/Interfaces/CustomerInterface.php | 17 +- src/Interfaces/ItemInterface.php | 25 +-- src/Interfaces/PaymentRequestInterface.php | 49 +++--- src/Interfaces/ResponseInterface.php | 4 +- .../TokenPaymentRequestInterface.php | 5 +- src/Model/Address.php | 18 +- src/Model/CallbackUrl.php | 6 +- src/Model/Commission.php | 165 +++++++++--------- src/Model/Customer.php | 4 +- src/Model/Item.php | 55 +++--- src/Model/Provider.php | 39 ++--- src/Model/RefundItem.php | 12 +- src/Model/Token/Card.php | 1 + src/Model/Token/Customer.php | 1 + src/PaytrailClient.php | 35 ++-- src/Request/AbstractPaymentRequest.php | 66 +++---- src/Request/AddCardFormRequest.php | 3 +- src/Request/CitPaymentRequest.php | 1 + src/Request/EmailRefundRequest.php | 2 +- src/Request/GetTokenRequest.php | 1 + src/Request/MitPaymentRequest.php | 1 + src/Request/PaymentRequest.php | 2 +- src/Request/PaymentStatusRequest.php | 5 +- src/Request/RefundRequest.php | 4 +- src/Request/ReportRequest.php | 8 +- src/Request/RevertPaymentAuthHoldRequest.php | 1 + src/Request/ShopInShopPaymentRequest.php | 63 +++---- src/Response/CitPaymentResponse.php | 3 +- src/Response/CurlResponse.php | 2 +- src/Response/EmailRefundResponse.php | 3 +- src/Response/GetTokenResponse.php | 3 +- src/Response/InvoiceActivationResponse.php | 4 +- src/Response/MitPaymentResponse.php | 3 +- src/Response/PaymentStatusResponse.php | 47 ++--- src/Response/RefundResponse.php | 10 +- src/Response/ReportRequestResponse.php | 3 +- .../RevertPaymentAuthHoldResponse.php | 3 +- src/Response/SettlementResponse.php | 1 + src/Util/CurlClient.php | 6 +- src/Util/JsonSerializable.php | 7 +- src/Util/ObjectPropertyConverter.php | 3 +- src/Util/PropertyBinder.php | 4 +- src/Util/RequestClient.php | 9 +- src/Util/Signature.php | 3 +- tests/Model/AbstractPaymentRequestTest.php | 18 +- tests/Model/AddressTest.php | 11 +- tests/Model/CallbackUrlTest.php | 14 +- tests/Model/CommissionTest.php | 4 +- tests/Model/CustomerTest.php | 4 +- tests/Model/ItemTest.php | 12 +- tests/Model/ProviderTest.php | 3 +- tests/Model/RefundItemTest.php | 1 + tests/Model/Token/CardTest.php | 1 + tests/Model/Token/CustomerTest.php | 4 +- tests/Request/AddCardFormRequestTest.php | 8 +- tests/Request/CitPaymentRequestTest.php | 8 +- tests/Request/EmailRefundRequestTest.php | 3 +- tests/Request/GetTokenRequestTest.php | 4 +- tests/Request/MitPaymentRequestTest.php | 1 + tests/Request/PaymentRequestTest.php | 13 +- tests/Request/PaymentStatusRequestTest.php | 3 +- .../Request/ShopInShopPaymentRequestTest.php | 1 + 71 files changed, 524 insertions(+), 520 deletions(-) diff --git a/.gitignore b/.gitignore index 4346a40..ade8a81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -.phpunit.result.cache test-reports/ -composer.lock \ No newline at end of file +composer.lock +*.cache \ No newline at end of file diff --git a/src/Client.php b/src/Client.php index f894ac8..d887c44 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1,12 +1,13 @@ validateRequestItem($payment); - - $uri = '/payments'; - - $payment_response = $this->post( - $uri, - $payment, - /** - * Create the response instance. - * - * @param mixed $decoded The decoded body. - * @return PaymentResponse - */ - function ($decoded) { - return (new PaymentResponse()) - ->setTransactionId($decoded->transactionId ?? null) - ->setHref($decoded->href ?? null) - ->setTerms($decoded->terms ?? null) - ->setGroups($decoded->groups ?? []) - ->setReference($decoded->reference ?? null) - ->setProviders($decoded->providers ?? []); - } - ); - - return $payment_response; - } - + public function createShopInShopPayment(ShopInShopPaymentRequest $payment): PaymentResponse + { + $this->validateRequestItem($payment); + + $uri = '/payments'; + + $paymentResponse = $this->post( + $uri, + $payment, + /** + * Create the response instance. + * + * @param mixed $decoded The decoded body. + * @return PaymentResponse + */ + function ($decoded) { + return (new PaymentResponse()) + ->setTransactionId($decoded->transactionId ?? null) + ->setHref($decoded->href ?? null) + ->setTerms($decoded->terms ?? null) + ->setGroups($decoded->groups ?? []) + ->setReference($decoded->reference ?? null) + ->setProviders($decoded->providers ?? []); + } + ); + return $paymentResponse; + } + /** * Create a payment status request. * @@ -454,7 +454,6 @@ function ($decoded) { true, $paytrailTokenizationId ); - } catch (HmacException $e) { throw $e; } @@ -525,8 +524,10 @@ public function createMitPaymentAuthorizationHold(MitPaymentRequest $mitPayment) * @throws HmacException Thrown if HMAC calculation fails for responses. * @throws ValidationException Thrown if payment validation fails. */ - public function createCitPaymentCommit(CitPaymentRequest $citPayment, string $transactionId = ''): CitPaymentResponse - { + public function createCitPaymentCommit( + CitPaymentRequest $citPayment, + string $transactionId = '' + ): CitPaymentResponse { $this->validateRequestItem($citPayment); $uri = '/payments/' . $transactionId . '/token/commit'; @@ -558,8 +559,10 @@ function ($decoded) { * @throws HmacException Thrown if HMAC calculation fails for responses. * @throws ValidationException Thrown if payment validation fails. */ - public function createMitPaymentCommit(MitPaymentRequest $mitPayment, string $transactionId = ''): MitPaymentResponse - { + public function createMitPaymentCommit( + MitPaymentRequest $mitPayment, + string $transactionId = '' + ): MitPaymentResponse { $this->validateRequestItem($mitPayment); $uri = '/payments/' . $transactionId . '/token/commit'; @@ -591,8 +594,9 @@ function ($decoded) { * @throws HmacException Thrown if HMAC calculation fails for responses. * @throws ValidationException Thrown if payment validation fails. */ - public function revertPaymentAuthorizationHold(RevertPaymentAuthHoldRequest $revertPaymentAuthHoldRequest): RevertPaymentAuthHoldResponse - { + public function revertPaymentAuthorizationHold( + RevertPaymentAuthHoldRequest $revertPaymentAuthHoldRequest + ): RevertPaymentAuthHoldResponse { $this->validateRequestItem($revertPaymentAuthHoldRequest); $transactionId = $revertPaymentAuthHoldRequest->getTransactionId(); @@ -628,8 +632,13 @@ function ($decoded) { * @return SettlementResponse * @throws HmacException */ - public function getSettlements(?string $startDate = null, ?string $endDate = null, ?string $reference = null, ?int $limit = null, ?int $subMerchant = null) - { + public function getSettlements( + ?string $startDate = null, + ?string $endDate = null, + ?string $reference = null, + ?int $limit = null, + ?int $subMerchant = null + ) { if ($startDate) { if ((new \DateTime())->createFromFormat('Y-m-d', $startDate) == false) { throw new ValidationException('startDate must be in Y-m-d format'); @@ -658,11 +667,13 @@ public function getSettlements(?string $startDate = null, ?string $endDate = nul $uri .= '?' . $query; } - return $this->get($uri, - function ($decoded) { - return (new SettlementResponse()) - ->setSettlements($decoded); - }); + return $this->get( + $uri, + function ($decoded) { + return (new SettlementResponse()) + ->setSettlements($decoded); + } + ); } /** @@ -674,7 +685,8 @@ function ($decoded) { * @throws HmacException * @throws ValidationException */ - public function requestPaymentReport(ReportRequest $reportRequest) { + public function requestPaymentReport(ReportRequest $reportRequest) + { $this->validateRequestItem($reportRequest); $uri = '/payments/report'; diff --git a/src/Exception/ClientException.php b/src/Exception/ClientException.php index 2d4185f..44adda7 100644 --- a/src/Exception/ClientException.php +++ b/src/Exception/ClientException.php @@ -1,4 +1,5 @@ responseBody = $responseBody; } diff --git a/src/Exception/HmacException.php b/src/Exception/HmacException.php index 6ff52c7..36da5c5 100644 --- a/src/Exception/HmacException.php +++ b/src/Exception/HmacException.php @@ -1,10 +1,11 @@ messages = $messages; @@ -52,7 +51,7 @@ public function setMessages(array $messages = []) : ValidationException * * @return array */ - public function getMessages() : array + public function getMessages(): array { return $this->messages; } diff --git a/src/Interfaces/AddressInterface.php b/src/Interfaces/AddressInterface.php index e11a757..7f8c5b5 100644 --- a/src/Interfaces/AddressInterface.php +++ b/src/Interfaces/AddressInterface.php @@ -1,10 +1,11 @@ postalCode; } @@ -136,7 +135,7 @@ public function getPostalCode(): ?string * * @return AddressInterface Return self to enable chaining. */ - public function setPostalCode(?string $postalCode) : AddressInterface + public function setPostalCode(?string $postalCode): AddressInterface { $this->postalCode = $postalCode; @@ -150,7 +149,6 @@ public function setPostalCode(?string $postalCode) : AddressInterface */ public function getCity(): ?string { - return $this->city; } @@ -161,7 +159,7 @@ public function getCity(): ?string * * @return AddressInterface Return self to enable chaining. */ - public function setCity(?string $city) : AddressInterface + public function setCity(?string $city): AddressInterface { $this->city = $city; @@ -175,7 +173,6 @@ public function setCity(?string $city) : AddressInterface */ public function getCounty(): ?string { - return $this->county; } @@ -186,7 +183,7 @@ public function getCounty(): ?string * * @return AddressInterface Return self to enable chaining. */ - public function setCounty(?string $county) : AddressInterface + public function setCounty(?string $county): AddressInterface { $this->county = $county; @@ -200,7 +197,6 @@ public function setCounty(?string $county) : AddressInterface */ public function getCountry(): ?string { - return $this->country; } @@ -211,7 +207,7 @@ public function getCountry(): ?string * * @return AddressInterface Return self to enable chaining. */ - public function setCountry(?string $country) : AddressInterface + public function setCountry(?string $country): AddressInterface { $this->country = $country; diff --git a/src/Model/CallbackUrl.php b/src/Model/CallbackUrl.php index f5d81e9..8dc92da 100644 --- a/src/Model/CallbackUrl.php +++ b/src/Model/CallbackUrl.php @@ -1,10 +1,11 @@ success; } @@ -97,7 +96,6 @@ public function setSuccess(?string $success): CallbackUrlInterface */ public function getCancel(): ?string { - return $this->cancel; } diff --git a/src/Model/Commission.php b/src/Model/Commission.php index da8e5ff..d545787 100644 --- a/src/Model/Commission.php +++ b/src/Model/Commission.php @@ -1,4 +1,5 @@ merchant = $merchant; - - return $this; - } - - /** - * The getter for the merchant. - * - * @return string - */ - public function getMerchant() : string - { - return $this->merchant; - } - - /** - * The setter for the amount. - * - * @param int $amount - * @return Commission Return self to enable chaining. - */ - public function setAmount(int $amount) : Commission - { - $this->amount = $amount; - - return $this; - } - - /** - * The getter for the amount. - * - * @return string - */ - public function getAmount() : int - { - return $this->amount; - } +{ + use JsonSerializable; + + /** + * Validate commission + * + * @throws ValidationException + */ + public function validate() + { + $props = get_object_vars($this); + + if (empty($props['merchant'])) { + throw new ValidationException('Merchant is empty'); + } + + if (filter_var($props['amount'], FILTER_VALIDATE_INT) === false) { + throw new ValidationException('Amount is not an integer'); + } + + return true; + } + + /** + * Merchant identifier for the commission. + * + * @var string + */ + protected $merchant; + + /** + * Total amount to refund this item, in currency's minor units. + * + * @var int + */ + protected $amount; + + /** + * The setter for the merchant. + * + * @param string $merchant + * @return Commission Return self to enable chaining. + */ + public function setMerchant(string $merchant): Commission + { + $this->merchant = $merchant; + + return $this; + } + + /** + * The getter for the merchant. + * + * @return string + */ + public function getMerchant(): string + { + return $this->merchant; + } + + /** + * The setter for the amount. + * + * @param int $amount + * @return Commission Return self to enable chaining. + */ + public function setAmount(int $amount): Commission + { + $this->amount = $amount; + + return $this; + } + + /** + * The getter for the amount. + * + * @return string + */ + public function getAmount(): int + { + return $this->amount; + } } diff --git a/src/Model/Customer.php b/src/Model/Customer.php index d1f65c1..33fdd80 100644 --- a/src/Model/Customer.php +++ b/src/Model/Customer.php @@ -1,10 +1,11 @@ unitPrice = $unitPrice; @@ -147,7 +148,7 @@ public function getUnits(): ?int * @param int $units * @return ItemInterface Return self to enable chaining. */ - public function setUnits(?int $units) : ItemInterface + public function setUnits(?int $units): ItemInterface { $this->units = $units; @@ -170,7 +171,7 @@ public function getVatPercentage(): ?int * @param int $vatPercentage * @return ItemInterface Return self to enable chaining. */ - public function setVatPercentage(?int $vatPercentage) : ItemInterface + public function setVatPercentage(?int $vatPercentage): ItemInterface { $this->vatPercentage = $vatPercentage; @@ -193,7 +194,7 @@ public function getProductCode(): ?string * @param string $productCode * @return ItemInterface Return self to enable chaining. */ - public function setProductCode(?string $productCode) : ItemInterface + public function setProductCode(?string $productCode): ItemInterface { $this->productCode = $productCode; @@ -216,7 +217,7 @@ public function getDeliveryDate(): ?string * @param string $deliveryDate * @return ItemInterface Return self to enable chaining. */ - public function setDeliveryDate(?string $deliveryDate) : ItemInterface + public function setDeliveryDate(?string $deliveryDate): ItemInterface { $this->deliveryDate = $deliveryDate; @@ -239,7 +240,7 @@ public function getDescription(): ?string * @param string $description * @return ItemInterface Return self to enable chaining. */ - public function setDescription(?string $description) : ItemInterface + public function setDescription(?string $description): ItemInterface { $this->description = $description; @@ -262,7 +263,7 @@ public function getCategory(): ?string * @param string $category * @return ItemInterface Return self to enable chaining. */ - public function setCategory(?string $category) : ItemInterface + public function setCategory(?string $category): ItemInterface { $this->category = $category; @@ -285,7 +286,7 @@ public function getStamp(): ?string * @param string $stamp * @return ItemInterface Return self to enable chaining. */ - public function setStamp(?string $stamp) : ItemInterface + public function setStamp(?string $stamp): ItemInterface { $this->stamp = $stamp; @@ -308,7 +309,7 @@ public function getReference(): ?string * @param string $reference * @return ItemInterface Return self to enable chaining. */ - public function setReference(?string $reference) : ItemInterface + public function setReference(?string $reference): ItemInterface { $this->reference = $reference; @@ -331,7 +332,7 @@ public function getMerchant(): ?string * @param string $merchant * @return ItemInterface Return self to enable chaining. */ - public function setMerchant(?string $merchant) : ItemInterface + public function setMerchant(?string $merchant): ItemInterface { $this->merchant = $merchant; @@ -354,7 +355,7 @@ public function getCommission(): ?CommissionInterface * @param CommissionInterface $commission * @return ItemInterface Return self to enable chaining. */ - public function setCommission(?CommissionInterface $commission) : ItemInterface + public function setCommission(?CommissionInterface $commission): ItemInterface { $this->commission = $commission; @@ -391,19 +392,19 @@ public function validate() return true; } - /** - * Validates shop-in-shop props with Respect\Validation library and throws an exception for invalid objects - * - * @throws ValidationException - */ - public function validateShopInShop() - { - $props = get_object_vars($this); - - if (empty($props['merchant'])) { - throw new ValidationException('merchant is empty'); - } - - return true; - } + /** + * Validates shop-in-shop props with Respect\Validation library and throws an exception for invalid objects + * + * @throws ValidationException + */ + public function validateShopInShop() + { + $props = get_object_vars($this); + + if (empty($props['merchant'])) { + throw new ValidationException('merchant is empty'); + } + + return true; + } } diff --git a/src/Model/Provider.php b/src/Model/Provider.php index c6f7883..cc851af 100644 --- a/src/Model/Provider.php +++ b/src/Model/Provider.php @@ -1,10 +1,11 @@ url; } @@ -91,7 +90,7 @@ public function getUrl() : ?string * @param string $url * @return Provider Return self to enable chaining. */ - public function setUrl(?string $url) : Provider + public function setUrl(?string $url): Provider { $this->url = $url; @@ -103,9 +102,8 @@ public function setUrl(?string $url) : Provider * * @return string */ - public function getIcon() : ?string + public function getIcon(): ?string { - return $this->icon; } @@ -115,7 +113,7 @@ public function getIcon() : ?string * @param string $icon * @return Provider Return self to enable chaining. */ - public function setIcon(?string $icon) : Provider + public function setIcon(?string $icon): Provider { $this->icon = $icon; @@ -127,9 +125,8 @@ public function setIcon(?string $icon) : Provider * * @return string */ - public function getSvg() : ?string + public function getSvg(): ?string { - return $this->svg; } @@ -139,7 +136,7 @@ public function getSvg() : ?string * @param string $svg * @return Provider Return self to enable chaining. */ - public function setSvg(?string $svg) : Provider + public function setSvg(?string $svg): Provider { $this->svg = $svg; @@ -151,9 +148,8 @@ public function setSvg(?string $svg) : Provider * * @return string */ - public function getName() : ?string + public function getName(): ?string { - return $this->name; } @@ -163,7 +159,7 @@ public function getName() : ?string * @param string $name * @return Provider Return self to enable chaining. */ - public function setName(?string $name) : Provider + public function setName(?string $name): Provider { $this->name = $name; @@ -175,9 +171,8 @@ public function setName(?string $name) : Provider * * @return string */ - public function getGroup() : ?string + public function getGroup(): ?string { - return $this->group; } @@ -187,7 +182,7 @@ public function getGroup() : ?string * @param string $group * @return Provider Return self to enable chaining. */ - public function setGroup(?string $group) : Provider + public function setGroup(?string $group): Provider { $this->group = $group; @@ -199,9 +194,8 @@ public function setGroup(?string $group) : Provider * * @return string */ - public function getId() : ?string + public function getId(): ?string { - return $this->id; } @@ -211,7 +205,7 @@ public function getId() : ?string * @param string $id * @return Provider Return self to enable chaining. */ - public function setId(?string $id) : Provider + public function setId(?string $id): Provider { $this->id = $id; @@ -223,9 +217,8 @@ public function setId(?string $id) : Provider * * @return array */ - public function getParameters() : ?array + public function getParameters(): ?array { - return $this->parameters; } @@ -235,7 +228,7 @@ public function getParameters() : ?array * @param array $parameters * @return Provider Return self to enable chaining. */ - public function setParameters(?array $parameters) : Provider + public function setParameters(?array $parameters): Provider { $this->parameters = $parameters; diff --git a/src/Model/RefundItem.php b/src/Model/RefundItem.php index ccfbb07..10b5ca3 100644 --- a/src/Model/RefundItem.php +++ b/src/Model/RefundItem.php @@ -1,10 +1,11 @@ amount; } @@ -76,7 +76,7 @@ public function getAmount() : int * @param int $amount The amount. * @return RefundItem Return self to enable chaining. */ - public function setAmount(? int $amount) : RefundItem + public function setAmount(?int $amount): RefundItem { $this->amount = $amount; @@ -88,7 +88,7 @@ public function setAmount(? int $amount) : RefundItem * * @return string */ - public function getStamp() : string + public function getStamp(): string { return $this->stamp; } @@ -99,7 +99,7 @@ public function getStamp() : string * @param string $stamp The stamp. * @return RefundItem Return self to enable chaining. */ - public function setStamp(?string $stamp) : RefundItem + public function setStamp(?string $stamp): RefundItem { $this->stamp = $stamp; diff --git a/src/Model/Token/Card.php b/src/Model/Token/Card.php index 9b87dc2..b306df4 100644 --- a/src/Model/Token/Card.php +++ b/src/Model/Token/Card.php @@ -1,4 +1,5 @@ secretKey); } -} \ No newline at end of file +} diff --git a/src/Request/AbstractPaymentRequest.php b/src/Request/AbstractPaymentRequest.php index 38f81cd..581a4fa 100644 --- a/src/Request/AbstractPaymentRequest.php +++ b/src/Request/AbstractPaymentRequest.php @@ -1,4 +1,5 @@ stamp; } @@ -247,9 +246,8 @@ public function setStamp(?string $stamp): PaymentRequestInterface * * @return string */ - public function getReference() : ?string + public function getReference(): ?string { - return $this->reference; } @@ -262,7 +260,6 @@ public function getReference() : ?string */ public function setReference(?string $reference): PaymentRequestInterface { - $this->reference = $reference; return $this; @@ -273,9 +270,8 @@ public function setReference(?string $reference): PaymentRequestInterface * * @return int */ - public function getAmount() : ?int + public function getAmount(): ?int { - return $this->amount; } @@ -286,9 +282,8 @@ public function getAmount() : ?int * * @return PaymentRequestInterface Return self to enable chaining. */ - public function setAmount(?int $amount) : PaymentRequestInterface + public function setAmount(?int $amount): PaymentRequestInterface { - $this->amount = $amount; return $this; @@ -299,9 +294,8 @@ public function setAmount(?int $amount) : PaymentRequestInterface * * @return string */ - public function getCurrency() : ?string + public function getCurrency(): ?string { - return $this->currency; } @@ -312,9 +306,8 @@ public function getCurrency() : ?string * * @return PaymentRequestInterface Return self to enable chaining. */ - public function setCurrency(?string $currency) : PaymentRequestInterface + public function setCurrency(?string $currency): PaymentRequestInterface { - $this->currency = $currency; return $this; @@ -325,9 +318,8 @@ public function setCurrency(?string $currency) : PaymentRequestInterface * * @return string */ - public function getLanguage() : ?string + public function getLanguage(): ?string { - return $this->language; } @@ -338,9 +330,8 @@ public function getLanguage() : ?string * * @return PaymentRequestInterface Return self to enable chaining. */ - public function setLanguage(?string $language) : PaymentRequestInterface + public function setLanguage(?string $language): PaymentRequestInterface { - $this->language = $language; return $this; @@ -351,9 +342,8 @@ public function setLanguage(?string $language) : PaymentRequestInterface * * @return ItemInterface[] */ - public function getItems() : ?array + public function getItems(): ?array { - return $this->items; } @@ -364,7 +354,7 @@ public function getItems() : ?array * * @return PaymentRequestInterface Return self to enable chaining. */ - public function setItems(?array $items) : PaymentRequestInterface + public function setItems(?array $items): PaymentRequestInterface { $this->items = $items; @@ -380,9 +370,8 @@ public function setItems(?array $items) : PaymentRequestInterface * * @return CustomerInterface */ - public function getCustomer() : ?CustomerInterface + public function getCustomer(): ?CustomerInterface { - return $this->customer; } @@ -393,9 +382,8 @@ public function getCustomer() : ?CustomerInterface * * @return PaymentRequestInterface Return self to enable chaining. */ - public function setCustomer(?CustomerInterface $customer) : PaymentRequestInterface + public function setCustomer(?CustomerInterface $customer): PaymentRequestInterface { - $this->customer = $customer; return $this; @@ -406,9 +394,8 @@ public function setCustomer(?CustomerInterface $customer) : PaymentRequestInterf * * @return AddressInterface */ - public function getDeliveryAddress() : ?AddressInterface + public function getDeliveryAddress(): ?AddressInterface { - return $this->deliveryAddress; } @@ -419,9 +406,8 @@ public function getDeliveryAddress() : ?AddressInterface * * @return PaymentRequestInterface Return self to enable chaining. */ - public function setDeliveryAddress(?AddressInterface $deliveryAddress) : PaymentRequestInterface + public function setDeliveryAddress(?AddressInterface $deliveryAddress): PaymentRequestInterface { - $this->deliveryAddress = $deliveryAddress; return $this; @@ -432,9 +418,8 @@ public function setDeliveryAddress(?AddressInterface $deliveryAddress) : Payment * * @return AddressInterface */ - public function getInvoicingAddress() : ?AddressInterface + public function getInvoicingAddress(): ?AddressInterface { - return $this->invoicingAddress; } @@ -445,9 +430,8 @@ public function getInvoicingAddress() : ?AddressInterface * * @return PaymentRequestInterface Return self to enable chaining. */ - public function setInvoicingAddress(?AddressInterface $invoicingAddress) : PaymentRequestInterface + public function setInvoicingAddress(?AddressInterface $invoicingAddress): PaymentRequestInterface { - $this->invoicingAddress = $invoicingAddress; return $this; @@ -458,9 +442,8 @@ public function setInvoicingAddress(?AddressInterface $invoicingAddress) : Payme * * @return CallbackUrlInterface */ - public function getRedirectUrls() : ?CallbackUrlInterface + public function getRedirectUrls(): ?CallbackUrlInterface { - return $this->redirectUrls; } @@ -471,9 +454,8 @@ public function getRedirectUrls() : ?CallbackUrlInterface * * @return PaymentRequestInterface Return self to enable chaining. */ - public function setRedirectUrls(?CallbackUrlInterface $redirectUrls) : PaymentRequestInterface + public function setRedirectUrls(?CallbackUrlInterface $redirectUrls): PaymentRequestInterface { - $this->redirectUrls = $redirectUrls; return $this; @@ -484,9 +466,8 @@ public function setRedirectUrls(?CallbackUrlInterface $redirectUrls) : PaymentRe * * @return CallbackUrlInterface */ - public function getCallbackUrls() : ?CallbackUrlInterface + public function getCallbackUrls(): ?CallbackUrlInterface { - return $this->callbackUrls; } @@ -497,9 +478,8 @@ public function getCallbackUrls() : ?CallbackUrlInterface * * @return PaymentRequestInterface Return self to enable chaining. */ - public function setCallbackUrls(?CallbackUrlInterface $callbackUrls) : PaymentRequestInterface + public function setCallbackUrls(?CallbackUrlInterface $callbackUrls): PaymentRequestInterface { - $this->callbackUrls = $callbackUrls; return $this; @@ -517,7 +497,7 @@ public function getCallbackDelay(): int * @param int $callbackDelay * @return PaymentRequestInterface Return self to enable chaining. */ - public function setCallbackDelay(int $callbackDelay) : PaymentRequestInterface + public function setCallbackDelay(int $callbackDelay): PaymentRequestInterface { $this->callbackDelay = $callbackDelay; @@ -528,7 +508,7 @@ public function setCallbackDelay(int $callbackDelay) : PaymentRequestInterface * @param array $groups * @return PaymentRequestInterface Return self to enable chaining. */ - public function setGroups(array $groups) : PaymentRequestInterface + public function setGroups(array $groups): PaymentRequestInterface { $this->groups = $groups; diff --git a/src/Request/AddCardFormRequest.php b/src/Request/AddCardFormRequest.php index 09e9f57..03a5dff 100644 --- a/src/Request/AddCardFormRequest.php +++ b/src/Request/AddCardFormRequest.php @@ -1,4 +1,5 @@ jsonSerialize()); return json_decode($dataArray, true); } -} \ No newline at end of file +} diff --git a/src/Request/CitPaymentRequest.php b/src/Request/CitPaymentRequest.php index d240a1c..8a9f9c0 100644 --- a/src/Request/CitPaymentRequest.php +++ b/src/Request/CitPaymentRequest.php @@ -1,4 +1,5 @@ transactionId; } @@ -50,7 +49,7 @@ public function getTransactionId() : string * * @return PaymentStatusRequest Return self to enable chaining. */ - public function setTransactionId(?string $transactionId) : PaymentStatusRequest + public function setTransactionId(?string $transactionId): PaymentStatusRequest { $this->transactionId = $transactionId; diff --git a/src/Request/RefundRequest.php b/src/Request/RefundRequest.php index f393652..5c1cba8 100644 --- a/src/Request/RefundRequest.php +++ b/src/Request/RefundRequest.php @@ -1,4 +1,5 @@ callbackUrls = $callbackUrls; return $this; diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index 2b791f3..8e5ce99 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -1,4 +1,5 @@ items, function (Item $item) { - $item->validateShopInShop(); - }); +/** + * Class PaymentRequest + * + * This class is used to create a payment request object for + * the Paytrail\SDK\Client class. + * + * @see https://Paytrail.github.io/api-documentation/#/?id=create-request-body + * @package Paytrail\SDK\Request + */ +class ShopInShopPaymentRequest extends PaymentRequest +{ + /** + * Validates with Respect\Validation library and throws an exception for invalid objects + * + * @throws ValidationException + */ + public function validate() + { + parent::validate(); - return true; - } - } + // Validate the shop-in-shop items. + array_walk($this->items, function (Item $item) { + $item->validateShopInShop(); + }); + + return true; + } +} diff --git a/src/Response/CitPaymentResponse.php b/src/Response/CitPaymentResponse.php index fe0688b..0d19bea 100644 --- a/src/Response/CitPaymentResponse.php +++ b/src/Response/CitPaymentResponse.php @@ -1,10 +1,11 @@ headers = $responseHeaders; } -} \ No newline at end of file +} diff --git a/src/Response/EmailRefundResponse.php b/src/Response/EmailRefundResponse.php index 92c991e..98a3a09 100644 --- a/src/Response/EmailRefundResponse.php +++ b/src/Response/EmailRefundResponse.php @@ -1,10 +1,11 @@ transactionId; @@ -116,7 +117,7 @@ public function getTransactionId(): string * @param string $transactionId * * @return PaymentStatusResponse Return self to enable chaining. - */ + */ public function setTransactionId(string $transactionId): PaymentStatusResponse { $this->transactionId = $transactionId; @@ -128,7 +129,7 @@ public function setTransactionId(string $transactionId): PaymentStatusResponse * Get the payment status. * * @return string - */ + */ public function getStatus(): ?string { return $this->status; @@ -141,7 +142,7 @@ public function getStatus(): ?string * pending, or delayed * * @return PaymentStatusResponse Return self to enable chaining. - */ + */ public function setStatus(?string $status): PaymentStatusResponse { $this->status = $status; @@ -152,7 +153,7 @@ public function setStatus(?string $status): PaymentStatusResponse * Get the total amount of the payment. * * @return integer - */ + */ public function getAmount(): ?int { return $this->amount; @@ -165,7 +166,7 @@ public function getAmount(): ?int * @param integer|null $amount * * @return PaymentStatusResponse Return self to enable chaining. - */ + */ public function setAmount(?int $amount): PaymentStatusResponse { $this->amount = $amount; @@ -176,7 +177,7 @@ public function setAmount(?int $amount): PaymentStatusResponse * Get currency. * * @return string - */ + */ public function getCurrency(): ?string { return $this->currency; @@ -188,7 +189,7 @@ public function getCurrency(): ?string * @param string|null $currency * * @return PaymentStatusResponse Return self to enable chaining. - */ + */ public function setCurrency(?string $currency): PaymentStatusResponse { $this->currency = $currency; @@ -199,7 +200,7 @@ public function setCurrency(?string $currency): PaymentStatusResponse * Get merchant unique identifier for the order. * * @return string - */ + */ public function getStamp(): ?string { return $this->stamp; @@ -211,7 +212,7 @@ public function getStamp(): ?string * @param string|null $stamp * * @return PaymentStatusResponse Return self to enable chaining. - */ + */ public function setStamp(?string $stamp): PaymentStatusResponse { $this->stamp = $stamp; @@ -222,7 +223,7 @@ public function setStamp(?string $stamp): PaymentStatusResponse * Get the order reference. * * @return string - */ + */ public function getReference(): string { return $this->reference; @@ -234,7 +235,7 @@ public function getReference(): string * @param string|null $reference * * @return PaymentStatusResponse Return self to enable chaining. - */ + */ public function setReference(?string $reference): PaymentStatusResponse { $this->reference = $reference; @@ -245,7 +246,7 @@ public function setReference(?string $reference): PaymentStatusResponse * Get the transaction creation timestamp. * * @return string - */ + */ public function getCreatedAt(): ?string { return $this->createdAt; @@ -257,7 +258,7 @@ public function getCreatedAt(): ?string * @param string|null $createdAt * * @return PaymentStatusResponse Return self to enable chaining. - */ + */ public function setCreatedAt(?string $createdAt): PaymentStatusResponse { $this->createdAt = $createdAt; @@ -268,7 +269,7 @@ public function setCreatedAt(?string $createdAt): PaymentStatusResponse * Get payment API url. * * @return string - */ + */ public function getHref(): ?string { return $this->href; @@ -280,7 +281,7 @@ public function getHref(): ?string * @param string|null $href * * @return PaymentStatusResponse Return self to enable chaining. - */ + */ public function setHref(?string $href): PaymentStatusResponse { $this->href = $href; @@ -291,7 +292,7 @@ public function setHref(?string $href): PaymentStatusResponse * Get provider name. * * @return string - */ + */ public function getProvider() { return $this->provider; @@ -303,7 +304,7 @@ public function getProvider() * @param string|null $provider If processed, the name of the payment method provider * * @return PaymentStatusResponse Return self to enable chaining. - */ + */ public function setProvider(?string $provider): PaymentStatusResponse { $this->provider = $provider; @@ -314,7 +315,7 @@ public function setProvider(?string $provider): PaymentStatusResponse * Get filing code. * * @return string - */ + */ public function getFilingCode(): ?string { return $this->filingCode; @@ -326,7 +327,7 @@ public function getFilingCode(): ?string * @param string|null $filingCode * * @return PaymentStatusResponse Return self to enable chaining. - */ + */ public function setFilingCode(?string $filingCode): PaymentStatusResponse { $this->filingCode = $filingCode; @@ -337,7 +338,7 @@ public function setFilingCode(?string $filingCode): PaymentStatusResponse * Get timestamp when the transaction was paid * * @return string - */ + */ public function getPaidAt(): ?string { return $this->paidAt; @@ -349,7 +350,7 @@ public function getPaidAt(): ?string * @param string|null $paidAt * * @return PaymentStatusResponse Return self to enable chaining. - */ + */ public function setPaidAt(?string $paidAt): PaymentStatusResponse { $this->paidAt = $paidAt; diff --git a/src/Response/RefundResponse.php b/src/Response/RefundResponse.php index cd3301a..b7e9512 100644 --- a/src/Response/RefundResponse.php +++ b/src/Response/RefundResponse.php @@ -1,10 +1,11 @@ provider; } @@ -58,7 +57,6 @@ public function getProvider(): string */ public function setProvider(?string $provider): RefundResponse { - $this->provider = $provider; return $this; @@ -71,7 +69,6 @@ public function setProvider(?string $provider): RefundResponse */ public function getStatus(): string { - return $this->status; } @@ -84,7 +81,6 @@ public function getStatus(): string */ public function setStatus(?string $status): RefundResponse { - $this->status = $status; return $this; @@ -97,7 +93,6 @@ public function setStatus(?string $status): RefundResponse */ public function getTransactionId(): string { - return $this->transactionId; } @@ -110,7 +105,6 @@ public function getTransactionId(): string */ public function setTransactionId(?string $transactionId): RefundResponse { - $this->transactionId = $transactionId; return $this; diff --git a/src/Response/ReportRequestResponse.php b/src/Response/ReportRequestResponse.php index acb38ea..8290a4f 100644 --- a/src/Response/ReportRequestResponse.php +++ b/src/Response/ReportRequestResponse.php @@ -1,10 +1,11 @@ $value) { - $result[] = $key .': ' . $value; + $result[] = $key . ': ' . $value; } return $result; @@ -99,6 +99,6 @@ private function formatBody($body): string if (!is_array($body)) { return $body; } - return http_build_query($body,'','&'); + return http_build_query($body, '', '&'); } -} \ No newline at end of file +} diff --git a/src/Util/JsonSerializable.php b/src/Util/JsonSerializable.php index 1e77d55..eb5c92b 100644 --- a/src/Util/JsonSerializable.php +++ b/src/Util/JsonSerializable.php @@ -1,18 +1,15 @@ getMessage()); if ($exception->hasResponse()) { $responseBody = $exception->getResponse()->getBody()->getContents(); - $clientException->SetResponseBody($responseBody); + $clientException->setResponseBody($responseBody); $clientException->setResponseCode($exception->getCode()); } throw $clientException; } catch (GuzzleConnectException $exception) { throw new RequestException($exception->getMessage()); - } - catch (GuzzleRequestException $exception) { + } catch (GuzzleRequestException $exception) { throw new RequestException($exception->getMessage()); } } @@ -70,8 +70,7 @@ private function createClient(): void 'timeout' => Client::DEFAULT_TIMEOUT, ] ); - } - else { + } else { $this->client = new CurlClient(Client::API_ENDPOINT, Client::DEFAULT_TIMEOUT); } } diff --git a/src/Util/Signature.php b/src/Util/Signature.php index f067665..f91504a 100644 --- a/src/Util/Signature.php +++ b/src/Util/Signature.php @@ -1,10 +1,11 @@ getMockForAbstractClass(AbstractPaymentRequest::class); @@ -90,15 +90,18 @@ public function testValidationExceptionMessages(): void } try { - $paymentRequest->setCustomer(new Customer); + $paymentRequest->setCustomer(new Customer()); $paymentRequest->validate(); } catch (Exception $e) { $this->assertEquals('RedirectUrls is empty', $e->getMessage()); } } - private function setProtectedProperty(AbstractPaymentRequest $paymentRequest, string $propertyName, string $value): void - { + private function setProtectedProperty( + AbstractPaymentRequest $paymentRequest, + string $propertyName, + string $value + ): void { $attribute = new ReflectionProperty($paymentRequest, $propertyName); $attribute->setAccessible(true); $attribute->setValue($paymentRequest, $value); @@ -107,14 +110,14 @@ private function setProtectedProperty(AbstractPaymentRequest $paymentRequest, st private function getPaymentItems(): array { return [ - (new Item) + (new Item()) ->setStamp('someStamp') ->setDeliveryDate('12.12.2020') ->setProductCode('pr1') ->setVatPercentage(25) ->setUnitPrice(10) ->setUnits(1), - (new Item) + (new Item()) ->setStamp('someOtherStamp') ->setDeliveryDate('12.12.2020') ->setProductCode('pr2') @@ -123,5 +126,4 @@ private function getPaymentItems(): array ->setUnits(2), ]; } - -} \ No newline at end of file +} diff --git a/tests/Model/AddressTest.php b/tests/Model/AddressTest.php index 9f32af8..6ef501b 100644 --- a/tests/Model/AddressTest.php +++ b/tests/Model/AddressTest.php @@ -1,4 +1,5 @@ expectException(ValidationException::class); - $a = new Address; + $a = new Address(); $a->validate(); } public function testIsAddressValid() { - $a = new Address; + $a = new Address(); $this->assertInstanceOf( Address::class, @@ -40,7 +40,7 @@ public function testIsAddressValid() public function testExeceptionMessages() { - $a = new Address; + $a = new Address(); try { $a->validate(); @@ -86,5 +86,4 @@ public function testSetStreetAddressAcceptsNull() $addressModel->setStreetAddress(null); $this->assertNull($addressModel->getStreetAddress()); } - -} \ No newline at end of file +} diff --git a/tests/Model/CallbackUrlTest.php b/tests/Model/CallbackUrlTest.php index b38a886..9137447 100644 --- a/tests/Model/CallbackUrlTest.php +++ b/tests/Model/CallbackUrlTest.php @@ -1,4 +1,5 @@ expectException(ValidationException::class); - $a = new CallbackUrl; + $a = new CallbackUrl(); $a->validate(); } public function testIsCallbackUrlValid() { - $c = new CallbackUrl; + $c = new CallbackUrl(); $this->assertInstanceOf(CallbackUrl::class, $c); @@ -28,14 +29,12 @@ public function testIsCallbackUrlValid() try { $this->assertIsBool($c->validate(), 'CallbackUrl::validate is bool'); } catch (ValidationException $e) { - } - } public function testExceptionMessages() { - $c = new CallbackUrl; + $c = new CallbackUrl(); try { $c->validate(); @@ -57,8 +56,5 @@ public function testExceptionMessages() $this->assertIsBool($c->validate(), 'CallbackUrl::validate is bool'); } catch (ValidationException $e) { } - - } - -} \ No newline at end of file +} diff --git a/tests/Model/CommissionTest.php b/tests/Model/CommissionTest.php index a321962..a47db80 100644 --- a/tests/Model/CommissionTest.php +++ b/tests/Model/CommissionTest.php @@ -1,4 +1,5 @@ setMerchant('123456'); $commission->validate(); } - -} +} diff --git a/tests/Model/CustomerTest.php b/tests/Model/CustomerTest.php index 673b1eb..7790644 100644 --- a/tests/Model/CustomerTest.php +++ b/tests/Model/CustomerTest.php @@ -1,4 +1,5 @@ setEmail('notAnEmailAddress'); $c2->validate(); } - -} \ No newline at end of file +} diff --git a/tests/Model/ItemTest.php b/tests/Model/ItemTest.php index 4b09ec8..cd5e5a0 100644 --- a/tests/Model/ItemTest.php +++ b/tests/Model/ItemTest.php @@ -1,4 +1,5 @@ assertInstanceOf( Item::class, @@ -31,13 +32,13 @@ public function testIsItemValid() public function testExceptions() { $this->expectException(ValidationException::class); - $i = new Item; + $i = new Item(); $i->validate(); } public function testExceptionMessages() { - $i = new Item; + $i = new Item(); try { $i->validate(); @@ -86,8 +87,5 @@ public function testExceptionMessages() $this->assertIsBool($i->validate(), 'Item::validate returns bool'); } catch (ValidationException $e) { } - - } - -} \ No newline at end of file +} diff --git a/tests/Model/ProviderTest.php b/tests/Model/ProviderTest.php index b6512ea..57ba5d2 100644 --- a/tests/Model/ProviderTest.php +++ b/tests/Model/ProviderTest.php @@ -1,4 +1,5 @@ assertContains(1, $p->getParameters()); $this->assertContains(2, $p->getParameters()); } -} \ No newline at end of file +} diff --git a/tests/Model/RefundItemTest.php b/tests/Model/RefundItemTest.php index 3749503..98dbd75 100644 --- a/tests/Model/RefundItemTest.php +++ b/tests/Model/RefundItemTest.php @@ -1,4 +1,5 @@ [['networkAddress' => ''], 'Network address is empty'], - 'Country code is empty' => [['networkAddress' => '93.174.192.154', 'countryCode' => ''], 'Country code is empty'] + 'Country code is empty' => [['networkAddress' => '93.174.192.154', + 'countryCode' => ''], 'Country code is empty'] ]; } diff --git a/tests/Request/AddCardFormRequestTest.php b/tests/Request/AddCardFormRequestTest.php index 0254281..3e7327a 100644 --- a/tests/Request/AddCardFormRequestTest.php +++ b/tests/Request/AddCardFormRequestTest.php @@ -1,12 +1,6 @@ [['checkoutTokenizationId' => ''], 'checkout-tokenization-id is empty'] + 'checkout-tokenization-id is empty' => [['checkoutTokenizationId' => ''], + 'checkout-tokenization-id is empty'] ]; } diff --git a/tests/Request/MitPaymentRequestTest.php b/tests/Request/MitPaymentRequestTest.php index e4f382a..4b46de9 100644 --- a/tests/Request/MitPaymentRequestTest.php +++ b/tests/Request/MitPaymentRequestTest.php @@ -1,4 +1,5 @@ setAmount(30) ->setStamp('RequestStamp') ->setReference('RequestReference123') ->setCurrency('EUR') ->setLanguage('EN'); - $customer = (new Customer) + $customer = (new Customer()) ->setEmail('customer@email.com'); $payment->setCustomer($customer); - $callback = (new CallbackUrl) + $callback = (new CallbackUrl()) ->setCancel('https://somedomain.com/cancel') ->setSuccess('https://somedomain.com/success'); $payment->setCallbackUrls($callback); - $redirect = (new CallbackUrl) + $redirect = (new CallbackUrl()) ->setSuccess('https://someother.com/success') ->setCancel('https://someother.com/cancel'); @@ -68,14 +69,14 @@ private function getPaymentRequest(): PaymentRequest private function getPaymentItems(): array { return [ - (new Item) + (new Item()) ->setStamp('someStamp') ->setDeliveryDate('12.12.2020') ->setProductCode('pr1') ->setVatPercentage(25) ->setUnitPrice(10) ->setUnits(1), - (new Item) + (new Item()) ->setStamp('someOtherStamp') ->setDeliveryDate('12.12.2020') ->setProductCode('pr2') diff --git a/tests/Request/PaymentStatusRequestTest.php b/tests/Request/PaymentStatusRequestTest.php index 2f23901..584d4fb 100644 --- a/tests/Request/PaymentStatusRequestTest.php +++ b/tests/Request/PaymentStatusRequestTest.php @@ -1,4 +1,5 @@ validate(); } -} \ No newline at end of file +} diff --git a/tests/Request/ShopInShopPaymentRequestTest.php b/tests/Request/ShopInShopPaymentRequestTest.php index 452d3cf..b55f965 100644 --- a/tests/Request/ShopInShopPaymentRequestTest.php +++ b/tests/Request/ShopInShopPaymentRequestTest.php @@ -1,4 +1,5 @@ Date: Tue, 15 Nov 2022 15:57:52 +0200 Subject: [PATCH 35/90] Add linter to workflow --- .github/workflows/run-phpunit.yaml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-phpunit.yaml b/.github/workflows/run-phpunit.yaml index b052022..e5ebcd2 100644 --- a/.github/workflows/run-phpunit.yaml +++ b/.github/workflows/run-phpunit.yaml @@ -1,10 +1,12 @@ name: Run PHPUnit on: - push: + on: + - push + - pull_request jobs: - run-phpunit: + run-checks: runs-on: ubuntu-latest strategy: matrix: @@ -12,12 +14,18 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Validate Composer Files + run: composer validate --strict + - name: Run composer install uses: php-actions/composer@v6 with: php_version: ${{ matrix.php-version }} args: --ignore-platform-reqs - + + - name: Run linter + run: composer lint + - name: Run tests uses: php-actions/phpunit@v3.0.0 with: From f9393e3a2c17ff143233ae0f019584a9bfeaca6a Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Tue, 15 Nov 2022 16:02:41 +0200 Subject: [PATCH 36/90] Fix workflow syntax --- .github/workflows/run-phpunit.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-phpunit.yaml b/.github/workflows/run-phpunit.yaml index e5ebcd2..f0116b0 100644 --- a/.github/workflows/run-phpunit.yaml +++ b/.github/workflows/run-phpunit.yaml @@ -1,9 +1,8 @@ name: Run PHPUnit on: - on: - - push - - pull_request + - push + - pull_request jobs: run-checks: From 1bd773d849036e6285636215735e43b2958adc04 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Tue, 15 Nov 2022 16:07:18 +0200 Subject: [PATCH 37/90] Remove unused variale and commented out code --- src/Client.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index d887c44..9a6ab53 100644 --- a/src/Client.php +++ b/src/Client.php @@ -167,7 +167,7 @@ public function getGroupedPaymentProviders(int $amount = null, string $locale = // Instantiate providers. $decoded = json_decode($body); - $providers = array_map(function ($provider_data) { + array_map(function ($provider_data) { return (new Provider())->bindProperties($provider_data); }, $decoded->providers); @@ -183,11 +183,9 @@ public function getGroupedPaymentProviders(int $amount = null, string $locale = ]; }, $decoded->groups); - //$res['providers'] = $providers; $res['terms'] = $decoded->terms; $res['groups'] = $groups; - //return $providers; return $res; } From 30ccdc01aa3033feeb5915858b49480f3e45e22d Mon Sep 17 00:00:00 2001 From: Kimmo Tapala Date: Wed, 16 Nov 2022 12:52:59 +0200 Subject: [PATCH 38/90] Store header keys in lower case The getHeader() method assumes all header keys are in lower case. Make sure they are. --- src/Response/CurlResponse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Response/CurlResponse.php b/src/Response/CurlResponse.php index cb44278..b3f8e95 100644 --- a/src/Response/CurlResponse.php +++ b/src/Response/CurlResponse.php @@ -60,8 +60,8 @@ private function setHeaders(string $headers): void continue; } [$key, $value] = explode(': ', $header); - $responseHeaders[$key] = [rtrim($value)]; + $responseHeaders[strtolower($key)] = [rtrim($value)]; } $this->headers = $responseHeaders; } -} \ No newline at end of file +} From 09032374db8b27f016e2f75bd97cba5b9265d0ea Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 16 Nov 2022 14:35:29 +0200 Subject: [PATCH 39/90] Split arrays to multiline --- tests/Model/Token/CustomerTest.php | 16 +++++++++++++--- tests/Request/GetTokenRequestTest.php | 8 ++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/Model/Token/CustomerTest.php b/tests/Model/Token/CustomerTest.php index 4fd5bb0..154f929 100644 --- a/tests/Model/Token/CustomerTest.php +++ b/tests/Model/Token/CustomerTest.php @@ -13,9 +13,19 @@ class CustomerTest extends TestCase public function validationProvider() { return [ - 'Network address is empty' => [['networkAddress' => ''], 'Network address is empty'], - 'Country code is empty' => [['networkAddress' => '93.174.192.154', - 'countryCode' => ''], 'Country code is empty'] + 'Network address is empty' => [ + [ + 'networkAddress' => '' + ], + 'Network address is empty' + ], + 'Country code is empty' => [ + [ + 'networkAddress' => '93.174.192.154', + 'countryCode' => '' + ], + 'Country code is empty' + ] ]; } diff --git a/tests/Request/GetTokenRequestTest.php b/tests/Request/GetTokenRequestTest.php index e5ad28d..6590ebe 100644 --- a/tests/Request/GetTokenRequestTest.php +++ b/tests/Request/GetTokenRequestTest.php @@ -13,8 +13,12 @@ class GetTokenRequestTest extends TestCase public function validationProvider() { return [ - 'checkout-tokenization-id is empty' => [['checkoutTokenizationId' => ''], - 'checkout-tokenization-id is empty'] + 'checkout-tokenization-id is empty' => [ + [ + 'checkoutTokenizationId' => '' + ], + 'checkout-tokenization-id is empty' + ] ]; } From 4eb9be54a31e4a8c5ab76faa608a5708b8705d31 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Fri, 18 Nov 2022 13:35:09 +0200 Subject: [PATCH 40/90] Improve workflow --- .../{run-phpunit.yaml => run-workflow.yaml} | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) rename .github/workflows/{run-phpunit.yaml => run-workflow.yaml} (70%) diff --git a/.github/workflows/run-phpunit.yaml b/.github/workflows/run-workflow.yaml similarity index 70% rename from .github/workflows/run-phpunit.yaml rename to .github/workflows/run-workflow.yaml index f0116b0..36411da 100644 --- a/.github/workflows/run-phpunit.yaml +++ b/.github/workflows/run-workflow.yaml @@ -1,15 +1,18 @@ -name: Run PHPUnit +name: Run Checks -on: - - push - - pull_request +on: [push, pull_request, fork] jobs: run-checks: runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental }} strategy: matrix: - php-version: ['7.3', '7.4', '8.0', '8.1', latest] + php-version: ['7.3', '7.4', '8.0', '8.1'] + experimental: [false] + include: + - version: 8.2 + experimental: true steps: - uses: actions/checkout@v3 From af43197a19cae0658d06e220bfcf921d32e96d57 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Fri, 18 Nov 2022 13:39:10 +0200 Subject: [PATCH 41/90] Run workflow on all cases instead of 'OR' --- .github/workflows/run-workflow.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-workflow.yaml b/.github/workflows/run-workflow.yaml index 36411da..4c9bb27 100644 --- a/.github/workflows/run-workflow.yaml +++ b/.github/workflows/run-workflow.yaml @@ -1,6 +1,9 @@ name: Run Checks -on: [push, pull_request, fork] +on: + - push + - pull_request + - fork jobs: run-checks: From 5d69112424cf497c1ba530edf6f610680c92e992 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Fri, 18 Nov 2022 13:42:22 +0200 Subject: [PATCH 42/90] Fix 8.2 experimental checks --- .github/workflows/run-workflow.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/run-workflow.yaml b/.github/workflows/run-workflow.yaml index 4c9bb27..de6d86c 100644 --- a/.github/workflows/run-workflow.yaml +++ b/.github/workflows/run-workflow.yaml @@ -4,6 +4,9 @@ on: - push - pull_request - fork + +env: + ACTION_PHP_VERSION: 8.2 jobs: run-checks: From 3abca8d9877267061c564420c12bc5dab9063e81 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Fri, 18 Nov 2022 14:12:25 +0200 Subject: [PATCH 43/90] Attempt to fix 8.2 pipeline --- .github/workflows/run-workflow.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run-workflow.yaml b/.github/workflows/run-workflow.yaml index de6d86c..c217741 100644 --- a/.github/workflows/run-workflow.yaml +++ b/.github/workflows/run-workflow.yaml @@ -4,9 +4,6 @@ on: - push - pull_request - fork - -env: - ACTION_PHP_VERSION: 8.2 jobs: run-checks: @@ -17,8 +14,10 @@ jobs: php-version: ['7.3', '7.4', '8.0', '8.1'] experimental: [false] include: - - version: 8.2 + - php-version: 8.2 experimental: true + env: + ACTION_PHP_VERSION: 8.2 steps: - uses: actions/checkout@v3 From 5fff937a2a98636be2cae7c218405fa59f2f9a91 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Fri, 18 Nov 2022 14:36:46 +0200 Subject: [PATCH 44/90] Add extensions to php8.2 setup --- .github/workflows/run-workflow.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-workflow.yaml b/.github/workflows/run-workflow.yaml index c217741..55599a8 100644 --- a/.github/workflows/run-workflow.yaml +++ b/.github/workflows/run-workflow.yaml @@ -16,6 +16,7 @@ jobs: include: - php-version: 8.2 experimental: true + extensions: json, curl, mbstring env: ACTION_PHP_VERSION: 8.2 steps: From 3c578e6be2df597b5d2d3c8b7ed7d4955c21d6ca Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Fri, 18 Nov 2022 14:39:28 +0200 Subject: [PATCH 45/90] Add extensions as env parameters --- .github/workflows/run-workflow.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-workflow.yaml b/.github/workflows/run-workflow.yaml index 55599a8..3816a12 100644 --- a/.github/workflows/run-workflow.yaml +++ b/.github/workflows/run-workflow.yaml @@ -16,9 +16,9 @@ jobs: include: - php-version: 8.2 experimental: true - extensions: json, curl, mbstring env: - ACTION_PHP_VERSION: 8.2 + - ACTION_PHP_VERSION: 8.2 + - ACTION_PHP_EXTENSIONS: json curl mbstring steps: - uses: actions/checkout@v3 From 4931f7228e509a90aeefacade42fd13eb99aaf40 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Fri, 18 Nov 2022 14:47:42 +0200 Subject: [PATCH 46/90] Remove PHP 8.2 from workflow --- .github/workflows/run-workflow.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/run-workflow.yaml b/.github/workflows/run-workflow.yaml index 3816a12..4d9aca1 100644 --- a/.github/workflows/run-workflow.yaml +++ b/.github/workflows/run-workflow.yaml @@ -13,12 +13,6 @@ jobs: matrix: php-version: ['7.3', '7.4', '8.0', '8.1'] experimental: [false] - include: - - php-version: 8.2 - experimental: true - env: - - ACTION_PHP_VERSION: 8.2 - - ACTION_PHP_EXTENSIONS: json curl mbstring steps: - uses: actions/checkout@v3 From a9df82b7a7dfec82466e95e556d9e99a6caa13d6 Mon Sep 17 00:00:00 2001 From: Tommi Martin <5362449+tommi-martin@users.noreply.github.com> Date: Mon, 19 Dec 2022 14:08:37 +0200 Subject: [PATCH 47/90] Add missing transaction-id to activateInvoice POST request --- CHANGELOG.md | 3 +++ src/Client.php | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bb5181..4d397a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.4.1] - 2022-12-19 +- Add missing transaction property to activateInvoice request + ## [2.4.0] - 2022-11-15 ### Added - Add missing properties to RefundRequest diff --git a/src/Client.php b/src/Client.php index f894ac8..7122b87 100644 --- a/src/Client.php +++ b/src/Client.php @@ -719,7 +719,8 @@ public function activateInvoice(string $transactionId) function ($decoded) { return (new InvoiceActivationResponse()) ->setStatus($decoded->status); - } + }, + $transactionId ); } From abed442625a65170d6d5bdbca0730a7c276b2d94 Mon Sep 17 00:00:00 2001 From: Joonas Loueranta Date: Wed, 11 Jan 2023 09:32:06 +0200 Subject: [PATCH 48/90] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d397a1..4077bbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [2.4.1] - 2022-12-19 +## [2.4.1] - 2023-01-11 - Add missing transaction property to activateInvoice request +- Use PSR-12 standard ## [2.4.0] - 2022-11-15 ### Added From d06c4ed56ddc7690459b4dd52efbb1751ada5e77 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 18:57:51 +0200 Subject: [PATCH 49/90] Remove useless statement --- src/Client.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index d78c0e4..974e773 100644 --- a/src/Client.php +++ b/src/Client.php @@ -167,10 +167,6 @@ public function getGroupedPaymentProviders(int $amount = null, string $locale = // Instantiate providers. $decoded = json_decode($body); - array_map(function ($provider_data) { - return (new Provider())->bindProperties($provider_data); - }, $decoded->providers); - $groups = array_map(function ($group_data) { return [ 'id' => $group_data->id, From 67332e1f703e43f99cba3d9388cde99a17cdc151 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:13:27 +0200 Subject: [PATCH 50/90] Add missing abstract function declaration --- src/PaytrailClient.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/PaytrailClient.php b/src/PaytrailClient.php index 78c10fc..37471ae 100644 --- a/src/PaytrailClient.php +++ b/src/PaytrailClient.php @@ -44,6 +44,18 @@ protected function createHttpClient() $this->http_client = new RequestClient(); } + /** + * A proxy for the Signature class' static method + * to be used via a client instance. + * + * @param array $response The response parameters. + * @param string $body The response body. + * @param string $signature The response signature key. + * + * @throws HmacException + */ + abstract public function validateHmac(array $response = [], string $body = '', string $signature = ''); + /** * A wrapper for post requests. * From 2f4c03f68d626f90449a6d523eb6e6b9a3ba022a Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:18:50 +0200 Subject: [PATCH 51/90] Fix invalid @param annotations --- src/Interfaces/ItemInterface.php | 4 ++-- src/Util/Signature.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Interfaces/ItemInterface.php b/src/Interfaces/ItemInterface.php index b25a202..7f8a031 100644 --- a/src/Interfaces/ItemInterface.php +++ b/src/Interfaces/ItemInterface.php @@ -36,7 +36,7 @@ public function getUnitPrice(): ?int; /** * Set the unit price. * - * @param int/null $unitPrice + * @param int|null $unitPrice * @return ItemInterface Return self to enable chaining. */ public function setUnitPrice(?int $unitPrice): ItemInterface; @@ -51,7 +51,7 @@ public function getUnits(): ?int; /** * Set the units. * - * @param int/null $units + * @param int|null $units * @return ItemInterface Return self to enable chaining. */ public function setUnits(?int $units): ItemInterface; diff --git a/src/Util/Signature.php b/src/Util/Signature.php index f91504a..f34e578 100644 --- a/src/Util/Signature.php +++ b/src/Util/Signature.php @@ -26,10 +26,10 @@ class Signature * @see https://paytrail.github.io/api-documentation/#/?id=headers-and-request-signing * @see https://paytrail.github.io/api-documentation/#/?id=redirect-and-callback-url-parameters * - * @param array[string] $params HTTP headers in an associative array. - * + * @param array $params HTTP headers in an associative array. * @param string $body HTTP request body, empty string for GET requests * @param string $secretKey The merchant secret key. + * * @return string SHA-256 HMAC */ public static function calculateHmac(array $params = [], string $body = '', string $secretKey = '') From 912b0b3a662bb4e914db5798c4a415aa15b05db2 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:19:01 +0200 Subject: [PATCH 52/90] Fix wrong @return annotation --- src/Model/Commission.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Model/Commission.php b/src/Model/Commission.php index d545787..b03bdc1 100644 --- a/src/Model/Commission.php +++ b/src/Model/Commission.php @@ -89,8 +89,6 @@ public function setAmount(int $amount): Commission /** * The getter for the amount. - * - * @return string */ public function getAmount(): int { From d5b6dbfc52074365e048867e50d1a7fd95395ba5 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:21:49 +0200 Subject: [PATCH 53/90] Remove useless inherited variable declaration --- src/Exception/ValidationException.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Exception/ValidationException.php b/src/Exception/ValidationException.php index fd29973..9d720b8 100644 --- a/src/Exception/ValidationException.php +++ b/src/Exception/ValidationException.php @@ -19,13 +19,6 @@ */ class ValidationException extends \Exception { - /** - * Holds the previous NestedValidationException instance. - * - * $var NestedValidationException - */ - protected $previous; - /** * Holds all error messages. * From 8e11773b0a4339e99b767b7307a1a266d0ca05fb Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:23:30 +0200 Subject: [PATCH 54/90] Remove references to Respect\Validation --- src/Exception/ValidationException.php | 2 -- src/Interfaces/AddressInterface.php | 2 +- src/Interfaces/CallbackUrlInterface.php | 2 +- src/Interfaces/CommissionInterface.php | 2 +- src/Interfaces/CustomerInterface.php | 2 +- src/Interfaces/ItemInterface.php | 2 +- src/Interfaces/PaymentRequestInterface.php | 2 +- src/Model/Address.php | 2 +- src/Model/CallbackUrl.php | 2 +- src/Model/Item.php | 4 ++-- src/Model/RefundItem.php | 2 +- src/Model/Token/Customer.php | 2 +- src/Request/AbstractPaymentRequest.php | 2 +- src/Request/AddCardFormRequest.php | 2 +- src/Request/CitPaymentRequest.php | 2 +- src/Request/EmailRefundRequest.php | 3 +-- src/Request/GetTokenRequest.php | 2 +- src/Request/MitPaymentRequest.php | 2 +- src/Request/PaymentStatusRequest.php | 2 +- src/Request/RefundRequest.php | 2 +- src/Request/RevertPaymentAuthHoldRequest.php | 2 +- src/Request/ShopInShopPaymentRequest.php | 2 +- 22 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/Exception/ValidationException.php b/src/Exception/ValidationException.php index 9d720b8..0fe0e9d 100644 --- a/src/Exception/ValidationException.php +++ b/src/Exception/ValidationException.php @@ -10,8 +10,6 @@ /** * Class ValidationException - * This exception is a simple wrapper for - * a Respect\Validation NestedValidationException instance. * * This exception holds the general expection message * diff --git a/src/Interfaces/AddressInterface.php b/src/Interfaces/AddressInterface.php index 7f8c5b5..7091983 100644 --- a/src/Interfaces/AddressInterface.php +++ b/src/Interfaces/AddressInterface.php @@ -20,7 +20,7 @@ interface AddressInterface { /** - * Validates with Respect\Validation library and throws exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Interfaces/CallbackUrlInterface.php b/src/Interfaces/CallbackUrlInterface.php index d8ef323..e3a5806 100644 --- a/src/Interfaces/CallbackUrlInterface.php +++ b/src/Interfaces/CallbackUrlInterface.php @@ -20,7 +20,7 @@ interface CallbackUrlInterface { /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Interfaces/CommissionInterface.php b/src/Interfaces/CommissionInterface.php index c1ccff2..1a28716 100644 --- a/src/Interfaces/CommissionInterface.php +++ b/src/Interfaces/CommissionInterface.php @@ -21,7 +21,7 @@ interface CommissionInterface { /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Interfaces/CustomerInterface.php b/src/Interfaces/CustomerInterface.php index b501f83..ea5c7b6 100644 --- a/src/Interfaces/CustomerInterface.php +++ b/src/Interfaces/CustomerInterface.php @@ -20,7 +20,7 @@ interface CustomerInterface { /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Interfaces/ItemInterface.php b/src/Interfaces/ItemInterface.php index 7f8a031..25b3a61 100644 --- a/src/Interfaces/ItemInterface.php +++ b/src/Interfaces/ItemInterface.php @@ -20,7 +20,7 @@ interface ItemInterface { /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Interfaces/PaymentRequestInterface.php b/src/Interfaces/PaymentRequestInterface.php index 16dfea1..b4ab3f0 100644 --- a/src/Interfaces/PaymentRequestInterface.php +++ b/src/Interfaces/PaymentRequestInterface.php @@ -20,7 +20,7 @@ interface PaymentRequestInterface { /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Model/Address.php b/src/Model/Address.php index 289e6d4..6fcb9c3 100644 --- a/src/Model/Address.php +++ b/src/Model/Address.php @@ -25,7 +25,7 @@ class Address implements \JsonSerializable, AddressInterface use JsonSerializable; /** - * Validates with Respect\Validation library and throws exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Model/CallbackUrl.php b/src/Model/CallbackUrl.php index 8dc92da..480ba67 100644 --- a/src/Model/CallbackUrl.php +++ b/src/Model/CallbackUrl.php @@ -25,7 +25,7 @@ class CallbackUrl implements \JsonSerializable, CallbackUrlInterface use JsonSerializable; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Model/Item.php b/src/Model/Item.php index 3b05553..8e870c4 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -363,7 +363,7 @@ public function setCommission(?CommissionInterface $commission): ItemInterface } /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ @@ -393,7 +393,7 @@ public function validate() } /** - * Validates shop-in-shop props with Respect\Validation library and throws an exception for invalid objects + * Validates shop-in-shop props and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Model/RefundItem.php b/src/Model/RefundItem.php index 10b5ca3..88f4473 100644 --- a/src/Model/RefundItem.php +++ b/src/Model/RefundItem.php @@ -23,7 +23,7 @@ class RefundItem implements \JsonSerializable use JsonSerializable; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Model/Token/Customer.php b/src/Model/Token/Customer.php index 80580d5..fb0033f 100644 --- a/src/Model/Token/Customer.php +++ b/src/Model/Token/Customer.php @@ -22,7 +22,7 @@ class Customer implements \JsonSerializable use ObjectPropertyConverter; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/AbstractPaymentRequest.php b/src/Request/AbstractPaymentRequest.php index 581a4fa..b952b0e 100644 --- a/src/Request/AbstractPaymentRequest.php +++ b/src/Request/AbstractPaymentRequest.php @@ -32,7 +32,7 @@ abstract class AbstractPaymentRequest implements \JsonSerializable, PaymentReque use JsonSerializable; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/AddCardFormRequest.php b/src/Request/AddCardFormRequest.php index 03a5dff..98fd7a5 100644 --- a/src/Request/AddCardFormRequest.php +++ b/src/Request/AddCardFormRequest.php @@ -52,7 +52,7 @@ class AddCardFormRequest implements \JsonSerializable protected $signature; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/CitPaymentRequest.php b/src/Request/CitPaymentRequest.php index 8a9f9c0..2ead458 100644 --- a/src/Request/CitPaymentRequest.php +++ b/src/Request/CitPaymentRequest.php @@ -24,7 +24,7 @@ class CitPaymentRequest extends AbstractPaymentRequest implements TokenPaymentRe protected $token; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/EmailRefundRequest.php b/src/Request/EmailRefundRequest.php index af32a6a..a4d4bd3 100644 --- a/src/Request/EmailRefundRequest.php +++ b/src/Request/EmailRefundRequest.php @@ -25,9 +25,8 @@ class EmailRefundRequest extends RefundRequest protected $email; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * - * @throws NestedValidationException Thrown when the validate() fails. * @throws ValidationException */ public function validate() diff --git a/src/Request/GetTokenRequest.php b/src/Request/GetTokenRequest.php index 72641ec..93aaba7 100644 --- a/src/Request/GetTokenRequest.php +++ b/src/Request/GetTokenRequest.php @@ -22,7 +22,7 @@ class GetTokenRequest implements \JsonSerializable protected $checkoutTokenizationId; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/MitPaymentRequest.php b/src/Request/MitPaymentRequest.php index 35d8b3f..3fecad9 100644 --- a/src/Request/MitPaymentRequest.php +++ b/src/Request/MitPaymentRequest.php @@ -24,7 +24,7 @@ class MitPaymentRequest extends AbstractPaymentRequest implements TokenPaymentRe protected $token; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/PaymentStatusRequest.php b/src/Request/PaymentStatusRequest.php index 0bc74df..25b0713 100644 --- a/src/Request/PaymentStatusRequest.php +++ b/src/Request/PaymentStatusRequest.php @@ -19,7 +19,7 @@ class PaymentStatusRequest protected $transactionId; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/RefundRequest.php b/src/Request/RefundRequest.php index 5c1cba8..4b34d83 100644 --- a/src/Request/RefundRequest.php +++ b/src/Request/RefundRequest.php @@ -23,7 +23,7 @@ class RefundRequest implements \JsonSerializable use JsonSerializable; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/RevertPaymentAuthHoldRequest.php b/src/Request/RevertPaymentAuthHoldRequest.php index 70eaa84..4ce275f 100644 --- a/src/Request/RevertPaymentAuthHoldRequest.php +++ b/src/Request/RevertPaymentAuthHoldRequest.php @@ -26,7 +26,7 @@ class RevertPaymentAuthHoldRequest implements \JsonSerializable protected $transactionId; /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ diff --git a/src/Request/ShopInShopPaymentRequest.php b/src/Request/ShopInShopPaymentRequest.php index b3c70f3..90634a1 100644 --- a/src/Request/ShopInShopPaymentRequest.php +++ b/src/Request/ShopInShopPaymentRequest.php @@ -20,7 +20,7 @@ class ShopInShopPaymentRequest extends PaymentRequest { /** - * Validates with Respect\Validation library and throws an exception for invalid objects + * Validates properties and throws an exception for invalid values * * @throws ValidationException */ From 921efdb4cd1d848e20bd7462f286bfb7bb44e15a Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:24:18 +0200 Subject: [PATCH 55/90] Fix wrong @var annotations --- src/Model/Item.php | 2 +- src/Request/AbstractPaymentRequest.php | 12 ++++++------ src/Request/RefundRequest.php | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 8e870c4..d2a8b02 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -97,7 +97,7 @@ class Item implements \JsonSerializable, ItemInterface * Merchant ID for the item. * Required for Shop-in-Shop payments, do not use for normal payments. * - * @var int + * @var string|null */ protected $merchant; diff --git a/src/Request/AbstractPaymentRequest.php b/src/Request/AbstractPaymentRequest.php index b952b0e..01cef0d 100644 --- a/src/Request/AbstractPaymentRequest.php +++ b/src/Request/AbstractPaymentRequest.php @@ -156,42 +156,42 @@ public function validate() /** * Array of items. * - * @var Item[] + * @var ItemInterface[] */ protected $items; /** * Customer information. * - * @var Customer + * @var CustomerInterface */ protected $customer; /** * Delivery address. * - * @var Address + * @var AddressInterface */ protected $deliveryAddress; /** * Invoicing address. * - * @var Address + * @var AddressInterface */ protected $invoicingAddress; /** * Where to redirect browser after a payment is paid or cancelled. * - * @var CallbackUrl; + * @var CallbackUrlInterface */ protected $redirectUrls; /** * Which url to ping after this payment is paid or cancelled. * - * @var CallbackUrl; + * @var CallbackUrlInterface */ protected $callbackUrls; diff --git a/src/Request/RefundRequest.php b/src/Request/RefundRequest.php index 4b34d83..5ac8af9 100644 --- a/src/Request/RefundRequest.php +++ b/src/Request/RefundRequest.php @@ -96,21 +96,21 @@ public function validate() /** * Refund recipient email address. * - * @var $mail + * @var string|null $email */ protected $email; /** * Merchant unique identifier for the refund. * - * @var $refundStamp + * @var string|null $refundStamp */ protected $refundStamp; /** * Refund reference. * - * @var $refundReference + * @var string|null $refundReference */ protected $refundReference; From 6d18422584328789030424ab38af33a23431f7fa Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:27:01 +0200 Subject: [PATCH 56/90] Add missing use --- src/Request/ShopInShopPaymentRequest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Request/ShopInShopPaymentRequest.php b/src/Request/ShopInShopPaymentRequest.php index 90634a1..7b63e3a 100644 --- a/src/Request/ShopInShopPaymentRequest.php +++ b/src/Request/ShopInShopPaymentRequest.php @@ -6,6 +6,7 @@ namespace Paytrail\SDK\Request; +use Paytrail\SDK\Exception\ValidationException; use Paytrail\SDK\Model\Item; /** From b69d532b8c2b17953493cd803171e6daa75c2cd7 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 19:59:41 +0200 Subject: [PATCH 57/90] Fix wrong class used in PaymentResponse --- src/Response/PaymentResponse.php | 4 ++-- tests/PaymentRequestTestCase.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Response/PaymentResponse.php b/src/Response/PaymentResponse.php index d280ab4..d1a8adb 100644 --- a/src/Response/PaymentResponse.php +++ b/src/Response/PaymentResponse.php @@ -141,8 +141,8 @@ public function getGroups(): array public function setGroups(array $groups): PaymentResponse { $this->groups = array_map(function ($group) { - if (! $group instanceof Provider) { - return (new Provider())->bindProperties($group); + if (! $group instanceof PaymentMethodGroup) { + return (new PaymentMethodGroup())->bindProperties($group); } return $group; diff --git a/tests/PaymentRequestTestCase.php b/tests/PaymentRequestTestCase.php index 730ba87..0928266 100644 --- a/tests/PaymentRequestTestCase.php +++ b/tests/PaymentRequestTestCase.php @@ -8,6 +8,7 @@ use Paytrail\SDK\Exception\HmacException; use Paytrail\SDK\Exception\ValidationException; use Paytrail\SDK\Interfaces\PaymentRequestInterface; +use Paytrail\SDK\Model\PaymentMethodGroup; use Paytrail\SDK\Request\PaymentRequest; use Paytrail\SDK\Request\ShopInShopPaymentRequest; use Paytrail\SDK\Response\PaymentResponse; @@ -98,6 +99,7 @@ public static function assertPaymentResponseIsValid(PaymentResponse $paymentResp static::assertNotEmpty($paymentResponse->getTerms()); static::assertNotEmpty($paymentResponse->getReference()); static::assertIsArray($paymentResponse->getGroups()); + static::assertContainsOnlyInstancesOf(PaymentMethodGroup::class, $paymentResponse->getGroups()); static::assertIsArray($paymentResponse->getProviders()); } } From 8232d0d68f51795480fc2a4cf53bab06109a15c1 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 20:03:29 +0200 Subject: [PATCH 58/90] Don't use dynamic properties (deprecated in PHP 8.2) --- tests/ClientTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index adf23a5..6cc088c 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -29,6 +29,10 @@ class ClientTest extends PaymentRequestTestCase protected $item2; + protected $shopInShopItem; + + protected $shopInShopItem2; + protected $redirect; protected $callback; From 6a3f95f178c8c2d2b962f17225b010bcd3187b52 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 20:08:30 +0200 Subject: [PATCH 59/90] Fix return type --- tests/Request/PaymentRequestTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Request/PaymentRequestTest.php b/tests/Request/PaymentRequestTest.php index 1da8411..20b26be 100644 --- a/tests/Request/PaymentRequestTest.php +++ b/tests/Request/PaymentRequestTest.php @@ -5,6 +5,7 @@ namespace Tests\Request; use Paytrail\SDK\Exception\ValidationException; +use Paytrail\SDK\Interfaces\PaymentRequestInterface; use Paytrail\SDK\Model\CallbackUrl; use Paytrail\SDK\Model\Customer; use Paytrail\SDK\Model\Item; @@ -37,7 +38,7 @@ public function testPaymentRequestWithoutItems(): void } } - private function getPaymentRequest(): PaymentRequest + private function getPaymentRequest(): PaymentRequestInterface { $payment = (new PaymentRequest()) ->setAmount(30) From fa438c61f89a057017bf807ef442b5378cf921e0 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Thu, 26 Jan 2023 13:08:27 +0200 Subject: [PATCH 60/90] Fix closure param type --- src/Request/AbstractPaymentRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Request/AbstractPaymentRequest.php b/src/Request/AbstractPaymentRequest.php index 01cef0d..93e5c6b 100644 --- a/src/Request/AbstractPaymentRequest.php +++ b/src/Request/AbstractPaymentRequest.php @@ -62,7 +62,7 @@ public function validate() }); // Count the total amount of the payment. - $items_total = array_reduce($this->getItems(), function ($carry = 0, ?Item $item = null) { + $items_total = array_reduce($this->getItems(), function ($carry = 0, ?ItemInterface $item = null) { if ($item === null) { return $carry; } From 62c5684f62cc7ef90ee55b10e653c9a414d7b3dc Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 20:15:25 +0200 Subject: [PATCH 61/90] Install phpstan static analyzer --- composer.json | 1 + phpstan.neon | 5 +++++ src/PaytrailClient.php | 3 +++ 3 files changed, 9 insertions(+) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index b39aad9..799d4bd 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "squizlabs/php_codesniffer": "^3.6", "phpcompatibility/php-compatibility": "^9.3", "phpmd/phpmd": "^2.10", + "phpstan/phpstan": "1.9.14", "mockery/mockery": "^1.5", "guzzlehttp/guzzle": "^7.0|^6.0" }, diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..749a32d --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 3 + paths: + - src + - tests diff --git a/src/PaytrailClient.php b/src/PaytrailClient.php index 37471ae..752d2c6 100644 --- a/src/PaytrailClient.php +++ b/src/PaytrailClient.php @@ -98,8 +98,11 @@ protected function post( $headers = $this->reduceHeaders($response->getHeaders()); $this->validateHmac($headers, $body, $headers['signature'] ?? ''); } else { + // @phpstan-ignore-next-line FIXME $mac = $this->calculateHmac($data->toArray()); + // @phpstan-ignore-next-line FIXME $data->setSignature($mac); + // @phpstan-ignore-next-line FIXME $body = json_encode($data->toArray(), JSON_UNESCAPED_SLASHES); $response = $this->http_client->request('POST', $uri, [ From be1ee4b09b3d46591f393624d776285026420d3c Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 20:24:24 +0200 Subject: [PATCH 62/90] Run phpstan in workflow --- .github/workflows/run-workflow.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/run-workflow.yaml b/.github/workflows/run-workflow.yaml index 4d9aca1..4c75e86 100644 --- a/.github/workflows/run-workflow.yaml +++ b/.github/workflows/run-workflow.yaml @@ -28,6 +28,14 @@ jobs: - name: Run linter run: composer lint + - name: Run phpstan + uses: php-actions/phpstan@v3.0.1 + with: + php_version: ${{ matrix.php-version }} + version: 1.9.14 + configuration: phpstan.neon + memory_limit: 256M + - name: Run tests uses: php-actions/phpunit@v3.0.0 with: From b3937f503eb2ade76e4340f58e0587eea73f2f22 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Thu, 26 Jan 2023 13:15:15 +0200 Subject: [PATCH 63/90] Add script "composer analyze" --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 799d4bd..b362b00 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,9 @@ } }, "scripts": { + "analyze": [ + "vendor/bin/phpstan" + ], "post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility", "post-update-cmd" : "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility", "test": "\"vendor/bin/phpunit\"", From d90533811bc979edb31647e12c7e6ec0e7628a31 Mon Sep 17 00:00:00 2001 From: Joonas Loueranta Date: Fri, 3 Feb 2023 08:45:39 +0200 Subject: [PATCH 64/90] Add disclaimer --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index a9a25da..2665036 100644 --- a/README.md +++ b/README.md @@ -111,3 +111,8 @@ List of `Client::class` methods | revertPaymentAuthorizationHold() | Revert existing Mit or CiT authorization hold | | getSettlements() | Request settlements | | requestPaymentReport() | Request payment report | + + +--- + +**_Disclaimer:_** *This open source project is made available to assist coders in getting started with our API. However, we do not provide any warranty or guarantee that the code will work as intended and offer limited support for it. Use at your own risk.* From 814b630e3aa5d7516716dbd00f85c0a686079a92 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Tue, 24 Jan 2023 13:18:12 +0200 Subject: [PATCH 65/90] Add missing validation, fix validation exception text --- src/Client.php | 2 +- src/Request/ReportRequest.php | 18 ++++++++++ tests/ClientTest.php | 66 +++++++++++++++++++++++------------ 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/src/Client.php b/src/Client.php index 974e773..04c4883 100644 --- a/src/Client.php +++ b/src/Client.php @@ -641,7 +641,7 @@ public function getSettlements( if ($endDate) { if ((new \DateTime())->createFromFormat('Y-m-d', $endDate) == false) { - throw new ValidationException('startDate must be in Y-m-d format'); + throw new ValidationException('endDate must be in Y-m-d format'); } } diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index 8e5ce99..9b3d0b9 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -59,6 +59,24 @@ public function validate() throw new ValidationException('ReportFields must be type of array'); } + if (!empty($props['startDate'])) { + if (!(new \DateTime())->createFromFormat('Y-m-d', $props['startDate'])) { + throw new ValidationException('startDate must be in Y-m-d format'); + } + } + + if (!empty($props['endDate'])) { + if (!(new \DateTime())->createFromFormat('Y-m-d', $props['endDate'])) { + throw new ValidationException('endDate must be in Y-m-d format'); + } + } + + if (!empty($props['startDate']) && !empty($props['endDate'])) { + if ((new \DateTime())->createFromFormat('Y-m-d', $props['startDate']) > (new \DateTime())->createFromFormat('Y-m-d', $props['endDate'])) { + throw new ValidationException('startDate cannot be lower than endDate'); + } + } + return true; } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 6cc088c..55b24bd 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -25,36 +25,25 @@ class ClientTest extends PaymentRequestTestCase { - protected $item; + private $item; + private $item2; + private $shopInShopItem; + private $shopInShopItem2; + private $redirect; + private $callback; + private $customer; + private $address; + private $paymentRequest; + private $shopInShopPaymentRequest; + private $citPaymentRequest; + private $mitPaymentRequest; - protected $item2; - - protected $shopInShopItem; - - protected $shopInShopItem2; - - protected $redirect; - - protected $callback; - - protected $customer; - - protected $address; - - protected $paymentRequest; - - protected $shopInShopPaymentRequest; - - protected $citPaymentRequest; - - protected $mitPaymentRequest; protected function setUp(): void { parent::setUp(); $this->item = (new Item()) - ->setDeliveryDate('2020-12-12') ->setProductCode('pr1') ->setVatPercentage(24) ->setReference('itemReference123') @@ -574,4 +563,35 @@ public function testRequestPaymentReportThrowsExceptionWhenUrlInvalid() ->setCallbackUrl('invalid-url'); $this->client->requestPaymentReport($reportRequest); } + + public function testRequestPaymentReportThrowsExceptionWhenEndDateIsLowerThanStartDate() + { + $this->expectException(ValidationException::class); + $reportRequest = (new ReportRequest()) + ->setRequestType('json') + ->setCallbackUrl('https://nourl.test') + ->setStartDate('2023-01-20') + ->setEndDate('2023-01-01'); + $this->client->requestPaymentReport($reportRequest); + } + + public function testRequestPaymentReportThrowsExceptionWhenStartDateIsInWrongFormat() + { + $this->expectException(ValidationException::class); + $reportRequest = (new ReportRequest()) + ->setRequestType('json') + ->setCallbackUrl('https://nourl.test') + ->setStartDate('1.1.2023'); + $this->client->requestPaymentReport($reportRequest); + } + + public function testRequestPaymentReportThrowsExceptionWhenEndDateIsInWrongFormat() + { + $this->expectException(ValidationException::class); + $reportRequest = (new ReportRequest()) + ->setRequestType('json') + ->setCallbackUrl('https://nourl.test') + ->setEndDate('1.1.2023'); + $this->client->requestPaymentReport($reportRequest); + } } From 5e04bd25c90a2e432790c13a7f582855fe5406eb Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Tue, 24 Jan 2023 13:26:00 +0200 Subject: [PATCH 66/90] Split long if statement to two lines (PSR-12 lint error) --- src/Request/ReportRequest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index 9b3d0b9..d7c5853 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -72,7 +72,10 @@ public function validate() } if (!empty($props['startDate']) && !empty($props['endDate'])) { - if ((new \DateTime())->createFromFormat('Y-m-d', $props['startDate']) > (new \DateTime())->createFromFormat('Y-m-d', $props['endDate'])) { + if ( + (new \DateTime())->createFromFormat('Y-m-d', $props['startDate']) + > (new \DateTime())->createFromFormat('Y-m-d', $props['endDate']) + ) { throw new ValidationException('startDate cannot be lower than endDate'); } } From 2781c68fa6bacd35c89110f41c4d4316e8e865d6 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 15 Feb 2023 14:26:20 +0200 Subject: [PATCH 67/90] Remove platform requirement ignoring from composer install --- .github/workflows/run-workflow.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/run-workflow.yaml b/.github/workflows/run-workflow.yaml index 4c75e86..548e835 100644 --- a/.github/workflows/run-workflow.yaml +++ b/.github/workflows/run-workflow.yaml @@ -23,7 +23,6 @@ jobs: uses: php-actions/composer@v6 with: php_version: ${{ matrix.php-version }} - args: --ignore-platform-reqs - name: Run linter run: composer lint From 3b998dd5bf42d6fca3e21fc1b9b38ec0b3d78e85 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 15 Feb 2023 15:24:04 +0200 Subject: [PATCH 68/90] Remove phpunit 9 for now --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b362b00..950f10e 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "ext-curl": "*" }, "require-dev": { - "phpunit/phpunit": "^9.0 | ^8.4", + "phpunit/phpunit": "^8.4", "squizlabs/php_codesniffer": "^3.6", "phpcompatibility/php-compatibility": "^9.3", "phpmd/phpmd": "^2.10", From 76a73dc6fc630119844f616a6f6ef41dc99da9ca Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Fri, 17 Feb 2023 08:39:32 +0200 Subject: [PATCH 69/90] Fix workflow --- .github/workflows/run-workflow.yaml | 8 ++++++-- composer.json | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-workflow.yaml b/.github/workflows/run-workflow.yaml index 548e835..84dd810 100644 --- a/.github/workflows/run-workflow.yaml +++ b/.github/workflows/run-workflow.yaml @@ -4,14 +4,17 @@ on: - push - pull_request - fork - + jobs: run-checks: runs-on: ubuntu-latest + permissions: + contents: read + packages: write continue-on-error: ${{ matrix.experimental }} strategy: matrix: - php-version: ['7.3', '7.4', '8.0', '8.1'] + php-version: ['7.3', '7.4', '8.0', '8.1', '8.2'] experimental: [false] steps: - uses: actions/checkout@v3 @@ -39,4 +42,5 @@ jobs: uses: php-actions/phpunit@v3.0.0 with: php_version: ${{ matrix.php-version }} + version: 9 configuration: phpunit.xml diff --git a/composer.json b/composer.json index 950f10e..ceb8b26 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "ext-curl": "*" }, "require-dev": { - "phpunit/phpunit": "^8.4", + "phpunit/phpunit": "^9.0", "squizlabs/php_codesniffer": "^3.6", "phpcompatibility/php-compatibility": "^9.3", "phpmd/phpmd": "^2.10", From 167ab2bf3f7c23c63a6f5ae02e5a6d88814be020 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Fri, 17 Feb 2023 10:45:46 +0200 Subject: [PATCH 70/90] Fix deprecated methods --- tests/ClientTest.php | 34 ++++++++++++++++---------------- tests/PaymentRequestTestCase.php | 4 ---- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 55b24bd..9fc5b64 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -248,9 +248,9 @@ public function testGetTokenRequest() ] ]; - $this->assertObjectHasAttribute('token', $response); - $this->assertObjectHasAttribute('card', $response); - $this->assertObjectHasAttribute('customer', $response); + $this->assertNotEmpty($response->getToken()); + $this->assertNotEmpty($response->getCard()); + $this->assertNotEmpty($response->getCustomer()); $this->assertJsonStringEqualsJsonString(json_encode($expectedArray), json_encode($responseJsonData)); } @@ -265,7 +265,7 @@ public function testCitPaymentRequestCharge() $response = $client->createCitPaymentCharge($citPaymentRequest); - $this->assertObjectHasAttribute('transactionId', $response); + $this->assertNotEmpty($response->getTransactionId()); $transactionId = $response->getTransactionId(); @@ -291,7 +291,7 @@ public function testMitPaymentRequestCharge() $response = $client->createMitPaymentCharge($mitPaymentRequest); - $this->assertObjectHasAttribute('transactionId', $response); + $this->assertNotEmpty($response->getTransactionId()); $transactionId = $response->getTransactionId(); @@ -317,8 +317,8 @@ public function testCitPaymentRequestCharge3DS() $response = $client->createCitPaymentCharge($citPaymentRequest); - $this->assertObjectHasAttribute('transactionId', $response); - $this->assertObjectHasAttribute('threeDSecureUrl', $response); + $this->assertNotEmpty($response->getTransactionId()); + $this->assertNotEmpty($response->getThreeDSecureUrl()); } public function testCitPaymentRequestAuthorizationHold() @@ -332,7 +332,7 @@ public function testCitPaymentRequestAuthorizationHold() $response = $client->createCitPaymentAuthorizationHold($citPaymentRequest); - $this->assertObjectHasAttribute('transactionId', $response); + $this->assertNotEmpty($response->getTransactionId()); $transactionId = $response->getTransactionId(); @@ -358,7 +358,7 @@ public function testMitPaymentRequestAuthorizationHold() $response = $client->createMitPaymentAuthorizationHold($mitPaymentRequest); - $this->assertObjectHasAttribute('transactionId', $response); + $this->assertNotEmpty($response->getTransactionId()); $transactionId = $response->getTransactionId(); @@ -384,8 +384,8 @@ public function testCitPaymentRequestAuthorizationHold3DS() $response = $client->createCitPaymentAuthorizationHold($citPaymentRequest); - $this->assertObjectHasAttribute('transactionId', $response); - $this->assertObjectHasAttribute('threeDSecureUrl', $response); + $this->assertNotEmpty($response->getTransactionId()); + $this->assertNotEmpty($response->getThreeDSecureUrl()); } public function testCitPaymentRequestCommit() @@ -399,7 +399,7 @@ public function testCitPaymentRequestCommit() $this->assertTrue($citPaymentRequest->validate()); $response = $client->createCitPaymentCommit($citPaymentRequest, $transactionId); - $this->assertObjectHasAttribute('transactionId', $response); + $this->assertNotEmpty($response->getTransactionId()); } public function testMitPaymentRequestCommit() @@ -413,7 +413,7 @@ public function testMitPaymentRequestCommit() $this->assertTrue($mitPaymentRequest->validate()); $response = $client->createMitPaymentCommit($mitPaymentRequest, $transactionId); - $this->assertObjectHasAttribute('transactionId', $response); + $this->assertNotEmpty($response->getTransactionId()); } public function testRevertCitPaymentAuthorizationHold() @@ -427,7 +427,7 @@ public function testRevertCitPaymentAuthorizationHold() // Create new CitPaymentAuthorizationHold $response = $client->createCitPaymentAuthorizationHold($citPaymentRequest); - $this->assertObjectHasAttribute('transactionId', $response); + $this->assertNotEmpty($response->getTransactionId()); $transactionId = $response->getTransactionId(); @@ -438,7 +438,7 @@ public function testRevertCitPaymentAuthorizationHold() $this->assertTrue($revertCitPaymentAuthHoldRequest->validate()); $revertResponse = $client->revertPaymentAuthorizationHold($revertCitPaymentAuthHoldRequest); - $this->assertObjectHasAttribute('transactionId', $revertResponse); + $this->assertNotEmpty($revertResponse->getTransactionId()); } public function testRevertMitPaymentAuthorizationHold() @@ -452,7 +452,7 @@ public function testRevertMitPaymentAuthorizationHold() // Create new CitPaymentAuthorizationHold $response = $client->createMitPaymentAuthorizationHold($mitPaymentRequest); - $this->assertObjectHasAttribute('transactionId', $response); + $this->assertNotEmpty($response->getTransactionId()); $transactionId = $response->getTransactionId(); @@ -463,7 +463,7 @@ public function testRevertMitPaymentAuthorizationHold() $this->assertTrue($revertCitPaymentAuthHoldRequest->validate()); $revertResponse = $client->revertPaymentAuthorizationHold($revertCitPaymentAuthHoldRequest); - $this->assertObjectHasAttribute('transactionId', $revertResponse); + $this->assertNotEmpty($revertResponse->getTransactionId()); } public function testRevertCitPaymentAuthorizationHoldException() diff --git a/tests/PaymentRequestTestCase.php b/tests/PaymentRequestTestCase.php index 0928266..860f37a 100644 --- a/tests/PaymentRequestTestCase.php +++ b/tests/PaymentRequestTestCase.php @@ -90,10 +90,6 @@ protected function createShopInShopPayment(PaymentRequestInterface $paymentReque */ public static function assertPaymentResponseIsValid(PaymentResponse $paymentResponse): void { - foreach (['transactionId', 'href', 'terms', 'groups', 'reference', 'providers'] as $field) { - static::assertObjectHasAttribute($field, $paymentResponse); - } - static::assertNotEmpty($paymentResponse->getTransactionId()); static::assertNotEmpty($paymentResponse->getHref()); static::assertNotEmpty($paymentResponse->getTerms()); From 838bdeb2eb99c30a04428cf5d92831c584602134 Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Wed, 25 Jan 2023 23:12:51 +0200 Subject: [PATCH 71/90] Fail phpunit tests on deprecation notices --- phpunit.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index c93f96a..039a248 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,10 @@ - + tests From ae22936d259190131dbf679623e5010acc7305c8 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 22 Feb 2023 12:55:29 +0200 Subject: [PATCH 72/90] Return empy array instead of null in PaymentResponse::getProviders() --- src/Response/PaymentResponse.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Response/PaymentResponse.php b/src/Response/PaymentResponse.php index d1a8adb..5ec4671 100644 --- a/src/Response/PaymentResponse.php +++ b/src/Response/PaymentResponse.php @@ -173,11 +173,11 @@ public function setReference(?string $reference): PaymentResponse /** * Get providers. * - * @return Provider[]|null + * @return Provider[] */ - public function getProviders(): ?array + public function getProviders(): array { - return $this->providers; + return $this->providers ?? []; } /** From 2bbe961b13b6dd844555ad84d9d85900c7d86738 Mon Sep 17 00:00:00 2001 From: Joonas Loueranta Date: Wed, 22 Feb 2023 13:35:50 +0200 Subject: [PATCH 73/90] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4077bbf..fc6afcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.3.2] - 2023-02-22 +### Added +- PHPStan (static analyser) added in workflow +### Fixed +- Code quality improvements and other fixes + ## [2.4.1] - 2023-01-11 - Add missing transaction property to activateInvoice request - Use PSR-12 standard From 4c651adbb1b2f3e0f50efd10c53357ee1cd42768 Mon Sep 17 00:00:00 2001 From: Joonas Loueranta Date: Wed, 22 Feb 2023 13:45:26 +0200 Subject: [PATCH 74/90] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc6afcd..3b5f6c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [2.3.2] - 2023-02-22 ### Added - PHPStan (static analyser) added in workflow +- Tests are now run also on PHP 8.2 ### Fixed - Code quality improvements and other fixes From 942c385cf0f8a8c1b0d081d39d8ba48bea983880 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 1 Mar 2023 10:03:44 +0200 Subject: [PATCH 75/90] Add proper settlement endpoint, deprecate old methods --- src/Client.php | 26 +++++++ src/Model/Item.php | 5 ++ src/Request/SettlementRequest.php | 119 ++++++++++++++++++++++++++++++ tests/ClientTest.php | 12 ++- 4 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 src/Request/SettlementRequest.php diff --git a/src/Client.php b/src/Client.php index 04c4883..16e2018 100644 --- a/src/Client.php +++ b/src/Client.php @@ -15,6 +15,7 @@ use Paytrail\SDK\Request\MitPaymentRequest; use Paytrail\SDK\Request\PaymentRequest; use Paytrail\SDK\Request\ReportRequest; +use Paytrail\SDK\Request\SettlementRequest; use Paytrail\SDK\Request\ShopInShopPaymentRequest; use Paytrail\SDK\Request\PaymentStatusRequest; use Paytrail\SDK\Request\RefundRequest; @@ -615,6 +616,29 @@ function ($decoded) { return $revertPaymentAuthHoldResponse; } + /** + * Get settlements for merchant + * + * @param SettlementRequest $settlementRequest + * @return mixed + * @throws HmacException + * @throws ValidationException + */ + public function requestSettlements(SettlementRequest $settlementRequest) + { + $this->validateRequestItem($settlementRequest); + + $uri = '/settlements'; + + return $this->get( + $uri, + function ($decoded) { + return (new SettlementResponse()) + ->setSettlements($decoded); + } + ); + } + /** * Get settlements for merchant * @@ -625,6 +649,8 @@ function ($decoded) { * @param int|null $subMerchant * @return SettlementResponse * @throws HmacException + * + * @deprecated Method deprecated, use requestSettlements() */ public function getSettlements( ?string $startDate = null, diff --git a/src/Model/Item.php b/src/Model/Item.php index d2a8b02..117d403 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -59,6 +59,7 @@ class Item implements \JsonSerializable, ItemInterface * The delivery date. * * @var string + * @deprecated */ protected $deliveryDate; @@ -205,6 +206,8 @@ public function setProductCode(?string $productCode): ItemInterface * Get the delivery date. * * @return string + * + * @deprecated Delivery date is deprecated */ public function getDeliveryDate(): ?string { @@ -216,6 +219,8 @@ public function getDeliveryDate(): ?string * * @param string $deliveryDate * @return ItemInterface Return self to enable chaining. + * + * @deprecated Delivery date is deprecated */ public function setDeliveryDate(?string $deliveryDate): ItemInterface { diff --git a/src/Request/SettlementRequest.php b/src/Request/SettlementRequest.php new file mode 100644 index 0000000..eae2b92 --- /dev/null +++ b/src/Request/SettlementRequest.php @@ -0,0 +1,119 @@ +createFromFormat('Y-m-d', $props['startDate'])) { + throw new ValidationException('startDate must be in Y-m-d format'); + } + } + + if (!empty($props['endDate'])) { + if (!(new \DateTime())->createFromFormat('Y-m-d', $props['endDate'])) { + throw new ValidationException('endDate must be in Y-m-d format'); + } + } + + if (!empty($props['startDate']) && !empty($props['endDate'])) { + if ( + (new \DateTime())->createFromFormat('Y-m-d', $props['startDate']) + > (new \DateTime())->createFromFormat('Y-m-d', $props['endDate']) + ) { + throw new ValidationException('startDate cannot be lower than endDate'); + } + } + + if ($props['limit'] < 0) { + throw new ValidationException('Limit must have a minimum value of 0'); + } + + return true; + } + + /** + * Set start date. + * + * @param string|null $startDate Start date as ISO format. + * @return $this + */ + public function setStartDate(?string $startDate): self + { + $this->startDate = $startDate; + return $this; + } + + /** + * Set end date. + * + * @param string|null $endDate End date as ISO format. + * @return $this + */ + public function setEndDate(?string $endDate): self + { + $this->endDate = $endDate; + return $this; + } + + /** + * Set the reference. + * + * @param string $reference + * + * @return $this + */ + public function setReference(?string $reference): self + { + $this->reference = $reference; + + return $this; + } + + /** + * Set limit. + * + * @param int $limit + * @return $this + */ + public function setLimit(int $limit): self + { + $this->limit = $limit; + return $this; + } + + /** + * Set submerchant. + * + * @param int $subMerchant + * @return $this + */ + public function setSubMerchant(int $subMerchant): self + { + $this->subMerchant = $subMerchant; + return $this; + } + + public function jsonSerialize(): array + { + $dataArray = json_encode(get_object_vars($this)); + return array_filter(json_decode($dataArray, true)); + } +} diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 9fc5b64..9e13a2b 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -21,6 +21,7 @@ use Paytrail\SDK\Request\PaymentStatusRequest; use Paytrail\SDK\Request\ReportRequest; use Paytrail\SDK\Request\RevertPaymentAuthHoldRequest; +use Paytrail\SDK\Request\SettlementRequest; use Paytrail\SDK\Request\ShopInShopPaymentRequest; class ClientTest extends PaymentRequestTestCase @@ -484,12 +485,19 @@ public function testRevertCitPaymentAuthorizationHoldException() } } - public function testGetSettlementsWithInvalidDateThrowsException() + public function testRequestSettlementsWithInvalidDateThrowsException() { + $settlementRequest = (new SettlementRequest())->setStartDate('30.5.2022'); $this->expectException(ValidationException::class); - $this->client->getSettlements('30.5.2022'); + $this->client->requestSettlements($settlementRequest); } + public function testRequestSettlementsReturnsValidResponse() + { + $settlementRequest = new SettlementRequest(); + $settlementResponse = $this->client->requestSettlements($settlementRequest); + $this->assertIsArray($settlementResponse->getSettlements()); + } public function testGetGroupedPaymentProvidersAcceptsLanguageParameters() { From 6b2e7bf182749560d37e65f5c3f6127f7243eddc Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 1 Mar 2023 10:06:49 +0200 Subject: [PATCH 76/90] Updte readme --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2665036..6ac8e92 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,9 @@ List of `Client::class` methods | createMitPaymentAuthorizationHold() | Create MiT authorization hold | | createMitPaymentCommit() | Commit MiT authorization hold | | revertPaymentAuthorizationHold() | Revert existing Mit or CiT authorization hold | -| getSettlements() | Request settlements | -| requestPaymentReport() | Request payment report | +| getSettlements() [Deprecated] | Deprecated Request settlements | +| requestSettlements() | Request settlements | +| requestPaymentReport() | Request payment report | --- From 6a7a8c21356685fbc4ed8e74faf5b2141da003ac Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 1 Mar 2023 10:08:30 +0200 Subject: [PATCH 77/90] fix autoformat error on inline --- src/Request/SettlementRequest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Request/SettlementRequest.php b/src/Request/SettlementRequest.php index eae2b92..d9179ac 100644 --- a/src/Request/SettlementRequest.php +++ b/src/Request/SettlementRequest.php @@ -11,11 +11,11 @@ class SettlementRequest implements \JsonSerializable { use ObjectPropertyConverter; -protected $startDate; -protected $endDate; -protected $reference; -protected $limit; -protected $subMerchant; + protected $startDate; + protected $endDate; + protected $reference; + protected $limit; + protected $subMerchant; public function validate() { From 7fee94eef574709ead1731df983a8cce901a37c5 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Thu, 9 Mar 2023 13:33:40 +0200 Subject: [PATCH 78/90] Fix Report date validation, throw exception in status 400 when not using guzzle --- src/Request/ReportRequest.php | 13 +++++-------- src/Util/CurlClient.php | 10 ++++++---- tests/ClientTest.php | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index d7c5853..0b46428 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -60,22 +60,19 @@ public function validate() } if (!empty($props['startDate'])) { - if (!(new \DateTime())->createFromFormat('Y-m-d', $props['startDate'])) { - throw new ValidationException('startDate must be in Y-m-d format'); + if (!preg_match('/^\d{4}(-\d{2}){2}T\d{2}(:\d{2}){2}(\.\d+)?\+\d{2}:\d{2}/', $props['startDate'])) { + throw new ValidationException('startDate must be in DateTimeInterface::ATOM, ISO8601 or RFC3339 format'); } } if (!empty($props['endDate'])) { - if (!(new \DateTime())->createFromFormat('Y-m-d', $props['endDate'])) { - throw new ValidationException('endDate must be in Y-m-d format'); + if (!preg_match('/^\d{4}(-\d{2}){2}T\d{2}(:\d{2}){2}(\.\d+)?\+\d{2}:\d{2}/', $props['endDate'])) { + throw new ValidationException('endDate must be in DateTimeInterface::ATOM, ISO8601 or RFC3339 format'); } } if (!empty($props['startDate']) && !empty($props['endDate'])) { - if ( - (new \DateTime())->createFromFormat('Y-m-d', $props['startDate']) - > (new \DateTime())->createFromFormat('Y-m-d', $props['endDate']) - ) { + if (substr($props['startDate'], 0, 10) > substr($props['endDate'], 0, 10)) { throw new ValidationException('startDate cannot be lower than endDate'); } } diff --git a/src/Util/CurlClient.php b/src/Util/CurlClient.php index 83abef5..3faadf4 100644 --- a/src/Util/CurlClient.php +++ b/src/Util/CurlClient.php @@ -2,6 +2,7 @@ namespace Paytrail\SDK\Util; +use Paytrail\SDK\Exception\ClientException; use Paytrail\SDK\Response\CurlResponse; class CurlClient @@ -47,12 +48,13 @@ public function request(string $method, string $uri, array $options) $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $headers = rtrim(substr($response, 0, $header_size)); $body = substr($response, $header_size); - - $curlResponse = new CurlResponse($headers, $body, $statusCode); - curl_close($curl); - return $curlResponse; + if ($statusCode == 400) { + throw new ClientException($body, $statusCode); + } + + return new CurlResponse($headers, $body, $statusCode); } /** diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 9fc5b64..51a1507 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -570,8 +570,8 @@ public function testRequestPaymentReportThrowsExceptionWhenEndDateIsLowerThanSta $reportRequest = (new ReportRequest()) ->setRequestType('json') ->setCallbackUrl('https://nourl.test') - ->setStartDate('2023-01-20') - ->setEndDate('2023-01-01'); + ->setStartDate('2023-01-20T12:00:00+02:00') + ->setEndDate('2023-01-01T23:59:50+02:00'); $this->client->requestPaymentReport($reportRequest); } From e47789c4a8053e2bf26469b3fb3e0aabeb3f0d73 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Thu, 9 Mar 2023 13:37:23 +0200 Subject: [PATCH 79/90] Shorten error message on report date valiadtion --- src/Request/ReportRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index 0b46428..7c120bb 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -61,7 +61,7 @@ public function validate() if (!empty($props['startDate'])) { if (!preg_match('/^\d{4}(-\d{2}){2}T\d{2}(:\d{2}){2}(\.\d+)?\+\d{2}:\d{2}/', $props['startDate'])) { - throw new ValidationException('startDate must be in DateTimeInterface::ATOM, ISO8601 or RFC3339 format'); + throw new ValidationException('startDate must be in ATOM, ISO8601 or RFC3339 format'); } } From 5c22f71e5d013010fd1c3cb1fc808725ad966715 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 1 Mar 2023 12:50:10 +0200 Subject: [PATCH 80/90] Add settlements by id endpoint --- README.md | 1 + src/Client.php | 27 ++++++- src/Request/ReportBySettlementRequest.php | 94 +++++++++++++++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src/Request/ReportBySettlementRequest.php diff --git a/README.md b/README.md index 6ac8e92..816d2a8 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ List of `Client::class` methods | getSettlements() [Deprecated] | Deprecated Request settlements | | requestSettlements() | Request settlements | | requestPaymentReport() | Request payment report | +| requestPaymentReportBySettlement() | Request payment report by settlement ID | --- diff --git a/src/Client.php b/src/Client.php index 16e2018..4ba674c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -14,6 +14,7 @@ use Paytrail\SDK\Request\GetTokenRequest; use Paytrail\SDK\Request\MitPaymentRequest; use Paytrail\SDK\Request\PaymentRequest; +use Paytrail\SDK\Request\ReportBySettlementRequest; use Paytrail\SDK\Request\ReportRequest; use Paytrail\SDK\Request\SettlementRequest; use Paytrail\SDK\Request\ShopInShopPaymentRequest; @@ -705,7 +706,7 @@ function ($decoded) { * @throws HmacException * @throws ValidationException */ - public function requestPaymentReport(ReportRequest $reportRequest) + public function requestPaymentReport(ReportRequest $reportRequest): ReportRequestResponse { $this->validateRequestItem($reportRequest); $uri = '/payments/report'; @@ -728,6 +729,30 @@ function ($decoded) { return $reportRequestResponse; } + /** + * Request payment report by settlement ID. + * + * @param ReportBySettlementRequest $reportRequest + * @param int $settlementId + * @return ReportRequestResponse + * @throws HmacException + * @throws ValidationException + */ + public function requestPaymentReportBySettlement(ReportBySettlementRequest $reportRequest, int $settlementId): ReportRequestResponse + { + $this->validateRequestItem($reportRequest); + $uri = "/settlements/{$settlementId}/payments/report"; + + return $this->post( + $uri, + $reportRequest, + function ($decoded) { + return (new ReportRequestResponse()) + ->setRequestId($decoded->requestId ?? null); + }, + ); + } + /** * Activate invoice created with manualInvoiceActivation set to true * diff --git a/src/Request/ReportBySettlementRequest.php b/src/Request/ReportBySettlementRequest.php new file mode 100644 index 0000000..1e84844 --- /dev/null +++ b/src/Request/ReportBySettlementRequest.php @@ -0,0 +1,94 @@ +requestType = $requestType; + return $this; + } + + /** + * Set callback url. + * + * @param string $callbackUrl + * @return $this + */ + public function setCallbackUrl(string $callbackUrl): self + { + $this->callbackUrl = $callbackUrl; + return $this; + } + + /** + * Set report fields. + * + * @param string[] $reportFields + * @return $this + */ + public function setReportFields(array $reportFields): self + { + $this->reportFields = $reportFields; + return $this; + } + + /** + * Set submerchant. + * + * @param int $subMerchant + * @return $this + */ + public function setSubMerchant(int $subMerchant): self + { + $this->subMerchant = $subMerchant; + return $this; + } + + public function jsonSerialize(): array + { + $dataArray = json_encode(get_object_vars($this)); + return array_filter(json_decode($dataArray, true)); + } +} From 446f33de842b07dd82129a01396eda525505dd66 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 1 Mar 2023 12:55:30 +0200 Subject: [PATCH 81/90] Fix styling errors --- src/Client.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index 4ba674c..9f7884e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -738,15 +738,17 @@ function ($decoded) { * @throws HmacException * @throws ValidationException */ - public function requestPaymentReportBySettlement(ReportBySettlementRequest $reportRequest, int $settlementId): ReportRequestResponse - { + public function requestPaymentReportBySettlement( + ReportBySettlementRequest $reportRequest, + int $settlementId + ): ReportRequestResponse { $this->validateRequestItem($reportRequest); $uri = "/settlements/{$settlementId}/payments/report"; return $this->post( $uri, $reportRequest, - function ($decoded) { + function ($decoded) { return (new ReportRequestResponse()) ->setRequestId($decoded->requestId ?? null); }, From 28339243b1389c7689fe54c18a27b4d6a3726ed0 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 1 Mar 2023 13:10:38 +0200 Subject: [PATCH 82/90] Change private methods to protected for future abstract parent --- src/Request/ReportBySettlementRequest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Request/ReportBySettlementRequest.php b/src/Request/ReportBySettlementRequest.php index 1e84844..a129fec 100644 --- a/src/Request/ReportBySettlementRequest.php +++ b/src/Request/ReportBySettlementRequest.php @@ -11,10 +11,10 @@ class ReportBySettlementRequest implements \JsonSerializable { use ObjectPropertyConverter; - private $requestType; - private $callbackUrl; - private $reportFields; - private $subMerchant; + protected $requestType; + protected $callbackUrl; + protected $reportFields; + protected $subMerchant; public function validate() { From 1e1847ca1cbd3cf71b7e146320114a0b9c828357 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Thu, 30 Mar 2023 10:15:52 +0300 Subject: [PATCH 83/90] Remove unused use statements --- src/Request/AbstractPaymentRequest.php | 2 -- src/Request/ReportBySettlementRequest.php | 3 --- src/Request/ReportRequest.php | 3 --- 3 files changed, 8 deletions(-) diff --git a/src/Request/AbstractPaymentRequest.php b/src/Request/AbstractPaymentRequest.php index 93e5c6b..c6bf131 100644 --- a/src/Request/AbstractPaymentRequest.php +++ b/src/Request/AbstractPaymentRequest.php @@ -12,9 +12,7 @@ use Paytrail\SDK\Interfaces\CustomerInterface; use Paytrail\SDK\Interfaces\ItemInterface; use Paytrail\SDK\Interfaces\PaymentRequestInterface; -use Paytrail\SDK\Model\Address; use Paytrail\SDK\Model\CallbackUrl; -use Paytrail\SDK\Model\Customer; use Paytrail\SDK\Model\Item; use Paytrail\SDK\Util\JsonSerializable; diff --git a/src/Request/ReportBySettlementRequest.php b/src/Request/ReportBySettlementRequest.php index a129fec..3a6645e 100644 --- a/src/Request/ReportBySettlementRequest.php +++ b/src/Request/ReportBySettlementRequest.php @@ -5,12 +5,9 @@ namespace Paytrail\SDK\Request; use Paytrail\SDK\Exception\ValidationException; -use Paytrail\SDK\Util\ObjectPropertyConverter; class ReportBySettlementRequest implements \JsonSerializable { - use ObjectPropertyConverter; - protected $requestType; protected $callbackUrl; protected $reportFields; diff --git a/src/Request/ReportRequest.php b/src/Request/ReportRequest.php index 7c120bb..0a7c216 100644 --- a/src/Request/ReportRequest.php +++ b/src/Request/ReportRequest.php @@ -5,12 +5,9 @@ namespace Paytrail\SDK\Request; use Paytrail\SDK\Exception\ValidationException; -use Paytrail\SDK\Util\ObjectPropertyConverter; class ReportRequest implements \JsonSerializable { - use ObjectPropertyConverter; - public const PAYMENT_STATUSES = [ 'default', 'paid', From 5b3c98f3999bcbe39b39a698ba43799d32f9a910 Mon Sep 17 00:00:00 2001 From: Joonas Loueranta Date: Tue, 11 Apr 2023 15:38:18 +0300 Subject: [PATCH 84/90] Update CHANGELOG.md --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b5f6c1..25a5f32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.5.0] - 2023-04-11 +### Added +- You can now request payment report by settlement ID +- Added new improved way for requesting payment reports: requestSettlements() +### Fixed +- Fixed date validation on report requests +- Code cleanup for request classes + ## [2.3.2] - 2023-02-22 ### Added - PHPStan (static analyser) added in workflow From 826eca229aaea94aa4ccbe0afa09e6cee07cc018 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Tue, 18 Apr 2023 09:42:36 +0300 Subject: [PATCH 85/90] Fix item validation --- composer.json | 2 +- src/Model/Item.php | 19 ++-- src/Model/RefundItem.php | 12 +-- tests/ClientTest.php | 4 +- tests/Model/ItemTest.php | 121 ++++++++++++----------- tests/Model/RefundItemTest.php | 26 +++-- tests/Model/Token/CardTest.php | 2 +- tests/Model/Token/CustomerTest.php | 2 +- tests/Request/AddCardFormRequestTest.php | 2 +- tests/Request/GetTokenRequestTest.php | 2 +- 10 files changed, 101 insertions(+), 91 deletions(-) diff --git a/composer.json b/composer.json index ceb8b26..a07cee6 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "ext-curl": "*" }, "require-dev": { - "phpunit/phpunit": "^9.0", + "phpunit/phpunit": "^10.0 || ^9.0", "squizlabs/php_codesniffer": "^3.6", "phpcompatibility/php-compatibility": "^9.3", "phpmd/phpmd": "^2.10", diff --git a/src/Model/Item.php b/src/Model/Item.php index 117d403..818e3d7 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -376,19 +376,20 @@ public function validate() { $props = get_object_vars($this); + if (empty($props['unitPrice'])) { + throw new ValidationException('Item unitPrice is empty'); + } if ($props['unitPrice'] < 0) { - throw new ValidationException('Items UnitPrice can\'t be a negative number'); + throw new ValidationException('Items unitPrice can\'t be a negative number'); } - - if (filter_var($props['unitPrice'], FILTER_VALIDATE_INT) === false) { - //throw new \Exception('UnitPrice is not an integer'); - throw new ValidationException('UnitPrice is not an integer'); + if (empty($props['units'])) { + throw new ValidationException('Item units is empty'); } - if (filter_var($props['units'], FILTER_VALIDATE_INT) === false) { - throw new ValidationException('Units is not an integer'); + if ($props['units'] < 0) { + throw new ValidationException('Items units can\'t be a negative number'); } - if (filter_var($props['vatPercentage'], FILTER_VALIDATE_INT) === false) { - throw new ValidationException('vatPercentage is not an integer'); + if ($props['vatPercentage'] < 0) { + throw new ValidationException('Items vatPercentage can\'t be a negative number'); } if (empty($props['productCode'])) { throw new ValidationException('productCode is empty'); diff --git a/src/Model/RefundItem.php b/src/Model/RefundItem.php index 88f4473..66ff6c3 100644 --- a/src/Model/RefundItem.php +++ b/src/Model/RefundItem.php @@ -32,15 +32,13 @@ public function validate() $props = get_object_vars($this); if (empty($props['amount'])) { - throw new ValidationException('Amount is empty'); + throw new ValidationException('RefundItem amount is empty'); } - - if (empty($props['stamp'])) { - throw new ValidationException('Stamp can not be empty'); + if ($props['amount'] < 0) { + throw new ValidationException('RefundItem amount can\'t be a negative number'); } - - if (!is_string($props['stamp'])) { - throw new ValidationException('Stamp is not a string'); + if (empty($props['stamp'])) { + throw new ValidationException('Stamp can\'t be empty'); } return true; diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 7fe55e1..c77aa80 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -48,7 +48,7 @@ protected function setUp(): void ->setProductCode('pr1') ->setVatPercentage(24) ->setReference('itemReference123') - ->setStamp('itemStamp-' . rand(1, 999999)) + ->setStamp('itemStamp-1' . rand(1, 999999)) ->setUnits(1) ->setDescription('some description') ->setUnitPrice(100); @@ -58,7 +58,7 @@ protected function setUp(): void ->setProductCode('pr2') ->setVatPercentage(24) ->setReference('itemReference123') - ->setStamp('itemStamp-' . rand(1, 999999)) + ->setStamp('itemStamp-2' . rand(1, 999999)) ->setUnits(2) ->setDescription('some description2') ->setUnitPrice(200); diff --git a/tests/Model/ItemTest.php b/tests/Model/ItemTest.php index cd5e5a0..53a56ef 100644 --- a/tests/Model/ItemTest.php +++ b/tests/Model/ItemTest.php @@ -12,80 +12,83 @@ class ItemTest extends TestCase { public function testIsItemValid() { - $i = new Item(); - - $this->assertInstanceOf( - Item::class, - $i - ); - - $i->setUnitPrice(1) + $item = (new Item())->setUnitPrice(1) ->setUnits(2) + ->setStamp('thisIsStamp') ->setVatPercentage(0) ->setProductCode('productCode123') - ->setDeliveryDate('12.12.1999') + ->setDeliveryDate('2023-01-01') ->setDescription('description'); - $this->assertEquals(true, $i->validate()); + $this->assertEquals(true, $item->validate()); } - public function testExceptions() + public function testItemWithoutUnitPriceThrowsError() { $this->expectException(ValidationException::class); - $i = new Item(); - $i->validate(); + (new Item())->setUnits(2) + ->setStamp('thisIsStamp') + ->setVatPercentage(0) + ->setProductCode('productCode123') + ->setDescription('description') + ->validate(); } - public function testExceptionMessages() + public function testItemWithNegativeUnitPriceThrowsError() { - $i = new Item(); - - try { - $i->validate(); - } catch (\Exception $e) { - $this->assertStringContainsString('UnitPrice is not an integer', $e->getMessage()); - } - - try { - $i->setUnitPrice(-10); - $i->validate(); - } catch (\Exception $e) { - $this->assertStringContainsString('UnitPrice can\'t be a negative number', $e->getMessage()); - } - - try { - $i->setUnitPrice(2); - $i->validate(); - } catch (\Exception $e) { - $this->assertStringContainsString('Units is not an integer', $e->getMessage()); - } - - try { - $i->setUnits(3); - $i->validate(); - } catch (ValidationException $e) { - $this->assertStringContainsString('vatPercentage is not an integer', $e->getMessage()); - } + $this->expectException(ValidationException::class); + (new Item())->setUnitPrice(-1) + ->setUnits(2) + ->setStamp('thisIsStamp') + ->setVatPercentage(0) + ->setProductCode('productCode123') + ->setDescription('description') + ->validate(); + } - try { - $i->setVatPercentage(12); - $i->validate(); - } catch (ValidationException $e) { - $this->assertStringContainsString('productCode is empty', $e->getMessage()); - } + public function testItemWithoutUnitsTrowsError() + { + $this->expectException(ValidationException::class); + (new Item())->setUnitPrice(1) + ->setStamp('thisIsStamp') + ->setVatPercentage(0) + ->setProductCode('productCode123') + ->setDescription('description') + ->validate(); + } - try { - $i->setProductCode('productCode123'); - $i->validate(); - } catch (ValidationException $e) { - $this->assertStringContainsString('deliveryDate is empty', $e->getMessage()); - } + public function testItemWithNegativeUnitsThrowsError() + { + $this->expectException(ValidationException::class); + (new Item())->setUnitPrice(1) + ->setUnits(-1) + ->setStamp('thisIsStamp') + ->setVatPercentage(0) + ->setProductCode('productCode123') + ->setDescription('description') + ->validate(); + } - $i->setDeliveryDate('12.12.1999'); + public function testItemWIthNegativeVatThrowsError() + { + $this->expectException(ValidationException::class); + (new Item())->setUnitPrice(1) + ->setUnits(2) + ->setStamp('thisIsStamp') + ->setVatPercentage(-10) + ->setProductCode('productCode123') + ->setDescription('description') + ->validate(); + } - try { - $this->assertIsBool($i->validate(), 'Item::validate returns bool'); - } catch (ValidationException $e) { - } + public function testItemWithoutProductCodeThrowsError() + { + $this->expectException(ValidationException::class); + (new Item())->setUnitPrice(1) + ->setUnits(2) + ->setStamp('thisIsStamp') + ->setVatPercentage(10) + ->setDescription('description') + ->validate(); } } diff --git a/tests/Model/RefundItemTest.php b/tests/Model/RefundItemTest.php index 98dbd75..0ce6180 100644 --- a/tests/Model/RefundItemTest.php +++ b/tests/Model/RefundItemTest.php @@ -17,19 +17,27 @@ public function testValidation() $rfi->setAmount(123.2322323); } - public function testTypeError() + + public function testRefundItemIsValid() { - $this->expectException(\TypeError::class); - $rfi = new RefundItem(); - $rfi->setAmount("not a number"); + $refundItem = (new RefundItem())->setAmount(123) + ->setStamp('thisIsStamp'); + + $this->assertEquals(true, $refundItem->validate()); } - public function testValidationExceptions() + public function testRefundItemWithoutAmountThrowsError() { $this->expectException(ValidationException::class); - $rfi = new RefundItem(); - $rfi->setAmount(123); - $rfi->setStamp(''); - $rfi->validate(); + (new RefundItem())->setStamp('thisIsStamp') + ->validate(); + } + + public function testRefundItemWithNegativeAmountThrowsError() + { + $this->expectException(ValidationException::class); + (new RefundItem())->setAmount(-1) + ->setStamp('thisIsStamp') + ->validate(); } } diff --git a/tests/Model/Token/CardTest.php b/tests/Model/Token/CardTest.php index 1912276..6371b33 100644 --- a/tests/Model/Token/CardTest.php +++ b/tests/Model/Token/CardTest.php @@ -10,7 +10,7 @@ class CardTest extends TestCase { - public function validationProvider() + public static function validationProvider() { return [ 'Type is empty' => [ diff --git a/tests/Model/Token/CustomerTest.php b/tests/Model/Token/CustomerTest.php index 154f929..1529ee7 100644 --- a/tests/Model/Token/CustomerTest.php +++ b/tests/Model/Token/CustomerTest.php @@ -10,7 +10,7 @@ class CustomerTest extends TestCase { - public function validationProvider() + public static function validationProvider() { return [ 'Network address is empty' => [ diff --git a/tests/Request/AddCardFormRequestTest.php b/tests/Request/AddCardFormRequestTest.php index 3e7327a..96557a1 100644 --- a/tests/Request/AddCardFormRequestTest.php +++ b/tests/Request/AddCardFormRequestTest.php @@ -10,7 +10,7 @@ class AddCardFormRequestTest extends TestCase { - public function validationProvider() + public static function validationProvider() { return [ 'checkout-account is empty' => [ diff --git a/tests/Request/GetTokenRequestTest.php b/tests/Request/GetTokenRequestTest.php index 6590ebe..2a5d874 100644 --- a/tests/Request/GetTokenRequestTest.php +++ b/tests/Request/GetTokenRequestTest.php @@ -10,7 +10,7 @@ class GetTokenRequestTest extends TestCase { - public function validationProvider() + public static function validationProvider() { return [ 'checkout-tokenization-id is empty' => [ From 713c86acd6fbbe27e039918a53fbd72de1471fba Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Tue, 18 Apr 2023 09:51:03 +0300 Subject: [PATCH 86/90] Pass request parameters as url parameters in requestSettlements --- src/Client.php | 6 ++++++ tests/ClientTest.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/Client.php b/src/Client.php index 9f7884e..9a43845 100644 --- a/src/Client.php +++ b/src/Client.php @@ -631,6 +631,12 @@ public function requestSettlements(SettlementRequest $settlementRequest) $uri = '/settlements'; + $query = http_build_query($settlementRequest->jsonSerialize()); + + if (!empty($query)) { + $uri .= '?' . $query; + } + return $this->get( $uri, function ($decoded) { diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 7fe55e1..70a93ab 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -493,6 +493,12 @@ public function testRequestSettlementsWithInvalidDateThrowsException() } public function testRequestSettlementsReturnsValidResponse() + { + $settlementRequest = (new SettlementRequest()); + $this->client->requestSettlements($settlementRequest); + } + + public function testGetSettlementsReturnsValidResponse() { $settlementRequest = new SettlementRequest(); $settlementResponse = $this->client->requestSettlements($settlementRequest); From e4e85cc0f04a4660b3403fa7b5ff21bba525fa43 Mon Sep 17 00:00:00 2001 From: Joonas Loueranta Date: Wed, 19 Apr 2023 09:40:04 +0300 Subject: [PATCH 87/90] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25a5f32..731895c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.5.1] - 2023-04-19 +### Fixed +- Fixed requestSettlements url parameters +- Fixed item validation + ## [2.5.0] - 2023-04-11 ### Added - You can now request payment report by settlement ID From 5756ed3f4b209e68018c38c777ac39a8a326cae2 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Mon, 24 Apr 2023 15:15:15 +0300 Subject: [PATCH 88/90] Allow zero amount items --- .github/workflows/run-workflow.yaml | 4 +-- src/Model/Item.php | 7 +++-- tests/ClientTest.php | 3 +- tests/Model/ItemTest.php | 46 +++++++++++++++++++++-------- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/.github/workflows/run-workflow.yaml b/.github/workflows/run-workflow.yaml index 84dd810..94b2bf7 100644 --- a/.github/workflows/run-workflow.yaml +++ b/.github/workflows/run-workflow.yaml @@ -31,7 +31,7 @@ jobs: run: composer lint - name: Run phpstan - uses: php-actions/phpstan@v3.0.1 + uses: php-actions/phpstan@v3 with: php_version: ${{ matrix.php-version }} version: 1.9.14 @@ -39,7 +39,7 @@ jobs: memory_limit: 256M - name: Run tests - uses: php-actions/phpunit@v3.0.0 + uses: php-actions/phpunit@v3 with: php_version: ${{ matrix.php-version }} version: 9 diff --git a/src/Model/Item.php b/src/Model/Item.php index 818e3d7..3847dca 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -376,13 +376,16 @@ public function validate() { $props = get_object_vars($this); - if (empty($props['unitPrice'])) { + if ($props['unitPrice'] === null) { throw new ValidationException('Item unitPrice is empty'); } if ($props['unitPrice'] < 0) { throw new ValidationException('Items unitPrice can\'t be a negative number'); } - if (empty($props['units'])) { + if ($props['unitPrice'] > 99999999) { + throw new ValidationException('Items unitPrice can\'t be over 99999999'); + } + if ($props['units'] === null) { throw new ValidationException('Item units is empty'); } if ($props['units'] < 0) { diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 2ca2a28..098d302 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -495,7 +495,8 @@ public function testRequestSettlementsWithInvalidDateThrowsException() public function testRequestSettlementsReturnsValidResponse() { $settlementRequest = (new SettlementRequest()); - $this->client->requestSettlements($settlementRequest); + $settlementResponse = $this->client->requestSettlements($settlementRequest); + $this->assertIsArray($settlementResponse->getSettlements()); } public function testGetSettlementsReturnsValidResponse() diff --git a/tests/Model/ItemTest.php b/tests/Model/ItemTest.php index 53a56ef..b544c34 100644 --- a/tests/Model/ItemTest.php +++ b/tests/Model/ItemTest.php @@ -20,7 +20,7 @@ public function testIsItemValid() ->setDeliveryDate('2023-01-01') ->setDescription('description'); - $this->assertEquals(true, $item->validate()); + $this->assertTrue($item->validate()); } public function testItemWithoutUnitPriceThrowsError() @@ -34,18 +34,6 @@ public function testItemWithoutUnitPriceThrowsError() ->validate(); } - public function testItemWithNegativeUnitPriceThrowsError() - { - $this->expectException(ValidationException::class); - (new Item())->setUnitPrice(-1) - ->setUnits(2) - ->setStamp('thisIsStamp') - ->setVatPercentage(0) - ->setProductCode('productCode123') - ->setDescription('description') - ->validate(); - } - public function testItemWithoutUnitsTrowsError() { $this->expectException(ValidationException::class); @@ -91,4 +79,36 @@ public function testItemWithoutProductCodeThrowsError() ->setDescription('description') ->validate(); } + + public static function providerForUnitPriceLimitValues() + { + return [ + 'Negative amount' => [-1, false], + 'Zero amount' => [0, true], + 'Maximum amount' => [99999999, true], + 'Over maximum amount' => [100000000, false] + ]; + } + + /** + * @dataProvider providerForUnitPriceLimitValues + */ + public function testUnitPriceLimitValues($unitPrice, $expectedResult) + { + $item = (new Item())->setUnitPrice($unitPrice) + ->setUnits(2) + ->setStamp('thisIsStamp') + ->setVatPercentage(0) + ->setProductCode('productCode123') + ->setDeliveryDate('2023-01-01') + ->setDescription('description'); + + try { + $validationResult = $item->validate(); + } catch (ValidationException $exception) { + $validationResult = false; + } + + $this->assertEquals($expectedResult, $validationResult); + } } From 56be907f74ddd4758a36e01fd92198ac4252d1a1 Mon Sep 17 00:00:00 2001 From: Joonas Loueranta Date: Fri, 5 May 2023 12:41:25 +0300 Subject: [PATCH 89/90] Preparing for 2.5.2 release --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 731895c..7e3ac96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.5.2] - 2023-05-05 +### Fixed +- Improved refundRequest Validation +- Fix to allow zero amount items + ## [2.5.1] - 2023-04-19 ### Fixed - Fixed requestSettlements url parameters From 2bb8f341cd47ae85c2ee6be01284a0cc0c092143 Mon Sep 17 00:00:00 2001 From: juhopekkavuorela Date: Wed, 19 Apr 2023 13:09:21 +0300 Subject: [PATCH 90/90] Improve refundRequest Validation --- src/Request/RefundRequest.php | 13 +-- tests/Request/EmailRefundRequestTest.php | 127 +++++------------------ 2 files changed, 31 insertions(+), 109 deletions(-) diff --git a/src/Request/RefundRequest.php b/src/Request/RefundRequest.php index 5ac8af9..25fc479 100644 --- a/src/Request/RefundRequest.php +++ b/src/Request/RefundRequest.php @@ -31,8 +31,8 @@ public function validate() { $props = get_object_vars($this); - if (! empty($this->items)) { - // Count the total amount of the payment. + if (!empty($this->items)) { + // Count the total amount of the refund. $items_total = array_reduce($this->items, function ($carry = 0, ?RefundItem $item = null) { if ($item === null) { return $carry; @@ -49,12 +49,8 @@ public function validate() $items_total = $this->amount; } - if (empty($props['amount'])) { - throw new ValidationException('Amount can not be empty'); - } - - if (filter_var($props['amount'], FILTER_VALIDATE_INT) === false) { - throw new ValidationException('Amount is not an integer'); + if (empty($props['amount']) && empty($this->items)) { + throw new ValidationException('Amount can not be empty when making refund without items'); } if ($items_total !== $props['amount']) { @@ -65,6 +61,7 @@ public function validate() throw new ValidationException('CallbackUrls are not set'); } + // Validate callbackUrls $this->callbackUrls->validate(); return true; diff --git a/tests/Request/EmailRefundRequestTest.php b/tests/Request/EmailRefundRequestTest.php index d72d8f7..79d6663 100644 --- a/tests/Request/EmailRefundRequestTest.php +++ b/tests/Request/EmailRefundRequestTest.php @@ -12,11 +12,11 @@ class EmailRefundRequestTest extends TestCase { - public function testEmailRefundRequest() + public function testEmailRefundRequestIsValid() { - $er = new EmailRefundRequest(); - $er->setAmount(20); - $er->setEmail('some@email.com'); + $emailRequest = new EmailRefundRequest(); + $emailRequest->setAmount(20); + $emailRequest->setEmail('some@email.com'); $item = new RefundItem(); $item->setAmount(10) @@ -26,115 +26,40 @@ public function testEmailRefundRequest() $item2->setAmount(10) ->setStamp('anotherStamp'); - $er->setItems([$item, $item2]); + $emailRequest->setItems([$item, $item2]); $cb = new CallbackUrl(); $cb->setCancel('https://some.url.com/cancel') ->setSuccess('https://some.url.com/success'); - $er->setCallbackUrls($cb); + $emailRequest->setCallbackUrls($cb); - $er->setRefundReference('ref-1234') + $emailRequest->setRefundReference('ref-1234') ->setRefundStamp('c7557cd5d5f548daa5332ccc4abb264f'); - $this->assertEquals(true, $er->validate()); + $this->assertTrue($emailRequest->validate()); } - public function testExceptions() + public function testRefundRequestWithoutItemsAndAmountThrowsException() { - $er = new EmailRefundRequest(); - - try { - $er->validate(); - } catch (ValidationException $e) { - $this->assertEquals("Amount can not be empty", $e->getMessage()); - } - - $er->setAmount(99999); - - try { - $er->validate(); - } catch (ValidationException $e) { - $this->assertEquals('CallbackUrls are not set', $e->getMessage()); - } - - $cb = new CallbackUrl(); - $er->setCallbackUrls($cb); - - try { - $er->validate(); - } catch (ValidationException $e) { - $this->assertEquals('Success is empty', $e->getMessage()); - } - - $cb->setSuccess('someurl.somewhere.com/success'); - $er->setCallbackUrls($cb); - - try { - $er->validate(); - } catch (ValidationException $e) { - $this->assertEquals('Cancel is empty', $e->getMessage()); - } - - $cb->setCancel('someurl.somewhere.com/cancel'); - $er->setCallbackUrls($cb); - - try { - $er->validate(); - } catch (ValidationException $e) { - $this->assertEquals('Success is not a valid URL', $e->getMessage()); - } - - $cb->setSuccess('https://someurl.somewhere.com/success'); - $er->setCallbackUrls($cb); - - try { - $er->validate(); - } catch (ValidationException $e) { - $this->assertEquals('Cancel is not a valid URL', $e->getMessage()); - } - - $cb->setCancel('https://someurl.somewhere.com/cancel'); - $er->setCallbackUrls($cb); - - try { - $er->validate(); - } catch (ValidationException $e) { - $this->assertEquals('email can not be empty', $e->getMessage()); - } - - $er->setEmail('some@email.com'); - - // Items are not mandatory, so should pass from here - try { - $er->validate(); - } catch (ValidationException $e) { - var_dump($e->getMessage()); - } - - $item = new RefundItem(); - $item->setAmount(110) - ->setStamp('someStamp'); - - $item2 = new RefundItem(); - $item2->setAmount(10) - ->setStamp('anotherStamp'); - - $er->setItems([$item, $item2]); - - // Fails, as refund->total was set to 9999 - try { - $er->validate(); - } catch (ValidationException $e) { - $this->assertEquals('ItemsTotal does not match Amount', $e->getMessage()); - } + $this->expectException(ValidationException::class); + (new EmailRefundRequest())->validate(); + } - // Set correct amount - $er->setAmount(120); + public function testRefundWithItemsAndAmountMismatchThrowsException() + { + $this->expectException(ValidationException::class); + (new EmailRefundRequest())->setAmount(100) + ->setItems([ + (new RefundItem())->setAmount(200) + ->setStamp('foobar') + ])->validate(); + } - try { - $this->assertEquals(true, $er->validate()); - } catch (ValidationException $e) { - } + public function testRefundRequestWithoutCallbackUrlsThrowsError() + { + $this->expectException(ValidationException::class); + (new EmailRefundRequest())->setAmount(100) + ->validate(); } }