Plugin Directory

Changeset 1472568


Ignore:
Timestamp:
08/11/2016 08:03:47 PM (10 years ago)
Author:
cueteam
Message:

webhooks barebones, removed place_id call with empty credentials, added 'apps/mylist' endpoint

Location:
cue-connect/trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • cue-connect/trunk/cue-connect.php

    r1468663 r1472568  
    33 * Plugin Name: Cue Connect
    44 * Description: Meet Cue, your customers’ personal shopping assistant that feeds you actionable data.
    5  * Version: 1.0.3
     5 * Version: 1.0.4
    66 * Author: Cue Connect
    77 * Author URI: http://business.cueconnect.com/
  • cue-connect/trunk/inc/class.cue-api.php

    r1468907 r1472568  
    3737        ),
    3838
    39         'select_verstion' => array(
     39        'select_version' => array(
    4040            'action' => 'selectVersion',
    4141            'key' => 'a2645def81375a4f88475acc6b4b0639fd87bfaef715b828e1704f79bac6262ef0e85876dd7047765360678b3372812b5f1741b3abfe9159a3d50fe01e05d757'
     
    160160        $params = array(
    161161            'storeId'   => $place_id,
    162             'id'        => 4,
    163             'email'     => 'sasha.anpilov@gmail.com',
     162            'id'        => 6,
     163            'email'     => 'aanpilov@cueconnect.com',
    164164            'fullName'  => "sasha",
    165165            'firstName' => "sasha",
     
    170170        );
    171171        $response = $this->do_webhook($url, $auth_key, $params);
    172         print_r($response);
     172        var_dump($response);
     173        die();
    173174        return $response;
    174175    }
    175176   
    176     public function select_version() {
    177 
     177    public function select_version($value) {
     178
     179        $options = cue_options::get();
     180
     181        $url = $this->get_webhook_url() . 'selectVersion';
     182        $version = $value;
     183
     184        $str =
     185            "v$version"
     186            . $this->webhook_actions['select_version']['key']
     187            . $this->get_webhook_url() . "selectVersion"
     188            . $options['api_key'];
     189
     190        $key = sha1($str) . "$" . $options['api_key'];
     191
     192        $params = array(
     193            'version' => $version
     194        );
     195
     196       
     197        $response = (int)$this->do_webhook($url, $key, $params);
     198        if ($response == $options['place_id']) {
     199            return true;
     200        } else {
     201            return false;
     202        }
     203        return false;
    178204    }
    179205
     
    183209
    184210        // do POST - use curl
    185         if (function_exists('curl_version') && 1==0) {
     211        if (function_exists('curl_version')) {
    186212            try {
     213               
    187214                $ch = curl_init();
    188215                curl_setopt($ch, CURLOPT_URL, $url);
    189                 curl_setopt($ch, CURLOPT_HEADER);
     216                // curl_setopt($ch, CURLOPT_HEADER);
    190217                curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    191218                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     
    195222                $response = curl_exec($ch);
    196223                $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    197                
    198224                curl_close($ch);
     225
    199226            } catch (Exception $e) {
    200                 // Mage::log($e->getMessage());
     227                // TODO: Log errors
    201228            }
    202229        }
     
    206233            $queryString  = '?' . http_build_query($params);
    207234            try {
    208                 // $response = file_get_contents($url . $queryString);
    209 
    210                 print_r($url . $queryString);
    211 
     235                $response = file_get_contents($url . $queryString);
    212236            } catch (Exception $e) {
    213                 // Mage::log($e->getMessage());
     237                // TODO: Log errors
    214238            }
    215239        }
  • cue-connect/trunk/inc/class.cue-connect.php

    r1468658 r1472568  
    2929        if (is_admin()) {
    3030            add_action('init', array('cue_options','init'));
     31        }
     32
     33        // add /apps/mylist endpoint if needed
     34        if (2 == self::$_options['version']) {
     35            require_once CUE_PLUGIN_DIR . 'inc/class.cue-endpoint.php';
     36            new Cue_Endpoint;
    3137        }
    3238
  • cue-connect/trunk/inc/class.cue-options.php

    r1468907 r1472568  
    9494         */
    9595        $connected = false;
     96
     97        $new = $options;
     98        $old = self::get();
     99
    96100        if (
    97101            $options['username'] !== self::$options['username']
    98102            || $options['password'] !== self::$options['password']
    99             || empty(self::$options['api_key'])
    100             || empty(self::$options['place_id'])
    101103        ) {
    102104            $connected = self::connect_cue_account(
     
    110112                );
    111113            } else {
     114                if (!empty(self::$options['username']) && !empty(self::$options['password'])) {               
     115                    self::$_notices['credentials'] = array(
     116                        'type' => 'error',
     117                        'message' => "Error. Please check credentials and try again."
     118                    );
     119                }
     120            }
     121        }
     122
     123        /**
     124         * Check if PB/CP version has changed and send webhook if true
     125         */
     126       
     127        if (!empty($new['version']) && $new['version'] !== $old['version']) {
     128            $version_changed = self::cue_select_version($new['version']);
     129            if ($version_changed) {
     130                if (2 == $new['version']) {
     131                    update_option('cue_flush_rewrite', 1);
     132                }
    112133                self::$_notices['credentials'] = array(
    113                     'type' => 'error',
    114                     'message' => "Error. Please check credentials and try again."
     134                    'type' => 'success',
     135                    'message' => "My-List version changed successfully"
    115136                );
    116137            }
     
    157178
    158179        return true;
     180    }
     181
     182    /**
     183     * Call to magento webhook, asking to change CP/PB
     184     *
     185     * @param  int      $value 1:PB, 2:CP
     186     * @return bool     true on success
     187     */
     188    private static function cue_select_version($value)
     189    {
     190        $api = new Cue_Api;
     191        $response = $api->select_version($value);
     192        return $response;
    159193    }
    160194
     
    282316    </form>
    283317
     318<?php /*
    284319<?php if (isset($_GET['dev'])) : ?>
    285320<pre>
     
    289324</pre>
    290325<?php endif; ?>
     326*/ ?>
    291327
    292328<?php if (isset($_GET['start_sync']) && $_GET['start_sync'] == $options['api_key']) {
  • cue-connect/trunk/readme.txt

    r1468667 r1472568  
    66WC requires at least: 1.6
    77WC tested up to: 2.6
    8 Stable tag: 1.0.3
     8Stable tag: 1.0.4
    99License: GPLv3 or later License
    1010License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    9393== Changelog ==
    9494
     95= 1.0.4 =
     96* Stability improvements
     97
    9598= 1.0.3 =
    9699* Added conversion tracking
Note: See TracChangeset for help on using the changeset viewer.