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); } }