feat: paygw_moneta 1.0.0, MONETA.Assistant payment gateway for Moodle

This commit is contained in:
2026-09-25 16:42:38 +03:00
parent 70464af858
commit 14b386a550
65 changed files with 5377 additions and 59 deletions
+77
View File
@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace paygw_moneta\local;
use paygw_moneta\local\protocol\PaymentServer;
use paygw_moneta\local\protocol\Signature;
use paygw_moneta\local\receipt\Client;
use paygw_moneta\local\receipt\Vat;
/**
* Настройки шлюза Moneta у платёжного аккаунта Moodle (`payment_gateways.config`);
* читает их из БД {@see GatewayConfigRepository}.
* Единственный читатель кода проверки целостности: дальше он живёт только
* внутри {@see Signature}.
*
* @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 GatewayConfig
{
public const GATEWAY = 'moneta';
public function __construct(
public readonly string $accountNumber,
#[\SensitiveParameter]
private readonly string $integrityCode,
public readonly PaymentServer $paymentServer,
public readonly bool $testMode,
public readonly bool $fiscalization,
public readonly Vat $vat,
public readonly bool $enabled,
public readonly ?string $receiptEmail = null,
public readonly bool $sendPaymentLink = false,
) {}
/**
* @param array<string, mixed> $config значения формы {@see \paygw_moneta\Gateway}
*/
public static function fromArray(array $config, bool $enabled = true): self
{
return new self(
trim((string) ($config['accountnumber'] ?? '')),
(string) ($config['integritycode'] ?? ''),
PaymentServer::fromSetting($config['paymentserver'] ?? null),
!empty($config['testmode']),
!empty($config['fiscalization']),
Vat::tryFrom((string) ($config['vat'] ?? '')) ?? Vat::None,
$enabled,
Client::normalizeEmail((string) ($config['receiptemail'] ?? '')),
!empty($config['sendpaymentlink']),
);
}
/**
* Можно ли создавать новые заказы: реквизиты и «Email для чеков», без
* которого чек покупателя без контактов не собрать. Колбэки проверяют
* только {@see isComplete()} — уже оплаченный заказ должен дойти до
* зачисления, даже если настройку потом очистили.
*/
public function acceptsNewOrders(): bool
{
return $this->isComplete() && $this->enabled && $this->receiptEmail !== null;
}
public function isComplete(): bool
{
return $this->accountNumber !== '' && $this->integrityCode !== '';
}
public function signature(): Signature
{
return new Signature($this->integrityCode);
}
}