3namespace Bitrix\Seo\LeadAds\Services;
5use Bitrix\Main\ArgumentNullException;
6use Bitrix\Main\Context;
9use Bitrix\Main\Security\Random;
10use Bitrix\Main\SystemException;
11use Bitrix\Main\Text\Encoding;
12use Bitrix\Main\Web\Json;
13use Bitrix\Seo\LeadAds;
14use Bitrix\Seo\Retargeting;
15use Bitrix\Seo\Retargeting\Response;
16use Bitrix\Seo\Service;
17use Bitrix\Seo\WebHook;
18use Bitrix\Seo\LeadAds\Response\FormResponse;
19use Bitrix\Seo\LeadAds\Response\Builder\VkontakteFormBuilder;
35 public const URL_FORM_LIST =
'https://www.facebook.com/ads/manager/audiences/manage/';
63 $row = LeadAds\Internals\CallbackSubscriptionTable::getRow([
65 '=TYPE' => static::TYPE_CODE,
70 'URL_PARAMETERS' => [
'group_ids' => $row[
'GROUP_ID']]
82 $mapper = static::getFieldMapper();
83 $adsName = $mapper->getAdsName($field->getName());
93 'type' => $field->getType(),
94 'key' => $field->getKey(),
95 'label' => $field->getLabel(),
98 if (!empty($field->getOptions()))
100 $item[
'options'] = array_map(
105 $key = static::$fieldKeyPrefix .
$key;
140 'methodName'=>
'leadads.form.get',
143 'group_id'=> (
int) $this->accountId,
160 public function unlink(
string $id) : bool
170 if ($confirmationCodeResponse instanceof
Error)
173 $confirmationCodeResponse
182 'SECURITY_CODE' => $secretKey = Random::getString(32),
183 'CONFIRMATION_CODE' => $confirmationCodeResponse,
189 $response->addError(
new Error(
'Can not register Form web hook.'));
195 if ($callbackServiceResponse instanceof
Error)
197 $response->addError($callbackServiceResponse);
211 $row = LeadAds\Internals\CallbackSubscriptionTable::getRow(
213 'select' => [
'ID',
'CALLBACK_SERVER_ID'],
215 '=TYPE' => static::TYPE_CODE,
216 '=GROUP_ID' => $this->accountId
223 return new Error(
"Group is not registred.");
226 if (!empty($row[
'CALLBACK_SERVER_ID']))
228 return $row[
'CALLBACK_SERVER_ID'];
231 $responseSetCallbackSettings = $this->
getRequest()->send([
232 'methodName' =>
'leadads.callback.server.settings.set',
234 'group_id' => $this->accountId,
235 'lead_forms_new' => 1,
239 if (!$responseSetCallbackSettings->isSuccess() || 1 !== current($responseSetCallbackSettings->getData()))
241 return new Error(
'Can not set Callback server settings.');
249 $row = LeadAds\Internals\CallbackSubscriptionTable::getRow([
251 '=TYPE' => static::TYPE_CODE,
252 '=GROUP_ID' => $groupId
256 if ($row && !empty($row[
'CALLBACK_SERVER_ID']))
259 'methodName' =>
'leadads.callback.server.delete',
261 'group_id' => $groupId,
262 'server_id' => $row[
'CALLBACK_SERVER_ID'],
275 'methodName' =>
'leadads.callback.server.code.get',
277 'group_id' => $this->accountId,
283 return new Error(
'Can not get confirmation code for Callback server.');
288 return empty($responseData[
'code'])
289 ?
new Error(
'Can not get confirmation code for Callback server.')
290 : $responseData[
'code']
302 $limit = self::LIMIT_DEFAULT;
309 'methodName' =>
'leadads.form.list',
315 $items = array_filter(
$response->getData(), fn ($item) => ((
int)$item[
'status'] === self::STATUS_FORM_ACTIVE));
324 if ($limit < self::LIMIT_MAX)
326 $limit = self::LIMIT_MAX;
332 return new FormResponse(
333 new VkontakteFormBuilder($this::getFieldMapper()),
348 $result->setId($item->getLeadId());
349 foreach ($item->getAnswers() as
$key => $values)
351 foreach ($values as $index => $value)
353 if (mb_strpos($value, static::$fieldKeyPrefix) !== 0)
358 $values[$index] = mb_substr($value, mb_strlen(static::$fieldKeyPrefix));
378 return parent::unRegisterGroup($groupId);
391 ->addError(
new Error(
'VK lead ads form register: Empty formId.'))
394 if (!isset($this->accountId))
397 ->addError(
new Error(
'VK lead ads form register: Empty accountId.'))
405 ->addError(
new Error(
'VK lead ads form register: Empty formId.'))
414 if (!isset(
$formId) || !isset($this->accountId))
417 ->addError(
new Error(
'Can not load leads'));
420 $limit = self::LIMIT_DEFAULT;
431 ->addError(
new Error(
'Can not load leads'));
435 if (
count($leads) === $limit)
437 $limit = self::LIMIT_MAX;
442 'offset' =>
count($leads),
450 $leads = array_merge($leads,
$response->getData());
459 return (
new Result())->setData($leads);
465 'methodName' =>
'leadads.form.leads.load',
467 'form_id' => $formId,
const TYPE_LOCATION_COUNTRY
const TYPE_PATRONYMIC_NAME
const TYPE_LOCATION_STREET_ADDRESS
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']