Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
accountyookassa.php
1<?php
2
4
10
11Loc::loadMessages(__FILE__);
12
18{
19 const TYPE_CODE = 'yookassa';
20
22 private $callbackEventUrl = null;
23
29 public static function getService()
30 {
31 return Service::getInstance();
32 }
33
37 public function setCallbackEventUrl(Web\Uri $callbackEventUrl)
38 {
39 $this->callbackEventUrl = $callbackEventUrl;
40 }
41
46 private function getCallbackEventUrl()
47 {
48 if (!$this->callbackEventUrl)
49 {
50 $request = \Bitrix\Main\Application::getInstance()->getContext()->getRequest();
51 $host = $request->isHttps() ? 'https' : 'http';
52
53 $this->callbackEventUrl = new Web\Uri($host.'://'.$request->getHttpHost().'/bitrix/tools/sale_ps_result.php');
54 }
55
56 return $this->callbackEventUrl;
57 }
58
63 private function isHttps(Web\Uri $url)
64 {
65 return ($url->getScheme() === 'https' ? true : false);
66 }
67
72 public function getProfile()
73 {
74 $response = $this->getRequest()->send([
75 'methodName' => 'profile.info',
76 'parameters' => []
77 ]);
78
79 $response = $response->getData();
80 if (\is_array($response) && isset($response['account_id']))
81 {
82 return [
83 'ID' => $response['account_id'],
84 'NAME' => $response['account_id'],
85 ];
86 }
87
88 return null;
89 }
90
97 public static function removeAuth()
98 {
99 static::getService()->getAuthAdapter(self::TYPE_CODE)->removeAuth();
100 }
101
107 {
108 $callbackUrl = $this->getCallbackEventUrl();
109 if (!$this->isHttps($callbackUrl))
110 {
111 $response = Response::create(self::TYPE_CODE);
112 $response->addError(new \Bitrix\Main\Error(Loc::getMessage('SEO_CHECKOUT_SERVICE_ACCOUNT_YOOKASSA_ERROR_SCHEME_CALLBACK_URL')));
113 return $response;
114 }
115
116 $response = $this->getRequest()->send([
117 'methodName' => 'webhook.register',
118 'parameters' => [
119 'EVENT' => 'payment.succeeded',
120 'URL' => $callbackUrl->getUri(),
121 ]
122 ]);
123
124 return $response;
125 }
126
132 {
133 $callbackUrl = $this->getCallbackEventUrl();
134 if (!$this->isHttps($callbackUrl))
135 {
136 $response = Response::create(self::TYPE_CODE);
137 $response->addError(new \Bitrix\Main\Error(Loc::getMessage('SEO_CHECKOUT_SERVICE_ACCOUNT_YOOKASSA_ERROR_SCHEME_CALLBACK_URL')));
138 return $response;
139 }
140
141 $response = $this->getRequest()->send([
142 'methodName' => 'webhook.register',
143 'parameters' => [
144 'EVENT' => 'payment.canceled',
145 'URL' => $callbackUrl->getUri(),
146 ]
147 ]);
148
149 return $response;
150 }
151
157 {
158 $callbackUrl = $this->getCallbackEventUrl();
159 if (!$this->isHttps($callbackUrl))
160 {
161 $response = Response::create(self::TYPE_CODE);
162 $response->addError(new \Bitrix\Main\Error(Loc::getMessage('SEO_CHECKOUT_SERVICE_ACCOUNT_YOOKASSA_ERROR_SCHEME_CALLBACK_URL')));
163 return $response;
164 }
165
166 $response = $this->getRequest()->send([
167 'methodName' => 'webhook.register',
168 'parameters' => [
169 'EVENT' => 'refund.succeeded',
170 'URL' => $callbackUrl->getUri(),
171 ]
172 ]);
173
174 return $response;
175 }
176
181 public function removeWebhook($id)
182 {
183 $response = $this->getRequest()->send([
184 'methodName' => 'webhook.remove',
185 'parameters' => [
186 'ID' => $id,
187 ]
188 ]);
189
190 return $response;
191 }
192
197 public function getWebhookList()
198 {
199 $response = $this->getRequest()->send([
200 'methodName' => 'webhook.list',
201 'parameters' => []
202 ]);
203
204 return $response;
205 }
206
211 public function getShopInfo()
212 {
213 $response = $this->getRequest()->send([
214 'methodName' => 'shop.info',
215 'parameters' => []
216 ]);
217
218 return $response;
219 }
220}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29