/** update access token */ public static function update_access_token() { $mailin = new Mailin('https://api.sendinblue.com/v1.0', SIB_Manager::$access_key, SIB_Manager::$secret_key); $mailin->delete_token(self::$access_token); $access_response = $mailin->get_access_tokens(); if ($access_response['code'] != 'success') { $access_response = $mailin->get_access_tokens(); } $access_token = $access_response['data']['access_token']; $token_settings = array('access_token' => $access_token); update_option(SIB_Manager::access_token_option_name, $token_settings); return $access_token; }
/** ajax module for validation (Home - welcome) */ public static function ajax_validation_process() { $access_key = trim($_POST['access_key']); try { $mailin = new Mailin(SIB_Manager::sendinblue_api_url, $access_key); } catch (Exception $e) { if ($e->getMessage() == 'Mailin requires CURL module') { echo 'curl_no_installed'; } else { echo 'curl_error'; } die; } $response = $mailin->get_access_tokens(); if (is_array($response)) { if ($response['code'] == 'success') { // store api info $settings = array('access_key' => $access_key); update_option(SIB_Manager::main_option_name, $settings); $access_token = $response['data']['access_token']; $token_settings = array('access_token' => $access_token); update_option(SIB_Manager::access_token_option_name, $token_settings); $mailin->partnerWordpress(); echo 'success'; } else { echo $response['code']; } } else { echo 'fail'; } die; }
/** * ajax module for validation of API access key * * @options : * ws_main_option * ws_token_store * ws_error_type */ public static function ajax_validation_process() { if (!class_exists('Mailin')) { require_once 'mailin.php'; } $access_key = trim($_POST['access_key']); try { $mailin = new Mailin(self::sendinblue_api_url, $access_key); } catch (Exception $e) { if ($e->getMessage() == 'Mailin requires CURL module') { $ws_error_type = __('Please install curl on site to use sendinblue plugin.', 'wc_sendinblue'); } else { $ws_error_type = __('Curl error.', 'wc_sendinblue'); } $settings = array('error_type' => $ws_error_type); update_option('ws_error_type', $settings); die; } $response = $mailin->get_access_tokens(); if (is_array($response)) { if ($response['code'] == 'success') { // store api info $settings = array('access_key' => $access_key); update_option('ws_main_option', $settings); // Create woocommerce attributes on SendinBlue $data = array("type" => "transactional", "data" => array('ORDER_ID' => 'ID', 'ORDER_DATE' => 'DATE', 'ORDER_PRICE' => 'NUMBER')); $mailin->create_attribute($data); $mailin->partnerWordpress(); echo 'success'; } else { $settings = array('error_type' => __('Please input correct information.', 'wc_sendinblue')); update_option('ws_error_type', $settings); } } else { echo 'fail'; } die; }
/** ajax module for validation (Home - welcome) */ public function ajax_validation_process() { $access_key = trim($_POST['access_key']); $secret_key = trim($_POST['secret_key']); $mailin = new Mailin('https://api.sendinblue.com/v1.0', $access_key, $secret_key); $response = $mailin->get_attribute('normal'); if (is_array($response)) { if ($response['code'] == 'success') { // store api info $settings = array('access_key' => $access_key, 'secret_key' => $secret_key); update_option(SIB_Manager::main_option_name, $settings); // store attribute list $attribute_list = $response['data']; update_option(SIB_Manager::attribute_list_option_name, $attribute_list); // get access_token $access_response = $mailin->get_access_tokens(); $access_token = $access_response['data']['access_token']; $token_settings = array('access_token' => $access_token); update_option(SIB_Manager::access_token_option_name, $token_settings); echo 'success'; } else { echo 'fail'; } } else { echo 'fail'; } die; }