Plugin Directory

Changeset 2530005


Ignore:
Timestamp:
05/11/2021 08:23:35 PM (5 years ago)
Author:
Oyova
Message:
  • New - Added support for updateLeads method. This addition will update a lead's information if the lead already exists.
  • Fixed - PHP notices that appeared when the Account ID was incorrect.
Location:
integrate-sharpspring-and-gravity-forms/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • integrate-sharpspring-and-gravity-forms/trunk/class-integrate-sharpspring-and-gravity-forms.php

    r2522883 r2530005  
    225225     * Initialize API.
    226226     */
    227     public function initialize_api( ) {
     227    public function initialize_api() {
    228228        // Send a request to verify credentials.
    229229        $params     = array( 'where' => array(), 'limit' => 0, 'offset' => 0 ); 
    230230        $results    = $this->sharpspring_post( $params, 'getActiveLists' );
    231         $results    = json_decode($results['body'], true);
    232 
    233         // If the account id or both the id and secret are incorrect the api will only return a string.
    234         // This will check if the secret key is valid if the account id is correct.
    235         $error_code = '';
    236         if( $results != 'Invalid Api Key' ) {
    237             $error_code = $results['error']['code'];
    238         }
    239         return $error_code || $results == 'Invalid Api Key' ? false : true;
     231       
     232        // Check to make sure the secret key is valid
     233        $secret_results = json_decode($results['body'], true);
     234
     235        // 104 = Header missing Secret Key
     236        // 105 = User authentication failed
     237        $error_code = isset($secret_results['error']) ? $secret_results['error']['code'] : '';
     238        $error_msg  = isset($secret_results['error']) ? $secret_results['error']['message'] : '';
     239
     240        // If the secret key response returns either a 104 or 105 return false
     241        if ( $error_code === 104 || $error_code === 105 ) {
     242            return false;
     243        }
     244
     245        // Check to make sure the Account ID is valid
     246        $id_results = $results['response'];
     247
     248        // If the response returns unathorized return false
     249        if( $id_results['code'] === 401 ) {
     250            return false;
     251        }
     252
     253        // If the Account ID & Secret Key are valid return true
     254        return true;
    240255    }
    241256
     
    382397            return false;
    383398        }
    384 
    385399       
    386400        // Retrieve the name => value pairs for all fields mapped in the 'mappedFields' field map.
     
    422436            $lead_results   = json_decode($lead_results['body'], true);
    423437            $lead_id        = $lead_results['result']['lead'][0]['id'];
     438
     439            // If lead already exists, update the lead's information
     440            $lead_updated   = $this->sharpspring_post( $params, 'updateLeads' );
    424441        } else {
    425442            $lead_id        = $lead_post['result']['creates'][0]['id'];
     
    429446        $list_id    = rgars( $feed, 'meta/sharpspring_list' );
    430447        $params     = array( 'listID' => $list_id, 'memberID' => $lead_id );
     448
    431449        $list_post  = $this->sharpspring_post( $params, 'addListMembers' );
    432450    }
  • integrate-sharpspring-and-gravity-forms/trunk/readme.txt

    r2522883 r2530005  
    3939== Changelog ==
    4040
     41= 1.0.3 =
     42*Release Date - 11 May 2021*
     43
     44* New - Added support for updateLeads method. This addition will update a lead's information if the lead already exists.
     45* Fixed - PHP notices that appeared when the Account ID was incorrect.
     46
    4147= 1.0.2 =
    4248*Release Date - 28 April 2021*
Note: See TracChangeset for help on using the changeset viewer.