forked from apoloz/alfa-bank-sdk
refactor(Sbp)
This commit is contained in:
@@ -18,7 +18,6 @@ use Saloon\Contracts\Body\HasBody;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
use Saloon\Traits\Body\HasJsonBody;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
@@ -26,7 +25,7 @@ use Saloon\Traits\Body\HasJsonBody;
|
||||
// <BELIEF_STATE "This class encapsulates the logic for modifying a Digital Ruble CashLink QR Code, which is a key management operation.">
|
||||
class ChangeAccForCashUniQrRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
use HasStringBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Modifying a resource via an action is correctly represented by a POST request in the SBP API context.">
|
||||
@@ -57,42 +56,42 @@ class ChangeAccForCashUniQrRequest extends Request implements HasBody
|
||||
|
||||
// <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 parameters for the new account, merchant, redirect URL, etc.">
|
||||
protected function defaultBody(): array
|
||||
protected function defaultBody(): string
|
||||
{
|
||||
$body = [
|
||||
$bodyArray = [
|
||||
'command' => 'ChangeAccForCashUniQr',
|
||||
'TermNo' => $this->data->TermNo,
|
||||
];
|
||||
|
||||
if ($this->data->messageID !== null) {
|
||||
$body['messageID'] = $this->data->messageID;
|
||||
$bodyArray['messageID'] = $this->data->messageID;
|
||||
}
|
||||
if ($this->data->qrcId !== null) {
|
||||
$body['qrcId'] = $this->data->qrcId;
|
||||
$bodyArray['qrcId'] = $this->data->qrcId;
|
||||
}
|
||||
if ($this->data->account !== null) {
|
||||
$body['account'] = $this->data->account;
|
||||
$bodyArray['account'] = $this->data->account;
|
||||
}
|
||||
if ($this->data->accountDR !== null) {
|
||||
$body['accountDR'] = $this->data->accountDR;
|
||||
$bodyArray['accountDR'] = $this->data->accountDR;
|
||||
}
|
||||
if ($this->data->NewTermNo !== null) {
|
||||
$body['NewTermNo'] = $this->data->NewTermNo;
|
||||
$bodyArray['NewTermNo'] = $this->data->NewTermNo;
|
||||
}
|
||||
if ($this->data->NewMerchantId !== null) {
|
||||
$body['NewMerchantId'] = $this->data->NewMerchantId;
|
||||
$bodyArray['NewMerchantId'] = $this->data->NewMerchantId;
|
||||
}
|
||||
if ($this->data->redirectUrl !== null) {
|
||||
$body['redirectUrl'] = $this->data->redirectUrl;
|
||||
$bodyArray['redirectUrl'] = $this->data->redirectUrl;
|
||||
}
|
||||
if ($this->data->paymentPageUrl !== null) {
|
||||
$body['paymentPageUrl'] = $this->data->paymentPageUrl;
|
||||
$bodyArray['paymentPageUrl'] = $this->data->paymentPageUrl;
|
||||
}
|
||||
if ($this->data->fraudScore !== null) {
|
||||
$body['fraudScore'] = $this->data->fraudScore;
|
||||
$bodyArray['fraudScore'] = $this->data->fraudScore;
|
||||
}
|
||||
|
||||
return $body;
|
||||
return CmsSigner::canonicalize($bodyArray);
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ use Saloon\Contracts\Body\HasBody;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
use Saloon\Traits\Body\HasJsonBody;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
@@ -26,7 +25,7 @@ use Saloon\Traits\Body\HasJsonBody;
|
||||
// <BELIEF_STATE "This class encapsulates the logic for generating a Digital Ruble CashLink QR Code, a key feature in the SBP Digital Ruble operations.">
|
||||
class CreateCashUniQrRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
use HasStringBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Creating a new QR Code resource or initiating a generation action is correctly represented by a POST request.">
|
||||
@@ -57,40 +56,40 @@ class CreateCashUniQrRequest extends Request implements HasBody
|
||||
|
||||
// <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.">
|
||||
protected function defaultBody(): array
|
||||
protected function defaultBody(): string
|
||||
{
|
||||
$body = [
|
||||
$bodyArray = [
|
||||
'command' => 'ReqCashUniQr',
|
||||
'TermNo' => $this->data->TermNo,
|
||||
];
|
||||
|
||||
if ($this->data->messageID !== null) {
|
||||
$body['messageID'] = $this->data->messageID;
|
||||
$bodyArray['messageID'] = $this->data->messageID;
|
||||
}
|
||||
if ($this->data->redirectUrl !== null) {
|
||||
$body['redirectUrl'] = $this->data->redirectUrl;
|
||||
$bodyArray['redirectUrl'] = $this->data->redirectUrl;
|
||||
}
|
||||
if ($this->data->paymentPageUrl !== null) {
|
||||
$body['paymentPageUrl'] = $this->data->paymentPageUrl;
|
||||
$bodyArray['paymentPageUrl'] = $this->data->paymentPageUrl;
|
||||
}
|
||||
if ($this->data->mediaType !== null) {
|
||||
$body['mediaType'] = $this->data->mediaType;
|
||||
$bodyArray['mediaType'] = $this->data->mediaType;
|
||||
}
|
||||
if ($this->data->width !== null) {
|
||||
$body['width'] = $this->data->width;
|
||||
$bodyArray['width'] = $this->data->width;
|
||||
}
|
||||
if ($this->data->height !== null) {
|
||||
$body['height'] = $this->data->height;
|
||||
$bodyArray['height'] = $this->data->height;
|
||||
}
|
||||
if ($this->data->qrcId !== null) {
|
||||
$body['qrcId'] = $this->data->qrcId;
|
||||
$bodyArray['qrcId'] = $this->data->qrcId;
|
||||
}
|
||||
|
||||
if ($this->data->notificationUrl !== null) {
|
||||
$body['queryData'] = ['notificationUrl' => $this->data->notificationUrl];
|
||||
$bodyArray['queryData'] = ['notificationUrl' => $this->data->notificationUrl];
|
||||
}
|
||||
|
||||
return $body;
|
||||
return CmsSigner::canonicalize($bodyArray);
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ use Saloon\Contracts\Body\HasBody;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
use Saloon\Traits\Body\HasJsonBody;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
@@ -26,7 +25,7 @@ use Saloon\Traits\Body\HasJsonBody;
|
||||
// <BELIEF_STATE "This class encapsulates the logic for querying the status of a Digital Ruble CashLink QR Code, which is crucial for tracking payment flows.">
|
||||
class GetCashUniQrStatusRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
use HasStringBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Even though it retrieves data, SBP status checks are often performed via POST requests with a JSON body.">
|
||||
@@ -57,9 +56,9 @@ class GetCashUniQrStatusRequest extends Request implements HasBody
|
||||
|
||||
// <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`, `uniQrId`, and `paramsId` identify the target. Optional fields like `messageID` and `payrrn` provide additional context.">
|
||||
protected function defaultBody(): array
|
||||
protected function defaultBody(): string
|
||||
{
|
||||
$body = [
|
||||
$bodyArray = [
|
||||
'command' => 'GetCashUniQrStatus',
|
||||
'TermNo' => $this->data->TermNo,
|
||||
'uniQrId' => $this->data->uniQrId,
|
||||
@@ -67,13 +66,13 @@ class GetCashUniQrStatusRequest extends Request implements HasBody
|
||||
];
|
||||
|
||||
if ($this->data->messageID !== null) {
|
||||
$body['messageID'] = $this->data->messageID;
|
||||
$bodyArray['messageID'] = $this->data->messageID;
|
||||
}
|
||||
if ($this->data->payrrn !== null) {
|
||||
$body['payrrn'] = $this->data->payrrn;
|
||||
$bodyArray['payrrn'] = $this->data->payrrn;
|
||||
}
|
||||
|
||||
return $body;
|
||||
return CmsSigner::canonicalize($bodyArray);
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
@@ -6,15 +6,16 @@ namespace Apoloz\AlfaBank\Sbp\Requests\DigitalRuble;
|
||||
|
||||
use Apoloz\AlfaBank\Sbp\Data\DigitalRuble\CreateUniQrRequestData;
|
||||
use Apoloz\AlfaBank\Sbp\Data\DigitalRuble\UniQrResponseData;
|
||||
use Apoloz\AlfaBank\Utils\CmsSigner;
|
||||
use Saloon\Contracts\Body\HasBody;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
use Saloon\Traits\Body\HasJsonBody;
|
||||
use Saloon\Traits\Body\HasStringBody;
|
||||
|
||||
class CreateUniQrRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
use HasStringBody;
|
||||
|
||||
protected Method $method = Method::POST;
|
||||
|
||||
@@ -32,40 +33,40 @@ class CreateUniQrRequest extends Request implements HasBody
|
||||
return UniQrResponseData::from($response->json());
|
||||
}
|
||||
|
||||
protected function defaultBody(): array
|
||||
protected function defaultBody(): string
|
||||
{
|
||||
$body = [
|
||||
$bodyArray = [
|
||||
'command' => 'ReqUniQr',
|
||||
'TermNo' => $this->data->TermNo,
|
||||
'uniQrType' => $this->data->uniQrType,
|
||||
];
|
||||
|
||||
if ($this->data->amount !== null) {
|
||||
$body['amount'] = $this->data->amount;
|
||||
$bodyArray['amount'] = $this->data->amount;
|
||||
}
|
||||
if ($this->data->paymentPurpose !== null) {
|
||||
$body['paymentPurpose'] = $this->data->paymentPurpose;
|
||||
$bodyArray['paymentPurpose'] = $this->data->paymentPurpose;
|
||||
}
|
||||
if ($this->data->redirectUrl !== null) {
|
||||
$body['redirectUrl'] = $this->data->redirectUrl;
|
||||
$bodyArray['redirectUrl'] = $this->data->redirectUrl;
|
||||
}
|
||||
if ($this->data->paymentPageUrl !== null) {
|
||||
$body['paymentPageUrl'] = $this->data->paymentPageUrl;
|
||||
$bodyArray['paymentPageUrl'] = $this->data->paymentPageUrl;
|
||||
}
|
||||
if ($this->data->mediaType !== null) {
|
||||
$body['mediaType'] = $this->data->mediaType;
|
||||
$bodyArray['mediaType'] = $this->data->mediaType;
|
||||
}
|
||||
if ($this->data->width !== null) {
|
||||
$body['width'] = $this->data->width;
|
||||
$bodyArray['width'] = $this->data->width;
|
||||
}
|
||||
if ($this->data->height !== null) {
|
||||
$body['height'] = $this->data->height;
|
||||
$bodyArray['height'] = $this->data->height;
|
||||
}
|
||||
if ($this->data->qrTtl !== null) {
|
||||
$body['qrTtl'] = $this->data->qrTtl;
|
||||
$bodyArray['qrTtl'] = $this->data->qrTtl;
|
||||
}
|
||||
if ($this->data->messageID !== null) {
|
||||
$body['messageID'] = $this->data->messageID;
|
||||
$bodyArray['messageID'] = $this->data->messageID;
|
||||
}
|
||||
|
||||
$queryData = [];
|
||||
@@ -83,9 +84,9 @@ class CreateUniQrRequest extends Request implements HasBody
|
||||
}
|
||||
|
||||
if (! empty($queryData)) {
|
||||
$body['queryData'] = $queryData;
|
||||
$bodyArray['queryData'] = $queryData;
|
||||
}
|
||||
|
||||
return $body;
|
||||
return CmsSigner::canonicalize($bodyArray);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,20 +12,21 @@ namespace Apoloz\AlfaBank\Sbp\Requests\DigitalRuble;
|
||||
|
||||
// <SECTION name="module_imports" intent="Import Saloon components for a JSON body request.">
|
||||
// <BELIEF_STATE "This POST request utilizes `HasBody` and `HasJsonBody` for proper payload serialization. It currently returns a raw array response.">
|
||||
use Apoloz\AlfaBank\Sbp\Data\DigitalRuble\GetUniQrStatusResponseData;
|
||||
use Apoloz\AlfaBank\Utils\CmsSigner;
|
||||
use Saloon\Contracts\Body\HasBody;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Traits\Body\HasJsonBody;
|
||||
use Saloon\Http\Response;
|
||||
use Saloon\Traits\Body\HasStringBody;
|
||||
|
||||
// <BELIEF_STATE "The `Response` object is fully qualified in `createDtoFromResponse` as it is not explicitly imported with a `use` statement at the top. This is acceptable but less explicit.">
|
||||
// use Saloon\Http\Response; // Explicit import would be cleaner
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define the request to get the status of Universal QR Codes.">
|
||||
// <BELIEF_STATE "This class encapsulates the logic for querying the status of multiple Uni QR Codes, which is part of managing digital ruble transactions.">
|
||||
class GetUniQrStatusRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
use HasStringBody;
|
||||
|
||||
// <SECTION name="http_method" intent="Declare the HTTP verb.">
|
||||
// <BELIEF_STATE "Even though it retrieves data, SBP status checks are often performed via POST requests with a JSON body.">
|
||||
@@ -49,21 +50,23 @@ class GetUniQrStatusRequest extends Request implements HasBody
|
||||
|
||||
// <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
|
||||
public function createDtoFromResponse(Response $response): GetUniQrStatusResponseData
|
||||
{
|
||||
return \Apoloz\AlfaBank\Sbp\Data\DigitalRuble\GetUniQrStatusResponseData::from($response->json());
|
||||
return GetUniQrStatusResponseData::from($response->json());
|
||||
}
|
||||
// </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 `uniQrIds` are included in the body to identify the targets.">
|
||||
protected function defaultBody(): array
|
||||
protected function defaultBody(): string
|
||||
{
|
||||
return [
|
||||
$bodyArray = [
|
||||
'command' => 'GetUniQrStatus',
|
||||
'TermNo' => $this->TermNo,
|
||||
'uniQrIds' => $this->uniQrIds,
|
||||
];
|
||||
|
||||
return CmsSigner::canonicalize($bodyArray);
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user