forked from apoloz/alfa-bank-sdk
69 lines
2.5 KiB
PHP
69 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Apoloz\AlfaBank\Sbp\Requests;
|
|
|
|
use Apoloz\AlfaBank\Sbp\Data\QrCodeRequestData;
|
|
use Apoloz\AlfaBank\Sbp\Data\QrCodeResponseData;
|
|
use Saloon\Contracts\Body\HasBody;
|
|
use Saloon\Enums\Method;
|
|
use Saloon\Http\Request;
|
|
use Saloon\Http\Response;
|
|
use Saloon\Traits\Body\HasJsonBody;
|
|
|
|
class GetQrCodeRequest extends Request implements HasBody
|
|
{
|
|
use HasJsonBody;
|
|
|
|
protected Method $method = Method::POST;
|
|
|
|
public function __construct(
|
|
protected QrCodeRequestData $data
|
|
) {}
|
|
|
|
public function resolveEndpoint(): string
|
|
{
|
|
return '';
|
|
}
|
|
|
|
protected function defaultBody(): array
|
|
{
|
|
$body = [
|
|
'command' => 'GetQRCd',
|
|
'TermNo' => $this->data->TermNo,
|
|
'qrcType' => $this->data->qrcType,
|
|
'currency' => $this->data->currency,
|
|
];
|
|
|
|
// Common Fields
|
|
if ($this->data->amount !== null) $body['amount'] = $this->data->amount;
|
|
if ($this->data->paymentPurpose !== null) $body['paymentPurpose'] = $this->data->paymentPurpose;
|
|
if ($this->data->redirectUrl !== null) $body['redirectUrl'] = $this->data->redirectUrl;
|
|
if ($this->data->messageID !== null) $body['messageID'] = $this->data->messageID;
|
|
if ($this->data->width !== null) $body['width'] = $this->data->width;
|
|
if ($this->data->height !== null) $body['height'] = $this->data->height;
|
|
|
|
// Dynamic QR Fields
|
|
if ($this->data->OrderNumber !== null) $body['OrderNumber'] = $this->data->OrderNumber;
|
|
if ($this->data->qrTtl !== null) $body['qrTtl'] = $this->data->qrTtl;
|
|
if ($this->data->subscriptionServiceId !== null) $body['subscriptionServiceId'] = $this->data->subscriptionServiceId;
|
|
if ($this->data->subscriptionServiceName !== null) $body['subscriptionServiceName'] = $this->data->subscriptionServiceName;
|
|
|
|
// Query Data nesting
|
|
$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)) {
|
|
$body['queryData'] = $queryData;
|
|
}
|
|
|
|
return $body;
|
|
}
|
|
|
|
public function createDtoFromResponse(Response $response): QrCodeResponseData
|
|
{
|
|
return QrCodeResponseData::from($response->json());
|
|
}
|
|
} |