1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
MarketSubscription.php
См. документацию.
1<?php
2
3namespace Bitrix\Rest\Infrastructure\Market;
4
5use Bitrix\Main\Application;
6use Bitrix\Main\Type\Date;
7use Bitrix\Rest\Marketplace\Client;
8use Bitrix\Rest\Marketplace\Url;
9use Bitrix\Rest\Service\RestOption;
10use Bitrix\Rest\Service\ServiceContainer;
11
13{
14 private const BASE_CACHE_DIR = 'rest/market_subscription';
15
16 public function __construct(
17 private readonly MarketOption $marketOption
18 )
19 {}
20
21 public static function createByDefault(): self
22 {
23 return new self(new MarketOption(new RestOption()));
24 }
25
26 public function isRequiredSubscriptionModelStarted(): bool
27 {
28 if (!Client::isSubscriptionAccess())
29 {
30 return false;
31 }
32
33 if (Application::getInstance()->getLicense()->getRegion() !== 'ru')
34 {
35 return false;
36 }
37
38 if ($this->marketOption->isNewPoliticsEnabled())
39 {
40 return true;
41 }
42
44 {
45 $this->marketOption->enableNewPolitics();
46
47 return true;
48 }
49
50 return $this->isTransitionPeriodEnds();
51 }
52
53 public function isAvailableToPurchase(): bool
54 {
55 return Client::isSubscriptionAccess();
56 }
57
58 public function isActive(): bool
59 {
60 return Client::isSubscriptionAvailable();
61 }
62
63 public function isDemo(): bool
64 {
65 return Client::isSubscriptionDemo();
66 }
67
68 public function isDemoAvailable(): bool
69 {
70 return Client::isSubscriptionDemoAvailable();
71 }
72
73 public function getEndDate(): ?Date
74 {
75 return Client::getSubscriptionFinalDate();
76 }
77
78 public function getDiscount(): MarketDiscount
79 {
80 return new MarketDiscount(
81 isAvailable: $this->marketOption->isDiscountAvailable(),
82 percentage: $this->marketOption->getDiscountPercentage(),
83 termsUrl: $this->marketOption->getDiscountTermsUrl(),
84 );
85 }
86
87 public function isPaidAppsOrIntegrationsInstalled(): bool
88 {
89 $cache = Application::getInstance()->getCache();
90
91 if (
92 $cache->initCache(
93 86400,
94 'has_subscription_app_or_integration',
95 self::BASE_CACHE_DIR,
96 )
97 )
98 {
99 return $cache->getVars();
100 }
101
102 $hasSubscriptionIntegrations =
103 ServiceContainer::getInstance()->getIntegrationService()->hasPaidIntegrations()
104 || ServiceContainer::getInstance()->getAppService()->hasPaidApps()
105 ;
106 $cache->startDataCache();
107 $cache->endDataCache($hasSubscriptionIntegrations);
108
109 return $hasSubscriptionIntegrations;
110 }
111
112 public function getBuyUrl(): string
113 {
115 }
116
118 {
119 return $this->marketOption->getSavedTransitionPeriodEndDate();
120 }
121
122 public function isTransitionPeriodEnds(): bool
123 {
124 return $this->isTransitionPeriodEnabled()
125 && $this->getTransitionPeriodEndDate()->getTimestamp() < time();
126 }
127
128 public function isTransitionPeriodEnabled(): bool
129 {
130 return $this->marketOption->isTransitionPeriodEnabled();
131 }
132}
Определения date.php:9
__construct(private readonly MarketOption $marketOption)
Определения MarketSubscription.php:16
static getSubscriptionBuyUrl()
Определения url.php:562