From 70d9d62370c46bb106390d881a305b3f4e61ccfd Mon Sep 17 00:00:00 2001 From: VojtaB Date: Wed, 11 Mar 2026 18:56:07 +0100 Subject: [PATCH 1/6] 6511 method getAccountStatementGPC added --- .github/workflows/ci.yml | 56 ++++++++++++++++++++++++ doc/download-account-transaction-GPC.md | 49 +++++++++++++++++++++ doc/index.md | 3 ++ src/Service/ApiService.php | 33 ++++++++++++-- src/Service/ApiServiceInterface.php | 4 ++ src/TheClient.php | 16 +++++++ src/TheConfig.php | 5 +++ src/ValueObject/GPCPaymentIdentifier.php | 24 ++++++++++ tests/BaseTestCase.php | 33 ++++++++++---- tests/PaymentMethodsTest.php | 2 +- tests/TheClientTest.php | 21 ++++++++- 11 files changed, 231 insertions(+), 15 deletions(-) create mode 100644 doc/download-account-transaction-GPC.md create mode 100644 src/ValueObject/GPCPaymentIdentifier.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a6d3c1f..0665853 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,11 @@ jobs: name: "php 8.4" runs-on: ubuntu-latest container: "nofutur3/php-tests:8.4" + services: + openAPImock: + image: mockserver/mockserver + ports: + - 1080:1080 steps: - name: Checkout repository uses: actions/checkout@v4 @@ -20,6 +25,9 @@ jobs: - name: Run static analysis run: composer stan + - name: Create mock server from our production OpenAPI + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + - name: Run tests run: composer test @@ -27,6 +35,11 @@ jobs: name: "php 8.3" runs-on: ubuntu-latest container: "nofutur3/php-tests:8.3" + services: + openAPImock: + image: mockserver/mockserver + ports: + - 1080:1080 steps: - name: Checkout repository uses: actions/checkout@v4 @@ -37,6 +50,9 @@ jobs: - name: Run static analysis run: composer stan + - name: Create mock server from our production OpenAPI + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + - name: Run tests run: composer test @@ -44,6 +60,11 @@ jobs: name: "php 8.2 psr/http-message 2.0" runs-on: ubuntu-latest container: "nofutur3/php-tests:8.2" + services: + openAPImock: + image: mockserver/mockserver + ports: + - 1080:1080 steps: - name: Checkout repository uses: actions/checkout@v3 @@ -57,6 +78,9 @@ jobs: - name: Run static analysis run: composer stan + - name: Create mock server from our production OpenAPI + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + - name: Run tests run: composer test @@ -64,6 +88,11 @@ jobs: name: "php 8.2 psr/http-message 1.0" runs-on: ubuntu-latest container: "nofutur3/php-tests:8.2" + services: + openAPImock: + image: mockserver/mockserver + ports: + - 1080:1080 steps: - name: Checkout repository uses: actions/checkout@v3 @@ -74,6 +103,9 @@ jobs: - name: Run static analysis run: composer stan + - name: Create mock server from our production OpenAPI + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + - name: Run tests run: composer test @@ -81,6 +113,11 @@ jobs: name: "php 8.1" runs-on: ubuntu-latest container: "nofutur3/php-tests:8.1" + services: + openAPImock: + image: mockserver/mockserver + ports: + - 1080:1080 steps: - name: Checkout repository uses: actions/checkout@v3 @@ -91,6 +128,9 @@ jobs: - name: Run static analysis run: composer stan + - name: Create mock server from our production OpenAPI + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + - name: Run tests run: composer test @@ -98,6 +138,11 @@ jobs: name: "php 8.0" runs-on: ubuntu-latest container: "nofutur3/php-tests:8.0" + services: + openAPImock: + image: mockserver/mockserver + ports: + - 1080:1080 steps: - name: Checkout repository uses: actions/checkout@v3 @@ -108,6 +153,9 @@ jobs: - name: Run static analysis run: composer stan + - name: Create mock server from our production OpenAPI + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + - name: Run tests run: composer test @@ -115,6 +163,11 @@ jobs: name: "php 7.4" runs-on: ubuntu-latest container: "nofutur3/php-tests:7.4" + services: + openAPImock: + image: mockserver/mockserver + ports: + - 1080:1080 steps: # Deprecation example for future support removal. # @@ -130,6 +183,9 @@ jobs: - name: Run static analysis run: composer stan + - name: Create mock server from our production OpenAPI + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + - name: Run tests run: composer test diff --git a/doc/download-account-transaction-GPC.md b/doc/download-account-transaction-GPC.md new file mode 100644 index 0000000..8896073 --- /dev/null +++ b/doc/download-account-transaction-GPC.md @@ -0,0 +1,49 @@ +# Download account transaction GPC statement + +Use the `getAccountStatementGPC` method to download the transaction GPC statement for a specific account within a given date range. + +## Example: Download statement to local file on server + +```php +/** @var \ThePay\ApiClient\TheConfig $theConfig */ + +$signatureService = new \ThePay\ApiClient\Service\SignatureService($theConfig); + +/** + * PSR-18 client MUST be configured correctly, to return real PSR-7 network stream! + * HTTP client CAN NOT read getAccountStatementGPC response body to memory at once! + * Because GPC statement is not paginated, and can contain big amount of data! + * + * @var \Psr\Http\Client\ClientInterface $httpClient + */ +// if you use suggested guzzle implementation you MUST use RequestOptions with true value! +// https://docs.guzzlephp.org/en/stable/request-options.html#stream +//$httpClient = new \GuzzleHttp\Client([\GuzzleHttp\RequestOptions::STREAM => true]); +/** @var \Psr\Http\Message\RequestFactoryInterface $requestFactory */ +/** @var \Psr\Http\Message\StreamFactoryInterface $streamFactory */ + +$apiService = new \ThePay\ApiClient\Service\ApiService( + $theConfig, + $signatureService, + $httpClient, + $requestFactory, + $streamFactory +); + +$thePayClient = new \ThePay\ApiClient\TheClient( + $theConfig, + $apiService, +); + +$from = new DateTime('2021-03-01'); +$to = new DateTime('2021-03-31'); +$filter = new \ThePay\ApiClient\Filter\TransactionFilter('TP3211114680489551165349', $from, $to); + +$psrResponseBodyStream = $thePayClient->getAccountStatementGPC($filter); +$phpResponseBodyStream = $psrResponseBodyStream->detach() ?? new \RuntimeException('PHP stream missing'); + +$file = fopen('some_path.gpc', 'w'); +stream_copy_to_stream($phpResponseBodyStream, $file); +fclose($file); + +``` diff --git a/doc/index.md b/doc/index.md index d0aa010..255b081 100644 --- a/doc/index.md +++ b/doc/index.md @@ -16,6 +16,7 @@ | getPaymentRefund | https://thepay.docs.apiary.io/#reference/0/project-level-resources/payment-refund-info | | createPaymentRefund | https://thepay.docs.apiary.io/#reference/0/project-level-resources/payment-refund-request | | getAccountTransactionHistory | https://thepay.docs.apiary.io/#reference/0/merchant-level-resources/get-account-transaction-history | +| getAccountStatementGPC | https://docs.thepay.cz/#tag/Transactions/paths/~1v1~1transactions~1%7Baccount_iban%7D~1account_statement~1gpc/get | | realizeRegularSubscriptionPayment | https://thepay.docs.apiary.io/#reference/0/project-level-resources/realize-regular-subscription-payment | | realizeIrregularSubscriptionPayment | https://thepay.docs.apiary.io/#reference/0/project-level-resources/realize-irregular-subscription-payment | | realizeUsageBasedSubscriptionPayment | https://thepay.docs.apiary.io/#reference/0/project-level-resources/realize-usage-based-subscription-payment | @@ -42,6 +43,8 @@ [Get account transaction history](get-transactions-history.md) +[Download account transaction GPC statement](download-account-transaction-GPC.md) + [Creating subscription](subscription.md) [Saving authorization](saving-authorization.md) diff --git a/src/Service/ApiService.php b/src/Service/ApiService.php index f1a1aa9..7912eb1 100644 --- a/src/Service/ApiService.php +++ b/src/Service/ApiService.php @@ -6,6 +6,7 @@ use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; +use Psr\Http\Message\StreamInterface; use ThePay\ApiClient\Exception\ApiException; use ThePay\ApiClient\Filter\PaymentsFilter; use ThePay\ApiClient\Filter\TransactionFilter; @@ -32,6 +33,7 @@ use ThePay\ApiClient\TheConfig; use ThePay\ApiClient\Utils\Json; use ThePay\ApiClient\ValueObject\Amount; +use ThePay\ApiClient\ValueObject\GPCPaymentIdentifier; use ThePay\ApiClient\ValueObject\Identifier; use ThePay\ApiClient\ValueObject\LanguageCode; use ThePay\ApiClient\ValueObject\StringValue; @@ -60,11 +62,11 @@ class ApiService implements ApiServiceInterface private StreamFactoryInterface $streamFactory; public function __construct( - TheConfig $config, - SignatureService $signatureService, - ClientInterface $httpClient, + TheConfig $config, + SignatureService $signatureService, + ClientInterface $httpClient, RequestFactoryInterface $requestFactory, - StreamFactoryInterface $streamFactory + StreamFactoryInterface $streamFactory ) { $this->config = $config; $this->signatureService = $signatureService; @@ -192,6 +194,29 @@ public function getAccountTransactionHistory(TransactionFilter $filter, int $pag return new TransactionCollection(Json::decode($response->getBody()->getContents(), true), $page, $limit, (int) $response->getHeaderLine('X-Total-Count')); } + public function getAccountStatementGPC(TransactionFilter $filter, ?GPCPaymentIdentifier $paymentIdentifier = null): StreamInterface + { + $arguments = [ + 'date_from' => $filter->getDateFrom()->format('Y-m-d'), + 'date_to' => $filter->getDateTo()->format('Y-m-d'), + ]; + if ($filter->getCurrencyCode() !== null) { + $arguments['currency_code'] = $filter->getCurrencyCode()->getValue(); + } + if ($paymentIdentifier !== null) { + $arguments['payment_identifier'] = $paymentIdentifier->getValue(); + } + + $url = $this->url(['transactions', $filter->getAccountIban(), 'account_statement', 'gpc'], $arguments, false); + + $response = $this->sendRequest(self::METHOD_GET, $url); + if ($response->getStatusCode() !== 200) { + throw $this->buildException($url, $response); + } + + return $response->getBody(); + } + /** * Get complete information about the specified payment. * diff --git a/src/Service/ApiServiceInterface.php b/src/Service/ApiServiceInterface.php index d2032b5..7ee8aef 100644 --- a/src/Service/ApiServiceInterface.php +++ b/src/Service/ApiServiceInterface.php @@ -2,6 +2,7 @@ namespace ThePay\ApiClient\Service; +use Psr\Http\Message\StreamInterface; use ThePay\ApiClient\Exception\ApiException; use ThePay\ApiClient\Filter\PaymentsFilter; use ThePay\ApiClient\Filter\TransactionFilter; @@ -23,6 +24,7 @@ use ThePay\ApiClient\Model\RealizeUsageBasedSubscriptionPaymentParams; use ThePay\ApiClient\Model\RecurringPaymentResult; use ThePay\ApiClient\ValueObject\Amount; +use ThePay\ApiClient\ValueObject\GPCPaymentIdentifier; use ThePay\ApiClient\ValueObject\Identifier; use ThePay\ApiClient\ValueObject\LanguageCode; use ThePay\ApiClient\ValueObject\StringValue; @@ -112,6 +114,8 @@ public function getAccountsBalances(?StringValue $accountIban = null, $projectId */ public function getAccountTransactionHistory(TransactionFilter $filter, int $page = 1, int $limit = 100): TransactionCollection; + public function getAccountStatementGPC(TransactionFilter $filter, ?GPCPaymentIdentifier $paymentIdentifier = null): StreamInterface; + /** * @param non-empty-string|null $methodCode * diff --git a/src/TheClient.php b/src/TheClient.php index 112fbb0..1b0fc10 100644 --- a/src/TheClient.php +++ b/src/TheClient.php @@ -4,6 +4,7 @@ use Exception; use InvalidArgumentException; +use Psr\Http\Message\StreamInterface; use ThePay\ApiClient\Exception\ApiException; use ThePay\ApiClient\Filter\PaymentMethodFilter; use ThePay\ApiClient\Filter\PaymentsFilter; @@ -29,6 +30,7 @@ use ThePay\ApiClient\Service\GateService; use ThePay\ApiClient\Service\GateServiceInterface; use ThePay\ApiClient\ValueObject\Amount; +use ThePay\ApiClient\ValueObject\GPCPaymentIdentifier; use ThePay\ApiClient\ValueObject\Identifier; use ThePay\ApiClient\ValueObject\LanguageCode; use ThePay\ApiClient\ValueObject\StringValue; @@ -99,6 +101,20 @@ public function getAccountTransactionHistory(TransactionFilter $filter, $page = ->getAccountTransactionHistory($filter, $page, $limit); } + /** + * @see https://docs.thepay.cz/#tag/Transactions/paths/~1v1~1transactions~1%7Baccount_iban%7D~1account_statement~1gpc/get + * @see ../doc/download-account-transaction-GPC.md + * + * @return StreamInterface MUST return real PSR-7 network stream, make sure you have your PSR-18 HTTP client correctly configured, GPC format is not paginated! + * @return StreamInterface content is windows-1250 encoded + */ + public function getAccountStatementGPC(TransactionFilter $filter, ?GPCPaymentIdentifier $paymentIdentifier = null): StreamInterface + { + return $this + ->api + ->getAccountStatementGPC($filter, $paymentIdentifier); + } + /** * @param PaymentMethodFilter|null $filter * @param LanguageCode|null $languageCode language for payment method titles, null value language from TheConfig used diff --git a/src/TheConfig.php b/src/TheConfig.php index 85b8805..ceb060a 100644 --- a/src/TheConfig.php +++ b/src/TheConfig.php @@ -68,6 +68,11 @@ public function getApiUrl(?string $specificVersion = null): string return $this->apiUrl->getValue() . $this->apiVersion . '/'; } + public function getApiVersion(): string + { + return $this->apiVersion; + } + /** * @return string */ diff --git a/src/ValueObject/GPCPaymentIdentifier.php b/src/ValueObject/GPCPaymentIdentifier.php new file mode 100644 index 0000000..abbcdf6 --- /dev/null +++ b/src/ValueObject/GPCPaymentIdentifier.php @@ -0,0 +1,24 @@ + + */ + public static function cases(): array + { + return [ + self::ORDER_NUMBER, + self::UID, + self::ID, + ]; + } +} diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 085888e..3a07da2 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -26,17 +26,32 @@ protected function setUp(): void } /** - * method return TheClient witch use apiary mock server + * method return TheClient witch use OpenAPI mock server */ - protected function getApiaryClient(): TheClient + protected function getOpenAPIMockClient(): TheClient { - $config = new TheConfig( - '6cdf1b24', - 1212, - 'password', - 'https://private-aa6aa3-thepay.apiary-mock.com/', - 'https://private-ddc40-gatezalozeniplatby.apiary-mock.com/' - ); + $config = new class () extends TheConfig { + public string $apiUrl = 'http://127.0.0.1:1080/'; + + public function __construct() + { + parent::__construct( + 'a471eab0-4054-11ef-ac09-116afd5362fb', + 1212, + 'password', + 'https://secure-url', + 'https://private-ddc40-gatezalozeniplatby.apiary-mock.com/', + ); + } + + public function getApiUrl(?string $specificVersion = null): string + { + if ($specificVersion !== null) { + return $this->apiUrl . $specificVersion . '/'; + } + return $this->apiUrl . $this->getApiVersion() . '/'; + } + }; $httpFactory = new HttpFactory(); diff --git a/tests/PaymentMethodsTest.php b/tests/PaymentMethodsTest.php index d73d3bc..34b3933 100644 --- a/tests/PaymentMethodsTest.php +++ b/tests/PaymentMethodsTest.php @@ -195,7 +195,7 @@ protected function setUp(): void public function testGettingActivePaymentMethods(): void { - $client = $this->getApiaryClient(); + $client = $this->getOpenAPIMockClient(); $methods = $client->getActivePaymentMethods(); $cardMethod = $methods->get('card'); diff --git a/tests/TheClientTest.php b/tests/TheClientTest.php index 9ca1efc..d62844a 100644 --- a/tests/TheClientTest.php +++ b/tests/TheClientTest.php @@ -2,11 +2,12 @@ namespace ThePay\ApiClient\Tests; +use ThePay\ApiClient\Filter\TransactionFilter; use ThePay\ApiClient\Model\Collection\PaymentMethodCollection; use ThePay\ApiClient\Service\ApiServiceInterface; use ThePay\ApiClient\TheClient; -class TheClientTest extends BaseTestCase +final class TheClientTest extends BaseTestCase { public function testPaymentMethods(): void { @@ -52,6 +53,24 @@ public function testPaymentMethods(): void static::assertSame('CZK', $methods[1]->getAvailableCurrencies()[0]); } + public function testGetAccountStatementGPC(): void + { + $thePayClient = $this->getOpenAPIMockClient(); + + $filter = new TransactionFilter( + 'TP7811112150822790787055', + new \DateTime('2024-01-01'), + new \DateTime('2024-01-31'), + ); + + $stream = $thePayClient->getAccountStatementGPC($filter); + + $content = $stream->getContents(); + + self::assertIsString($content); + self::assertGreaterThan(0, strlen($content)); + } + public function testRenderPaymentMethods(): void { self::markTestSkipped(); From 9f5ad4df2814bc792aee8b256e26eaef6352a1ea Mon Sep 17 00:00:00 2001 From: VojtaB Date: Wed, 11 Mar 2026 19:00:43 +0100 Subject: [PATCH 2/6] fix for open API mock in CI tests --- tests/BaseTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 3a07da2..3f313b6 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -31,7 +31,7 @@ protected function setUp(): void protected function getOpenAPIMockClient(): TheClient { $config = new class () extends TheConfig { - public string $apiUrl = 'http://127.0.0.1:1080/'; + public string $apiUrl = 'http://openAPImock:1080/'; public function __construct() { From ba0571b4dd883eb84fa9de1218878e8404772bc2 Mon Sep 17 00:00:00 2001 From: VojtaB Date: Wed, 11 Mar 2026 19:03:13 +0100 Subject: [PATCH 3/6] fix for open API mock in CI tests vol 2 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0665853..d869c4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: run: composer stan - name: Create mock server from our production OpenAPI - run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://openAPImock:1080/mockserver/openapi - name: Run tests run: composer test From 26ecc6b650b59b250ef4333644fb1aeb2d842a53 Mon Sep 17 00:00:00 2001 From: VojtaB Date: Wed, 11 Mar 2026 19:05:29 +0100 Subject: [PATCH 4/6] fix for open API mock in CI tests vol 3 --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d869c4c..8ab8d12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: run: composer stan - name: Create mock server from our production OpenAPI - run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://openAPImock:1080/mockserver/openapi - name: Run tests run: composer test @@ -79,7 +79,7 @@ jobs: run: composer stan - name: Create mock server from our production OpenAPI - run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://openAPImock:1080/mockserver/openapi - name: Run tests run: composer test @@ -104,7 +104,7 @@ jobs: run: composer stan - name: Create mock server from our production OpenAPI - run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://openAPImock:1080/mockserver/openapi - name: Run tests run: composer test @@ -129,7 +129,7 @@ jobs: run: composer stan - name: Create mock server from our production OpenAPI - run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://openAPImock:1080/mockserver/openapi - name: Run tests run: composer test @@ -154,7 +154,7 @@ jobs: run: composer stan - name: Create mock server from our production OpenAPI - run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://openAPImock:1080/mockserver/openapi - name: Run tests run: composer test @@ -184,7 +184,7 @@ jobs: run: composer stan - name: Create mock server from our production OpenAPI - run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://127.0.0.1:1080/mockserver/openapi + run: curl -X PUT -d "{\"specUrlOrPayload\":\"https://gate.thepay.cz/openapi.yaml\"}" http://openAPImock:1080/mockserver/openapi - name: Run tests run: composer test From 469607e1dc31781d2728c076d03b2dae2b62dccf Mon Sep 17 00:00:00 2001 From: VojtaB Date: Wed, 11 Mar 2026 19:11:37 +0100 Subject: [PATCH 5/6] code style fix --- src/Service/ApiService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Service/ApiService.php b/src/Service/ApiService.php index 7912eb1..c79855c 100644 --- a/src/Service/ApiService.php +++ b/src/Service/ApiService.php @@ -62,11 +62,11 @@ class ApiService implements ApiServiceInterface private StreamFactoryInterface $streamFactory; public function __construct( - TheConfig $config, - SignatureService $signatureService, - ClientInterface $httpClient, + TheConfig $config, + SignatureService $signatureService, + ClientInterface $httpClient, RequestFactoryInterface $requestFactory, - StreamFactoryInterface $streamFactory + StreamFactoryInterface $streamFactory ) { $this->config = $config; $this->signatureService = $signatureService; From 40a8303e5d529124eb6bfe7518ca5a037634ac60 Mon Sep 17 00:00:00 2001 From: VojtaB Date: Mon, 16 Mar 2026 17:17:47 +0100 Subject: [PATCH 6/6] documentation imrovement --- .github/README.md | 8 ++++- doc/download-account-transaction-GPC.md | 39 +++++++------------------ 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/.github/README.md b/.github/README.md index 906fa2f..654ffb6 100644 --- a/.github/README.md +++ b/.github/README.md @@ -84,6 +84,10 @@ $theConfig->setLanguage($language); Make sure to prepare the necessary dependencies before creating the `\ThePay\ApiClient\TheClient` instance. +In any case of dependencies preparation, you MUST check if your PSR-18 HTTP client, will return real PSR-7 network stream! +Because some API endpoints are not paginated for example: [getAccountStatementGPC](../doc/download-account-transaction-GPC.md), and can contain big amount of data! +If an HTTP client will try load full response to memory, some of your API calls can crash on out of memory error! + ### With dependency injection If you're using automatic dependency injection (as most frameworks do), all dependencies except `TheConfig` @@ -103,7 +107,9 @@ $signatureService = new \ThePay\ApiClient\Service\SignatureService($theConfig); /** @var \Psr\Http\Message\RequestFactoryInterface $requestFactory some PSR-17 implementation */ /** @var \Psr\Http\Message\StreamFactoryInterface $streamFactory some PSR-17 implementation */ // if you install suggested guzzle implementation you can use this: -// $httpClient = new \GuzzleHttp\Client(); +// you MUST use RequestOptions::STREAM with true value! +// https://docs.guzzlephp.org/en/stable/request-options.html#stream +// $httpClient = new \GuzzleHttp\Client([\GuzzleHttp\RequestOptions::STREAM => true]); // $requestFactory = $streamFactory = new \GuzzleHttp\Psr7\HttpFactory(); $apiService = new \ThePay\ApiClient\Service\ApiService( $theConfig, diff --git a/doc/download-account-transaction-GPC.md b/doc/download-account-transaction-GPC.md index 8896073..c4a31b0 100644 --- a/doc/download-account-transaction-GPC.md +++ b/doc/download-account-transaction-GPC.md @@ -5,35 +5,8 @@ Use the `getAccountStatementGPC` method to download the transaction GPC statemen ## Example: Download statement to local file on server ```php -/** @var \ThePay\ApiClient\TheConfig $theConfig */ - -$signatureService = new \ThePay\ApiClient\Service\SignatureService($theConfig); - -/** - * PSR-18 client MUST be configured correctly, to return real PSR-7 network stream! - * HTTP client CAN NOT read getAccountStatementGPC response body to memory at once! - * Because GPC statement is not paginated, and can contain big amount of data! - * - * @var \Psr\Http\Client\ClientInterface $httpClient - */ -// if you use suggested guzzle implementation you MUST use RequestOptions with true value! -// https://docs.guzzlephp.org/en/stable/request-options.html#stream -//$httpClient = new \GuzzleHttp\Client([\GuzzleHttp\RequestOptions::STREAM => true]); -/** @var \Psr\Http\Message\RequestFactoryInterface $requestFactory */ -/** @var \Psr\Http\Message\StreamFactoryInterface $streamFactory */ - -$apiService = new \ThePay\ApiClient\Service\ApiService( - $theConfig, - $signatureService, - $httpClient, - $requestFactory, - $streamFactory -); - -$thePayClient = new \ThePay\ApiClient\TheClient( - $theConfig, - $apiService, -); + +/** @var \ThePay\ApiClient\TheClient $thePayClient */ $from = new DateTime('2021-03-01'); $to = new DateTime('2021-03-31'); @@ -47,3 +20,11 @@ stream_copy_to_stream($phpResponseBodyStream, $file); fclose($file); ``` + +**Parameters:** +- `$filter` - An instance of `\ThePay\ApiClient\Filter\TransactionFilter()`. (See online API documentation for all available filter options.) + +**Returns:** + +A `Psr\Http\Message\StreamInterface` object containing: +- Binary stream with GPC transaction statement in windows-1250 encoding