Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
accountyandex.php
1
<?php
2
3
namespace
Bitrix\Seo\Checkout\Services
;
4
5
use
Bitrix\Main\Web
;
6
use
Bitrix\Main\Localization\Loc
;
7
use
Bitrix\Seo\Checkout\BaseApiObject
;
8
use
Bitrix\Seo\Checkout\Response
;
9
use
Bitrix\Seo\Checkout\Service
;
10
11
Loc::loadMessages
(__FILE__);
12
18
class
AccountYandex
extends
BaseApiObject
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
109
public
function
registerPaymentSucceededWebhook
()
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
134
public
function
registerPaymentCanceledWebhook
()
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
159
public
function
registerRefundSucceededWebhook
()
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
}
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Web\Uri
Definition
uri.php:17
Bitrix\Seo\Checkout\BaseApiObject
Definition
baseapiobject.php:10
Bitrix\Seo\Checkout\BaseApiObject\$request
$request
Definition
baseapiobject.php:14
Bitrix\Seo\Checkout\BaseApiObject\getRequest
getRequest()
Definition
baseapiobject.php:30
Bitrix\Seo\Checkout\Response
Definition
response.php:12
Bitrix\Seo\Checkout\Response\create
static create($type)
Definition
response.php:77
Bitrix\Seo\Checkout\Service
Definition
service.php:10
Bitrix\Seo\Checkout\Service\getInstance
static getInstance()
Definition
service.php:20
Bitrix\Seo\Checkout\Services\AccountYandex
Definition
accountyandex.php:19
Bitrix\Seo\Checkout\Services\AccountYandex\TYPE_CODE
const TYPE_CODE
Definition
accountyandex.php:20
Bitrix\Seo\Checkout\Services\AccountYandex\removeWebhook
removeWebhook($id)
Definition
accountyandex.php:184
Bitrix\Seo\Checkout\Services\AccountYandex\getService
static getService()
Definition
accountyandex.php:30
Bitrix\Seo\Checkout\Services\AccountYandex\registerPaymentCanceledWebhook
registerPaymentCanceledWebhook()
Definition
accountyandex.php:134
Bitrix\Seo\Checkout\Services\AccountYandex\removeAuth
static removeAuth()
Definition
accountyandex.php:100
Bitrix\Seo\Checkout\Services\AccountYandex\registerPaymentSucceededWebhook
registerPaymentSucceededWebhook()
Definition
accountyandex.php:109
Bitrix\Seo\Checkout\Services\AccountYandex\getWebhookList
getWebhookList()
Definition
accountyandex.php:200
Bitrix\Seo\Checkout\Services\AccountYandex\getShopInfo
getShopInfo()
Definition
accountyandex.php:214
Bitrix\Seo\Checkout\Services\AccountYandex\getProfile
getProfile()
Definition
accountyandex.php:73
Bitrix\Seo\Checkout\Services\AccountYandex\registerRefundSucceededWebhook
registerRefundSucceededWebhook()
Definition
accountyandex.php:159
Bitrix\Seo\Checkout\Services\AccountYandex\setCallbackEventUrl
setCallbackEventUrl(Web\Uri $callbackEventUrl)
Definition
accountyandex.php:38
Bitrix\Main\Web
Definition
cookie.php:3
Bitrix\Seo\Checkout\Services
Definition
accountyandex.php:3
Bitrix
modules
seo
lib
checkout
services
accountyandex.php
Создано системой
1.10.0