Skip to content

Commit

Permalink
Add PSU IP address as optional parameter when fetching transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo Kovačić committed May 12, 2023
1 parent 1fd0357 commit 45613dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/ErsteBankClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public function getAccounts(string $token, string $consentId, array $params): ar
return $this->serializer->deserialize(json_encode($accountsArray), Account::class.'[]', 'json');
}

public function getTransactions(string $token, string $consentId, string $accountId, array $params): TransactionType
public function getTransactions(string $token, string $consentId, string $accountId, array $params, ?string $psuIpAddress = null): TransactionType
{
$transactionsResponse = $this->httpClient->getTransactions($token, $consentId, $accountId, $params);
$transactionsResponse = $this->httpClient->getTransactions($token, $consentId, $accountId, $params, $psuIpAddress);
return $this->serializer->deserialize(
$transactionsResponse->getBody()->getContents(),
TransactionResponse::class,
Expand Down
26 changes: 17 additions & 9 deletions src/http/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,28 @@ public function getTransactions
string $token,
string $consentId,
string $accountId,
array $params
array $params,
?string $psuIpAddress = null
): ResponseInterface
{
$defaultParams = [
'bookingStatus' => "both",
'bookingStatus' => 'both',
];
$params = array_merge($params, $defaultParams);
$params = array_merge($defaultParams, $params);

$headers = [
'X-Request-ID' => Uuid::uuid4()->toString(),
'consent-id' => $consentId,
'Authorization' => "Bearer {$token}",
'web-api-key' => $this->apiUser->getWebApiKey(),
];

if ($psuIpAddress !== null) {
$headers['PSU-IP-Address'] = $psuIpAddress;
}

return $this->client->get(sprintf('%s/accounts/%s/transactions', $this->dataEndpoint, $accountId), [
RequestOptions::HEADERS => [
'X-Request-ID' => Uuid::uuid4()->toString(),
'consent-id' => $consentId,
'Authorization' => "Bearer {$token}",
'web-api-key' => $this->apiUser->getWebApiKey(),
],
RequestOptions::HEADERS => $headers,
RequestOptions::QUERY => $params,
]);
}
Expand Down

0 comments on commit 45613dd

Please sign in to comment.