forked from apoloz/alfa-bank-sdk
98 lines
4.4 KiB
PHP
98 lines
4.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
/*
|
|
// MODULE_CONTRACT: Represents the SBP API call to change the account for a CashLink Universal QR Code.
|
|
// RESPONSIBILITY: To define the POST request for updating the linked account for a Digital Ruble CashLink QR.
|
|
// INPUTS: ChangeAccForCashUniQrRequestData (DTO) with relevant parameters.
|
|
// OUTPUTS: ChangeAccForCashUniQrResponseData (DTO).
|
|
*/
|
|
|
|
namespace Apoloz\AlfaBank\Sbp\Requests\DigitalRuble\CashLink;
|
|
|
|
// <SECTION name="module_imports" intent="Import DTOs and Saloon components for a JSON body request.">
|
|
// <BELIEF_STATE "This POST request requires specific DTOs for its JSON body and its response, along with Saloon's body-handling traits.">
|
|
use Apoloz\AlfaBank\Sbp\Data\DigitalRuble\CashLink\ChangeAccForCashUniQrRequestData;
|
|
use Apoloz\AlfaBank\Sbp\Data\DigitalRuble\CashLink\ChangeAccForCashUniQrResponseData;
|
|
use Saloon\Contracts\Body\HasBody;
|
|
use Saloon\Enums\Method;
|
|
use Saloon\Http\Request;
|
|
use Saloon\Http\Response;
|
|
|
|
// </SECTION>
|
|
|
|
// <SECTION name="class_definition" intent="Define the request to change the account for a CashLink Uni QR Code.">
|
|
// <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 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.">
|
|
protected Method $method = Method::POST;
|
|
// </SECTION>
|
|
|
|
// <SECTION name="constructor" intent="Inject the DTO containing the account change data.">
|
|
// <BELIEF_STATE "Using a strongly-typed DTO (`ChangeAccForCashUniQrRequestData`) ensures that all necessary information for the account change is provided and correctly structured.">
|
|
public function __construct(
|
|
protected ChangeAccForCashUniQrRequestData $data
|
|
) {}
|
|
|
|
// <SECTION name="endpoint_resolver" intent="Define the endpoint for SBP CashLink Uni QR Code account changes.">
|
|
// <BELIEF_STATE "The SBP API often uses generic endpoints with a 'command' field in the body, implying the endpoint itself might be empty or a base SBP URL.">
|
|
public function resolveEndpoint(): string
|
|
{
|
|
return ''; // Endpoint is determined by SbpConnector's base URL
|
|
}
|
|
// </SECTION>
|
|
|
|
// <SECTION name="response_caster" intent="Map the JSON response to a DTO.">
|
|
// <BELIEF_STATE "Casting the response to a `ChangeAccForCashUniQrResponseData` DTO provides a type-safe and structured object for the result of the account change operation.">
|
|
public function createDtoFromResponse(Response $response): ChangeAccForCashUniQrResponseData
|
|
{
|
|
return ChangeAccForCashUniQrResponseData::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. Fields from the DTO are mapped, including conditional parameters for the new account, merchant, redirect URL, etc.">
|
|
protected function defaultBody(): string
|
|
{
|
|
$bodyArray = [
|
|
'command' => 'ChangeAccForCashUniQr',
|
|
'TermNo' => $this->data->TermNo,
|
|
];
|
|
|
|
if ($this->data->messageID !== null) {
|
|
$bodyArray['messageID'] = $this->data->messageID;
|
|
}
|
|
if ($this->data->qrcId !== null) {
|
|
$bodyArray['qrcId'] = $this->data->qrcId;
|
|
}
|
|
if ($this->data->account !== null) {
|
|
$bodyArray['account'] = $this->data->account;
|
|
}
|
|
if ($this->data->accountDR !== null) {
|
|
$bodyArray['accountDR'] = $this->data->accountDR;
|
|
}
|
|
if ($this->data->NewTermNo !== null) {
|
|
$bodyArray['NewTermNo'] = $this->data->NewTermNo;
|
|
}
|
|
if ($this->data->NewMerchantId !== null) {
|
|
$bodyArray['NewMerchantId'] = $this->data->NewMerchantId;
|
|
}
|
|
if ($this->data->redirectUrl !== null) {
|
|
$bodyArray['redirectUrl'] = $this->data->redirectUrl;
|
|
}
|
|
if ($this->data->paymentPageUrl !== null) {
|
|
$bodyArray['paymentPageUrl'] = $this->data->paymentPageUrl;
|
|
}
|
|
if ($this->data->fraudScore !== null) {
|
|
$bodyArray['fraudScore'] = $this->data->fraudScore;
|
|
}
|
|
|
|
return CmsSigner::canonicalize($bodyArray);
|
|
}
|
|
// </SECTION>
|
|
}
|