Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
accountyandex.php
1<?php
2
4
10
11Loc::loadMessages(__FILE__);
12
19{
20 const TYPE_CODE = 'yandex';
21
23 private $callbackEventUrl = null;
24
30 public static function getService()
31 {
32 return Service::getInstance();
33 }
34
38 public function setCallbackEventUrl(Web\Uri $callbackEventUrl)
39 {
40 $this->callbackEventUrl = $callbackEventUrl;
41 }
42
47 private function getCallbackEventUrl()
48 {
49 if (!$this->callbackEventUrl)
50 {
51 $request = \Bitrix\Main\Application::getInstance()->getContext()->getRequest();
52 $host = $request->isHttps() ? 'https' : 'http';
53
54 $this->callbackEventUrl = new Web\Uri($host.'://'.$request->getHttpHost().'/bitrix/tools/sale_ps_result.php');
55 }
56
57 return $this->callbackEventUrl;
58 }
59
64 private function isHttps(Web\Uri $url)
65 {
66 return ($url->getScheme() === 'https' ? true : false);
67 }
68
73 public function getProfile()
74 {
75 $response = $this->getRequest()->send([
76 'methodName' => 'profile.info',
77 'parameters' => []
78 ]);
79
80 $response = $response->getData();
81 if (\is_array($response))
82 {
83 return [
84 'ID' => $response['id'],
85 'NAME' => $response['login'],
86 'LINK' => '',
87 'PICTURE' => '',
88 ];
89 }
90
91 return null;
92 }
93
100 public static function removeAuth()
101 {
102 static::getService()->getAuthAdapter(self::TYPE_CODE)->removeAuth();
103 }
104
110 {
111 $callbackUrl = $this->getCallbackEventUrl();
112 if (!$this->isHttps($callbackUrl))
113 {
114 $response = Response::create(self::TYPE_CODE);
115 $response->addError(new \Bitrix\Main\Error(Loc::getMessage('SEO_CHECKOUT_SERVICE_ACCOUNT_YANDEX_ERROR_SCHEME_CALLBACK_URL')));
116 return $response;
117 }
118
119 $response = $this->getRequest()->send([
120 'methodName' => 'webhook.register',
121 'parameters' => [
122 'EVENT' => 'payment.succeeded',
123 'URL' => $callbackUrl->getUri(),
124 ]
125 ]);
126
127 return $response;
128 }
129
135 {
136 $callbackUrl = $this->getCallbackEventUrl();
137 if (!$this->isHttps($callbackUrl))
138 {
139 $response = Response::create(self::TYPE_CODE);
140 $response->addError(new \Bitrix\Main\Error(Loc::getMessage('SEO_CHECKOUT_SERVICE_ACCOUNT_YANDEX_ERROR_SCHEME_CALLBACK_URL')));
141 return $response;
142 }
143
144 $response = $this->getRequest()->send([
145 'methodName' => 'webhook.register',
146 'parameters' => [
147 'EVENT' => 'payment.canceled',
148 'URL' => $callbackUrl->getUri(),
149 ]
150 ]);
151
152 return $response;
153 }
154
160 {
161 $callbackUrl = $this->getCallbackEventUrl();
162 if (!$this->isHttps($callbackUrl))
163 {
164 $response = Response::create(self::TYPE_CODE);
165 $response->addError(new \Bitrix\Main\Error(Loc::getMessage('SEO_CHECKOUT_SERVICE_ACCOUNT_YANDEX_ERROR_SCHEME_CALLBACK_URL')));
166 return $response;
167 }
168
169 $response = $this->getRequest()->send([
170 'methodName' => 'webhook.register',
171 'parameters' => [
172 'EVENT' => 'refund.succeeded',
173 'URL' => $callbackUrl->getUri(),
174 ]
175 ]);
176
177 return $response;
178 }
179
184 public function removeWebhook($id)
185 {
186 $response = $this->getRequest()->send([
187 'methodName' => 'webhook.remove',
188 'parameters' => [
189 'ID' => $id,
190 ]
191 ]);
192
193 return $response;
194 }
195
200 public function getWebhookList()
201 {
202 $response = $this->getRequest()->send([
203 'methodName' => 'webhook.list',
204 'parameters' => []
205 ]);
206
207 return $response;
208 }
209
214 public function getShopInfo()
215 {
216 $response = $this->getRequest()->send([
217 'methodName' => 'shop.info',
218 'parameters' => []
219 ]);
220
221 return $response;
222 }
223}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
setCallbackEventUrl(Web\Uri $callbackEventUrl)