57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace paygw_moneta\local\protocol;
|
|
|
|
use paygw_moneta\local\Money;
|
|
use paygw_moneta\local\receipt\Receipt;
|
|
|
|
/**
|
|
* @package paygw_moneta
|
|
* @copyright 2026 Moneta Labs {@link https://moneta.ru/}
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
final class PayResponse
|
|
{
|
|
public function __construct(
|
|
private readonly string $accountId,
|
|
private readonly string $transactionId,
|
|
private readonly Money $amount,
|
|
private readonly ResultCode $resultCode,
|
|
private readonly Signature $signature,
|
|
private readonly string $cms,
|
|
private readonly ?Receipt $receipt = null,
|
|
) {}
|
|
|
|
/**
|
|
* @throws \DOMException
|
|
* @throws \JsonException
|
|
*/
|
|
public function toXml(): CallbackResponse
|
|
{
|
|
$attributes = [];
|
|
if ($this->receipt !== null) {
|
|
$attributes['INVENTORY'] = $this->receipt->toInventoryAttribute();
|
|
$attributes['CLIENT'] = $this->receipt->toClientAttribute();
|
|
$duplicates = [
|
|
'CUSTOMER' => $this->receipt->toCustomerAttribute(),
|
|
'PHONE' => $this->receipt->toPhoneAttribute(),
|
|
];
|
|
$attributes += array_filter($duplicates, static fn(?string $value): bool => $value !== null);
|
|
}
|
|
|
|
return CallbackResponse::xml(
|
|
MntResponseXml::build(
|
|
accountId: $this->accountId,
|
|
transactionId: $this->transactionId,
|
|
resultCode: $this->resultCode,
|
|
amount: $this->amount,
|
|
signature: $this->signature->forResponse($this->resultCode, $this->accountId, $this->transactionId),
|
|
cms: $this->cms,
|
|
attributes: $attributes,
|
|
),
|
|
);
|
|
}
|
|
}
|