16use PhpParser\Node\Expr\Isset_;
25 public const TYPE_CODE = LeadAds\Service::TYPE_VKONTAKTE;
31 public const URL_INFO =
'https://vk.com/page-19542789_53868676';
48 while ($row = $list->fetch())
50 if ($row[
'ID'] === $id)
68 'methodName' =>
'leadads.groups.list',
69 'parameters' => array(
70 'fields' =>
'id,name',
75 $items = $response->getData();
76 $items = (!empty($items[
'items']) && is_array($items[
'items'])) ? $items[
'items'] : [];
78 $response->setData($items);
91 'methodName' =>
'leadads.profile',
95 if ($response->isSuccess() && $data = $response->fetch())
99 'NAME' => $data[
'FIRST_NAME'] .
' ' . $data[
'LAST_NAME'],
102 $result[
'LINK'] =
'https://ads.vk.com/hq/leadforms/';
105 .
Context::getCurrent()->getServer()->getHttpHost() .
'/bitrix/images/seo/integration/vklogo.svg';
116 if (!$response->isSuccess())
120 $data = $response->getData();
121 if (isset($data[
'hasAuthInfo']) && isset($data[
'hasProfile']))
123 if (!$data[
'hasAuthInfo'])
128 return $data[
'hasProfile'];
137 if ($response->isSuccess())
139 $data = $response->getData();
140 if (isset($data[
'id']) && isset($data[
'type']))
142 $this->
unregisterCode((
int)$response->getData()[
'id'], $response->getData()[
'type']);
145 if (isset($data[
'form_ids']) && is_array($data[
'form_ids']))
147 return (
new Result())->setData([
'formIds' => $data[
'form_ids']]);
157 if ($response->isSuccess())
159 return $this->registerCode((
int)$response->getData()[
'id'], self::RESOURCE_LEAD);
162 return (
new Result())->addError(
new Error(
'Failed to perform all actions after authorization'));
173 $webhookQueryParams = http_build_query(
176 'action' =>
'web_hook',
181 'methodName' =>
'leadads.subscribe.lead.add',
183 'resource' => $resource,
184 'callback_url' =>
"{$remoteServiceUrl}/register/?{$webhookQueryParams}",
189 private function registerCode(
int $confirmCode,
string $resource)
195 'SECURITY_CODE' => Random::getString(32),
196 'CONFIRMATION_CODE' => $resource,
202 $response->addError(
new Error(
'Can not register web hook.'));
212 return WebHook\Service::create(
215 )->register($parameters);
221 'methodName' =>
'leadads.unsubscribe.lead.add',
231 WebHook\Internals\WebHookTable::delete($webHook[
'ID']);
239 return WebHook\Internals\WebHookTable::getRow([
241 'EXTERNAL_ID' => $externalId,
250 'methodName' =>
'leadads.account.check.auth',
static getEngineCode($type)
unregisterCode(int $externalId, string $type)
unsubscribeToLeadAdding()
subcribeToLeadAdding(string $resource)
getWebHookByExternalId($externalId, $type)
registerWebHook($confirmCode, array $parameters=[])