/** * Get the api connection * @static * @return null */ public static function getApi($with_overlay = true) { $obj = new Mailjet(); if ($with_overlay) { MailjetTemplate::$api = Mailjet_ApiOverlay::getInstance(); MailjetTemplate::$api->setKeys($obj->getAccountSettingsKey('API_KEY'), $obj->getAccountSettingsKey('SECRET_KEY')); MailjetTemplate::$api->secure(false); } else { MailjetTemplate::$api = new Mailjet_Api($obj->getAccountSettingsKey('API_KEY'), $obj->getAccountSettingsKey('SECRET_KEY')); } unset($obj); return MailjetTemplate::$api; }
public function auth($apiKey, $secretKey) { $test = new Mailjet_ApiOverlay($apiKey, $secretKey); $result = $test->getUser(); if ($result !== false) { $this->account->API_KEY = $apiKey; $this->account->SECRET_KEY = $secretKey; $this->account->EMAIL = $result->Email; $this->account->AUTHENTICATION = 1; $this->updateAccountSettings(); Configuration::updateValue('PS_MAIL_SERVER', $this->mj_mail_server); Configuration::updateValue('PS_MAIL_SMTP_PORT', $this->mj_mail_port); //Configuration::updateValue('PS_MAIL_SMTP_ENCRYPTION', 'tls'); Configuration::updateValue('PS_MAIL_USER', $apiKey); Configuration::updateValue('PS_MAIL_PASSWD', $secretKey); Configuration::updateValue('PS_MAIL_METHOD', 2); $account = Tools::jsonDecode(Configuration::get('MAILJET'), true); Configuration::updateValue('PS_SHOP_EMAIL', $result->Email); self::setSMTPconnectionParams(); if ($this->account->MASTER_LIST_SYNCHRONIZED == 0) { return $this->initalSynchronize(); } return true; } else { $this->errors_list[] = $this->l('Please verify that you have entered your API and secret key correctly. Please note this plug-in is compatible for Mailjet v3 accounts only.') . '<a href="https://app.mailjet.com/support/why-do-i-get-an-api-error-when-trying-to-activate-a-mailjet-plug-in,497.htm" target="_blank" style="text-decoration:underline;">' . $this->l('Click here ') . '</a>' . $this->l(' to check the version of your Mailjet account'); } return false; }
/** * Singleton pattern : * Get the instance of the object if it already exists * or create a new one. * * @access public * @uses Mailjet::ApiOverlay::$_instance * * @return instance */ public static function getInstance() { if (!self::$_instance instanceof self) { self::$_instance = new self(); } return self::$_instance; }