Skip to content

Commit 8418265

Browse files
committed
almost working ?!?
1 parent c0255e8 commit 8418265

File tree

13 files changed

+161
-31
lines changed

13 files changed

+161
-31
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ composer.phar
1515
# PHPUnit cache
1616
.phpunit.result.cache
1717
composer.lock
18-
/.env
18+
/.env
19+
/doc/

.openapi-generator/templates/ApiClient.mustache

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ class ApiClient extends \GuzzleHttp\Client
7272
$this->token = boolval(\Ease\Shared::cfg('SANDBOX_MODE'));
7373
}
7474

75-
$config['base_uri'] = ($this->sandBoxMode ? 'https://webapi.developers.erstegroup.com/api/csas/public/sandbox' : 'https://www.csas.cz/webapi/api') . '/v3/accounts/' ;
76-
$config['headers']['web-api-key'] = $this->apiKey;
77-
$config['headers']['authorization'] = 'Bearer '.$this->token;
78-
7975
parent::__construct($config);
8076
}
8177

Examples/accounts.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use Ease\Shared as Shr;
4+
5+
require_once dirname(__DIR__) . '/vendor/autoload.php';
6+
7+
Shr::init([], dirname(__DIR__) . '/.env');
8+
9+
$apiInstance = new \SpojeNET\Csas\Accounts\DefaultApi(new SpojeNET\Csas\ApiClient(
10+
[
11+
'apikey' => Shr::cfg('API_KEY'),
12+
'token' => Shr::cfg('API_TOKEN'),
13+
'debug' => Shr::cfg('API_DEBUG', false),
14+
'sandbox' => Shr::cfg('SANDBOX_MODE')
15+
]
16+
));
17+
18+
try {
19+
$result = $apiInstance->getAccounts();
20+
print_r($result);
21+
} catch (Exception $e) {
22+
echo 'Exception when calling DefaultApi->getAccounts: ', $e->getMessage(), PHP_EOL;
23+
}

Examples/auth.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
$productionSite = 'https://bezpecnost.csas.cz/api/psd2/fl/oidc/v1';
1212
$sandboxSite = 'https://webapi.developers.erstegroup.com/api/csas/sandbox/v1/sandbox-idp';
13-
$idpLink = (strtolower(Shr::cfg('API_ENVIRONMENT', 'production')) === 'sandbox') ? $sandboxSite : $productionSite;
13+
$idpLink = Shr::cfg('SANDBOX_MODE', false) ? $sandboxSite : $productionSite;
1414

1515
/**
1616
* @link https://developers.erstegroup.com/docs/tutorial/csas-how-to-call-api Authentization & Authorization
@@ -19,9 +19,9 @@
1919
$idpParams = [
2020
'client_id' => Shr::cfg('CLIENT_ID'),
2121
'response_type' => 'code',
22-
'prompt' => 'consent',
2322
'redirect_uri' => Shr::cfg('REDIRECT_URI'),
2423
'state' => Fnc::randomString(),
24+
'access_type' => 'offline',
2525
'scope' => implode('%20', [
2626
'siblings.accounts',
2727
// 'siblings.payments',

Examples/balance.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
<?php
22

33
use Ease\Shared as Shr;
4-
use Ease\Functions as Fnc;
54

65
require_once dirname(__DIR__) . '/vendor/autoload.php';
76

87
Shr::init([], dirname(__DIR__) . '/.env');
98

109
$apiInstance = new \SpojeNET\Csas\Accounts\DefaultApi(new SpojeNET\Csas\ApiClient(
1110
[
12-
'apikey' => \Ease\Shared::cfg('API_KEY'),
13-
'token' => \Ease\Shared::cfg('API_TOKEN'),
14-
'debug' => \Ease\Shared::cfg('API_DEBUG', false),
15-
'sandbox' => \Ease\Shared::cfg('SANDBOX_MODE')
11+
'apikey' => Shr::cfg('API_KEY'),
12+
'token' => Shr::cfg('API_TOKEN'),
13+
'debug' => Shr::cfg('API_DEBUG', false),
14+
'sandbox' => Shr::cfg('SANDBOX_MODE')
1615
]
1716
));
1817

1918
try {
20-
$result = $apiInstance->getAccountBalance(\Ease\Shared::cfg('ACCOUNT'));
19+
$result = $apiInstance->getAccountBalance(Shr::cfg('ACCOUNT'));
2120
print_r($result);
2221
} catch (Exception $e) {
2322
echo 'Exception when calling DefaultApi->getAccountBalance: ', $e->getMessage(), PHP_EOL;

Examples/redirectedFromBank.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
$productionSite = 'https://bezpecnost.csas.cz/api/psd2/fl/oidc/v1';
1616
$sandboxSite = 'https://webapi.developers.erstegroup.com/api/csas/sandbox/v1/sandbox-idp';
17-
$idpLink = (strtolower(Shr::cfg('API_ENVIRONMENT', 'production')) === 'sandbox') ? $sandboxSite : $productionSite;
18-
17+
$idpLink = Shr::cfg('SANDBOX_MODE', false) ? $sandboxSite : $productionSite;
1918
$tokenUrl = $idpLink . '/token';
2019

2120
// Start session
@@ -55,7 +54,11 @@
5554
if (isset($responseData['access_token'])) {
5655
// Store the access token in the session
5756
$_SESSION['access_token'] = $responseData['access_token'];
58-
echo 'Access token obtained successfully!';
57+
echo '<h2>Access token obtained successfully!</h2>';
58+
59+
echo 'access token:<textarea>' . $responseData['access_token'] . '</textarea>';
60+
echo 'refresh token:<textarea>' . $responseData['refresh_token'] . '</textarea>';
61+
var_dump($responseData);
5962
} else {
6063
echo 'Error obtaining access token!';
6164

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,20 @@ require_once(__DIR__ . '/vendor/autoload.php');
5050

5151

5252

53+
// Configure API key authorization: ApiKeyAuth
54+
$config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setApiKey('web-api-key', 'YOUR_API_KEY');
55+
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
56+
// $config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setApiKeyPrefix('web-api-key', 'Bearer');
57+
58+
// Configure Bearer (JWT) authorization: bearerAuth
59+
$config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
60+
5361

5462
$apiInstance = new SpojeNET\Csas\Api\DefaultApi(
5563
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
5664
// This is optional, `GuzzleHttp\Client` will be used as default.
57-
new GuzzleHttp\Client()
65+
new GuzzleHttp\Client(),
66+
$config
5867
);
5968
$id = 'id_example'; // string | Opaque system ID of the account
6069

@@ -105,7 +114,18 @@ Class | Method | HTTP request | Description
105114
- [TransactionListTransactionsInner](docs/Model/TransactionListTransactionsInner.md)
106115

107116
## Authorization
108-
Endpoints do not require authorization.
117+
118+
Authentication schemes defined for the API:
119+
### bearerAuth
120+
121+
- **Type**: Bearer authentication (JWT)
122+
123+
### ApiKeyAuth
124+
125+
- **Type**: API key
126+
- **API key parameter name**: web-api-key
127+
- **Location**: HTTP header
128+
109129

110130
## Tests
111131

docs/Api/DefaultApi.md

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,20 @@ Get the current balance of the account.
2727
require_once(__DIR__ . '/vendor/autoload.php');
2828

2929

30+
// Configure API key authorization: ApiKeyAuth
31+
$config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setApiKey('web-api-key', 'YOUR_API_KEY');
32+
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
33+
// $config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setApiKeyPrefix('web-api-key', 'Bearer');
34+
35+
// Configure Bearer (JWT) authorization: bearerAuth
36+
$config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
37+
3038

3139
$apiInstance = new SpojeNET\Csas\Api\DefaultApi(
3240
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
3341
// This is optional, `GuzzleHttp\Client` will be used as default.
34-
new GuzzleHttp\Client()
42+
new GuzzleHttp\Client(),
43+
$config
3544
);
3645
$id = 'id_example'; // string | Opaque system ID of the account
3746

@@ -55,7 +64,7 @@ try {
5564

5665
### Authorization
5766

58-
No authorization required
67+
[ApiKeyAuth](../../README.md#ApiKeyAuth), [bearerAuth](../../README.md#bearerAuth)
5968

6069
### HTTP request headers
6170

@@ -83,11 +92,20 @@ Get a list of accounts for the authenticated user.
8392
require_once(__DIR__ . '/vendor/autoload.php');
8493

8594

95+
// Configure API key authorization: ApiKeyAuth
96+
$config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setApiKey('web-api-key', 'YOUR_API_KEY');
97+
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
98+
// $config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setApiKeyPrefix('web-api-key', 'Bearer');
99+
100+
// Configure Bearer (JWT) authorization: bearerAuth
101+
$config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
102+
86103

87104
$apiInstance = new SpojeNET\Csas\Api\DefaultApi(
88105
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
89106
// This is optional, `GuzzleHttp\Client` will be used as default.
90-
new GuzzleHttp\Client()
107+
new GuzzleHttp\Client(),
108+
$config
91109
);
92110
$size = 56; // int | Number of accounts to return
93111
$page = 56; // int | Page number to return
@@ -117,7 +135,7 @@ try {
117135

118136
### Authorization
119137

120-
No authorization required
138+
[ApiKeyAuth](../../README.md#ApiKeyAuth), [bearerAuth](../../README.md#bearerAuth)
121139

122140
### HTTP request headers
123141

@@ -145,11 +163,20 @@ Obtain list of statements for a given account.
145163
require_once(__DIR__ . '/vendor/autoload.php');
146164

147165

166+
// Configure API key authorization: ApiKeyAuth
167+
$config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setApiKey('web-api-key', 'YOUR_API_KEY');
168+
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
169+
// $config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setApiKeyPrefix('web-api-key', 'Bearer');
170+
171+
// Configure Bearer (JWT) authorization: bearerAuth
172+
$config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
173+
148174

149175
$apiInstance = new SpojeNET\Csas\Api\DefaultApi(
150176
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
151177
// This is optional, `GuzzleHttp\Client` will be used as default.
152-
new GuzzleHttp\Client()
178+
new GuzzleHttp\Client(),
179+
$config
153180
);
154181
$id = 'id_example'; // string | Unique system identification of the client account
155182
$fromDate = new \DateTime('2013-10-20T19:20:30+01:00'); // \DateTime | Date from which the statement history should be obtained (yyyy-MM-dd)
@@ -183,7 +210,7 @@ try {
183210

184211
### Authorization
185212

186-
No authorization required
213+
[ApiKeyAuth](../../README.md#ApiKeyAuth), [bearerAuth](../../README.md#bearerAuth)
187214

188215
### HTTP request headers
189216

@@ -211,11 +238,20 @@ Paginated and optionally filtered (by dates) transaction list for given account.
211238
require_once(__DIR__ . '/vendor/autoload.php');
212239

213240

241+
// Configure API key authorization: ApiKeyAuth
242+
$config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setApiKey('web-api-key', 'YOUR_API_KEY');
243+
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
244+
// $config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setApiKeyPrefix('web-api-key', 'Bearer');
245+
246+
// Configure Bearer (JWT) authorization: bearerAuth
247+
$config = SpojeNET\Csas\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
248+
214249

215250
$apiInstance = new SpojeNET\Csas\Api\DefaultApi(
216251
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
217252
// This is optional, `GuzzleHttp\Client` will be used as default.
218-
new GuzzleHttp\Client()
253+
new GuzzleHttp\Client(),
254+
$config
219255
);
220256
$id = 'id_example'; // string | Unique system identification of the client account
221257
$fromDate = new \DateTime('2013-10-20T19:20:30+01:00'); // \DateTime | Filter transactions starting from a specific day in UTC (yyyy-MM-dd)
@@ -251,7 +287,7 @@ try {
251287

252288
### Authorization
253289

254-
No authorization required
290+
[ApiKeyAuth](../../README.md#ApiKeyAuth), [bearerAuth](../../README.md#bearerAuth)
255291

256292
### HTTP request headers
257293

example.env

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
3+
APPLICATION_ID=cb00b9a2-4499-454e-a97b-xxxxxxxxxxxx
4+
API_KEY=041cf408-2deb-4a70-933d-xxxxxxxxxxxx
5+
CLIENT_ID=51b58567-22b6-46bd-877b-xxxxxxxxxxxx
6+
CLIENT_SECRET=6f0684d8-e87b-43cb-80e6-xxxxxxxxxxxx
7+
8+
SANDBOX_MODE=1
9+
DEBUG_API=1
10+
11+
REDIRECT_URI=http://localhost/php-csas-webapi/Examples/redirectedFromBank.php
12+
13+
ACCOUNT=CZ1208000000000259459101
14+
#ACCOUNT=CZ4108000000000782553098
15+
16+
API_TOKEN=<Get your using http://localhost/php-csas-webapi/Examples/auth.php>

lib/Accounts/DefaultApi.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,15 @@ public function getAccountBalanceRequest($id, string $contentType = self::conten
753753
}
754754
}
755755

756+
// this endpoint requires API key authentication
757+
$apiKey = $this->config->getApiKeyWithPrefix('web-api-key');
758+
if ($apiKey !== null) {
759+
$headers['web-api-key'] = $apiKey;
760+
}
761+
// this endpoint requires Bearer (JWT) authentication (access token)
762+
if (!empty($this->config->getAccessToken())) {
763+
$headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
764+
}
756765

757766
$defaultHeaders = [];
758767
if ($this->config->getUserAgent()) {
@@ -1381,6 +1390,15 @@ public function getAccountsRequest($size = null, $page = null, $sort = null, $or
13811390
}
13821391
}
13831392

1393+
// this endpoint requires API key authentication
1394+
$apiKey = $this->config->getApiKeyWithPrefix('web-api-key');
1395+
if ($apiKey !== null) {
1396+
$headers['web-api-key'] = $apiKey;
1397+
}
1398+
// this endpoint requires Bearer (JWT) authentication (access token)
1399+
if (!empty($this->config->getAccessToken())) {
1400+
$headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
1401+
}
13841402

13851403
$defaultHeaders = [];
13861404
if ($this->config->getUserAgent()) {
@@ -1974,6 +1992,15 @@ public function getStatementsRequest($id, $fromDate = null, $toDate = null, $for
19741992
}
19751993
}
19761994

1995+
// this endpoint requires API key authentication
1996+
$apiKey = $this->config->getApiKeyWithPrefix('web-api-key');
1997+
if ($apiKey !== null) {
1998+
$headers['web-api-key'] = $apiKey;
1999+
}
2000+
// this endpoint requires Bearer (JWT) authentication (access token)
2001+
if (!empty($this->config->getAccessToken())) {
2002+
$headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
2003+
}
19772004

19782005
$defaultHeaders = [];
19792006
if ($this->config->getUserAgent()) {
@@ -2687,6 +2714,15 @@ public function getTransactionsRequest($id, $fromDate = null, $toDate = null, $s
26872714
}
26882715
}
26892716

2717+
// this endpoint requires API key authentication
2718+
$apiKey = $this->config->getApiKeyWithPrefix('web-api-key');
2719+
if ($apiKey !== null) {
2720+
$headers['web-api-key'] = $apiKey;
2721+
}
2722+
// this endpoint requires Bearer (JWT) authentication (access token)
2723+
if (!empty($this->config->getAccessToken())) {
2724+
$headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
2725+
}
26902726

26912727
$defaultHeaders = [];
26922728
if ($this->config->getUserAgent()) {

0 commit comments

Comments
 (0)