66
77namespace BitCode \FI \Actions \Sendy ;
88
9- use WP_Error ;
10- use BitCode \FI \Log \LogHandler ;
119use BitCode \FI \Core \Util \HttpHelper ;
10+ use BitCode \FI \Log \LogHandler ;
11+ use WP_Error ;
1212
1313/**
1414 * Provide functionality for MailChimp integration
1515 */
1616class SendyController
1717{
18- private $ _integrationID ;
19-
20- // public function __construct($integrationID)
21- // {
22- // $this->_integrationID = $integrationID;
23- // }
24-
2518 /**
2619 * Process ajax request for generate_token
2720 *
@@ -31,7 +24,7 @@ class SendyController
3124 */
3225 public static function sendyAuthorize ($ requestsParams )
3326 {
34- if (empty ($ requestsParams ->api_key )) {
27+ if (empty ($ requestsParams ->api_key ) || empty ( $ requestsParams -> sendy_url ) ) {
3528 wp_send_json_error (
3629 __ (
3730 'Requested parameter is empty ' ,
@@ -40,16 +33,16 @@ public static function sendyAuthorize($requestsParams)
4033 400
4134 );
4235 }
43- $ apiKey = $ requestsParams ->api_key ;
44- $ sendy_url = $ requestsParams ->sendy_url ;
45- $ apiEndpoint = "{$ sendy_url }/includes/helpers/integrations/zapier/triggers/dropdowns.php?api_key= {$ apiKey }&event=brands " ;
46- $ authorizationHeader ['Accept ' ] = 'application/json ' ;
47- // $authorizationHeader["api-key"] = $requestsParams->api_key;
48- $ apiResponse = HttpHelper::get ($ apiEndpoint , null , $ authorizationHeader );
4936
50- if (is_wp_error ($ apiResponse ) || !\is_array ($ apiResponse )) {
37+ $ apiEndpoint = "{$ requestsParams ->sendy_url }/api/brands/get-brands.php " ;
38+ $ authorizationHeader = ['Accept ' => 'application/json ' ];
39+ $ requestsParams = ['api_key ' => $ requestsParams ->api_key ];
40+
41+ $ apiResponse = HttpHelper::post ($ apiEndpoint , $ requestsParams , $ authorizationHeader );
42+
43+ if (HttpHelper::$ responseCode !== 200 && (is_wp_error ($ apiResponse ) || !\is_array ($ apiResponse ))) {
5144 wp_send_json_error (
52- empty ($ apiResponse ->code ) ? ' Unknown ' : $ apiResponse ->message ,
45+ empty ($ apiResponse ->message ) ? $ apiResponse : $ apiResponse ->message ,
5346 400
5447 );
5548 }
0 commit comments