93 lines
2.8 KiB
PHP
93 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
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\HasStringBody;
|
|
|
|
class CreateUniQrRequest extends Request implements HasBody
|
|
{
|
|
use HasStringBody;
|
|
|
|
protected Method $method = Method::POST;
|
|
|
|
public function __construct(
|
|
protected CreateUniQrRequestData $data
|
|
) {}
|
|
|
|
public function resolveEndpoint(): string
|
|
{
|
|
return '';
|
|
}
|
|
|
|
public function createDtoFromResponse(Response $response): UniQrResponseData
|
|
{
|
|
return UniQrResponseData::from($response->json());
|
|
}
|
|
|
|
protected function defaultBody(): string
|
|
{
|
|
$bodyArray = [
|
|
'command' => 'ReqUniQr',
|
|
'TermNo' => $this->data->TermNo,
|
|
'uniQrType' => $this->data->uniQrType,
|
|
];
|
|
|
|
if ($this->data->amount !== null) {
|
|
$bodyArray['amount'] = $this->data->amount;
|
|
}
|
|
if ($this->data->paymentPurpose !== null) {
|
|
$bodyArray['paymentPurpose'] = $this->data->paymentPurpose;
|
|
}
|
|
if ($this->data->redirectUrl !== null) {
|
|
$bodyArray['redirectUrl'] = $this->data->redirectUrl;
|
|
}
|
|
if ($this->data->paymentPageUrl !== null) {
|
|
$bodyArray['paymentPageUrl'] = $this->data->paymentPageUrl;
|
|
}
|
|
if ($this->data->mediaType !== null) {
|
|
$bodyArray['mediaType'] = $this->data->mediaType;
|
|
}
|
|
if ($this->data->width !== null) {
|
|
$bodyArray['width'] = $this->data->width;
|
|
}
|
|
if ($this->data->height !== null) {
|
|
$bodyArray['height'] = $this->data->height;
|
|
}
|
|
if ($this->data->qrTtl !== null) {
|
|
$bodyArray['qrTtl'] = $this->data->qrTtl;
|
|
}
|
|
if ($this->data->messageID !== null) {
|
|
$bodyArray['messageID'] = $this->data->messageID;
|
|
}
|
|
|
|
$queryData = [];
|
|
if ($this->data->notificationUrl !== null) {
|
|
$queryData['notificationUrl'] = $this->data->notificationUrl;
|
|
}
|
|
if ($this->data->SenderFIO !== null) {
|
|
$queryData['SenderFIO'] = $this->data->SenderFIO;
|
|
}
|
|
if ($this->data->SenderID !== null) {
|
|
$queryData['SenderID'] = $this->data->SenderID;
|
|
}
|
|
if ($this->data->SenderBankBIC !== null) {
|
|
$queryData['SenderBankBIC'] = $this->data->SenderBankBIC;
|
|
}
|
|
|
|
if (! empty($queryData)) {
|
|
$bodyArray['queryData'] = $queryData;
|
|
}
|
|
|
|
return CmsSigner::canonicalize($bodyArray);
|
|
}
|
|
}
|