public function validation() { if (!$this->active) { return; } if (!array_key_exists('xml', $_POST)) { return; } if (_PS_MAGIC_QUOTES_GPC_) { $_POST['xml'] = stripslashes($_POST['xml']); } require_once dirname(__FILE__) . '/mapi/mapi_package.php'; if (HIPAY_MAPI_COMM_XML::analyzeNotificationXML($_POST['xml'], $operation, $status, $date, $time, $transid, $amount, $currency, $id_cart, $data) === false) { file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] Analysis error: ' . htmlentities($_POST['xml']) . "\n", FILE_APPEND); return false; } if (_PS_VERSION_ >= 1.5) { Context::getContext()->cart = new Cart((int) $id_cart); } $cart = new Cart((int) $id_cart); if (Tools::encrypt($cart->id . $cart->secure_key . Configuration::get('HIPAY_SALT')) != Tools::getValue('token')) { file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] Token error: ' . htmlentities($_POST['xml']) . "\n", FILE_APPEND); } else { if (trim($operation) == 'capture' and trim(strtolower($status)) == 'ok') { /* Paiement capturé sur Hipay = Paiement accepté sur Prestashop */ $orderMessage = $operation . ': ' . $status . '\\ndate: ' . $date . ' ' . $time . '\\ntransaction: ' . $transid . '\\namount: ' . (double) $amount . ' ' . $currency . '\\nid_cart: ' . (int) $id_cart; $this->validateOrder((int) $id_cart, Configuration::get('PS_OS_PAYMENT'), (double) $amount, $this->displayName, $orderMessage, array(), NULL, false, $cart->secure_key); } elseif (trim($operation) == 'refund' and trim(strtolower($status)) == 'ok') { /* Paiement remboursé sur Hipay */ if (!($id_order = Order::getOrderByCartId((int) $id_cart))) { die(Tools::displayError()); } $order = new Order((int) $id_order); if (!$order->valid or $order->getCurrentState() === Configuration::get('PS_OS_REFUND')) { die(Tools::displayError()); } $orderHistory = new OrderHistory(); $orderHistory->id_order = (int) $order->id; $orderHistory->changeIdOrderState((int) Configuration::get('PS_OS_REFUND'), (int) $id_order); $orderHistory->addWithemail(); } } }
public function validation() { if (!array_key_exists('xml', $_POST)) { return; } if (_PS_MAGIC_QUOTES_GPC_) { $_POST['xml'] = stripslashes($_POST['xml']); } require_once dirname(__FILE__) . '/mapi/mapi_package.php'; if (HIPAY_MAPI_COMM_XML::analyzeNotificationXML($_POST['xml'], $operation, $status, $date, $time, $transid, $amount, $currency, $id_cart, $data) === false) { file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] ' . $_POST['xml'] . "\n", FILE_APPEND); } if (trim($operation) == 'capture' and trim(strtolower($status)) == 'ok') { /* Paiement capturé sur Hipay = Paiement accepté sur Prestashop */ $orderMessage = $operation . ': ' . $status . "\n" . 'date: ' . $date . ' ' . $time . "\n" . 'transaction: ' . $transid . "\n" . 'amount: ' . (double) $amount . ' ' . $currency . "\n" . 'id_cart: ' . (int) $id_cart; $this->validateOrder((int) $id_cart, _PS_OS_PAYMENT_, (double) $amount, $this->displayName, $orderMessage); } elseif (trim($operation) == 'refund' and trim(strtolower($status)) == 'ok') { /* Paiement remboursé sur Hipay */ if (!($id_order = Order::getOrderByCartId(intval($id_cart)))) { die(Tools::displayError()); } $order = new Order(intval($id_order)); if (!$order->valid or $order->getCurrentState() === _PS_OS_REFUND_) { die(Tools::displayError()); } $orderHistory = new OrderHistory(); $orderHistory->id_order = intval($order->id); $orderHistory->changeIdOrderState(intval(_PS_OS_REFUND_), intval($id_order)); $orderHistory->addWithemail(); } }
public function validation() { # LOG $message = '######################################' . "\r\n"; $message .= '# Date Début Validation - ' . date("d/m/Y H:i:s") . "\r\n"; $message .= '#### Module actif - ' . ($this->active ? 'TRUE' : 'FALSE') . "\r\n"; $message .= '#### Variable POST :' . "\r\n"; $message .= print_r($_POST, true); $message .= "\r\n"; # --- $this->HipayLog($message); if (!$this->active) { return; } if (!array_key_exists('xml', $_POST)) { return; } if (_PS_MAGIC_QUOTES_GPC_) { $_POST['xml'] = stripslashes($_POST['xml']); } require_once dirname(__FILE__) . '/mapi/mapi_package.php'; # LOG $this->HipayLog('#### Début HIPAY_MAPI_COMM_XML::analyzeNotificationXML' . "\r\n"); # --- if (HIPAY_MAPI_COMM_XML::analyzeNotificationXML($_POST['xml'], $operation, $status, $date, $time, $transid, $amount, $currency, $id_cart, $data) === false) { file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] Analysis error: ' . htmlentities($_POST['xml']) . "\n", FILE_APPEND); return false; } # LOG $message = '#### Fin HIPAY_MAPI_COMM_XML::analyzeNotificationXML' . "\r\n"; $message .= '#### Version Prestashop : ' . _PS_VERSION_; # --- $this->HipayLog($message); if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { # LOG $this->HipayLog('#### ID Panier : ' . (int) $id_cart . "\r\n"); # --- Context::getContext()->cart = new Cart((int) $id_cart); } $cart = new Cart((int) $id_cart); # LOG $message = '#### TOKEN : ' . Tools::getValue('token') . "\r\n"; $message .= '#### SECURE KEY : ' . $cart->secure_key . "\r\n"; $message .= '#### HIPAY SALT : ' . Configuration::get('HIPAY_SALT') . "\r\n"; $message .= '#### CLE ENCRYPTE : ' . Tools::encrypt($cart->id . $cart->secure_key . Configuration::get('HIPAY_SALT')) . "\r\n"; # --- $this->HipayLog($message); if (Tools::encrypt($cart->id . $cart->secure_key . Configuration::get('HIPAY_SALT')) != Tools::getValue('token')) { # LOG $this->HipayLog('#### TOKEN = CLE : NOK' . "\r\n"); # --- file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] Token error: ' . htmlentities($_POST['xml']) . "\n", FILE_APPEND); } else { # LOG $message = '#### Opération : ' . trim($operation) . "\r\n"; $message .= '#### Status : ' . trim(strtolower($status)) . "\r\n"; # --- $this->HipayLog($message); if (trim($operation) == 'authorization' && trim(strtolower($status)) == 'waiting') { // Authorization WAITING $orderMessage = $operation . ": " . $status . "\ndate: " . $date . " " . $time . "\ntransaction: " . $transid . "\namount: " . (double) $amount . " " . $currency . "\nid_cart: " . (int) $id_cart; //$this->_createAuthorizationOrderState(); $this->validateOrder((int) $id_cart, Configuration::get('HIPAY_WAITINGPAYMENT_OS'), (double) $amount, $this->displayName, $orderMessage, array(), NULL, false, $cart->secure_key); # LOG $this->HipayLog('######## AW - création Commande / status : ' . (int) Configuration::get('HIPAY_WAITINGPAYMENT_OS') . "\r\n"); # --- } else { if (trim($operation) == 'authorization' && trim(strtolower($status)) == 'ok') { // vérification si commande existante $id_order = Order::getOrderByCartId((int) $id_cart); # LOG $this->HipayLog('######## AOK - ID Commande : ' . ($id_order ? $id_order : 'Pas de commande') . "\r\n"); # --- if ($id_order !== false) { // change statut si commande en attente de paiement $order = new Order((int) $id_order); if ((int) $order->getCurrentState() == (int) Configuration::get('HIPAY_WAITINGPAYMENT_OS')) { // on affecte à la commande au statut paiement autorisé par HiPay $statut_id = Configuration::get('HIPAY_AUTHORIZATION_OS'); $order_history = new OrderHistory(); $order_history->id_order = $id_order; $order_history->changeIdOrderState($statut_id, $id_order); $order_history->addWithemail(); # LOG $this->HipayLog('######## AOK - Historique Commande / Change status : ' . (int) Configuration::get('HIPAY_AUTHORIZATION_OS') . "\r\n"); # --- } } else { // on revérifie si la commande n'existe pas au cas où la capture soit arrivée avant // sinon on ne fait rien $id_order = Order::getOrderByCartId((int) $id_cart); if ($id_order === false) { // Authorization OK $orderMessage = $operation . ": " . $status . "\ndate: " . $date . " " . $time . "\ntransaction: " . $transid . "\namount: " . (double) $amount . " " . $currency . "\nid_cart: " . (int) $id_cart; //$this->_createAuthorizationOrderState(); $this->validateOrder((int) $id_cart, Configuration::get('HIPAY_AUTHORIZATION_OS'), (double) $amount, $this->displayName, $orderMessage, array(), NULL, false, $cart->secure_key); # LOG $this->HipayLog('######## AOK - création Commande / status : ' . (int) Configuration::get('HIPAY_AUTHORIZATION_OS') . "\r\n"); # --- } } } else { if (trim($operation) == 'capture' && trim(strtolower($status)) == 'ok') { // Capture OK $orderMessage = $operation . ": " . $status . "\ndate: " . $date . " " . $time . "\ntransaction: " . $transid . "\namount: " . (double) $amount . " " . $currency . "\nid_cart: " . (int) $id_cart; $id_order = Order::getOrderByCartId((int) $id_cart); # LOG $this->HipayLog('######## C*K - ID Commande : ' . ($id_order ? $id_order : 'Pas de commande') . "\r\n"); # --- if ($id_order !== false) { # LOG $this->HipayLog('######## C*K - id_order existant' . "\r\n"); # --- $order = new Order((int) $id_order); # LOG $this->HipayLog('######## C*K - objet order loadé' . "\r\n"); # --- // si la commande est au statut Autorisation ok ou en attente de paiement // on change le statut en paiement accepté if ((int) $order->getCurrentState() == (int) Configuration::get('HIPAY_AUTHORIZATION_OS') || (int) $order->getCurrentState() == (int) Configuration::get('HIPAY_WAITINGPAYMENT_OS')) { $statut_id = Configuration::get('PS_OS_PAYMENT'); $order_history = new OrderHistory(); $order_history->id_order = $id_order; $order_history->changeIdOrderState($statut_id, $id_order); $order_history->addWithemail(); # LOG $this->HipayLog('######## C*K - Historique Commande / Change status : ' . (int) Configuration::get('PS_OS_PAYMENT') . "\r\n"); # --- } } else { $this->validateOrder((int) $id_cart, Configuration::get('PS_OS_PAYMENT'), (double) $amount, $this->displayName, $orderMessage, array(), NULL, false, $cart->secure_key); # LOG $this->HipayLog('######## C*K - création Commande / status : ' . (int) Configuration::get('PS_OS_PAYMENT') . "\r\n"); # --- } // Commande que prestashop lance mais n'a aucune incidence dans le module... // Ajouté en commentaire // Configuration::updateValue('HIPAY_CONFIGURATION_OK', true); } else { if (trim($operation) == 'capture' && trim(strtolower($status)) == 'nok') { // Capture NOK $id_order = Order::getOrderByCartId((int) $id_cart); # LOG $this->HipayLog('######## CNOK - ID Commande : ' . ($id_order ? $id_order : 'Pas de commande') . "\r\n"); # --- if ($id_order !== false) { $order = new Order((int) $id_order); if ((int) $order->getCurrentState() == (int) Configuration::get('HIPAY_AUTHORIZATION_OS')) { $statut_id = Configuration::get('PS_OS_ERROR'); $order_history = new OrderHistory(); $order_history->id_order = $id_order; $order_history->changeIdOrderState($statut_id, $id_order); $order_history->addWithemail(); # LOG $this->HipayLog('######## CNOK - Historique Commande / Change status : ' . (int) Configuration::get('PS_OS_ERROR') . "\r\n"); # --- } } } elseif (trim($operation) == 'refund' and trim(strtolower($status)) == 'ok') { /* Paiement remboursé sur Hipay */ if (!($id_order = Order::getOrderByCartId((int) $id_cart))) { die(Tools::displayError()); } $order = new Order((int) $id_order); if (!$order->valid or $order->getCurrentState() === Configuration::get('PS_OS_REFUND')) { die(Tools::displayError()); } $statut_id = Configuration::get('PS_OS_REFUND'); $order_history = new OrderHistory(); $order_history->id_order = $id_order; $order_history->changeIdOrderState($statut_id, $id_order); $order_history->addWithemail(); # LOG ${$this}->HipayLog('######## ROK - Historique Commande / Change status : ' . (int) Configuration::get('PS_OS_REFUND') . "\r\n"); # --- } } } } } # # Patch LOG Pour les erreurs 500 # $message = '# Date Fin Validation - ' . date("d/m/Y H:i:s") . "\r\n"; $message .= '######################################' . "\r\n"; $this->HipayLog($message); # --------------------------------------------------------- return true; }
public function validation() { if (!$this->active) { return; } if (!array_key_exists('xml', $_POST)) { return; } if (_PS_MAGIC_QUOTES_GPC_) { $_POST['xml'] = stripslashes($_POST['xml']); } require_once dirname(__FILE__) . '/mapi/mapi_package.php'; if (HIPAY_MAPI_COMM_XML::analyzeNotificationXML($_POST['xml'], $operation, $status, $date, $time, $transid, $amount, $currency, $id_cart, $data) === false) { file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] Analysis error: ' . htmlentities($_POST['xml']) . "\n", FILE_APPEND); return false; } if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { Context::getContext()->cart = new Cart((int) $id_cart); } $cart = new Cart((int) $id_cart); if (Tools::encrypt($cart->id . $cart->secure_key . Configuration::get('HIPAY_SALT')) != Tools::getValue('token')) { file_put_contents('logs' . Configuration::get('HIPAY_UNIQID') . '.txt', '[' . date('Y-m-d H:i:s') . '] Token error: ' . htmlentities($_POST['xml']) . "\n", FILE_APPEND); } else { if (trim($operation) == 'authorization' && trim(strtolower($status)) == 'ok') { // Authorization OK $orderMessage = $operation . ": " . $status . "\ndate: " . $date . " " . $time . "\ntransaction: " . $transid . "\namount: " . (double) $amount . " " . $currency . "\nid_cart: " . (int) $id_cart; $this->_createAuthorizationOrderState(); $this->validateOrder((int) $id_cart, Configuration::get('HIPAY_AUTHORIZATION_OS'), (double) $amount, $this->displayName, $orderMessage, array(), NULL, false, $cart->secure_key); } else { if (trim($operation) == 'capture' && trim(strtolower($status)) == 'ok') { // Capture OK $orderMessage = $operation . ": " . $status . "\ndate: " . $date . " " . $time . "\ntransaction: " . $transid . "\namount: " . (double) $amount . " " . $currency . "\nid_cart: " . (int) $id_cart; $id_order = Order::getOrderByCartId((int) $id_cart); if ($id_order !== false) { $order = new Order((int) $id_order); if ((int) $order->getCurrentState() == (int) Configuration::get('HIPAY_AUTHORIZATION_OS')) { $orderHistory = new OrderHistory(); $orderHistory->id_order = (int) $order->id; $orderHistory->changeIdOrderState((int) Configuration::get('PS_OS_PAYMENT'), (int) $id_order); $orderHistory->addWithemail(); } } else { $this->validateOrder((int) $id_cart, Configuration::get('PS_OS_PAYMENT'), (double) $amount, $this->displayName, $orderMessage, array(), NULL, false, $cart->secure_key); } Configuration::updateValue('HIPAY_CONFIGURATION_OK', true); } else { if (trim($operation) == 'capture' && trim(strtolower($status)) == 'nok') { // Capture NOK $id_order = Order::getOrderByCartId((int) $id_cart); if ($id_order !== false) { $order = new Order((int) $id_order); if ((int) $order->getCurrentState() == (int) Configuration::get('HIPAY_AUTHORIZATION_OS')) { $orderHistory = new OrderHistory(); $orderHistory->id_order = (int) $order->id; $orderHistory->changeIdOrderState((int) Configuration::get('PS_OS_ERROR'), (int) $id_order); $orderHistory->addWithemail(); } } } elseif (trim($operation) == 'refund' && trim(strtolower($status)) == 'ok') { /* Paiement remboursé sur Hipay */ if (!($id_order = Order::getOrderByCartId((int) $id_cart))) { die(Tools::displayError()); } $order = new Order((int) $id_order); if (!$order->valid or $order->getCurrentState() === Configuration::get('PS_OS_REFUND')) { die(Tools::displayError()); } $orderHistory = new OrderHistory(); $orderHistory->id_order = (int) $order->id; $orderHistory->changeIdOrderState((int) Configuration::get('PS_OS_REFUND'), (int) $id_order); $orderHistory->addWithemail(); } } } } }