Exemplo n.º 1
0
    header('Pragma: no-cache');
    exit;
}
$post = trim(Tools::file_get_contents('php://input'));
/* mail("*****@*****.**", "callback ajax mailjet", $post.print_r($_POST, true).print_r($_GET, true)); */
/* die(); */
require_once _PS_ROOT_DIR_ . '/config/config.inc.php';
$method = Tools::getValue('method');
$back_office_method = Tools::getValue('back_office_method');
if (in_array($method, $back_office_method)) {
    define('_PS_ADMIN_DIR_', true);
}
require_once _PS_MODULE_DIR_ . 'mailjet/mailjet.php';
$method = Tools::isSubmit('method') ? Tools::getValue('method') : '';
$token = Tools::isSubmit('token') ? Tools::getValue('token') : '';
$mj = new Mailjet();
$result = array();
MailJetLog::write(MailJetLog::$file, 'New request sent');
if ($mj->getToken() != Tools::getValue('token')) {
    $result['error'] = $mj->l('Bad token sent');
} else {
    if (!method_exists($mj, $method)) {
        $result['error'] = $mj->l('Method requested doesn\'t exist:') . ' ' . $method;
    } else {
        $result = $mj->{$method}();
    }
}
$message = isset($result['error']) ? $result['error'] : 'Success with method: ' . $method;
MailJetLog::write(MailJetLog::$file, $message);
header('Content-Type: application/json');
die(Tools::jsonEncode($result));
 /**
  * setContactMetaData()
  * First checks if certain contact meta data field is already created, 
  * and if not - creates it in order to be populated by the followed createContacts call
  * @return boolean
  */
 public function setContactMetaData($params = array())
 {
     try {
         /*
          * Add contact properties like First Name and Last Name
          */
         $resContactMetaData = $this->getContactMetaData();
         if (isset($resContactMetaData->Data) && count($resContactMetaData->Data) > 0) {
             foreach ($resContactMetaData->Data as $metaData) {
                 foreach ($params as $paramsMetaData) {
                     if (isset($metaData->Name) && ($metaData->Name = $paramsMetaData['Name'])) {
                         $flagName = $paramsMetaData['Name'] . "NameExists";
                         ${$flagName} = true;
                     }
                 }
             }
         }
         foreach ($params as $paramsMetaData) {
             $flagName = $paramsMetaData['Name'] . "NameExists";
             if (!${$flagName}) {
                 $resContactMetaData = $this->createContactMetaData($paramsMetaData);
             }
         }
         return true;
     } catch (Exception $ex) {
         MailJetLog::write(MailJetLog::$file, 'Exception : ' . $ex->getMessage());
         throw new Mailjet_ApiException($ex->getMessage());
     }
     return false;
 }