Skip to content

Commit f1f4ff4

Browse files
committed
Environment simplified to use uri as an environement parameter
1 parent c284ba0 commit f1f4ff4

13 files changed

+41
-105
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ composer require mkorkmaz/msu-php-sdk
1818
## Basic Usage
1919

2020
```php
21-
$env = 'test'; // Options: 'test', 'production'
21+
$env = 'https://test.merchantsafeunipay.com/msu/api/v2';
2222
$merchant = 'COMPANYNAME'; // Given by Asseco
2323
$merchantUser = 'apiuser@companyname.com'; // Created on MSU Panel
2424
$merchantPassword = 'u+B56?mcjh23'; // Created on MSU Panel

src/SDK/Client.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
namespace MerchantSafeUnipay\SDK;
1212

1313
use GuzzleHttp\Client as GuzzleClient;
14-
use MerchantSafeUnipay\SDK\Environment\EnvironmentInterface as Environment;
14+
use function MerchantSafeUnipay\convertSnakeCase;
15+
use MerchantSafeUnipay\SDK\Environment;
1516
use Psr\Http\Message\ResponseInterface;
1617
use Psr\Log\LoggerInterface;
1718
use MerchantSafeUnipay\SDK\Action\ActionInterface;
@@ -146,7 +147,7 @@ public function query(string $name, array $arguments)
146147
private function getCallAction(string $name, array $arguments)
147148
{
148149
$namespace = '\\MerchantSafeUnipay\\SDK\\Action';
149-
$actionClass = $namespace . '\\'. ucfirst($name);
150+
$actionClass = $namespace . '\\'. convertSnakeCase($name);
150151
if (!in_array($name, self::$validActions, true) || !class_exists($actionClass)) {
151152
$message = sprintf('%s is not valid MerchantSafeUnipay API action.', $name);
152153
throw new BadMethodCallException($message);
@@ -157,7 +158,7 @@ private function getQueryAction(string $name, array $arguments)
157158
{
158159
$name = str_replace(' ', '', ucwords(str_replace('_', '', $name)));
159160
$namespace = '\\MerchantSafeUnipay\\SDK\\Action\\Query';
160-
$actionClass = $namespace . '\\'. ucfirst($name);
161+
$actionClass = $namespace . '\\'. convertSnakeCase($name);
161162
if (!in_array($name, self::$validQueryActions, true) || !class_exists($actionClass)) {
162163
$message = sprintf('%s is not valid MerchantSafeUnipay API query action.', $name);
163164
throw new BadMethodCallException($message);
@@ -175,7 +176,7 @@ private function getQueryAction(string $name, array $arguments)
175176
*/
176177
private function actionFactory(string $name, array $arguments, string $namespace)
177178
{
178-
$actionClass = $namespace . '\\'. ucfirst($name);
179+
$actionClass = $namespace . '\\'. convertSnakeCase($name);
179180
$actionName = $arguments[0];
180181
$actionObject = new $actionClass($this->environment->getMerchantData());
181182
if (!method_exists($actionObject, $actionName)) {

src/SDK/ClientBuilder.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,19 @@ final class ClientBuilder
1616
private $environment;
1717
private $logger;
1818

19-
static private $validEnvironments = ['Test', 'Production'];
2019

2120
public static function create()
2221
{
2322
return new static();
2423
}
2524

2625
public function setEnvironment(
27-
string $environment,
26+
string $apiUrl,
2827
string $merchant,
2928
string $merchantUser,
3029
string $merchantPassword
3130
) {
32-
33-
$environment = ucfirst(strtolower($environment));
34-
if (!in_array($environment, self::$validEnvironments, true)) {
35-
$message = sprintf('%s is not valid environment.', $environment);
36-
throw new InvalidArgumentException($message);
37-
}
38-
$environmentClass = "\\MerchantSafeUnipay\\SDK\\Environment\\{$environment}";
39-
$this->environment = new $environmentClass($merchant, $merchantUser, $merchantPassword);
31+
$this->environment = new Environment($apiUrl, $merchant, $merchantUser, $merchantPassword);
4032
return $this;
4133
}
4234

src/SDK/Environment/EnvironmentAbstract.php renamed to src/SDK/Environment.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
<?php declare(strict_types=1);
22

3-
namespace MerchantSafeUnipay\SDK\Environment;
3+
namespace MerchantSafeUnipay\SDK;
44

5-
abstract class EnvironmentAbstract
5+
class Environment
66
{
77
protected $merchant;
88
protected $merchantUser;
99
protected $merchantPassword;
1010

11-
public function __construct(string $merchant, string $merchantUser, string $merchantPassword)
11+
public function __construct(string $apiUrl, string $merchant, string $merchantUser, string $merchantPassword)
1212
{
13+
$this->apiUrl = $apiUrl;
1314
$this->merchant = $merchant;
1415
$this->merchantUser = $merchantUser;
1516
$this->merchantPassword = $merchantPassword;
1617
}
1718

1819
public function getUrl()
1920
{
20-
return static::$apiUrl;
21+
return $this->apiUrl;
2122
}
2223

2324
public function getMerchantData()

src/SDK/Environment/EnvironmentInterface.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/SDK/Environment/Integration.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/SDK/Environment/Production.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/SDK/Environment/Test.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/functions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ function ($match) use ($separator) {
2424
$str
2525
);
2626
}
27+
28+
function convertSnakeCase(string $str)
29+
{
30+
return str_replace(' ','', ucwords(str_replace('_', ' ', $str)));
31+
}

tests/SDK/Actions/FinancialTransactionsClassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function setUp()
2424
}
2525
$this->client = ClientBuilder::create()
2626
->setEnvironment(
27-
'test',
27+
'https://test.merchantsafeunipay.com/msu/api/v2',
2828
$MSUPHPSDK_M,
2929
$MSUPHPSDK_U,
3030
$MSUPHPSDK_P

0 commit comments

Comments
 (0)