Skip to content

Commit eeee239

Browse files
authored
Merge pull request #5 from WeGetFinancing/GET-1975
GET-1975
2 parents b2e2f12 + 9dd0e11 commit eeee239

12 files changed

Lines changed: 63 additions & 103 deletions

File tree

.env.dist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
TEST_USERNAME=
22
TEST_PASSWORD=
33
TEST_MERCHANT_ID=
4-
TEST_WEGETFINANCING_URL=
5-
TEST_WEGETFINANCING_URL_V3=

src/Client.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414

1515
class Client
1616
{
17-
protected AuthEntity $authEntity;
18-
19-
public function __construct(AuthEntity $authEntity)
20-
{
21-
$this->authEntity = $authEntity;
17+
public function __construct(
18+
protected AuthEntity $authEntity
19+
) {
2220
}
2321

2422
/**

src/Command/AbstractCommand.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
abstract class AbstractCommand implements CommandInterface
1010
{
11-
protected HttpClientInterface $httpClient;
12-
13-
public function __construct(HttpClientInterface $httpClient)
11+
public function __construct(protected HttpClientInterface $httpClient)
1412
{
15-
$this->httpClient = $httpClient;
1613
}
1714
}

src/Command/RequestNewLoanCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
class RequestNewLoanCommand extends AbstractCommand
1717
{
1818
public const LOAN_REQUEST_VERB = 'POST';
19-
2019
public const LOAN_REQUEST_PATH = '/merchant/' . HttpClientInterface::MERCHANT_ID_REPLACE . '/requests';
2120

2221
/**

src/Command/UpdateShippingStatusCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use WeGetFinancing\SDK\Entity\Request\AbstractRequestEntity;
99
use WeGetFinancing\SDK\Entity\Request\UpdateShippingStatusRequestEntity;
1010
use WeGetFinancing\SDK\Entity\Response\ResponseEntity;
11-
use WeGetFinancing\SDK\Exception\EntityValidationException;
12-
use WeGetFinancing\SDK\Service\Http\HttpClientInterface;
1311
use WeGetFinancing\SDK\Service\Http\V3\HttpClientV3;
1412

1513
class UpdateShippingStatusCommand extends AbstractCommand

src/Entity/AbstractEntity.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,18 @@
1212

1313
abstract class AbstractEntity implements EntityInterface
1414
{
15-
protected ValidatorInterface $validator;
16-
17-
protected NameConverterInterface $camelCaseToSnakeCase;
18-
1915
/**
2016
* @param ValidatorInterface $validator
2117
* @param NameConverterInterface $camelCaseToSnakeCase
2218
* @param null|array<string, mixed> $data
2319
* @throws EntityValidationException
2420
*/
2521
public function __construct(
26-
ValidatorInterface $validator,
27-
NameConverterInterface $camelCaseToSnakeCase,
22+
protected ValidatorInterface $validator,
23+
protected NameConverterInterface $camelCaseToSnakeCase,
2824
array $data = null
2925
) {
30-
$this->validator = $validator;
31-
$this->camelCaseToSnakeCase = $camelCaseToSnakeCase;
32-
33-
if (
34-
true === is_null($data) ||
35-
true === empty($data)
36-
) {
26+
if (true === is_null($data) || true === empty($data)) {
3727
return;
3828
}
3929

src/Entity/AuthEntity.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,7 @@ class AuthEntity extends AbstractEntity
3737
*/
3838
protected string $merchantId;
3939

40-
/**
41-
* @Assert\Url(
42-
* protocols = { "https" },
43-
* message = "The value of url is not a valid URL."
44-
* )
45-
* @Assert\NotBlank(message = "The value of url should not be blank.")
46-
*/
47-
protected string $url;
40+
protected bool $prod = false;
4841

4942
/**
5043
* @SuppressWarnings(PHPMD.StaticAccess)
@@ -77,8 +70,8 @@ public function getMerchantId(): string
7770
return $this->merchantId;
7871
}
7972

80-
public function getUrl(): string
73+
public function isProd(): bool
8174
{
82-
return $this->url;
75+
return $this->prod;
8376
}
8477
}

src/Service/Http/AbstractHttpClient.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,39 @@
99

1010
abstract class AbstractHttpClient implements HttpClientInterface
1111
{
12-
public AuthEntity $authEntity;
13-
14-
protected ClientInterface $httpClient;
12+
public const URL_API_V1_PROD = 'https://api.wegetfinancing.com';
13+
public const URL_API_V1_SANDBOX = 'https://api.sandbox.wegetfinancing.com';
14+
public const URL_API_V3_PROD = 'https://apisrv.wegetfinancing.com';
15+
public const URL_API_V3_SANDBOX = 'https://apisrv.sandbox.wegetfinancing.com';
1516

1617
/**
1718
* @param AuthEntity $authEntity
1819
* @param ClientInterface $httpClient
1920
*/
2021
public function __construct(
21-
AuthEntity $authEntity,
22-
ClientInterface $httpClient
22+
public AuthEntity $authEntity,
23+
protected ClientInterface $httpClient
2324
) {
24-
$this->authEntity = $authEntity;
25-
$this->httpClient = $httpClient;
2625
}
2726

28-
protected function getUrlFromPath(string $path): string
27+
protected function getBaseUrlApiV1(): string
28+
{
29+
return (true === $this->authEntity->isProd()) ? self::URL_API_V1_PROD : self::URL_API_V1_SANDBOX;
30+
}
31+
32+
protected function getBaseUrlApiV3(): string
33+
{
34+
return (true === $this->authEntity->isProd()) ? self::URL_API_V3_PROD : self::URL_API_V3_SANDBOX;
35+
}
36+
37+
protected function getUrlApiV1FromPath(string $path): string
38+
{
39+
return $this->getBaseUrlApiV1() . $path;
40+
}
41+
42+
protected function getUrlApiV3FromPath(string $path): string
2943
{
30-
return $this->authEntity->getUrl() . $path;
44+
return $this->getBaseUrlApiV3() . $path;
3145
}
3246

3347
protected function getMerchantIdPath(string $path): string
@@ -39,9 +53,9 @@ protected function getMerchantIdPath(string $path): string
3953
);
4054
}
4155

42-
protected function getUrlFromMerchantIdPath(string $path): string
56+
protected function getUrlApiV1FromMerchantIdPath(string $path): string
4357
{
44-
return $this->getUrlFromPath(
58+
return $this->getUrlApiV1FromPath(
4559
$this->getMerchantIdPath($path)
4660
);
4761
}

src/Service/Http/V1/HttpClientV1.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@
1414
class HttpClientV1 extends AbstractHttpClient
1515
{
1616
public const DEFAULT_ERROR_ERROR = 'unknown-error';
17-
1817
public const DEFAULT_ERROR_MESSAGE = 'Impossible to decode response content.';
19-
2018
public const DEFAULT_ERROR_STAMP = '0x0';
21-
2219
public const DEFAULT_ERROR_TYPE = 'error';
23-
2420
public const HEADERS = [
2521
'Content-Type' => 'application/json',
2622
'Accept' => 'application/json',
@@ -51,7 +47,7 @@ public function request(string $verb, string $path, array $data): ResponseEntity
5147
{
5248
$response = $this->httpClient->request(
5349
$verb,
54-
$this->getUrlFromMerchantIdPath($path),
50+
$this->getUrlApiV1FromMerchantIdPath($path),
5551
[
5652
'http_errors' => false,
5753
'headers' => $this->getHeaders(),

src/Service/Http/V3/HttpClientV3.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function request(string $verb, string $path, array $data): ResponseEntity
4848

4949
$response = $this->httpClient->request(
5050
$verb,
51-
$this->getUrlFromPath($path),
51+
$this->getUrlApiV3FromPath($path),
5252
[
5353
'http_errors' => false,
5454
'headers' => $this->getAuthenticatedHeaders($token['access_token']),
@@ -97,7 +97,7 @@ public function getToken(): mixed
9797
{
9898
$response = $this->httpClient->request(
9999
'POST',
100-
$this->getUrlFromPath('/v3/auth'),
100+
$this->getUrlApiV3FromPath('/v3/auth'),
101101
[
102102
'http_errors' => false,
103103
'headers' => self::HEADERS,

0 commit comments

Comments
 (0)