$mailjet = Tools::jsonDecode(Tools::getValue('mailjet'));
        $data = $mailjet->data;
    } else {
        $data = new stdClass();
    }
}
require_once _PS_MODULE_DIR_ . 'mailjet/mailjet.php';
require_once _PS_MODULE_DIR_ . 'mailjet/classes/MailJetLog.php';
$mj = new Mailjet();
MailJetLog::init();
if (Tools::getIsset('response')) {
    $response = (object) Tools::getValue('response');
}
if ($data->next_step_url) {
    if (!empty($response) && ($response->message == 'last change of campaigns parameters' || $response->message == 'send details saved successfully')) {
        $mj_data = new Mailjet_Api($mj->getAccountSettingsKey('API_KEY'), $mj->getAccountSettingsKey('SECRET_KEY'));
        $campaignId = (int) $data->campaign_id;
        $html = $mj_data->data('newsletter', $campaignId, 'HTML', 'text/html', null, 'GET', 'LAST')->getResponse();
        /* On enregistre la campagne en BDD et on génère un token */
        $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'mj_campaign WHERE campaign_id = ' . $campaignId;
        $res_campaign = Db::getInstance()->GetRow($sql);
        if (empty($res_campaign)) {
            $token_presta = md5(uniqid('mj', true));
            $sql = 'INSERT INTO ' . _DB_PREFIX_ . 'mj_campaign (campaign_id, token_presta, date_add)
			VALUES (' . $campaignId . ', \'' . $token_presta . '\', NOW())';
            Db::getInstance()->Execute($sql);
            $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'mj_campaign WHERE campaign_id = ' . $campaignId;
            $res_campaign = Db::getInstance()->GetRow($sql);
        }
        $regexp = '<a\\s[^>]*href=(\\"??)([^\\" >]*?)\\1[^>]*>(.*)<\\/a>';
        preg_match_all("/{$regexp}/siU", $html, $liens);
 /**
  * Singleton pattern :
  * Get the instance of the object if it already exists
  * or create a new one.
  *
  * @access	public
  * @uses	Mailjet::Api::$_instance
  *
  * @return resource instance
  */
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }