Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
yarusofd.php
1<?php
2
3namespace Bitrix\Sale\Cashbox;
4
7
8Localization\Loc::loadMessages(__FILE__);
9
14class YarusOfd extends Ofd
15{
16 const HEADER_TOKEN_NAME = 'Ofdapitoken';
17
18 const ACTIVE_URL = 'https://api.ofd-ya.ru/ofdapi/v1/getChequeLink';
19 const TEST_URL = 'https://testapi.ofd-ya.ru/ofdapi/v1/getChequeLink';
20
24 protected function getUrl()
25 {
26 if ($this->getValueFromSettings('OFD_MODE', 'IS_TEST') === 'Y')
27 {
28 return static::TEST_URL;
29 }
30
31 return static::ACTIVE_URL;
32 }
33
37 protected function getLinkParamsMap()
38 {
39 return array(
40 'fiscalDocumentNumber' => Check::PARAM_FISCAL_DOC_NUMBER,
41 'fiscalDriveNumber' => Check::PARAM_FN_NUMBER
42 );
43 }
44
48 public static function getName()
49 {
50 return Localization\Loc::getMessage('SALE_CASHBOX_YARUS_OFD_NAME');
51 }
52
58 public function generateCheckLink($data)
59 {
60 $queryString = $this->getQueryString($data);
61 $result = $this->sendQuery($queryString);
62
63 if (isset($result[0]['link']))
64 {
65 return $result[0]['link'];
66 }
67
68 return '';
69 }
70
76 private function getQueryString($data)
77 {
78 $queryData = array();
79 $paramsMap = $this->getLinkParamsMap();
80 foreach ($paramsMap as $param => $key)
81 {
82 $queryData[$param] = $data[$key];
83 }
84
85 return Main\Web\Json::encode($queryData);
86 }
87
92 private function sendQuery($queryString)
93 {
94 $authKey = $this->getValueFromSettings('AUTH', 'INN');
95 if (!$authKey)
96 {
97 return '';
98 }
99
100 $client = new Main\Web\HttpClient();
101 $client->setHeader(static::HEADER_TOKEN_NAME, $authKey);
102
103 $client->query('POST', $this->getUrl(), $queryString);
104 $result = $client->getResult();
105 try
106 {
107 $result = Main\Web\Json::decode($result);
108 }
109 catch (Main\ArgumentException $exception)
110 {
111 return false;
112 }
113
114 return $result;
115 }
116
120 public static function getSettings()
121 {
122 $settings = parent::getSettings();
123
124 $settings['AUTH'] = array(
125 'LABEL' => Localization\Loc::getMessage('SALE_CASHBOX_YARUS_SETTINGS_AUTH'),
126 'ITEMS' => array(
127 'INN' => array(
128 'TYPE' => 'STRING',
129 'LABEL' => Localization\Loc::getMessage('SALE_CASHBOX_YARUS_AUTH_KEY'),
130 'VALUE' => ''
131 )
132 )
133 );
134
135 return $settings;
136 }
137
138}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
getValueFromSettings($name, $code=null)
Definition ofd.php:185