feat: paygw_moneta 1.0.2, receipt attributes by fiscalization, pm/po settings

This commit is contained in:
2026-10-12 13:24:13 +03:00
parent 2be833119b
commit e4e04236cc
17 changed files with 234 additions and 75 deletions
+32 -7
View File
@@ -8,6 +8,8 @@ use core_payment\form\account_gateway;
use paygw_moneta\local\protocol\AssistantProtocol;
use paygw_moneta\local\protocol\PaymentServer;
use paygw_moneta\local\receipt\Client;
use paygw_moneta\local\receipt\PaymentMethod;
use paygw_moneta\local\receipt\PaymentObject;
use paygw_moneta\local\receipt\Vat;
use stdClass;
@@ -42,7 +44,7 @@ class gateway extends \core_payment\gateway
$servers = [];
foreach (PaymentServer::cases() as $server) {
$servers[$server->value] = get_string($server->label(), 'paygw_moneta');
$servers[$server->value] = get_string($server->langKey(), 'paygw_moneta');
}
$mform->addElement('select', 'paymentserver', get_string('paymentserver', 'paygw_moneta'), $servers);
$mform->setDefault('paymentserver', PaymentServer::Prod->value);
@@ -51,20 +53,41 @@ class gateway extends \core_payment\gateway
$mform->addElement('advcheckbox', 'testmode', get_string('testmode', 'paygw_moneta'));
$mform->addHelpButton('testmode', 'testmode', 'paygw_moneta');
$mform->addElement('text', 'receiptemail', get_string('receiptemail', 'paygw_moneta'));
$mform->setType('receiptemail', PARAM_RAW_TRIMMED);
$mform->addRule('receiptemail', null, 'required', null, 'client');
$mform->addHelpButton('receiptemail', 'receiptemail', 'paygw_moneta');
$mform->addElement('advcheckbox', 'fiscalization', get_string('fiscalization', 'paygw_moneta'));
$mform->addHelpButton('fiscalization', 'fiscalization', 'paygw_moneta');
// Поля чека нужны только при фискализации. Скрываются, а не блокируются:
// заблокированное поле браузер не отправляет, и значение потерялось бы.
$mform->addElement('text', 'receiptemail', get_string('receiptemail', 'paygw_moneta'));
$mform->setType('receiptemail', PARAM_RAW_TRIMMED);
$mform->addHelpButton('receiptemail', 'receiptemail', 'paygw_moneta');
$mform->hideIf('receiptemail', 'fiscalization', 'notchecked');
$vatOptions = [];
foreach (Vat::cases() as $vat) {
$vatOptions[$vat->value] = get_string($vat->langKey(), 'paygw_moneta');
}
$mform->addElement('select', 'vat', get_string('vat', 'paygw_moneta'), $vatOptions);
$mform->setDefault('vat', Vat::None->value);
$mform->hideIf('vat', 'fiscalization', 'notchecked');
$methods = [];
foreach (PaymentMethod::cases() as $method) {
$methods[$method->value] = get_string($method->langKey(), 'paygw_moneta');
}
$mform->addElement('select', 'paymentmethod', get_string('paymentmethod', 'paygw_moneta'), $methods);
$mform->setDefault('paymentmethod', PaymentMethod::FullPayment->value);
$mform->addHelpButton('paymentmethod', 'paymentmethod', 'paygw_moneta');
$mform->hideIf('paymentmethod', 'fiscalization', 'notchecked');
$objects = [];
foreach (PaymentObject::cases() as $object) {
$objects[$object->value] = get_string($object->langKey(), 'paygw_moneta');
}
$mform->addElement('select', 'paymentobject', get_string('paymentobject', 'paygw_moneta'), $objects);
$mform->setDefault('paymentobject', PaymentObject::Service->value);
$mform->addHelpButton('paymentobject', 'paymentobject', 'paygw_moneta');
$mform->hideIf('paymentobject', 'fiscalization', 'notchecked');
$mform->addElement('advcheckbox', 'sendpaymentlink', get_string('sendpaymentlink', 'paygw_moneta'));
$mform->addHelpButton('sendpaymentlink', 'sendpaymentlink', 'paygw_moneta');
@@ -87,8 +110,10 @@ class gateway extends \core_payment\gateway
$errors['accountnumber'] = get_string('error:accountnumber', 'paygw_moneta');
}
// «Email для чеков» обязателен только при фискализации, но мусор не сохраняем и без неё.
$receiptEmail = trim((string) ($data->receiptemail ?? ''));
if (Client::normalizeEmail($receiptEmail) === null) {
$required = !empty($data->fiscalization);
if (($required || $receiptEmail !== '') && Client::normalizeEmail($receiptEmail) === null) {
$errors['receiptemail'] = get_string('error:receiptemail', 'paygw_moneta');
}