Улучшена документация, добавлена поддержка цифрового рубля и улучшена структура DTO

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
2026-01-21 12:46:02 +03:00
parent 58affe3e97
commit 60c99bca40
30 changed files with 385 additions and 156 deletions

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Apoloz\AlfaBank\Sbp\Data\DigitalRuble;
use Spatie\LaravelData\Attributes\DataCollectionOf;
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\DataCollection;
class GetUniQrStatusResponseData extends Data
{
#[MapName('ErrorCode')]
public int $errorCode;
public string $message;
#[DataCollectionOf(UniQrStatusRecordData::class)]
public DataCollection $data; // Renamed from 'data' to 'records' if it's always a collection of records.
public ?string $messageID = null;
}
class UniQrStatusRecordData extends Data
{
#[MapName('uniQrId')]
public string $uniQrId;
public string $code;
public string $message;
public ?string $paymentServiceId = null;
public string $status;
public ?string $trxId = null;
public ?string $kzo = null;
}

View File

@@ -13,6 +13,7 @@ namespace Apoloz\AlfaBank\Sbp\Data\Management;
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from arrays and provides DTO benefits.">
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Data;
// </SECTION>
@@ -21,9 +22,10 @@ use Spatie\LaravelData\Data;
class BlockQrRequestData extends Data
{
// <SECTION name="constructor_properties" intent="Define the properties for the QR Code block/unblock request.">
// <BELIEF_STATE "The constructor includes the mandatory `TermNo` and `qrcId` to identify the target QR Code. An optional `reason` can be provided for blocking actions.">
// <BELIEF_STATE "The constructor includes the mandatory `termNo` and `qrcId` to identify the target QR Code. An optional `reason` can be provided for blocking actions.">
public function __construct(
public string $TermNo,
#[MapName('TermNo')]
public string $termNo,
public string $qrcId,
public ?string $reason = null,
) {}

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Apoloz\AlfaBank\Sbp\Data\Management;
use Spatie\LaravelData\Attributes\DataCollectionOf;
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\DataCollection;
class GetBlockedQrListResponseData extends Data
{
public function __construct(
#[MapName('ErrorCode')]
public int $errorCode,
#[MapName('TermNo')]
public string $termNo,
public string $message,
#[MapName('QRcIdList'), DataCollectionOf(BlockedQrItemData::class)]
public ?DataCollection $qrCodeList = null,
) {}
}
class BlockedQrItemData extends Data
{
public function __construct(
public string $date,
public string $qrcId,
public ?string $reason = null,
) {}
}

View File

@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Apoloz\AlfaBank\Sbp\Data\Management;
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Data;
class SbpManagementResponseData extends Data
{
public function __construct(
#[MapName('ErrorCode')]
public int $errorCode,
public string $message,
#[MapName('TermNo')]
public ?string $termNo = null,
) {}
}

View File

@@ -13,6 +13,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 arrays and provides DTO benefits.">
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Data;
// </SECTION>
@@ -21,9 +22,10 @@ use Spatie\LaravelData\Data;
class GetQrcReversalDataRequestData extends Data
{
// <SECTION name="constructor_properties" intent="Define the properties for the QR Code reversal data request.">
// <BELIEF_STATE "The constructor includes the mandatory `TermNo` and `currency`. Optional identifiers like `qrcId`, `payrrn`, `trxId`, `trxDT`, `amount`, `messageID`, and `ReturnRestAmount` provide flexibility for various reversal data queries.">
// <BELIEF_STATE "The constructor includes the mandatory `termNo` and `currency`. Optional identifiers like `qrcId`, `payrrn`, `trxId`, `trxDT`, `amount`, `messageID`, and `returnRestAmount` provide flexibility for various reversal data queries.">
public function __construct(
public string $TermNo,
#[MapName('TermNo')]
public string $termNo,
public ?string $qrcId = null,
public ?string $payrrn = null,
public ?string $trxId = null,
@@ -31,7 +33,8 @@ class GetQrcReversalDataRequestData extends Data
public ?string $amount = null,
public string $currency = 'RUB',
public ?string $messageID = null,
public ?bool $ReturnRestAmount = null,
#[MapName('ReturnRestAmount')]
public ?bool $returnRestAmount = null,
) {}
// </SECTION>
}

View File

@@ -13,6 +13,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 arrays and provides DTO benefits.">
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Data;
// </SECTION>
@@ -21,9 +22,10 @@ use Spatie\LaravelData\Data;
class GetQrcReversalStatusRequestData extends Data
{
// <SECTION name="constructor_properties" intent="Define the properties for the QR Code reversal status request.">
// <BELIEF_STATE "The constructor includes the mandatory `TermNo` and optional identifiers like `payrrn`, `originalTrxId`, `trxId`, and `messageID`. These allow for flexible and precise querying of a reversal's status.">
// <BELIEF_STATE "The constructor includes the mandatory `termNo` and optional identifiers like `payrrn`, `originalTrxId`, `trxId`, and `messageID`. These allow for flexible and precise querying of a reversal's status.">
public function __construct(
public string $TermNo,
#[MapName('TermNo')]
public string $termNo,
public ?string $payrrn = null,
public ?string $originalTrxId = null,
public ?string $trxId = null,

View File

@@ -13,6 +13,9 @@ 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 arrays and provides DTO benefits.">
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Attributes\MapOutputName;
use Spatie\LaravelData\Data;
// </SECTION>
@@ -21,9 +24,10 @@ use Spatie\LaravelData\Data;
class QrcReversalRequestData extends Data
{
// <SECTION name="constructor_properties" intent="Define the properties for the QR Code reversal request.">
// <BELIEF_STATE "The constructor includes the mandatory `TermNo` and `currency`. Optional identifiers like `qrcId`, `payrrn`, `trxId`, `trxDT`, `amount`, `messageID`, `notificationUrl`, and `ReturnRestAmount` provide flexibility for various reversal scenarios.">
// <BELIEF_STATE "The constructor includes the mandatory `termNo` and `currency`. Optional identifiers like `qrcId`, `payrrn`, `trxId`, `trxDT`, `amount`, `messageID`, `notificationUrl`, and `returnRestAmount` provide flexibility for various reversal scenarios.">
public function __construct(
public string $TermNo,
#[MapName('TermNo')]
public string $termNo,
public ?string $qrcId = null,
public ?string $payrrn = null,
public ?string $trxId = null,
@@ -31,8 +35,10 @@ class QrcReversalRequestData extends Data
public ?string $amount = null,
public string $currency = 'RUB',
public ?string $messageID = null,
#[MapOutputName('queryData.notificationUrl')]
public ?string $notificationUrl = null,
public ?bool $ReturnRestAmount = null,
#[MapName('ReturnRestAmount')]
public ?bool $returnRestAmount = null,
// extJsonParams not fully implemented as it's optional and dynamic
) {}
// </SECTION>

View File

@@ -13,6 +13,7 @@ namespace Apoloz\AlfaBank\Sbp\Data\Status;
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from arrays and provides DTO benefits.">
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Data;
// </SECTION>
@@ -21,9 +22,10 @@ use Spatie\LaravelData\Data;
class GetQrcStatusRequestData extends Data
{
// <SECTION name="constructor_properties" intent="Define the properties for the QR Code status request.">
// <BELIEF_STATE "The constructor includes the mandatory `TermNo` and optional identifiers like `qrcId`, `payrrn`, and `messageID`. These allow for flexible and precise querying of a QR Code's status.">
// <BELIEF_STATE "The constructor includes the mandatory `termNo` and optional identifiers like `qrcId`, `payrrn`, and `messageID`. These allow for flexible and precise querying of a QR Code's status.">
public function __construct(
public string $TermNo,
#[MapName('TermNo')]
public string $termNo,
public ?string $qrcId = null,
public ?string $payrrn = null,
public ?string $messageID = null,

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Apoloz\AlfaBank\Sbp\Data\Subscription;
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Data;
class GetQrSubStatusResponseData extends Data
{
public function __construct(
#[MapName('ErrorCode')]
public int $errorCode,
public string $message,
#[MapName('TermNo')]
public ?string $termNo = null,
public ?string $qrcId = null,
public ?string $status = null,
public ?string $trxId = null,
public ?string $trxDT = null,
public ?int $amount = null,
public ?string $currency = null,
public ?string $payerId = null,
) {}
}

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Apoloz\AlfaBank\Sbp\Data\Subscription;
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Data;
class QrcSubPayPetitionResponseData extends Data
{
public function __construct(
#[MapName('ErrorCode')]
public int $errorCode,
public string $message,
#[MapName('TermNo')]
public ?string $termNo = null,
public ?string $qrcId = null,
public ?string $status = null,
public ?string $payrrn = null,
public ?string $trxId = null,
public ?string $trxDT = null,
public ?int $amount = null,
public ?string $currency = null,
public ?string $payerId = null,
) {}
}

View File

@@ -13,6 +13,8 @@ namespace Apoloz\AlfaBank\Sbp\Data\Subscription;
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from arrays and provides DTO benefits.">
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Attributes\MapOutputName;
use Spatie\LaravelData\Data;
// </SECTION>
@@ -21,10 +23,12 @@ use Spatie\LaravelData\Data;
class RegQrSubRequestData extends Data
{
// <SECTION name="constructor_properties" intent="Define the properties for the QR Code subscription registration request.">
// <BELIEF_STATE "The constructor includes mandatory `TermNo`, `subscriptionPurpose`, `notificationUrl`, and defaults `qrcType` to '03' (subscription). Optional fields like `qrTtl`, `redirectUrl`, `subscriptionServiceId`, and `subscriptionServiceName` provide flexibility for detailed subscription setup.">
// <BELIEF_STATE "The constructor includes mandatory `termNo`, `subscriptionPurpose`, `notificationUrl`, and defaults `qrcType` to '03' (subscription). Optional fields like `qrTtl`, `redirectUrl`, `subscriptionServiceId`, and `subscriptionServiceName` provide flexibility for detailed subscription setup.">
public function __construct(
public string $TermNo,
#[MapName('TermNo')]
public string $termNo,
public string $subscriptionPurpose,
#[MapOutputName('queryData.notificationUrl')]
public string $notificationUrl,
public string $qrcType = '03', // '03' = Subscription
public ?string $qrTtl = null,

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Apoloz\AlfaBank\Sbp\Data\Subscription;
use Spatie\LaravelData\Attributes\MapName;
use Spatie\LaravelData\Data;
class RegQrSubResponseData extends Data
{
public function __construct(
#[MapName('ErrorCode')]
public int $errorCode,
#[MapName('TermNo')]
public string $termNo,
public string $message,
public ?string $image = null,
public ?string $payload = null,
public ?string $qrcId = null,
public ?string $status = null,
) {}
}

View File

@@ -59,11 +59,11 @@ class GetUniQrStatusRequest extends Request implements HasBody
}
// </SECTION>
// <SECTION name="response_caster" intent="Return the raw JSON response as an array.">
// <BELIEF_STATE "For this specific request, the response is currently returned as a raw array. A dedicated DTO could be created if a structured object is required.">
public function createDtoFromResponse(\Saloon\Http\Response $response): array
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
// <BELIEF_STATE "Casting the response to a `GetUniQrStatusResponseData` DTO provides a type-safe and structured object for the status of Universal QR Codes.">
public function createDtoFromResponse(\Saloon\Http\Response $response): \Apoloz\AlfaBank\Sbp\Data\DigitalRuble\GetUniQrStatusResponseData
{
return $response->json();
return \Apoloz\AlfaBank\Sbp\Data\DigitalRuble\GetUniQrStatusResponseData::from($response->json());
}
// </SECTION>
}

View File

@@ -48,28 +48,21 @@ class BlockQrRequest extends Request implements HasBody
// </SECTION>
// <SECTION name="body_builder" intent="Construct the JSON body for the request.">
// <BELIEF_STATE "The `command` field specifies the operation to the SBP API. The `TermNo` and `qrcId` identify the target, and `reason` provides context for the block.">
// <BELIEF_STATE "The `command` field specifies the operation to the SBP API. Using the DTO's `toArray` method ensures the payload is correctly structured.">
protected function defaultBody(): array
{
$body = [
'command' => 'BlockQRcId',
'TermNo' => $this->data->TermNo,
'qrcId' => $this->data->qrcId,
];
if ($this->data->reason !== null) {
$body['reason'] = $this->data->reason;
}
return $body;
return array_merge(
['command' => 'BlockQRcId'],
$this->data->toArray()
);
}
// </SECTION>
// <SECTION name="response_caster" intent="Return the raw JSON response as an array.">
// <BELIEF_STATE "For this specific request, the response is currently returned as a raw array. A dedicated DTO could be created if a structured object is required.">
public function createDtoFromResponse(\Saloon\Http\Response $response): array
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
// <BELIEF_STATE "Casting the response to a `SbpManagementResponseData` DTO provides a structured object for the result of the block operation.">
public function createDtoFromResponse(\Saloon\Http\Response $response): \Apoloz\AlfaBank\Sbp\Data\Management\SbpManagementResponseData
{
return $response->json();
return \Apoloz\AlfaBank\Sbp\Data\Management\SbpManagementResponseData::from($response->json());
}
// </SECTION>
}

View File

@@ -57,11 +57,11 @@ class GetBlockedQrListRequest extends Request implements HasBody
}
// </SECTION>
// <SECTION name="response_caster" intent="Return the raw JSON response as an array.">
// <BELIEF_STATE "For this specific request, the response is currently returned as a raw array. A dedicated DTO could be created if a structured object is required.">
public function createDtoFromResponse(\Saloon\Http\Response $response): array
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
// <BELIEF_STATE "Casting the response to a `GetBlockedQrListResponseData` DTO provides a type-safe object for the list of blocked QR Codes.">
public function createDtoFromResponse(\Saloon\Http\Response $response): \Apoloz\AlfaBank\Sbp\Data\Management\GetBlockedQrListResponseData
{
return $response->json();
return \Apoloz\AlfaBank\Sbp\Data\Management\GetBlockedQrListResponseData::from($response->json());
}
// </SECTION>
}

View File

@@ -48,22 +48,21 @@ class UnblockQrRequest extends Request implements HasBody
// </SECTION>
// <SECTION name="body_builder" intent="Construct the JSON body for the request.">
// <BELIEF_STATE "The `command` field specifies the operation to the SBP API. The `TermNo` and `qrcId` identify the target QR Code.">
// <BELIEF_STATE "The `command` field specifies the operation to the SBP API. Using the DTO's `toArray` method ensures the payload is correctly structured.">
protected function defaultBody(): array
{
return [
'command' => 'UnblockQRcId',
'TermNo' => $this->data->TermNo,
'qrcId' => $this->data->qrcId,
];
return array_merge(
['command' => 'UnblockQRcId'],
$this->data->toArray()
);
}
// </SECTION>
// <SECTION name="response_caster" intent="Return the raw JSON response as an array.">
// <BELIEF_STATE "For this specific request, the response is currently returned as a raw array. A dedicated DTO could be created if a structured object is required.">
public function createDtoFromResponse(\Saloon\Http\Response $response): array
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
// <BELIEF_STATE "Casting the response to a `SbpManagementResponseData` DTO provides a structured object for the result of the unblock operation.">
public function createDtoFromResponse(\Saloon\Http\Response $response): \Apoloz\AlfaBank\Sbp\Data\Management\SbpManagementResponseData
{
return $response->json();
return \Apoloz\AlfaBank\Sbp\Data\Management\SbpManagementResponseData::from($response->json());
}
// </SECTION>
}

View File

@@ -50,21 +50,10 @@ class GetQrcReversalDataRequest extends Request implements HasBody
// <BELIEF_STATE "The `command` field specifies the operation to the SBP API. Other fields from the DTO are conditionally added, ensuring the payload precisely matches the API specification.">
protected function defaultBody(): array
{
$body = [
'command' => 'GetQRCreversalData',
'TermNo' => $this->data->TermNo,
'currency' => $this->data->currency,
];
if ($this->data->qrcId !== null) $body['qrcId'] = $this->data->qrcId;
if ($this->data->payrrn !== null) $body['payrrn'] = $this->data->payrrn;
if ($this->data->trxId !== null) $body['trxId'] = $this->data->trxId;
if ($this->data->trxDT !== null) $body['trxDT'] = $this->data->trxDT;
if ($this->data->amount !== null) $body['amount'] = $this->data->amount;
if ($this->data->messageID !== null) $body['messageID'] = $this->data->messageID;
if ($this->data->ReturnRestAmount !== null) $body['ReturnRestAmount'] = $this->data->ReturnRestAmount;
return $body;
return array_merge(
['command' => 'GetQRCreversalData'],
$this->data->toArray()
);
}
// </SECTION>

View File

@@ -50,17 +50,10 @@ class GetQrcReversalStatusRequest extends Request implements HasBody
// <BELIEF_STATE "The `command` field specifies the operation to the SBP API. Other fields from the DTO are conditionally added, ensuring the payload precisely matches the API specification.">
protected function defaultBody(): array
{
$body = [
'command' => 'GetQRCreversalStatus',
'TermNo' => $this->data->TermNo,
];
if ($this->data->payrrn !== null) $body['payrrn'] = $this->data->payrrn;
if ($this->data->originalTrxId !== null) $body['originalTrxId'] = $this->data->originalTrxId;
if ($this->data->trxId !== null) $body['trxId'] = $this->data->trxId;
if ($this->data->messageID !== null) $body['messageID'] = $this->data->messageID;
return $body;
return array_merge(
['command' => 'GetQRCreversalStatus'],
$this->data->toArray()
);
}
// </SECTION>

View File

@@ -50,22 +50,10 @@ class QrcReversalRequest extends Request implements HasBody
// <BELIEF_STATE "The `command` field specifies the operation to the SBP API. Other fields from the DTO are conditionally added, ensuring the payload precisely matches the API specification.">
protected function defaultBody(): array
{
$body = [
'command' => 'QRCreversal',
'TermNo' => $this->data->TermNo,
'currency' => $this->data->currency,
];
if ($this->data->qrcId !== null) $body['qrcId'] = $this->data->qrcId;
if ($this->data->payrrn !== null) $body['payrrn'] = $this->data->payrrn;
if ($this->data->trxId !== null) $body['trxId'] = $this->data->trxId;
if ($this->data->trxDT !== null) $body['trxDT'] = $this->data->trxDT;
if ($this->data->amount !== null) $body['amount'] = $this->data->amount;
if ($this->data->messageID !== null) $body['messageID'] = $this->data->messageID;
if ($this->data->notificationUrl !== null) $body['queryData'] = ['notificationUrl' => $this->data->notificationUrl];
if ($this->data->ReturnRestAmount !== null) $body['ReturnRestAmount'] = $this->data->ReturnRestAmount;
return $body;
return array_merge(
['command' => 'QRCreversal'],
$this->data->toArray()
);
}
// </SECTION>

View File

@@ -50,16 +50,10 @@ class GetQrcStatusRequest extends Request implements HasBody
// <BELIEF_STATE "The `command` field specifies the operation to the SBP API. The `TermNo` is mandatory, and `qrcId`, `payrrn`, and `messageID` are optional filters to pinpoint the transaction.">
protected function defaultBody(): array
{
$body = [
'command' => 'GetQRCstatus',
'TermNo' => $this->data->TermNo,
];
if ($this->data->qrcId !== null) $body['qrcId'] = $this->data->qrcId;
if ($this->data->payrrn !== null) $body['payrrn'] = $this->data->payrrn;
if ($this->data->messageID !== null) $body['messageID'] = $this->data->messageID;
return $body;
return array_merge(
['command' => 'GetQRCstatus'],
$this->data->toArray()
);
}
// </SECTION>

View File

@@ -66,11 +66,11 @@ class GetQrSubStatusRequest extends Request implements HasBody
}
// </SECTION>
// <SECTION name="response_caster" intent="Return the raw JSON response as an array.">
// <BELIEF_STATE "For this specific request, the response is currently returned as a raw array. A dedicated DTO could be created if a structured object is required.">
public function createDtoFromResponse(\Saloon\Http\Response $response): array
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
// <BELIEF_STATE "Casting the response to a `GetQrSubStatusResponseData` DTO provides a structured object for the status of the subscription.">
public function createDtoFromResponse(\Saloon\Http\Response $response): \Apoloz\AlfaBank\Sbp\Data\Subscription\GetQrSubStatusResponseData
{
return $response->json();
return \Apoloz\AlfaBank\Sbp\Data\Subscription\GetQrSubStatusResponseData::from($response->json());
}
// </SECTION>
}

View File

@@ -61,11 +61,11 @@ class QrcSubPayPetitionRequest extends Request implements HasBody
}
// </SECTION>
// <SECTION name="response_caster" intent="Return the raw JSON response as an array.">
// <BELIEF_STATE "For this specific request, the response is currently returned as a raw array. A dedicated DTO could be created if a structured object is required.">
public function createDtoFromResponse(Response $response): array
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
// <BELIEF_STATE "Casting the response to a `QrcSubPayPetitionResponseData` DTO provides a structured object for the result of the payment petition.">
public function createDtoFromResponse(Response $response): \Apoloz\AlfaBank\Sbp\Data\Subscription\QrcSubPayPetitionResponseData
{
return $response->json();
return \Apoloz\AlfaBank\Sbp\Data\Subscription\QrcSubPayPetitionResponseData::from($response->json());
}
// </SECTION>
}

View File

@@ -46,33 +46,21 @@ class RegQrSubRequest extends Request implements HasBody
// </SECTION>
// <SECTION name="body_builder" intent="Construct the JSON body for the request.">
// <BELIEF_STATE "The `command` field specifies the operation to the SBP API. Fields from the DTO are mapped, including conditional and nested `queryData` for notification URLs.">
// <BELIEF_STATE "The `command` field specifies the operation to the SBP API. Using the DTO's `toArray` method ensures the payload is correctly structured.">
protected function defaultBody(): array
{
$body = [
'command' => 'RegQRcSub',
'TermNo' => $this->data->TermNo,
'qrcType' => $this->data->qrcType,
'subscriptionPurpose' => $this->data->subscriptionPurpose,
'queryData' => [
'notificationUrl' => $this->data->notificationUrl,
],
];
if ($this->data->qrTtl !== null) $body['qrTtl'] = $this->data->qrTtl;
if ($this->data->redirectUrl !== null) $body['redirectUrl'] = $this->data->redirectUrl;
if ($this->data->subscriptionServiceId !== null) $body['subscriptionServiceId'] = $this->data->subscriptionServiceId;
if ($this->data->subscriptionServiceName !== null) $body['subscriptionServiceName'] = $this->data->subscriptionServiceName;
return $body;
return array_merge(
['command' => 'RegQRcSub'],
$this->data->toArray()
);
}
// </SECTION>
// <SECTION name="response_caster" intent="Return the raw JSON response as an array.">
// <BELIEF_STATE "For this specific request, the response is currently returned as a raw array. A dedicated DTO could be created if a structured object is required.">
public function createDtoFromResponse(Response $response): array
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
// <BELIEF_STATE "Casting the response to a `RegQrSubResponseData` DTO provides a structured object for the result of the subscription registration.">
public function createDtoFromResponse(Response $response): \Apoloz\AlfaBank\Sbp\Data\Subscription\RegQrSubResponseData
{
return $response->json();
return \Apoloz\AlfaBank\Sbp\Data\Subscription\RegQrSubResponseData::from($response->json());
}
// </SECTION>
}

View File

@@ -54,7 +54,15 @@ class SbpConnector extends Connector implements HasPagination
return \Apoloz\AlfaBank\Sbp\Data\Webhooks\SbpRefundNotificationData::from($data);
}
protected function defaultHeaders(): array
/**
* Parse digital ruble payment notification from request body.
*/
public function parseDigitalRubleNotification(array $data): \Apoloz\AlfaBank\Sbp\Data\DigitalRuble\Notifications\PaymentDrNotificationData
{
return \Apoloz\AlfaBank\Sbp\Data\DigitalRuble\Notifications\PaymentDrNotificationData::from($data);
}
protected function defaultConfig(): array
{
$config = [
'cert' => $this->alfaConfig->certificatePath,
@@ -69,6 +77,13 @@ class SbpConnector extends Connector implements HasPagination
return $config;
}
protected function defaultHeaders(): array
{
return [
'Accept' => 'application/json',
];
}
protected function defaultMiddleware(): array
{
return [