-
Notifications
You must be signed in to change notification settings - Fork 14
Add Collect endpoints support for managing allowed bank accounts #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
KamilBalwierz
merged 3 commits into
tpay-com:master
from
rgwsk65:feature/collect-endpoints
Jan 16, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| namespace Tpay\OpenApi\Api\Collect; | ||
|
|
||
| use Tpay\OpenApi\Api\ApiAction; | ||
| use Tpay\OpenApi\Model\Objects\RequestBody\CollectBankAccount; | ||
|
|
||
| class CollectApi extends ApiAction | ||
| { | ||
| public function getBankAccounts($page = 1, $limit = 35) | ||
| { | ||
| $requestUrl = $this->addQueryFields('/collect/bank-accounts', ['page' => $page, 'limit' => $limit]); | ||
|
|
||
| return $this->run(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()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| namespace Tpay\OpenApi\Model\Fields\Collect; | ||
|
|
||
| use Tpay\OpenApi\Model\Fields\Field; | ||
|
|
||
| class AccountNumber extends Field | ||
| { | ||
| protected $name = __CLASS__; | ||
| protected $type = self::STRING; | ||
| protected $minLength = 28; | ||
| protected $maxLength = 28; | ||
| protected $pattern = '^PL\d{26}$'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?php | ||
|
|
||
| namespace Tpay\OpenApi\Model\Fields\Collect; | ||
|
|
||
| use Tpay\OpenApi\Model\Fields\Field; | ||
|
|
||
| class AdditionalInformation extends Field | ||
| { | ||
| protected $name = __CLASS__; | ||
| protected $type = self::STRING; | ||
| protected $maxLength = 1000; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?php | ||
|
|
||
| namespace Tpay\OpenApi\Model\Fields\Collect; | ||
|
|
||
| use Tpay\OpenApi\Model\Fields\Field; | ||
|
|
||
| class OwnerName extends Field | ||
| { | ||
| protected $name = __CLASS__; | ||
| protected $type = self::STRING; | ||
| protected $maxLength = 1000; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| namespace Tpay\OpenApi\Model\Objects\RequestBody; | ||
|
|
||
| use Tpay\OpenApi\Model\Fields\Collect\AccountNumber; | ||
| use Tpay\OpenApi\Model\Fields\Collect\AdditionalInformation; | ||
| use Tpay\OpenApi\Model\Fields\Collect\OwnerName; | ||
| use Tpay\OpenApi\Model\Objects\Objects; | ||
|
|
||
| class CollectBankAccount extends Objects | ||
| { | ||
| const OBJECT_FIELDS = [ | ||
| 'accountNumber' => AccountNumber::class, | ||
| 'ownerName' => OwnerName::class, | ||
| 'additionalInformation' => AdditionalInformation::class, | ||
| ]; | ||
|
|
||
| public $accountNumber; | ||
|
|
||
| public $ownerName; | ||
|
|
||
| public $additionalInformation; | ||
|
|
||
| public function getRequiredFields() | ||
| { | ||
| return [ | ||
| $this->accountNumber, | ||
| $this->ownerName, | ||
| $this->additionalInformation, | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| <?php | ||
|
|
||
| namespace Tpay\Tests\OpenApi\Api\Collect; | ||
|
|
||
| use InvalidArgumentException; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Tpay\OpenApi\Api\Collect\CollectApi; | ||
| use Tpay\OpenApi\Model\Fields\Token\AccessToken; | ||
| use Tpay\OpenApi\Model\Objects\Authorization\Token; | ||
| use Tpay\Tests\OpenApi\Mock\CurlMock; | ||
| use UnexpectedValueException; | ||
|
|
||
| /** | ||
| * @covers \Tpay\OpenApi\Api\Collect\CollectApi | ||
| */ | ||
| class CollectApiTest extends TestCase | ||
| { | ||
| /** @dataProvider validBankAccountData */ | ||
| public function testAddingValidBankAccount($accountNumber, $ownerName, $additionalInformation) | ||
| { | ||
| $collectApi = $this->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' => '', | ||
| 'additionalInformation' => '', | ||
| ]; | ||
|
|
||
| yield 'Max length owner name' => [ | ||
| 'accountNumber' => 'PL99999999999999999999999999', | ||
| 'ownerName' => str_repeat('A', 1000), | ||
| 'additionalInformation' => str_repeat('B', 1000), | ||
| ]; | ||
| } | ||
|
|
||
| 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 long' => [ | ||
| 'accountNumber' => 'PL12345678901234567890123456', | ||
| '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 1000', | ||
| ]; | ||
|
|
||
| yield 'Additional information too long' => [ | ||
| 'accountNumber' => 'PL12345678901234567890123456', | ||
| 'ownerName' => 'Jan Kowalski', | ||
| 'additionalInformation' => str_repeat('X', 1001), | ||
| 'exception' => InvalidArgumentException::class, | ||
| 'exceptionMessage' => 'Value of field Tpay\OpenApi\Model\Fields\Collect\AdditionalInformation is too long. Max allowed 1000', | ||
| ]; | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.