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
+43
View File
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace MonetaPhpShop;
/**
* Òåëåôîí ïîêóïàòåëÿ â ôîðìàòå `+<öèôðû>` — äëÿ `MNT_SUBSCRIBER_ID` è äàííûõ ÷åêà.
* PHPShop õðàíèò åãî êàê ââ¸ë ïîêóïàòåëü: `+7(926) 111-11-11`, `8 926 111 11 11`, `9261111111`.
*/
final class PhoneNumber
{
/** E.164: íå áîëüøå 15 öèôð. */
private const MAX_DIGITS = 15;
private const MIN_DIGITS = 10;
private function __construct() {}
/**
* Íîðìàëèçîâàííûé íîìåð èëè null, åñëè ñòðîêà íà òåëåôîí íå ïîõîæà.
* Ðîññèéñêèå íîìåðà ïðèâîäÿòñÿ ê `+7`: `8XXXXXXXXXX` è äåñÿòèçíà÷íûé `9XXXXXXXXX`.
*/
public static function normalize(string $raw): ?string
{
if (preg_match('/[^0-9+()\-\s.]/', $raw) === 1) {
return null;
}
$digits = preg_replace('/[^0-9]/', '', $raw) ?? '';
if ((strlen($digits) === 11) && ($digits[0] === '8')) {
$digits = '7' . substr($digits, 1);
} elseif ((strlen($digits) === 10) && ($digits[0] === '9')) {
$digits = '7' . $digits;
}
$length = strlen($digits);
if (($length < self::MIN_DIGITS) || ($length > self::MAX_DIGITS)) {
return null;
}
return '+' . $digits;
}
}