Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change buildForPaymentsMethodList signature: amount and currency are optional #26

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions WebToPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
*/

Expand All @@ -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.
Expand Down Expand Up @@ -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]);

Expand All @@ -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
*/
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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'];

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down
19 changes: 5 additions & 14 deletions src/WebToPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
*/

Expand All @@ -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.
Expand Down Expand Up @@ -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]);

Expand All @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/WebToPay/PaymentMethodListProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/WebToPay/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
20 changes: 16 additions & 4 deletions tests/StaticMethods/WebToPayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
33 changes: 27 additions & 6 deletions tests/WebToPay/UrlBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}