86 lines
3.4 KiB
PHP
86 lines
3.4 KiB
PHP
<?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\PaymentMethod;
|
|
use paygw_moneta\local\receipt\PaymentObject;
|
|
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,
|
|
public readonly PaymentMethod $paymentMethod = PaymentMethod::FullPayment,
|
|
public readonly PaymentObject $paymentObject = PaymentObject::Service,
|
|
) {}
|
|
|
|
/**
|
|
* @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']),
|
|
PaymentMethod::tryFrom((string) ($config['paymentmethod'] ?? '')) ?? PaymentMethod::FullPayment,
|
|
PaymentObject::tryFrom((string) ($config['paymentobject'] ?? '')) ?? PaymentObject::Service,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Можно ли создавать новые заказы: реквизиты, а при фискализации ещё и
|
|
* «Email для чеков», без которого чек покупателя без контактов не собрать.
|
|
* Колбэки проверяют только {@see isComplete()} — уже оплаченный заказ
|
|
* должен дойти до зачисления, даже если настройку потом очистили.
|
|
*/
|
|
public function acceptsNewOrders(): bool
|
|
{
|
|
return $this->isComplete()
|
|
&& $this->enabled
|
|
&& (!$this->fiscalization || $this->receiptEmail !== null);
|
|
}
|
|
|
|
public function isComplete(): bool
|
|
{
|
|
return $this->accountNumber !== '' && $this->integrityCode !== '';
|
|
}
|
|
|
|
public function signature(): Signature
|
|
{
|
|
return new Signature($this->integrityCode);
|
|
}
|
|
}
|