feat: moneta 2.0, MONETA.Assistant payment module for PHPShop 6.7+

This commit is contained in:
2026-10-27 11:45:22 +03:00
parent 78b7405637
commit f8c12ce44a
82 changed files with 7387 additions and 58 deletions
+220
View File
@@ -0,0 +1,220 @@
<?php
declare(strict_types=1);
namespace MonetaPhpShop;
use MonetaPhpShop\protocol\PaymentServer;
use MonetaPhpShop\protocol\Signature;
use MonetaPhpShop\receipt\PaymentMethod;
use MonetaPhpShop\receipt\PaymentObject;
use MonetaPhpShop\receipt\TaxSystem;
use MonetaPhpShop\receipt\VatSetting;
/**
* Íàñòðîéêè ìîäóëÿ — ñòðîêà `phpshop_modules_moneta_system`. Òåêñòîâûå ïîëÿ — â êîäèðîâêå
* âèòðèíû ìîäóëÿ (cp1251): ïåðåêîäèðóåò èõ {@see \MonetaPhpShop\host\SettingsRepository}.
*/
final class Settings
{
/** Ñòàòóñ PHPShop «Íîâûé çàêàç» — â íàñòðîéêå «Îïëàòà ïðè ñòàòóñå» çíà÷èò «ñðàçó ïîñëå îôîðìëåíèÿ». */
public const STATUS_NEW = 0;
/** Ñòàòóñ, êîòîðûé ÿäðî PHPShop ñîçäà¸ò äëÿ îïëà÷åííûõ çàêàçîâ (`PHPShopPaymentResult::set_order_status_101()`). */
public const STATUS_PAID_BY_GATEWAY = 101;
/** @var string */
private $accountId;
/** @var string */
private $integrityCode;
/** @var PaymentServer */
private $paymentServer;
/** @var bool */
private $testMode;
/** @var bool */
private $fiscalization;
/** @var string */
private $receiptEmail;
/** @var string */
private $paymentDescription;
/** @var PaymentMethod */
private $paymentMethod;
/** @var PaymentObject */
private $paymentObject;
/** @var TaxSystem */
private $taxSystem;
/** @var VatSetting */
private $goodsVat;
/** @var VatSetting */
private $deliveryVat;
/** @var int */
private $payableStatus;
/** @var int */
private $paidStatus;
/** @var string */
private $version;
private function __construct() {}
/**
* @param array<string, mixed> $row ñòðîêà òàáëèöû íàñòðîåê
*/
public static function fromRow(array $row): self
{
$settings = new self();
$settings->accountId = trim(self::string($row, 'account_id'));
$settings->integrityCode = self::string($row, 'integrity_code');
$settings->paymentServer = PaymentServer::fromSetting(self::string($row, 'payment_server'));
$settings->testMode = self::string($row, 'test_mode') === '1';
$settings->fiscalization = self::string($row, 'fiscalization') === '1';
$settings->receiptEmail = trim(self::string($row, 'receipt_email'));
$settings->paymentDescription = trim(self::string($row, 'title_end'));
$settings->paymentMethod = PaymentMethod::fromSetting(self::string($row, 'payment_method'));
$settings->paymentObject = PaymentObject::fromSetting(self::string($row, 'payment_object'));
$settings->taxSystem = TaxSystem::fromSetting(self::string($row, 'sno'));
$settings->goodsVat = VatSetting::fromSetting(self::string($row, 'goods_vat'));
$settings->deliveryVat = VatSetting::fromSetting(self::string($row, 'delivery_vat'));
$settings->payableStatus = (int) self::string($row, 'status');
$paidStatus = (int) self::string($row, 'paid_status');
$settings->paidStatus = ($paidStatus > 0) ? $paidStatus : self::STATUS_PAID_BY_GATEWAY;
$settings->version = self::string($row, 'version');
return $settings;
}
/**
* Ìîæíî ïðèíèìàòü îïëàòó: çàäàí íîìåð ñ÷¸òà (òîëüêî öèôðû) è êîä ïðîâåðêè öåëîñòíîñòè äàííûõ.
*/
public function isConfigured(): bool
{
return preg_match('/\A[0-9]{1,20}\z/', $this->accountId) === 1 && $this->integrityCode !== '';
}
public function getAccountId(): string
{
return $this->accountId;
}
public function signature(): Signature
{
return new Signature($this->integrityCode);
}
/**
* Êîä ïðîâåðêè öåëîñòíîñòè äàííûõ íå âûâîäèòñÿ â var_dump()/print_r() è æóðíàëû, êàê ó {@see Signature};
* âèäíî òîëüêî, çàäàí ëè îí.
*
* @return array<string, mixed>
*/
public function __debugInfo(): array
{
$properties = get_object_vars($this);
$properties['integrityCode'] = ($this->integrityCode === '') ? '' : '***';
return $properties;
}
public function getPaymentServer(): PaymentServer
{
return $this->paymentServer;
}
public function isTestMode(): bool
{
return $this->testMode;
}
public function isFiscalization(): bool
{
return $this->fiscalization;
}
public function getReceiptEmail(): string
{
return $this->receiptEmail;
}
/**
* «Îïèñàíèå îïëàòû» (êîëîíêà `title_end`, êàê ó øòàòíûõ ìîäóëåé PHPShop è âñòðîåííîé «Ìîíåòû»):
* òåêñò íàä ñóììîé è êíîïêîé îïëàòû. Îáû÷íûé òåêñò â êîäèðîâêå ÁÄ; ïóñòî — áåç òåêñòà.
*/
public function getPaymentDescription(): string
{
return $this->paymentDescription;
}
public function getPaymentMethod(): PaymentMethod
{
return $this->paymentMethod;
}
public function getPaymentObject(): PaymentObject
{
return $this->paymentObject;
}
public function getTaxSystem(): TaxSystem
{
return $this->taxSystem;
}
public function getGoodsVat(): VatSetting
{
return $this->goodsVat;
}
public function getDeliveryVat(): VatSetting
{
return $this->deliveryVat;
}
/**
* Ñòàòóñ, ïðè êîòîðîì ïîêóïàòåëþ äîñòóïíà îïëàòà; {@see self::STATUS_NEW} — ñðàçó ïîñëå îôîðìëåíèÿ.
*/
public function getPayableStatus(): int
{
return $this->payableStatus;
}
public function isPayableRightAfterCheckout(): bool
{
return $this->payableStatus === self::STATUS_NEW;
}
/**
* Ñòàòóñ, â êîòîðûé ìîäóëü ïåðåâîäèò çàêàç ïîñëå ïîäòâåðæäåíèÿ îïëàòû.
*/
public function getPaidStatus(): int
{
return $this->paidStatus;
}
public function getVersion(): string
{
return $this->version;
}
/**
* @param array<string, mixed> $row
*/
private static function string(array $row, string $key): string
{
$value = $row[$key] ?? '';
return is_scalar($value) ? (string) $value : '';
}
}