Compare commits

...

5 Commits

Author SHA1 Message Date
a81f6b0d21 move put to patch UpdateRequisiteRequest.php 2026-09-02 17:17:51 +03:00
88760ed127 fix(PayoffDubleAccept): response struct 2026-07-08 21:38:24 +03:00
Anatoliy Poloz
be2aa4b8d3 refactor(payoff): manual acceptens scrukt chancged 2026-07-08 17:08:04 +03:00
da3ea113ef refactor(sbp): refund 2026-06-25 16:05:46 +03:00
Anatoliy Poloz
3437cba042 payoff list 2026-06-16 22:25:04 +03:00
9 changed files with 245 additions and 17 deletions

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
/*
// MODULE_CONTRACT: Defines the data structure for the GET /payoffs list response.
// RESPONSIBILITY: To hold and type-safely represent the paginated list of payoffs returned by the bank API.
// INPUTS: Raw JSON object from the API response.
// OUTPUTS: A structured object containing pagination metadata, account number, and an array of payoff items.
// LINKS: Requests/NominalAccounts/Payouts/GetPayoffsRequest.php, PayoffListItemData.php
*/
namespace Apoloz\AlfaBank\Data\NominalAccounts\Payouts;
use Apoloz\AlfaBank\Data\Shared\PaginationData;
use Spatie\LaravelData\Data;
/**
* DTO for the GET /payoffs list response.
*
* @property-read PaginationData $pagination Pagination metadata
* @property-read string $accountNumber Номер номинального счёта
* @property-read PayoffListItemData[] $payoffs Список выплат
*/
class PayOffsListResponseData extends Data
{
/**
* @param PaginationData $pagination Pagination metadata
* @param string $accountNumber Номер номинального счёта
* @param PayoffListItemData[] $payoffs Список выплат
*/
public function __construct(
public PaginationData $pagination,
public string $accountNumber,
public array $payoffs,
) {}
}

View File

@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
/*
// MODULE_CONTRACT: Defines the data structure for a single payoff item in the list response from GET /payoffs.
// RESPONSIBILITY: To hold and type-safely represent comprehensive information about a single payoff from the list endpoint.
// INPUTS: Raw JSON object from the API response.
// OUTPUTS: A structured object containing payoff details.
// LINKS: PayOffsListResponseData.php, Requests/NominalAccounts/Payouts/GetPayoffsRequest.php
*/
namespace Apoloz\AlfaBank\Data\NominalAccounts\Payouts;
use Spatie\LaravelData\Data;
/**
* DTO for a single payoff item in the GET /payoffs list response.
*
* Based on OpenAPI PayoffItemResponse schema.
* Поля payer и recipient — array (raw JSON) вместо typed DTO, потому что
* существующие PayerInfoData/RecipientInfoData имеют другую структуру полей
* (accountNumber вместо bankAccount, нет bankName/bankBik/beneficiaryId в нужных местах)
* и их модификация может сломать DetailedPayoffData.
*
* @property-read string $id Идентификатор платежа (UUID)
* @property-read string|null $dealId Идентификатор сделки (UUID)
* @property-read string|null $stepId Идентификатор этапа сделки (UUID)
* @property-read string $payoffType Тип платежа
* @property-read string $type Тип платежа (PayoffType)
* @property-read string $channel Направление: INTERNAL|EXTERNAL
* @property-read string $requisiteType Тип реквизитов
* @property-read int $amount Сумма в рублях
* @property-read string|null $purpose Назначение платежа
* @property-read array|null $payer Плательщик (raw JSON)
* @property-read array|null $recipient Получатель (raw JSON)
* @property-read string $status Статус
* @property-read string|null $createdAt Дата создания (YYYY-MM-DD)
* @property-read string|null $updatedAt Дата обновления (YYYY-MM-DD)
*/
class PayoffListItemData extends Data
{
public function __construct(
public string $id,
public ?string $dealId = null,
public ?string $stepId = null,
public string $payoffType = 'REGULAR',
public string $type = 'REGULAR',
public string $channel = 'EXTERNAL',
public string $requisiteType = 'ACCOUNT',
public int $amount = 0,
public ?string $purpose = null,
public ?array $payer = null,
public ?array $recipient = null,
public string $status = 'NEW',
public ?string $createdAt = null,
public ?string $updatedAt = null,
) {}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/*
// MODULE_CONTRACT: Defines the data structure for pagination metadata.
// RESPONSIBILITY: To hold and type-safely represent pagination information from paginated API responses.
// INPUTS: Raw JSON object from the API response.
// OUTPUTS: A structured object containing pagination details.
// LINKS: NominalAccounts/Payouts/PayOffsListResponseData.php
*/
namespace Apoloz\AlfaBank\Data\Shared;
use Spatie\LaravelData\Data;
/**
* DTO for pagination metadata.
*
* @property-read int $limit Maximum items per page
* @property-read int $offset Number of items skipped
* @property-read int $totalCount Total items across all pages
*/
class PaginationData extends Data
{
public function __construct(
public int $limit,
public int $offset,
public int $totalCount,
) {}
}

View File

@@ -23,7 +23,7 @@ class UpdateRequisiteRequest extends Request implements HasBody
{
use HasJsonBody;
protected Method $method = Method::PUT;
protected Method $method = Method::PATCH;
public function __construct(
protected string $beneficiaryId,

View File

@@ -0,0 +1,96 @@
<?php
declare(strict_types=1);
/*
// MODULE_CONTRACT: Represents the API call to retrieve a list of payoffs by account number.
// RESPONSIBILITY: To define the GET request for fetching a paginated list of payoffs with optional filters.
// INPUTS: accountNumber (required), limit, offset, channel, status, createdDateFrom/To, updatedDateFrom/To.
// OUTPUTS: PayOffsListResponseData (DTO).
// LINKS: Data/NominalAccounts/Payouts/PayOffsListResponseData.php
*/
namespace Apoloz\AlfaBank\Requests\NominalAccounts\Payouts;
use Apoloz\AlfaBank\Data\NominalAccounts\Payouts\PayOffsListResponseData;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
/**
* Request to list payoffs by account number (GET /api/na/jp/v1/payoffs).
*
* Supports filtering by status, date range, and pagination.
*/
class GetPayoffsRequest extends Request
{
protected Method $method = Method::GET;
/**
* @param string $accountNumber Номер номинального счёта (required, 20 digits)
* @param int|null $limit Количество объектов на странице (1-100, default 100)
* @param int|null $offset Количество объектов, которые необходимо пропустить (default 0)
* @param string|null $channel Направление платежа: EXTERNAL|INTERNAL
* @param string|null $status Статус платежа: NEW|IN_PROGRESS|FAILED|AWAIT_EXTERNAL|READY
* @param string|null $createdDateFrom Начало выборки по дате создания (YYYY-MM-DD)
* @param string|null $createdDateTo Конец выборки по дате создания (YYYY-MM-DD)
* @param string|null $updatedDateFrom Начало выборки по дате обновления (YYYY-MM-DD)
* @param string|null $updatedDateTo Конец выборки по дате обновления (YYYY-MM-DD)
*/
public function __construct(
protected string $accountNumber,
protected ?int $limit = 100,
protected ?int $offset = 0,
protected ?string $channel = null,
protected ?string $status = null,
protected ?string $createdDateFrom = null,
protected ?string $createdDateTo = null,
protected ?string $updatedDateFrom = null,
protected ?string $updatedDateTo = null,
) {}
public function resolveEndpoint(): string
{
$params = [];
$params['accountNumber'] = $this->accountNumber;
if ($this->limit !== null) {
$params['limit'] = $this->limit;
}
if ($this->offset !== null) {
$params['offset'] = $this->offset;
}
if ($this->channel !== null) {
$params['channel'] = $this->channel;
}
if ($this->status !== null) {
$params['status'] = $this->status;
}
if ($this->createdDateFrom !== null) {
$params['createdDateFrom'] = $this->createdDateFrom;
}
if ($this->createdDateTo !== null) {
$params['createdDateTo'] = $this->createdDateTo;
}
if ($this->updatedDateFrom !== null) {
$params['updatedDateFrom'] = $this->updatedDateFrom;
}
if ($this->updatedDateTo !== null) {
$params['updatedDateTo'] = $this->updatedDateTo;
}
return '/api/na/jp/v1/payoffs?' . http_build_query($params);
}
public function createDtoFromResponse(Response $response): PayOffsListResponseData
{
return PayOffsListResponseData::from($response->json());
}
}

View File

@@ -4,17 +4,13 @@ declare(strict_types=1);
namespace Apoloz\AlfaBank\Requests\NominalAccounts\Payouts;
use Apoloz\AlfaBank\Data\Shared\ResultResponseData;
use Saloon\Contracts\Body\HasBody;
use Apoloz\AlfaBank\Data\NominalAccounts\Payouts\PayoffResponseData;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
class PayoffAcceptRequest extends Request implements HasBody
class PayoffAcceptRequest extends Request
{
use HasJsonBody;
protected Method $method = Method::PATCH;
public function __construct(
@@ -24,18 +20,13 @@ class PayoffAcceptRequest extends Request implements HasBody
public function resolveEndpoint(): string
{
return "/api/na/jp/v1/payoffs/{$this->payoffId}/accept";
$query = http_build_query(['accept' => $this->accept ? 'true' : 'false']);
return "/api/na/jp/v1/payoffs/{$this->payoffId}/accept?{$query}";
}
public function createDtoFromResponse(Response $response): ResultResponseData
public function createDtoFromResponse(Response $response): PayoffResponseData
{
return ResultResponseData::from($response->json());
}
protected function defaultBody(): array
{
return [
'accept' => $this->accept,
];
return PayoffResponseData::from($response->json());
}
}

View File

@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Sbp\Data\Reversal;
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides DTO benefits.">
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Attributes\MapName;
// </SECTION>
@@ -36,6 +37,7 @@ class GetQrcReversalDataResponseData extends Data
public ?string $qrcId = null,
public ?string $trxDT = null,
public ?string $trxId = null,
#[MapName('RestAmount')]
public ?string $restAmount = null,
) {}
// </SECTION>

View File

@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Sbp\Data\Reversal;
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides DTO benefits.">
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Attributes\MapName;
// </SECTION>
@@ -33,6 +34,7 @@ class QrcReversalResponseData extends Data
public ?string $trxDT = null,
public ?string $trxId = null,
public ?string $payrrn = null,
#[MapName('RestAmount')]
public ?string $restAmount = null,
) {}
// </SECTION>

View File

@@ -5,7 +5,9 @@ use Apoloz\AlfaBank\Core\AlfaConfig;
use Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\AddressData;
use Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\CreateBeneficiaryRequestData;
use Apoloz\AlfaBank\Requests\NominalAccounts\Beneficiaries\CreateBeneficiaryRequest;
use Apoloz\AlfaBank\Requests\NominalAccounts\Beneficiaries\Requisites\UpdateRequisiteRequest;
use Apoloz\AlfaBank\Services\OpenSslCmsSigner;
use Saloon\Enums\Method;
use Saloon\Http\Faking\MockResponse;
use Spatie\LaravelData\DataCollection;
@@ -58,3 +60,14 @@ test('can create a beneficiary with automatic signing', function (): void {
expect($response->status())->toBe(202)
->and($response->dto()->requestId)->toBe('req-123');
});
test('update requisite request uses PATCH', function (): void {
$request = new UpdateRequisiteRequest(
beneficiaryId: 'ben-1',
requisiteId: 'req-1',
data: ['phoneNumber' => '79031234567'],
);
expect($request->getMethod())->toBe(Method::PATCH)
->and($request->resolveEndpoint())->toBe('/api/na/jp/v1/beneficiaries/ben-1/requisites/req-1');
});