Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
checkoutwebhookregistrationagent.php
1<?php
2
3namespace Bitrix\Sale\Update;
4
6use Bitrix\Seo;
7
9{
10 public static function exec()
11 {
12 if (!Main\Loader::includeModule('seo'))
13 {
14 return;
15 }
16
17 if (self::isYandexOauth())
18 {
19 self::registerWebhook(Seo\Checkout\Service::TYPE_YANDEX);
20 }
21 elseif (self::isYookassaOauth())
22 {
23 self::registerWebhook(Seo\Checkout\Service::TYPE_YOOKASSA);
24 }
25 }
26
27 private static function isYandexOauth(): bool
28 {
29 $authAdapter = Seo\Checkout\Service::getAuthAdapter(Seo\Checkout\Service::TYPE_YANDEX);
30 return $authAdapter->hasAuth();
31 }
32
33 private static function isYookassaOauth(): bool
34 {
35 $authAdapter = Seo\Checkout\Service::getAuthAdapter(Seo\Checkout\Service::TYPE_YOOKASSA);
36 return $authAdapter->hasAuth();
37 }
38
39 private static function registerWebhook(string $type): void
40 {
41 $authAdapter = Seo\Checkout\Service::getAuthAdapter($type);
42 $oauthService = Seo\Checkout\Services\Factory::createService($authAdapter->getType());
43
44 $registerPaymentSucceededResult = $oauthService->registerPaymentSucceededWebhook();
45 $registerPaymentCanceledWebhookResult = $oauthService->registerPaymentCanceledWebhook();
46 if ($registerPaymentSucceededResult->isSuccess() && $registerPaymentCanceledWebhookResult->isSuccess())
47 {
48 Main\Config\Option::set('sale', 'YANDEX_CHECKOUT_OAUTH_WEBHOOK_REGISTER', true);
49 }
50 }
51}