From 6e6da699790c9a8769e6d6da8f6c1e328b766c01 Mon Sep 17 00:00:00 2001 From: Oleksandr Gribiennikov Date: Tue, 14 May 2024 15:30:25 +0300 Subject: [PATCH 1/2] Change `buildForPaymentsMethodList` signature: `amount` and `currency` are optional --- WebToPay.php | 19 ++++--------- src/WebToPay.php | 15 ++-------- src/WebToPay/PaymentMethodListProvider.php | 2 +- src/WebToPay/UrlBuilder.php | 2 +- tests/StaticMethods/WebToPayTest.php | 20 ++++++++++--- tests/WebToPay/UrlBuilderTest.php | 33 ++++++++++++++++++---- 6 files changed, 53 insertions(+), 38 deletions(-) diff --git a/WebToPay.php b/WebToPay.php index d53b8ae..9995155 100644 --- a/WebToPay.php +++ b/WebToPay.php @@ -240,18 +240,13 @@ public static function smsAnswer(array $userData): void /** * Gets available payment methods for project. Gets methods min and max amounts in specified currency. * - * @param integer $projectId - * @param float $amount - * @param string $currency - * - * @return WebToPay_PaymentMethodList - * * @throws WebToPayException + * @throws WebToPay_Exception_Configuration */ public static function getPaymentMethodList( int $projectId, - float $amount, - string $currency = 'EUR' + ?float $amount, + ?string $currency = 'EUR' ): WebToPay_PaymentMethodList { $factory = new WebToPay_Factory(['projectId' => $projectId]); @@ -261,10 +256,6 @@ public static function getPaymentMethodList( /** * Logs to file. Just skips logging if file is not writeable * - * @param string $type - * @param string $msg - * @param string $logfile - * * @deprecated * @codeCoverageIgnore */ @@ -1550,7 +1541,7 @@ public function __construct( * * @throws WebToPayException */ - public function getPaymentMethodList(float $amount, string $currency): WebToPay_PaymentMethodList + public function getPaymentMethodList(?float $amount, ?string $currency): WebToPay_PaymentMethodList { if (!isset($this->methodListCache[$currency])) { $xmlAsString = $this->webClient->get( @@ -1865,7 +1856,7 @@ public function buildForRequest(array $request): string /** * Builds a complete URL for payment list API */ - public function buildForPaymentsMethodList(int $projectId, string $amount, string $currency): string + public function buildForPaymentsMethodList(int $projectId, ?string $amount, ?string $currency): string { $route = $this->environmentSettings['paymentMethodList']; diff --git a/src/WebToPay.php b/src/WebToPay.php index cbb3674..42a5b0d 100644 --- a/src/WebToPay.php +++ b/src/WebToPay.php @@ -236,18 +236,13 @@ public static function smsAnswer(array $userData): void /** * Gets available payment methods for project. Gets methods min and max amounts in specified currency. * - * @param integer $projectId - * @param float $amount - * @param string $currency - * - * @return WebToPay_PaymentMethodList - * * @throws WebToPayException + * @throws WebToPay_Exception_Configuration */ public static function getPaymentMethodList( int $projectId, - float $amount, - string $currency = 'EUR' + ?float $amount, + ?string $currency = 'EUR' ): WebToPay_PaymentMethodList { $factory = new WebToPay_Factory(['projectId' => $projectId]); @@ -257,10 +252,6 @@ public static function getPaymentMethodList( /** * Logs to file. Just skips logging if file is not writeable * - * @param string $type - * @param string $msg - * @param string $logfile - * * @deprecated * @codeCoverageIgnore */ diff --git a/src/WebToPay/PaymentMethodListProvider.php b/src/WebToPay/PaymentMethodListProvider.php index 5977e22..5287c1e 100644 --- a/src/WebToPay/PaymentMethodListProvider.php +++ b/src/WebToPay/PaymentMethodListProvider.php @@ -48,7 +48,7 @@ public function __construct( * * @throws WebToPayException */ - public function getPaymentMethodList(float $amount, string $currency): WebToPay_PaymentMethodList + public function getPaymentMethodList(?float $amount, ?string $currency): WebToPay_PaymentMethodList { if (!isset($this->methodListCache[$currency])) { $xmlAsString = $this->webClient->get( diff --git a/src/WebToPay/UrlBuilder.php b/src/WebToPay/UrlBuilder.php index 603bc04..c2ec5a3 100644 --- a/src/WebToPay/UrlBuilder.php +++ b/src/WebToPay/UrlBuilder.php @@ -54,7 +54,7 @@ public function buildForRequest(array $request): string /** * Builds a complete URL for payment list API */ - public function buildForPaymentsMethodList(int $projectId, string $amount, string $currency): string + public function buildForPaymentsMethodList(int $projectId, ?string $amount, ?string $currency): string { $route = $this->environmentSettings['paymentMethodList']; diff --git a/tests/StaticMethods/WebToPayTest.php b/tests/StaticMethods/WebToPayTest.php index b91d903..c51eb81 100644 --- a/tests/StaticMethods/WebToPayTest.php +++ b/tests/StaticMethods/WebToPayTest.php @@ -141,16 +141,28 @@ public function testValidateAndParseData(): void WebToPay::validateAndParseData($request, 123, 'password'); } + public function getDataForTestingGetPaymentMethodList(): iterable + { + yield 'amount is null' => [ + 'amount' => null, + 'currency' => 'EUR', + ]; + + yield 'currency is null' => [ + 'amount' => 1000, + 'currency' => null, + ]; + } + /** + * @dataProvider getDataForTestingGetPaymentMethodList + * * @throws WebToPayException * @throws WebToPay_Exception_Callback * @throws WebToPay_Exception_Configuration */ - public function testGetPaymentMethodList(): void + public function testGetPaymentMethodList(?int $amount, ?string $currency): void { - $amount = 1000; - $currency = 'EUR'; - $paymentMethodListProviderMock = $this->createMock(WebToPay_PaymentMethodListProvider::class); $paymentMethodListProviderMock->expects($this->once()) ->method('getPaymentMethodList') diff --git a/tests/WebToPay/UrlBuilderTest.php b/tests/WebToPay/UrlBuilderTest.php index bd5934b..d480ad7 100644 --- a/tests/WebToPay/UrlBuilderTest.php +++ b/tests/WebToPay/UrlBuilderTest.php @@ -37,13 +37,34 @@ public function testBuildForRequest() ); } - public function testBuildForPaymentsMethodList() + public function getDataForTestingBuildForPaymentsMethodList(): iterable { - $url = $this->urlBuilder->buildForPaymentsMethodList(1, '1.00', 'EUR'); + yield 'amount is not null; currency is not null' => [ + 'amount' => '1.00', + 'currency' => 'EUR', + 'expectedUrl' => 'https://sandbox.paysera.com/new/api/paymentMethods/1/currency:EUR/amount:1.00', + ]; - $this->assertEquals( - 'https://sandbox.paysera.com/new/api/paymentMethods/1/currency:EUR/amount:1.00', - $url - ); + yield 'amount is null; currency is not null' => [ + 'amount' => null, + 'currency' => 'EUR', + 'expectedUrl' => 'https://sandbox.paysera.com/new/api/paymentMethods/1/currency:EUR/amount:', + ]; + + yield 'amount is not null; currency is null' => [ + 'amount' => '1.00', + 'currency' => null, + 'expectedUrl' => 'https://sandbox.paysera.com/new/api/paymentMethods/1/currency:/amount:1.00', + ]; + } + + /** + * @dataProvider getDataForTestingBuildForPaymentsMethodList + */ + public function testBuildForPaymentsMethodList(?string $amount, ?string $currency, string $expectedUrl) + { + $url = $this->urlBuilder->buildForPaymentsMethodList(1, $amount, $currency); + + $this->assertEquals($expectedUrl, $url); } } From d582535acd86c7fff1102a7f82169f541be1c377 Mon Sep 17 00:00:00 2001 From: Oleksandr Gribiennikov Date: Tue, 14 May 2024 15:38:22 +0300 Subject: [PATCH 2/2] Change `buildForPaymentsMethodList` signature: `amount` and `currency` are optional --- WebToPay.php | 4 ++-- composer.json | 2 +- src/WebToPay.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/WebToPay.php b/WebToPay.php index 9995155..c815e07 100644 --- a/WebToPay.php +++ b/WebToPay.php @@ -26,7 +26,7 @@ * @package WebToPay * @author EVP International * @license http://www.gnu.org/licenses/lgpl.html - * @version 1.6 + * @version 3.0.1 * @link http://www.webtopay.com/ */ @@ -38,7 +38,7 @@ class WebToPay /** * WebToPay Library version. */ - public const VERSION = '3.0.0'; + public const VERSION = '3.0.1'; /** * Server URL where all requests should go. diff --git a/composer.json b/composer.json index 8ccdf86..90620a1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "webtopay/libwebtopay", "description": "PHP Library for Paysera payment gateway integration", - "version": "3.0.0", + "version": "3.0.1", "license": "LGPL-3.0", "authors": [ { diff --git a/src/WebToPay.php b/src/WebToPay.php index 42a5b0d..5d1cdc9 100644 --- a/src/WebToPay.php +++ b/src/WebToPay.php @@ -22,7 +22,7 @@ * @package WebToPay * @author EVP International * @license http://www.gnu.org/licenses/lgpl.html - * @version 1.6 + * @version 3.0.1 * @link http://www.webtopay.com/ */ @@ -34,7 +34,7 @@ class WebToPay /** * WebToPay Library version. */ - public const VERSION = '3.0.0'; + public const VERSION = '3.0.1'; /** * Server URL where all requests should go.