Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
accountyookassa.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
17
class
AccountYookassa
extends
BaseApiObject
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
106
public
function
registerPaymentSucceededWebhook
()
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
131
public
function
registerPaymentCanceledWebhook
()
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
156
public
function
registerRefundSucceededWebhook
()
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
}
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\AccountYookassa
Definition
accountyookassa.php:18
Bitrix\Seo\Checkout\Services\AccountYookassa\TYPE_CODE
const TYPE_CODE
Definition
accountyookassa.php:19
Bitrix\Seo\Checkout\Services\AccountYookassa\removeWebhook
removeWebhook($id)
Definition
accountyookassa.php:181
Bitrix\Seo\Checkout\Services\AccountYookassa\getService
static getService()
Definition
accountyookassa.php:29
Bitrix\Seo\Checkout\Services\AccountYookassa\registerPaymentCanceledWebhook
registerPaymentCanceledWebhook()
Definition
accountyookassa.php:131
Bitrix\Seo\Checkout\Services\AccountYookassa\removeAuth
static removeAuth()
Definition
accountyookassa.php:97
Bitrix\Seo\Checkout\Services\AccountYookassa\registerPaymentSucceededWebhook
registerPaymentSucceededWebhook()
Definition
accountyookassa.php:106
Bitrix\Seo\Checkout\Services\AccountYookassa\getWebhookList
getWebhookList()
Definition
accountyookassa.php:197
Bitrix\Seo\Checkout\Services\AccountYookassa\getShopInfo
getShopInfo()
Definition
accountyookassa.php:211
Bitrix\Seo\Checkout\Services\AccountYookassa\getProfile
getProfile()
Definition
accountyookassa.php:72
Bitrix\Seo\Checkout\Services\AccountYookassa\registerRefundSucceededWebhook
registerRefundSucceededWebhook()
Definition
accountyookassa.php:156
Bitrix\Seo\Checkout\Services\AccountYookassa\setCallbackEventUrl
setCallbackEventUrl(Web\Uri $callbackEventUrl)
Definition
accountyookassa.php:37
Bitrix\Main\Web
Definition
cookie.php:3
Bitrix\Seo\Checkout\Services
Definition
accountyandex.php:3
Bitrix
modules
seo
lib
checkout
services
accountyookassa.php
Создано системой
1.10.0