Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
registeryookassawebhookaction.php
1<?php
2
4
7use Bitrix\Seo;
8
16{
17 public function run()
18 {
19 if (!Main\Loader::includeModule('seo'))
20 {
21 $this->addError(new Main\Error('Module seo not installed'));
22 return;
23 }
24
25 $authAdapter = Seo\Checkout\Service::getAuthAdapter(Seo\Checkout\Service::TYPE_YOOKASSA);
26 $hasAuth = $authAdapter->hasAuth();
27 if ($hasAuth)
28 {
29 Main\Config\Option::set('sale', 'YANDEX_CHECKOUT_OAUTH', true);
30
31 $oauthService = Seo\Checkout\Services\Factory::createService($authAdapter->getType());
32 $this->registerWebhooks($oauthService);
33 }
34 else
35 {
36 $this->addError(new Main\Error('Yokassa is not authorized'));
37 }
38 }
39
40 private function registerWebhooks(Seo\Checkout\Services\AccountYookassa $oauthService): void
41 {
42 $registerPaymentSucceededResult = $oauthService->registerPaymentSucceededWebhook();
43 $registerPaymentCanceledWebhookResult = $oauthService->registerPaymentCanceledWebhook();
44 if ($registerPaymentSucceededResult->isSuccess() && $registerPaymentCanceledWebhookResult->isSuccess())
45 {
46 Main\Config\Option::set('sale', 'YANDEX_CHECKOUT_OAUTH_WEBHOOK_REGISTER', true);
47 }
48
49 if (!$registerPaymentSucceededResult->isSuccess())
50 {
51 $this->addErrors($registerPaymentSucceededResult->getErrors());
52 }
53 if (!$registerPaymentCanceledWebhookResult->isSuccess())
54 {
55 $this->addErrors(($registerPaymentCanceledWebhookResult->getErrors()));
56 }
57 }
58}
addError(Error $error)
Definition action.php:200
addErrors(array $errors)
Definition action.php:213