Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ofd.php
1<?php
2
3namespace Bitrix\Sale\Cashbox;
4
9
14abstract class Ofd
15{
16 protected const EVENT_ON_GET_CUSTOM_OFD_HANDLERS = 'OnGetCustomOfdHandlers';
17 private const BX_OFD_PREFIX = 'bx_';
18
23 public static function getHandlerList()
24 {
25 $handlerList = self::getSystemHandlerList();
26
27 $event = new Main\Event('sale', static::EVENT_ON_GET_CUSTOM_OFD_HANDLERS);
28 $event->send();
29 $resultList = $event->getResults();
30
31 if (is_array($resultList) && !empty($resultList))
32 {
33 foreach ($resultList as $eventResult)
34 {
36 if ($eventResult->getType() === Main\EventResult::SUCCESS)
37 {
38 $params = $eventResult->getParameters();
39 if (!empty($params) && is_array($params))
40 {
41 $handlerList = array_merge($handlerList, $params);
42 }
43 }
44 }
45 }
46
47 return $handlerList;
48 }
49
53 private static function getSystemHandlerList()
54 {
55 return [
56 '\Bitrix\Sale\Cashbox\FirstOfd' => FirstOfd::getName(),
57 '\Bitrix\Sale\Cashbox\PlatformaOfd' => PlatformaOfd::getName(),
58 '\Bitrix\Sale\Cashbox\YarusOfd' => YarusOfd::getName(),
59 '\Bitrix\Sale\Cashbox\TaxcomOfd' => TaxcomOfd::getName(),
60 '\Bitrix\Sale\Cashbox\OfdruOfd' => OfdruOfd::getName(),
61 '\Bitrix\Sale\Cashbox\TenzorOfd' => TenzorOfd::getName(),
62 '\Bitrix\Sale\Cashbox\ConturOfd' => ConturOfd::getName(),
63 ];
64 }
65
69 final public static function getCode(): string
70 {
71 $reflectionOfdClass = new \ReflectionClass(static::class);
72 $code = $reflectionOfdClass->getShortName();
73 $systemHandlers = array_keys(self::getSystemHandlerList());
74 if (in_array('\\' . static::class, $systemHandlers))
75 {
76 $code = self::BX_OFD_PREFIX . $code;
77 }
78 return mb_strtolower($code);
79 }
80
85 public static function create(Cashbox $cashbox)
86 {
87 $handler = $cashbox->getField('OFD');
88 if (class_exists($handler))
89 {
90 return new $handler($cashbox);
91 }
92
93 return null;
94 }
95
100 private function __construct(Cashbox $cashbox)
101 {
102 $this->cashbox = $cashbox;
103 }
104
108 protected function getUrl()
109 {
110 return '';
111 }
112
116 protected function getLinkParamsMap()
117 {
118 return array();
119 }
120
125 public function generateCheckLink($data)
126 {
127 $queryParams = array();
128
129 $map = $this->getLinkParamsMap();
130 foreach ($map as $queryKey => $checkKey)
131 {
132 if ($data[$checkKey])
133 $queryParams[] = $queryKey.'='.$data[$checkKey];
134 }
135
136 if (empty($queryParams))
137 return '';
138
139 $url = $this->getUrl();
140 return $url.implode('&', $queryParams);
141 }
142
147 public static function getName()
148 {
149 throw new NotImplementedException();
150 }
151
155 public static function getSettings()
156 {
157 return array(
158 'OFD_MODE' => array(
159 'LABEL' => Loc::getMessage('SALE_CASHBOX_OFD_SETTINGS'),
160 'ITEMS' => array(
161 'IS_TEST' => array(
162 'TYPE' => 'Y/N',
163 'LABEL' => Loc::getMessage('SALE_CASHBOX_OFD_TEST_MODE'),
164 'VALUE' => 'N'
165 )
166 )
167 )
168 );
169 }
170
175 public function validate()
176 {
177 return new Result();
178 }
179
185 public function getValueFromSettings($name, $code = null)
186 {
187 $map = $this->cashbox->getField('OFD_SETTINGS');
188 if (isset($map[$name]))
189 {
190 if (is_array($map[$name]))
191 {
192 if (isset($map[$name][$code]))
193 return $map[$name][$code];
194 }
195 else
196 {
197 return $map[$name];
198 }
199 }
200
201 return null;
202 }
203
207 protected function isTestMode()
208 {
209 return $this->getValueFromSettings('OFD_MODE', 'IS_TEST') === 'Y';
210 }
211}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static create(Cashbox $cashbox)
Definition ofd.php:85
const EVENT_ON_GET_CUSTOM_OFD_HANDLERS
Definition ofd.php:16
getValueFromSettings($name, $code=null)
Definition ofd.php:185
generateCheckLink($data)
Definition ofd.php:125
static getSettings()
Definition ofd.php:155