Skip to content

Commit b991e66

Browse files
committed
The mocking api is now availble
1 parent 8e294c9 commit b991e66

File tree

12 files changed

+291
-16
lines changed

12 files changed

+291
-16
lines changed

.openapi-generator/templates/ApiClient.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class ApiClient extends \GuzzleHttp\Client
5757
public function __construct(array $config = [])
5858
{
5959
if (array_key_exists('clientid', $config) === false) {
60-
$this->xIBMClientID = \Ease\Functions::cfg('XIBMCLIENTID');
60+
$this->xIBMClientId = \Ease\Functions::cfg('XIBMCLIENTID');
61+
} else {
62+
$this->xIBMClientId = $config['clientid'];
6163
}
6264

6365
if (array_key_exists('cert', $config) === false) {
@@ -72,7 +74,7 @@ public function __construct(array $config = [])
7274

7375
if (array_key_exists('debug', $config) === false) {
7476
$config['debug'] = \Ease\Functions::cfg('API_DEBUG', false);
75-
}
77+
}
7678

7779
if(array_key_exists('clientpubip', $config)){
7880
$this->pSUIPAddress = $config['clientpubip'];

.openapi-generator/templates/api.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ use {{invokerPackage}}\ObjectSerializer;
148148
* @param boolean $mocking Use mocking api for development purposes ?
149149
*/
150150
public function setMockMode($mocking) {
151-
$his->mockMode = $mocking;
151+
$this->mockMode = $mocking;
152152
}
153153

154154
/**
@@ -668,7 +668,7 @@ use {{invokerPackage}}\ObjectSerializer;
668668

669669
$resourcePath = '{{{path}}}';
670670
if($this->mockMode === true){
671-
$resoucePath = str_replace('/rbcz/premium/api/', '/rbcz/premium/mock/', $sourcePath);
671+
$resourcePath = str_replace('/rbcz/premium/api/', '/rbcz/premium/mock/', $resourcePath);
672672
}
673673
$formParams = [];
674674
$queryParams = [];

debian/changelog

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
php-vitexsoftware-rbczpremiumapi (1.0) UNRELEASED; urgency=medium
1+
php-vitexsoftware-rbczpremiumapi (1.1.0) UNRELEASED; urgency=medium
22

33
[ Vítězslav Dvořák ]
44
* initial content
55

66
[ vitex ]
77
* Production Endoint Used
8+
* mocking ability added
89

9-
-- vitex <info@vitexsoftware.cz> Sun, 02 Apr 2023 11:49:51 +0200
10+
-- vitex <info@vitexsoftware.cz> Tue, 25 Apr 2023 23:46:16 +0200

examples/getstatements.php

Lines changed: 127 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,140 @@
1212
//Always provide the closest IP address to the real end-user possible.
1313

1414
$request_body = new Model\GetStatementsRequest(['account_number' => '1899297002', 'currency' => 'CZK', 'statementLine' => 'MAIN']);
15-
$page = 56; // int | Number of the requested page. Default is 1.
16-
$size = 56; // int | Number of items on the page. Default is 15.
15+
$page = 1; // int | Number of the requested page. Default is 1.
16+
$size = 80; // int | Number of items on the page. Default is 15.
1717

1818
$apiInstance = new PremiumAPI\GetStatementListApi(new ApiClient([
1919
'clientpubip' => $psu_ip_address,
20-
'clientid' => $x_ibm_client_id
20+
'clientid' => $x_ibm_client_id,
21+
'mocking' => true
2122
]));
2223
try {
2324
$result = $apiInstance->getStatements($x_request_id, $request_body, $page, $size);
2425
print_r($result);
2526
} catch (\Ease\Exception $e) {
2627
echo 'Exception when calling GetStatementListApi->getStatements: ', $e->getMessage(), PHP_EOL;
2728
}
29+
30+
31+
/**
32+
33+
34+
"/usr/bin/php" "/home/vitex/Projects/VitexSoftware/php-vitexsoftware-rbczpremiumapi/examples/getstatements.php"
35+
* Trying 82.99.167.1:443...
36+
* Connected to api.rb.cz (82.99.167.1) port 443 (#0)
37+
* ALPN, offering http/1.1
38+
* successfully set certificate verify locations:
39+
* CAfile: /etc/ssl/certs/ca-certificates.crt
40+
* CApath: /etc/ssl/certs
41+
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
42+
* ALPN, server accepted to use http/1.1
43+
* Server certificate:
44+
* subject: C=CZ; L=Praha; O=Raiffeisenbank a.s.; CN=api.rb.cz
45+
* start date: May 4 00:00:00 2022 GMT
46+
* expire date: May 4 23:59:59 2023 GMT
47+
* subjectAltName: host "api.rb.cz" matched cert's "api.rb.cz"
48+
* issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS RSA SHA256 2020 CA1
49+
* SSL certificate verify ok.
50+
> POST /rbcz/premium/mock/accounts/statements?page=1&size=80 HTTP/1.1
51+
Host: api.rb.cz
52+
User-Agent: VitexSoftware/RBCZPremiumAPI/0.1.0/PHP
53+
X-IBM-Client-Id: FbboLD2r1WHDRcuKS4wWUbSRHxlDloWL
54+
X-Request-Id: 1682458803
55+
Accept: application/json
56+
Content-Type: application/json
57+
Content-Length: 41
58+
59+
* upload completely sent off: 41 out of 41 bytes
60+
* old SSL session ID is stale, removing
61+
* Mark bundle as not supporting multiuse
62+
< HTTP/1.1 200 OK
63+
< Date: Tue, 25 Apr 2023 21:40:46 GMT
64+
< Server: RBCZ
65+
< content-type: application/json; charset=utf-8
66+
< content-length: 1313
67+
< x-ratelimit-limit-second: 5
68+
< x-ratelimit-remaining-second: 4
69+
< x-ratelimit-limit-day: 1000
70+
< x-ratelimit-remaining-day: 999
71+
< ratelimit-limit: 5
72+
< ratelimit-remaining: 4
73+
< ratelimit-reset: 1
74+
< x-kong-upstream-latency: 6
75+
< x-kong-proxy-latency: 6
76+
< via: kong/2.8.1.1-enterprise-edition
77+
< set-cookie: 00cdf75109dda7379df35556e601cac3=bf1c63b65fd3d882f20faa636a31ad8b; path=/; HttpOnly; Secure; SameSite=None
78+
< X-Correlation-Id: 1682458803
79+
<
80+
* Connection #0 to host api.rb.cz left intact
81+
Array
82+
(
83+
[statements] => Array
84+
(
85+
[0] => stdClass Object
86+
(
87+
[statementId] => ab0cb1e8-1926-4c8c-b51e-66f0781f302c
88+
[accountId] => 3
89+
[statementNumber] => 06/2015
90+
[dateFrom] => 2015-06-01
91+
[dateTo] => 2015-06-30
92+
[statementFormats] => Array
93+
(
94+
[0] => pdf
95+
)
96+
97+
)
98+
99+
[1] => stdClass Object
100+
(
101+
[statementId] => f729e637-acf9-4261-8200-8a4e83421759
102+
[accountId] => 3
103+
[statementNumber] => 07/2015
104+
[dateFrom] => 2015-07-01
105+
[dateTo] => 2015-07-31
106+
[statementFormats] => Array
107+
(
108+
[0] => xml
109+
)
110+
111+
)
112+
113+
[2] => stdClass Object
114+
(
115+
[statementId] => 940bc713-919e-4a32-81b8-3be7927081f0
116+
[accountId] => 3
117+
[statementNumber] => 08/2015
118+
[dateFrom] => 2015-08-01
119+
[dateTo] => 2015-08-31
120+
[statementFormats] => Array
121+
(
122+
[0] => MT940
123+
)
124+
125+
)
126+
127+
[3] => stdClass Object
128+
(
129+
[statementId] => 911f1790-1f78-4881-af50-f46054a82698
130+
[accountId] => 3
131+
[statementNumber] => 09/2015
132+
[dateFrom] => 2015-08-01
133+
[dateTo] => 2015-08-31
134+
[statementFormats] => Array
135+
(
136+
)
137+
138+
)
139+
140+
)
141+
142+
[page] => 1
143+
[size] => 10
144+
[first] => 1
145+
[last] => 1
146+
[totalSize] => 4
147+
[totalPages] => 1
148+
)
149+
Done.
150+
151+
*/

lib/ApiClient.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,41 +36,53 @@ class ApiClient extends \GuzzleHttp\Client
3636
*/
3737
protected $pSUIPAddress = null;
3838

39+
/**
40+
* Use mocking for api calls ?
41+
* @var boolean
42+
*/
43+
protected $mockMode = false;
3944

4045
/**
4146
* @inheritDoc
4247
*
4348
* $config['clientid'] - obtained from Developer Portal - when you registered your app with us.
4449
* $config['cert'] = ['/path/to/cert.p12','certificat password']
4550
* $config['clientpubip'] = the closest IP address to the real end-user
51+
* $config['mocking'] = true to use /rbcz/premium/mock/* endpoints
4652
*
4753
* @param array $config
48-
* @throws Exception CERT_FILE is not set
49-
* @throws Exception CERT_PASS is not set
54+
* @throws \Exception CERT_FILE is not set
55+
* @throws \Exception CERT_PASS is not set
5056
*/
5157
public function __construct(array $config = [])
5258
{
5359
if (array_key_exists('clientid', $config) === false) {
54-
$this->xIBMClientID = \Ease\Functions::cfg('XIBMCLIENTID');
60+
$this->xIBMClientId = \Ease\Functions::cfg('XIBMCLIENTID');
61+
} else {
62+
$this->xIBMClientId = $config['clientid'];
5563
}
5664

5765
if (array_key_exists('cert', $config) === false) {
5866
$config['cert'] = [\Ease\Functions::cfg('CERT_FILE'), \Ease\Functions::cfg('CERT_PASS')];
5967
if (empty($config['cert'][0])) {
60-
throw new Exception('Certificate (CERT_FILE) not specified');
68+
throw new \Exception('Certificate (CERT_FILE) not specified');
6169
}
6270
if (empty($config['cert'][1])) {
63-
throw new Exception('Certificate password (CERT_PASS) not specified');
71+
throw new \Exception('Certificate password (CERT_PASS) not specified');
6472
}
6573
}
6674

6775
if (array_key_exists('debug', $config) === false) {
6876
$config['debug'] = \Ease\Functions::cfg('API_DEBUG', false);
69-
}
77+
}
7078

7179
if(array_key_exists('clientpubip', $config)){
7280
$this->pSUIPAddress = $config['clientpubip'];
7381
}
82+
83+
if(array_key_exists('mocking', $config)){
84+
$this->mockMode = boolval($config['mocking']);
85+
}
7486

7587
parent::__construct($config);
7688
}
@@ -82,7 +94,7 @@ public function __construct(array $config = [])
8294
*/
8395
public function getXIBMClientId()
8496
{
85-
return $this->xIBMClientID;
97+
return $this->xIBMClientId;
8698
}
8799

88100
/**
@@ -94,6 +106,16 @@ public function getpSUIPAddress()
94106
{
95107
return $this->pSUIPAddress;
96108
}
109+
110+
/**
111+
* Use mocking uri for api calls ?
112+
*
113+
* @return boolean
114+
*/
115+
public function getMockMode()
116+
{
117+
return $this->mockMode;
118+
}
97119

98120
/**
99121
* Obtain Your current Public IP

lib/PremiumAPI/DownloadStatementApi.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ class DownloadStatementApi
7777
*/
7878
protected $xIBMClientId = null;
7979

80+
/**
81+
* Use the /rbcz/premium/mock/* path for endpoints ?
82+
*/
83+
protected $mockMode = false;
84+
8085
/**
8186
* the end IP address of the client application (no server) in IPv4 or IPv6 format. If the bank client (your user) uses a browser by which he accesses your server app, we need to know the IP address of his browser. Always provide the closest IP address to the real end-user possible. (optional)
8287
*
@@ -113,6 +118,9 @@ public function __construct(
113118
if(method_exists($this->client, 'getpSUIPAddress')){
114119
$this->setSUIPAddress($this->client->getpSUIPAddress());
115120
}
121+
if(method_exists($this->client, 'getMockMode')){
122+
$this->setMockMode($this->client->getMockMode());
123+
}
116124
}
117125

118126
/**
@@ -144,6 +152,13 @@ public function setSUIPAddress($SUIPAddress) {
144152
$this->SUIPAddress;
145153
}
146154

155+
/**
156+
* @param boolean $mocking Use mocking api for development purposes ?
157+
*/
158+
public function setMockMode($mocking) {
159+
$this->mockMode = $mocking;
160+
}
161+
147162
/**
148163
* Set the host index
149164
*
@@ -535,6 +550,9 @@ public function downloadStatementRequest( $xRequestId, $acceptLanguage, $request
535550

536551

537552
$resourcePath = '/rbcz/premium/api/accounts/statements/download';
553+
if($this->mockMode === true){
554+
$resourcePath = str_replace('/rbcz/premium/api/', '/rbcz/premium/mock/', $resourcePath);
555+
}
538556
$formParams = [];
539557
$queryParams = [];
540558
$headerParams = [];

lib/PremiumAPI/GetAccountBalanceApi.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ class GetAccountBalanceApi
7777
*/
7878
protected $xIBMClientId = null;
7979

80+
/**
81+
* Use the /rbcz/premium/mock/* path for endpoints ?
82+
*/
83+
protected $mockMode = false;
84+
8085
/**
8186
* the end IP address of the client application (no server) in IPv4 or IPv6 format. If the bank client (your user) uses a browser by which he accesses your server app, we need to know the IP address of his browser. Always provide the closest IP address to the real end-user possible. (optional)
8287
*
@@ -113,6 +118,9 @@ public function __construct(
113118
if(method_exists($this->client, 'getpSUIPAddress')){
114119
$this->setSUIPAddress($this->client->getpSUIPAddress());
115120
}
121+
if(method_exists($this->client, 'getMockMode')){
122+
$this->setMockMode($this->client->getMockMode());
123+
}
116124
}
117125

118126
/**
@@ -144,6 +152,13 @@ public function setSUIPAddress($SUIPAddress) {
144152
$this->SUIPAddress;
145153
}
146154

155+
/**
156+
* @param boolean $mocking Use mocking api for development purposes ?
157+
*/
158+
public function setMockMode($mocking) {
159+
$this->mockMode = $mocking;
160+
}
161+
147162
/**
148163
* Set the host index
149164
*
@@ -500,6 +515,9 @@ public function getBalanceRequest( $xRequestId, $accountNumber, string $content
500515

501516

502517
$resourcePath = '/rbcz/premium/api/accounts/{accountNumber}/balance';
518+
if($this->mockMode === true){
519+
$resourcePath = str_replace('/rbcz/premium/api/', '/rbcz/premium/mock/', $resourcePath);
520+
}
503521
$formParams = [];
504522
$queryParams = [];
505523
$headerParams = [];

0 commit comments

Comments
 (0)