public static function ManageUrlSys() { $payment = new Kwixo(); if (!$payment->isInstalled('kwixo')) { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Module Kwixo non installé, retour UrlSys échoué'); return false; } $transactionID = Tools::getValue('TransactionID'); $refID = Tools::getValue('RefID'); $tag = Tools::getValue('Tag'); $id_cart = Tools::getValue('custom', false); $amount = Tools::getValue('amount', false); $cart = new Cart((int) $id_cart); //Multishop if (_PS_VERSION_ < '1.5') { $kwixo = new KwixoPayment(); } else { $kwixo = new KwixoPayment($cart->id_shop); } if ($kwixo->getAuthKey() == '') { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Clé privée Kwixo vide, retour UrlSys échoué'); return false; } $md5 = new KwixoMD5(); $waitedhash = $md5->hash($kwixo->getAuthKey() . $refID . $transactionID); $receivedhash = Tools::getValue('HashControl', '0'); //Hash control if ($waitedhash != $receivedhash) { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'URLSys erreur : HashControl invalide (valeur attendue = "' . $waitedhash . '", valeur reçue = "' . $receivedhash . '"). IP expediteur : ' . Tools::getRemoteAddr()); } else { //if cart if empty : error and exit if (!$cart->id) { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, "Le panier pour la commande {$refid}/{$transactionid} n'existe pas."); exit; } global $cookie; //Give order_id $id_order = Order::getOrderByCartId($cart->id); if ($id_order !== false) { $order = new Order((int) $id_order); KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'URLSys : id_cart = ' . $id_cart . (!Order::getOrderByCartId($id_cart) ? '' : ' | id_order = ' . Order::getOrderByCartId($id_cart)) . ' | tag = ' . $tag); } else { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'URLSys : order false'); } switch ($tag) { //Give up payment, tag sent after 1 hour case 0: KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'URLSys abandon après 1h : id_cart = ' . $id_cart . (!Order::getOrderByCartId($id_cart) ? '' : ' | id_order = ' . Order::getOrderByCartId($id_cart)) . ' | tag = ' . $tag); break; //Accepted payment //Accepted payment case 1: case 13: case 14: case 10: //Retrieve score if present $score = Tools::getValue('Score', false); //if order current state in cancelled or waiting or under control or credit status, status updated if ($id_order === false || in_array($order->getCurrentState(), array((int) _PS_OS_CANCELED_, (int) Configuration::get('KW_OS_WAITING'), (int) Configuration::get('KW_OS_CREDIT'), (int) Configuration::get('KW_OS_CONTROL')))) { if ($score == 'positif') { $psosstatus = (int) Configuration::get('KW_OS_PAYMENT_GREEN'); } elseif ($score == 'negatif') { $psosstatus = (int) Configuration::get('KW_OS_PAYMENT_RED'); } else { $psosstatus = (int) _PS_OS_PAYMENT_; } } break; //Payment refused //Payment refused case 2: if (!in_array($order->getCurrentState(), array((int) Configuration::get('KW_OS_PAYMENT_GREEN'), (int) Configuration::get('KW_OS_PAYMENT_RED'), (int) Configuration::get('KW_OS_CONTROL'), (int) Configuration::get('KW_OS_CREDIT')))) { $psosstatus = (int) _PS_OS_CANCELED_; } break; //order under control //order under control case 3: //if order current state in cancelled or waiting or credit status, status updated if ($id_order === false || in_array($order->getCurrentState(), array((int) _PS_OS_CANCELED_, (int) Configuration::get('KW_OS_WAITING'), (int) Configuration::get('KW_OS_CREDIT')))) { $psosstatus = (int) Configuration::get('KW_OS_CONTROL'); } break; //order on waiting status //order on waiting status case 4: if ($id_order === false) { $psosstatus = (int) Configuration::get('KW_OS_WAITING'); } break; //order under credit status //order under credit status case 6: //if order current state in cancelled or waiting, status updated if ($id_order === false || in_array($order->getCurrentState(), array((int) _PS_OS_CANCELED_, (int) Configuration::get('KW_OS_WAITING')))) { $psosstatus = (int) Configuration::get('KW_OS_CREDIT'); } break; //payment refused //payment refused case 11: case 12: //if order current state in cancelled or waiting, status updated if ($id_order === false || in_array($order->getCurrentState(), array((int) _PS_OS_CANCELED_, (int) Configuration::get('KW_OS_WAITING'), (int) Configuration::get('KW_OS_CREDIT'), (int) Configuration::get('KW_OS_CONTROL')))) { $psosstatus = (int) _PS_OS_CANCELED_; } break; //payment cancelled //payment cancelled case 101: $psosstatus = (int) _PS_OS_CANCELED_; break; //delivery done //delivery done case 100: if ($id_order === false || !in_array($order->getCurrentState(), array((int) _PS_OS_DELIVERED_, (int) _PS_OS_PREPARATION_, (int) _PS_OS_SHIPPING_, (int) _PS_OS_PAYMENT_))) { $psosstatus = (int) _PS_OS_PAYMENT_; } break; default: break; KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Appel URLSys : id_cart = ' . $id_cart . (!Order::getOrderByCartId($id_cart) ? '' : ' | id_order = ' . Order::getOrderByCartId($id_cart)) . ' | tag = ' . $tag); } } //Validate order and update status if (isset($psosstatus)) { if ($id_order === false) { $feedback = 'Order Create'; $payment->validateOrder((int) $cart->id, $psosstatus, $amount, $payment->displayName, $feedback, NULL, $cart->id_currency); $id_order = Order::getOrderByCartId($cart->id); $payment->manageKwixoOrder($id_order, $tag, $transactionID, $id_cart, 'urlsys'); if ($cookie->id_cart == (int) $cookie->last_id_cart) { unset($cookie->id_cart); } } else { //update order history $order->setCurrentState($psosstatus); } } }
public static function ManageUrlCall() { $payment = new Kwixo(); if (!$payment->isInstalled('kwixo')) { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Module Kwixo non installé, retour UrlCall échoué'); return false; } global $cart, $cookie; $errors = array(); $payment_ok = false; $params = array(); $TransactionID = Tools::getValue('TransactionID'); $RefID = Tools::getValue('RefID'); //Multishop if (_PS_VERSION_ < '1.5') { $kwixo = new KwixoPayment(); } else { $kwixo = new KwixoPayment($cart->id_shop); } if ($kwixo->getAuthKey() == '') { KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Clé privée Kwixo vide, retour UrlCall échoué'); return false; } $md5 = new KwixoMD5(); $waitedhash = $md5->hash($kwixo->getAuthKey() . $RefID . $TransactionID); $receivedhash = Tools::getValue('HashControl', '0'); $id_order = false; //Hash control if ($waitedhash != $receivedhash) { KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, "Hash control invalide (les données ne proviennent pas de Kwixo)"); } else { //check xml_params for urlcall payment $xml_params = $payment->checkUrlCallXMLParams(); if ($xml_params['errors'] == 0) { $tag = Tools::getValue('Tag', false); $id_cart = $xml_params['id_cart']; $amount = $xml_params['amount']; $id_module = $xml_params['id_module']; $order_created = $xml_params['order_created']; switch ($tag) { //Give up payment or payment refused by bank -> back to cart without order creation case '0': KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'URLCall abandon paiement : id_cart = ' . $id_cart . (!$order_created ? '' : ' / id_order = ' . Order::getOrderByCartId($id_cart)) . ' / tag = ' . $tag); $payment_ok = false; break; case '2': $errors[] = $payment->l('Your payment has been refused.'); KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'URLCall : id_cart = ' . $id_cart . (!$order_created ? '' : ' / id_order = ' . Order::getOrderByCartId($id_cart)) . ' / tag = ' . $tag); $payment_ok = false; break; //Payment accepted -> order creation with waiting payment status and back to confirmation page //Payment accepted -> order creation with waiting payment status and back to confirmation page case '1': $feedback = $payment->l('Transaction OK:') . ' RefID=' . $RefID . ' & TransactionID=' . $TransactionID; //order validation if ($order_created == false) { $payment->validateOrder((int) $cart->id, (int) Configuration::get('KW_OS_WAITING'), $amount, $payment->displayName, $feedback, '', $cart->id_currency, false, $cart->secure_key); } $payment_ok = true; //get id_order to update database $id_order = Order::getOrderByCartId($id_cart); KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Paiement accepté : $order->id = ' . $id_order); //Insert in kwixo order with urlcall method $payment->manageKwixoOrder($id_order, '', $TransactionID, $id_cart, 'urlcall'); //cart clean if ($cookie->id_cart == (int) $cookie->last_id_cart) { unset($cookie->id_cart); } $customer = new Customer((int) $cart->id_customer); break; //for unknowned tag //for unknowned tag default: //error saved $errors[] = $payment->l('One or more error occured during the validation') . "\n"; KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Tag inconnu "' . $tag . '" recu.'); //cart clean if ($cookie->id_cart == (int) $cookie->last_id_cart) { unset($cookie->id_cart); } $payment_ok = false; break; } } else { //error saved $errors[] = $payment->l('One or more error occured during the validation') . "\n"; if ($cookie->id_cart == (int) $cookie->last_id_cart) { unset($cookie->id_cart); } } $params['payment_status'] = $payment_ok; $params['errors'] = $errors; $params['id_order'] = $id_order; return $params; } }