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

Split api token endpoints into production and sandbox #5

Merged
merged 1 commit into from
Apr 24, 2023
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
16 changes: 12 additions & 4 deletions src/ErsteBankClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class ErsteBankClient
private $token;
private $consent;
private $apiUser;
/**
* @var string
*/
private $authEndpoint;


public function __construct(
Expand All @@ -37,7 +41,9 @@ public function __construct(
string $redirectUri,
string $pemFilePath,
string $keyFilePath,
string $dataEndpoint = ApiEndpoint::AISP
string $dataEndpoint = ApiEndpoint::AISP_SANDBOX,
string $tokenEndpoint = ApiEndpoint::TOKEN_SANDBOX,
string $authEndpoint = ApiEndpoint::AUTH_SANDBOX
)
{
$this->redirectUri = $redirectUri;
Expand All @@ -49,8 +55,10 @@ public function __construct(
$this->apiUser,
$redirectUri,
new SSLCertificates($pemFilePath, $keyFilePath),
$dataEndpoint
$dataEndpoint,
$tokenEndpoint
);
$this->authEndpoint = $authEndpoint;
}

public function getConsent(): Consent
Expand Down Expand Up @@ -80,8 +88,8 @@ public function getAuthPageUrl(string $consentId): string
];

return sprintf(
'%s/api/ebc/sandbox/v1/sandbox-idp/auth?%s',
HttpClient::BASE_URL, http_build_query($options));
'%s?%s',
$this->authEndpoint, http_build_query($options));
}

public function getTokenByAuthCode(string $authCode): Token
Expand Down
17 changes: 14 additions & 3 deletions src/enum/ApiEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

class ApiEndpoint
{
public const AISP = "https://webapi.developers.erstegroup.com/api/ebc/sandbox/v1/psd2-aisp";
public const NETAPI = "https://webapi.developers.erstegroup.com/api/ebc/sandbox/v1/netapi";
}

public const AISP_SANDBOX = "https://webapi.developers.erstegroup.com/api/ebc/sandbox/v1/psd2-aisp";
public const NETAPI_SANDBOX = "https://webapi.developers.erstegroup.com/api/ebc/sandbox/v1/netapi";

public const AUTH_SANDBOX = 'https://webapi.developers.erstegroup.com/api/ebc/sandbox/v1/sandbox-idp/auth';

public const TOKEN_SANDBOX = 'https://webapi.developers.erstegroup.com/api/ebc/sandbox/v1/sandbox-idp';


public const AISP_PROD = "https://webapi.developers.erstegroup.com/api/ebc/production/v1/psd2-aisp";
public const NETAPI_PROD = "https://webapi.developers.erstegroup.com/api/ebc/production/v1/netapi";
public const TOKEN_PROD = 'https://webapi.developers.erstegroup.com/api/ebc/production/v1/production-idp';
public const AUTH_PROD = 'https://webapi.developers.erstegroup.com/api/ebc/production/v1/production-idp/auth';
}
14 changes: 6 additions & 8 deletions src/http/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,27 @@

class HttpClient
{
public const BASE_URL = 'https://webapi.developers.erstegroup.com';
private const TOKEN_ENDPOINT = 'https://webapi.developers.erstegroup.com/api/ebc/sandbox/v1/sandbox-idp';

private $redirectUri;
private $apiUser;
private $dataEndpoint;
private $tokenEndpoint;

public function __construct(ApiUser $apiUser, string $redirectUri, SSLCertificates $sslCertificates, $dataEndpoint)
public function __construct(ApiUser $apiUser, string $redirectUri, SSLCertificates $sslCertificates, $dataEndpoint, $tokenEndpoint)
{

$this->redirectUri = $redirectUri;
$this->apiUser = $apiUser;
$this->dataEndpoint = $dataEndpoint;

$this->client = new Client([
'base_uri' => self::BASE_URL,
RequestOptions::HEADERS => [
'Content-Type' => 'application/json',
'cache-control' => 'no-cache',
],
RequestOptions::CERT => $sslCertificates->getPemFilePath(),
RequestOptions::SSL_KEY => $sslCertificates->getKeyFilePath(),
]);
$this->tokenEndpoint = $tokenEndpoint;
}

public function getConsent(): ResponseInterface
Expand All @@ -56,7 +54,7 @@ public function getConsent(): ResponseInterface
'transactions' => [],
],
'recurringIndicator' => false,
'validUntil' => '2019-06-30',
'validUntil' => '2030-06-30',
'frequencyPerDay' => 4,
'combinedServiceIndicator' => false,
],
Expand All @@ -74,7 +72,7 @@ public function getTokenByAuthCode(string $authCode): ResponseInterface
'code' => $authCode,
];

return $this->client->post(sprintf('%s/token', self::TOKEN_ENDPOINT), [
return $this->client->post(sprintf('%s/token', $this->tokenEndpoint), [
RequestOptions::FORM_PARAMS => $queryParams,
]
);
Expand All @@ -91,7 +89,7 @@ public function getTokenByRefreshToken(string $refreshToken): ResponseInterface
'refresh_token' => $refreshToken,
];

return $this->client->get(sprintf('%s/token', self::TOKEN_ENDPOINT), [
return $this->client->get(sprintf('%s/token', $this->tokenEndpoint), [
RequestOptions::QUERY => $queryParams,
]
);
Expand Down