Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
responsefacebook.php
1<?php
2
4
5use \Bitrix\Main\Error;
6use \Bitrix\Main\Localization\Loc;
7use \Bitrix\Main\Web\Json;
9use \Bitrix\Seo\Retargeting\Response;
10
11Loc::loadMessages(__FILE__);
12
14{
15 public const TYPE_CODE = 'facebook';
16
18 protected $pagingData;
19
26 public function parse($data) : void
27 {
28 $parsed = is_array($data) ? $data : Json::decode($data);
29
30 if ($parsed['error'])
31 {
32 $errorText = (isset($parsed['error']['error_user_msg']) && $parsed['error']['error_user_msg'])
33 ? $parsed['error']['error_user_msg']
34 : $parsed['error']['message']
35 ;
36
37 if ($errorText === '(#100) The parameter follow_up_action_url is required')
38 {
39 $errorText = Loc::getMessage('SEO_RETARGETING_SERVICE_RESPONSE_FACEBOOK_ERROR_URL_REQUIRED');
40 }
41 if ($errorText === 'To create or edit a Custom Audience made from a customer list, your admin needs to add this ad account to a business.')
42 {
43 $errorText = Loc::getMessage('SEO_RETARGETING_SERVICE_RESPONSE_FACEBOOK_ERROR_ADD_TO_BUSINESS');
44 }
45
46 $this->addError(
47 new Error(
48 Loc::getMessage('SEO_RETARGETING_SERVICE_RESPONSE_FACEBOOK_ERROR') . ': ' . $errorText,
49 $parsed['error']['code']
50 )
51 );
52 }
53
54 if ($parsed['data'])
55 {
56 $this->setData($parsed['data']);
57 }
58 elseif (!isset($parsed['error']))
59 {
60 $this->setData($parsed);
61 }
62
63 if (isset($parsed['paging']))
64 {
65 $this->pagingData = $parsed['paging'];
66 }
67 }
68
75 public function prepareRequestParams(array $params) : ?array
76 {
77 if (isset($this->pagingData['next'], $this->pagingData['cursors']['after']))
78 {
79 $params['parameters']['params']['after'] = $this->pagingData['cursors']['after'];
80
81 return $params;
82 }
83
84 return null;
85 }
86}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29