From e826d76ab88e90dd808e83d79c7b36409965064e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Grabosz?= Date: Thu, 15 Jan 2026 01:56:14 +0100 Subject: [PATCH 1/3] Add collect bank accounts API endpoints --- src/Api/Collect/CollectApi.php | 27 ++++++++++++++++ src/Api/TpayApi.php | 18 +++++++++++ src/Model/Fields/Collect/AccountNumber.php | 14 ++++++++ .../Fields/Collect/AdditionalInformation.php | 13 ++++++++ src/Model/Fields/Collect/OwnerName.php | 13 ++++++++ .../RequestBody/CollectBankAccount.php | 32 +++++++++++++++++++ 6 files changed, 117 insertions(+) create mode 100644 src/Api/Collect/CollectApi.php create mode 100644 src/Model/Fields/Collect/AccountNumber.php create mode 100644 src/Model/Fields/Collect/AdditionalInformation.php create mode 100644 src/Model/Fields/Collect/OwnerName.php create mode 100644 src/Model/Objects/RequestBody/CollectBankAccount.php diff --git a/src/Api/Collect/CollectApi.php b/src/Api/Collect/CollectApi.php new file mode 100644 index 0000000..4c3318d --- /dev/null +++ b/src/Api/Collect/CollectApi.php @@ -0,0 +1,27 @@ +addQueryFields('/collect/bank-accounts', ['page' => $page, 'limit' => $limit]); + + return $this->sendRequest(static::GET, $requestUrl); + } + + public function addBankAccount($accountNumber, $ownerName, $additionalInformation) + { + $fields = [ + 'accountNumber' => $accountNumber, + 'ownerName' => $ownerName, + 'additionalInformation' => $additionalInformation, + ]; + + return $this->run(static::POST, '/collect/bank-accounts', $fields, new CollectBankAccount()); + } +} diff --git a/src/Api/TpayApi.php b/src/Api/TpayApi.php index d791405..d0a5e35 100644 --- a/src/Api/TpayApi.php +++ b/src/Api/TpayApi.php @@ -5,6 +5,7 @@ use RuntimeException; use Tpay\OpenApi\Api\Accounts\AccountsApi; use Tpay\OpenApi\Api\Authorization\AuthorizationApi; +use Tpay\OpenApi\Api\Collect\CollectApi; use Tpay\OpenApi\Api\Refunds\RefundsApi; use Tpay\OpenApi\Api\Reports\ReportsApi; use Tpay\OpenApi\Api\Transactions\TransactionsApi; @@ -20,6 +21,9 @@ class TpayApi /** @var null|AuthorizationApi */ private $authorization; + /** @var null|CollectApi */ + private $collect; + /** @var null|RefundsApi */ private $refunds; @@ -169,6 +173,20 @@ public function transactions() return $this->transactions; } + /** @return CollectApi */ + public function collect() + { + $this->authorize(); + if (null === $this->collect) { + $this->collect = (new CollectApi($this->token, $this->productionMode)) + ->overrideApiUrl($this->apiUrl); + + if ($this->clientName) { + $this->collect->setClientName($this->clientName); + } + } + } + private function authorize() { $fields = [ diff --git a/src/Model/Fields/Collect/AccountNumber.php b/src/Model/Fields/Collect/AccountNumber.php new file mode 100644 index 0000000..532a8c4 --- /dev/null +++ b/src/Model/Fields/Collect/AccountNumber.php @@ -0,0 +1,14 @@ + AccountNumber::class, + 'ownerName' => OwnerName::class, + 'additionalInformation' => AdditionalInformation::class, + ]; + + public $accountNumber; + + public $ownerName; + + public $additionalInformation; + + public function getRequiredFields() + { + return [ + $this->accountNumber, + $this->ownerName, + $this->additionalInformation, + ]; + } +} From c6ec264a76cf35820d7342b2e645b8ff2c74cfa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Grabosz?= Date: Thu, 15 Jan 2026 10:02:00 +0100 Subject: [PATCH 2/3] Adds tests for CollectApi::addBankAccount method --- tests/Api/Collect/CollectApiTest.php | 141 +++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 tests/Api/Collect/CollectApiTest.php diff --git a/tests/Api/Collect/CollectApiTest.php b/tests/Api/Collect/CollectApiTest.php new file mode 100644 index 0000000..5785d32 --- /dev/null +++ b/tests/Api/Collect/CollectApiTest.php @@ -0,0 +1,141 @@ +createCollectApiWithCurlMock('ok'); + + $result = $collectApi->addBankAccount($accountNumber, $ownerName, $additionalInformation); + + self::assertSame('ok', $result); + } + + /** @dataProvider invalidBankAccountData */ + public function testAddingInvalidBankAccount($accountNumber, $ownerName, $additionalInformation, $exception, $exceptionMessage) + { + $collectApi = $this->createCollectApiWithCurlMock('error'); + + $this->expectException($exception); + $this->expectExceptionMessage($exceptionMessage); + + $collectApi->addBankAccount($accountNumber, $ownerName, $additionalInformation); + } + + public function validBankAccountData() + { + yield 'Valid bank account' => [ + 'accountNumber' => 'PL12345678901234567890123456', + 'ownerName' => 'Jan Kowalski', + 'additionalInformation' => 'Konto firmowe', + ]; + + yield 'Min length owner name' => [ + 'accountNumber' => 'PL00000000000000000000000000', + 'ownerName' => 'Jan', + 'additionalInformation' => 'Inf', + ]; + + yield 'Max length owner name' => [ + 'accountNumber' => 'PL99999999999999999999999999', + 'ownerName' => str_repeat('A', 70), + 'additionalInformation' => str_repeat('B', 70), + ]; + } + + public function invalidBankAccountData() + { + yield 'Empty account number' => [ + 'accountNumber' => '', + 'ownerName' => 'Jan Kowalski', + 'additionalInformation' => 'Konto firmowe', + 'exception' => InvalidArgumentException::class, + 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\AccountNumber is too short. Min required 28', + ]; + + yield 'Invalid account number format - missing PL prefix' => [ + 'accountNumber' => '1234567890123456789012345678', + 'ownerName' => 'Jan Kowalski', + 'additionalInformation' => 'Konto firmowe', + 'exception' => InvalidArgumentException::class, + 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\AccountNumber is invalid. Should match ^PL\d{26}$ pattern', + ]; + + yield 'Account number too short' => [ + 'accountNumber' => 'PL1234567890123456789012345', + 'ownerName' => 'Jan Kowalski', + 'additionalInformation' => 'Konto firmowe', + 'exception' => InvalidArgumentException::class, + 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\AccountNumber is too short. Min required 28', + ]; + + yield 'Account number too long' => [ + 'accountNumber' => 'PL123456789012345678901234567', + 'ownerName' => 'Jan Kowalski', + 'additionalInformation' => 'Konto firmowe', + 'exception' => InvalidArgumentException::class, + 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\AccountNumber is too long. Max allowed 28', + ]; + + yield 'Owner name too short' => [ + 'accountNumber' => 'PL12345678901234567890123456', + 'ownerName' => 'Ja', + 'additionalInformation' => 'Konto firmowe', + 'exception' => InvalidArgumentException::class, + 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\OwnerName is too short. Min required 3', + ]; + + yield 'Owner name too long' => [ + 'accountNumber' => 'PL12345678901234567890123456', + 'ownerName' => str_repeat('A', 71), + 'additionalInformation' => 'Konto firmowe', + 'exception' => InvalidArgumentException::class, + 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\OwnerName is too long. Max allowed 70', + ]; + + yield 'Additional information too short' => [ + 'accountNumber' => 'PL12345678901234567890123456', + 'ownerName' => 'Jan Kowalski', + 'additionalInformation' => 'Ko', + 'exception' => InvalidArgumentException::class, + 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\AdditionalInformation is too short. Min required 3', + ]; + + yield 'Additional information too long' => [ + 'accountNumber' => 'PL12345678901234567890123456', + 'ownerName' => 'Jan Kowalski', + 'additionalInformation' => str_repeat('X', 71), + 'exception' => InvalidArgumentException::class, + 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\AdditionalInformation is too long. Max allowed 70', + ]; + } + + private function createCollectApiWithCurlMock($response) + { + $accessToken = $this->createMock(AccessToken::class); + + $token = $this->createMock(Token::class); + + $token->access_token = $accessToken; + + $collectApi = new CollectApi($token, false); + + CurlMock::setConsecutiveReturnedTransfers(json_encode($response)); + + return $collectApi; + } +} From 2cb16fb9fe2f05f5e303560683722ae9b17c3eb1 Mon Sep 17 00:00:00 2001 From: Kamil Balwierz Date: Thu, 15 Jan 2026 15:28:20 +0100 Subject: [PATCH 3/3] Change field validation to match official documentation; fix invalid call code --- src/Api/Collect/CollectApi.php | 2 +- src/Api/TpayApi.php | 2 ++ .../Fields/Collect/AdditionalInformation.php | 3 +- src/Model/Fields/Collect/OwnerName.php | 3 +- tests/Api/Collect/CollectApiTest.php | 32 +++++-------------- 5 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/Api/Collect/CollectApi.php b/src/Api/Collect/CollectApi.php index 4c3318d..df77d72 100644 --- a/src/Api/Collect/CollectApi.php +++ b/src/Api/Collect/CollectApi.php @@ -11,7 +11,7 @@ public function getBankAccounts($page = 1, $limit = 35) { $requestUrl = $this->addQueryFields('/collect/bank-accounts', ['page' => $page, 'limit' => $limit]); - return $this->sendRequest(static::GET, $requestUrl); + return $this->run(static::GET, $requestUrl); } public function addBankAccount($accountNumber, $ownerName, $additionalInformation) diff --git a/src/Api/TpayApi.php b/src/Api/TpayApi.php index d0a5e35..66ca600 100644 --- a/src/Api/TpayApi.php +++ b/src/Api/TpayApi.php @@ -185,6 +185,8 @@ public function collect() $this->collect->setClientName($this->clientName); } } + + return $this->collect; } private function authorize() diff --git a/src/Model/Fields/Collect/AdditionalInformation.php b/src/Model/Fields/Collect/AdditionalInformation.php index 7edd4d7..027fe4c 100644 --- a/src/Model/Fields/Collect/AdditionalInformation.php +++ b/src/Model/Fields/Collect/AdditionalInformation.php @@ -8,6 +8,5 @@ class AdditionalInformation extends Field { protected $name = __CLASS__; protected $type = self::STRING; - protected $minLength = 3; - protected $maxLength = 70; + protected $maxLength = 1000; } diff --git a/src/Model/Fields/Collect/OwnerName.php b/src/Model/Fields/Collect/OwnerName.php index c2d55ba..1a3d1e9 100644 --- a/src/Model/Fields/Collect/OwnerName.php +++ b/src/Model/Fields/Collect/OwnerName.php @@ -8,6 +8,5 @@ class OwnerName extends Field { protected $name = __CLASS__; protected $type = self::STRING; - protected $minLength = 3; - protected $maxLength = 70; + protected $maxLength = 1000; } diff --git a/tests/Api/Collect/CollectApiTest.php b/tests/Api/Collect/CollectApiTest.php index 5785d32..80e1f27 100644 --- a/tests/Api/Collect/CollectApiTest.php +++ b/tests/Api/Collect/CollectApiTest.php @@ -46,14 +46,14 @@ public function validBankAccountData() yield 'Min length owner name' => [ 'accountNumber' => 'PL00000000000000000000000000', - 'ownerName' => 'Jan', - 'additionalInformation' => 'Inf', + 'ownerName' => '', + 'additionalInformation' => '', ]; yield 'Max length owner name' => [ 'accountNumber' => 'PL99999999999999999999999999', - 'ownerName' => str_repeat('A', 70), - 'additionalInformation' => str_repeat('B', 70), + 'ownerName' => str_repeat('A', 1000), + 'additionalInformation' => str_repeat('B', 1000), ]; } @@ -91,36 +91,20 @@ public function invalidBankAccountData() 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\AccountNumber is too long. Max allowed 28', ]; - yield 'Owner name too short' => [ - 'accountNumber' => 'PL12345678901234567890123456', - 'ownerName' => 'Ja', - 'additionalInformation' => 'Konto firmowe', - 'exception' => InvalidArgumentException::class, - 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\OwnerName is too short. Min required 3', - ]; - yield 'Owner name too long' => [ 'accountNumber' => 'PL12345678901234567890123456', - 'ownerName' => str_repeat('A', 71), + 'ownerName' => str_repeat('A', 1001), 'additionalInformation' => 'Konto firmowe', 'exception' => InvalidArgumentException::class, - 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\OwnerName is too long. Max allowed 70', - ]; - - yield 'Additional information too short' => [ - 'accountNumber' => 'PL12345678901234567890123456', - 'ownerName' => 'Jan Kowalski', - 'additionalInformation' => 'Ko', - 'exception' => InvalidArgumentException::class, - 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\AdditionalInformation is too short. Min required 3', + 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\OwnerName is too long. Max allowed 1000', ]; yield 'Additional information too long' => [ 'accountNumber' => 'PL12345678901234567890123456', 'ownerName' => 'Jan Kowalski', - 'additionalInformation' => str_repeat('X', 71), + 'additionalInformation' => str_repeat('X', 1001), 'exception' => InvalidArgumentException::class, - 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\AdditionalInformation is too long. Max allowed 70', + 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\AdditionalInformation is too long. Max allowed 1000', ]; }