feat: paygw_moneta 1.0.0, MONETA.Assistant payment gateway for Moodle
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user