From 45613dde7ec02a28f0c65f154cf540da5687a4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Kova=C4=8Di=C4=87?= Date: Fri, 12 May 2023 14:29:30 +0200 Subject: [PATCH] Add PSU IP address as optional parameter when fetching transactions --- src/ErsteBankClient.php | 4 ++-- src/http/HttpClient.php | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/ErsteBankClient.php b/src/ErsteBankClient.php index 79cbd51..66f6b26 100644 --- a/src/ErsteBankClient.php +++ b/src/ErsteBankClient.php @@ -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, diff --git a/src/http/HttpClient.php b/src/http/HttpClient.php index 224c0a4..04445c4 100644 --- a/src/http/HttpClient.php +++ b/src/http/HttpClient.php @@ -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, ]); }