Ejemplo n.º 1
0
 /**
  * @brief Validate a payment, verify if everything is right
  */
 public function validation()
 {
     if (!isset($_POST['sign']) && !isset($_POST['signature'])) {
         Logger::AddLog('[Payulatam] the signature is missing.', 2, null, null, null, true);
     } else {
         $token = isset($_POST['sign']) ? $_POST['sign'] : $_POST['signature'];
     }
     if (!isset($_POST['reference_sale']) && !isset($_POST['referenceCode'])) {
         Logger::AddLog('[Payulatam] the reference is missing.', 2, null, null, null, true);
     } else {
         $ref = isset($_POST['reference_sale']) ? $_POST['reference_sale'] : $_POST['referenceCode'];
     }
     if (!isset($_POST['value']) && !isset($_POST['amount'])) {
         Logger::AddLog('[Payulatam] the amount is missing.', 2, null, null, null, true);
     } else {
         $amount = isset($_POST['value']) ? $_POST['value'] : $_POST['amount'];
     }
     if (!isset($_POST['merchant_id']) && !isset($_POST['merchantId'])) {
         Logger::AddLog('[Payulatam] the merchantId is missing.', 2, null, null, null, true);
     } else {
         $merchantId = isset($_POST['merchant_id']) ? $_POST['merchant_id'] : $_POST['merchantId'];
     }
     if (!isset($_POST['lap_state']) && !isset($_POST['state_pol'])) {
         Logger::AddLog('[Payulatam] the lap_state is missing.', 2, null, null, null, true);
     } else {
         $statePol = isset($_POST['lap_state']) ? $_POST['lap_state'] : $_POST['state_pol'];
     }
     $idCart = substr($ref, 6 + strlen(Configuration::get('PS_SHOP_NAME')));
     $this->context->cart = new Cart((int) $idCart);
     if (!$this->context->cart->OrderExists()) {
         Logger::AddLog('[Payulatam] The shopping card ' . (int) $idCart . ' doesn\'t have any order created', 2, null, null, null, true);
         return false;
     }
     if (Validate::isLoadedObject($this->context->cart)) {
         $id_orders = Db::getInstance()->ExecuteS('SELECT `id_order` FROM `' . _DB_PREFIX_ . 'orders` WHERE `id_cart` = ' . (int) $this->context->cart->id . '');
         foreach ($id_orders as $val) {
             $order = new Order((int) $val['id_order']);
             if ($this->context->cart->getOrderTotal() != $amount) {
                 Logger::AddLog('[Payulatam] The shopping card ' . (int) $idCart . ' doesn\'t have the correct amount expected during payment validation', 2, null, null, null, true);
             } else {
                 $currency = new Currency((int) $this->context->cart->id_currency);
                 if ($token == md5(Configuration::get('PAYU_API_KEY') . '~' . Tools::safeOutput(Configuration::get('PAYU_MERCHANT_ID')) . '~payU_' . Configuration::get('PS_SHOP_NAME') . '_' . (int) $this->context->cart->id . '~' . (double) $this->context->cart->getOrderTotal() . '~' . $currency->iso_code . '~' . $statePol)) {
                     if ($statePol == 7) {
                         $order->setCurrentState((int) Configuration::get('PAYU_WAITING_PAYMENT'));
                     } else {
                         if ($statePol == 4) {
                             $order->setCurrentState((int) Configuration::get('PS_OS_PAYMENT'));
                         } else {
                             $order->setCurrentState((int) Configuration::get('PS_OS_ERROR'));
                             Logger::AddLog('[PayU] The shopping card ' . (int) $idCart . ' has been rejected by PayU state pol=' . (int) $statePol, 2, null, null, null, true);
                         }
                     }
                 } else {
                     Logger::AddLog('[PayU] The shopping card ' . (int) $idCart . ' has an incorrect token given from payU during payment validation', 2, null, null, null, true);
                 }
             }
             if (_PS_VERSION_ >= 1.5) {
                 $payment = $order->getOrderPaymentCollection();
                 if (isset($payment[0])) {
                     $payment[0]->transaction_id = pSQL($ref);
                     $payment[0]->save();
                 }
             }
         }
     } else {
         Logger::AddLog('[PayU] The shopping card ' . (int) $idCart . ' was not found during the payment validation step', 2, null, null, null, true);
     }
 }
Ejemplo n.º 2
0
 public function updateOrder(ShopgateOrder $order)
 {
     $shopgateOrder = PSShopgateOrder::instanceByOrderNumber($order->getOrderNumber());
     if (!Validate::isLoadedObject($shopgateOrder)) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_ORDER_NOT_FOUND, 'Order not found', true);
     }
     $order_states = array();
     if ($order->getUpdatePayment() && $order->getIsPaid()) {
         array_push($order_states, $this->getOrderStateId('PS_OS_PAYMENT'));
     }
     if ($order->getUpdateShipping() && !$order->getIsShippingBlocked()) {
         array_push($order_states, $this->getOrderStateId('PS_OS_PREPARATION'));
     }
     if (count($order_states)) {
         $ps_order = new Order($shopgateOrder->id_order);
         foreach ($order_states as $id_order_state) {
             if (version_compare(_PS_VERSION_, '1.4.1.0', '<')) {
                 $history = new OrderHistory();
                 $history->id_order = (int) $shopgateOrder->id_order;
                 $history->changeIdOrderState((int) $id_order_state, (int) $shopgateOrder->id_order);
             } else {
                 $ps_order->setCurrentState($id_order_state);
             }
         }
     }
     return array('external_order_id' => $shopgateOrder->id_order, 'external_order_number' => $shopgateOrder->id_order);
 }
Ejemplo n.º 3
0
 public function confirm()
 {
     // Global vars
     $kccPath = Configuration::get(KCC_PATH);
     $kccLogPath = Configuration::get(KCC_LOG);
     // Order States
     $order_state_completed = (int) Configuration::get('PS_OS_PAYMENT');
     $order_state_failed = (int) Configuration::get('PS_OS_ERROR');
     $order_state_waiting_payment = (int) Configuration::get(KCC_WAITING_PAYMENT_STATE);
     // TBK Vars
     $tbk_session_id = isset($_POST['TBK_ID_SESION']) ? trim($_POST['TBK_ID_SESION']) : null;
     $tbk_order_id = isset($_POST['TBK_ORDEN_COMPRA']) ? trim($_POST['TBK_ORDEN_COMPRA']) : null;
     $tbk_response = isset($_POST['TBK_RESPUESTA']) ? trim($_POST['TBK_RESPUESTA']) : null;
     $tbk_total_amount = isset($_POST['TBK_MONTO']) ? trim($_POST['TBK_MONTO']) : null;
     // Log helper closure
     $logger = function ($message) {
         $today = date('Y-m-d');
         $now = date('Y-m-d H:i:s');
         $name = "validation.{$today}.log";
         $path = _PS_MODULE_DIR_ . 'webpaykcc/logs/';
         $logPath = Configuration::get(KCC_LOG);
         if ($logPath) {
             $path = $logPath;
         }
         $logFile = $path . $name;
         $log = fopen($logFile, 'a');
         $text = "{$now} : {$message}\n";
         fwrite($log, $text);
         fclose($log);
     };
     // Helper closure
     // for the total amount
     $getOrderTotalAmount = function ($cart) {
         $order_total = 0;
         if ($cart) {
             $order_total = Tools::ps_round(floatval($cart->getOrderTotal(true, Cart::BOTH)), 0);
         }
         return $order_total;
     };
     // Default Values
     $result = KCC_REJECTED_RESULT;
     $order = null;
     $cart = null;
     $isDone = false;
     // Start Validation Process
     $logger("Start Validation");
     $logger("#################");
     // Log Params Received
     if (count($_POST) > 0) {
         $logger("Params Received");
         foreach ($_POST as $key => $value) {
             $logger("{$key} => {$value}");
         }
     } else {
         $logger("Params Not Found");
     }
     // Get cart data
     if (isset($tbk_order_id)) {
         try {
             $order = new Order(Order::getOrderByCartId($tbk_order_id));
             $cart = Cart::getCartByOrderId($order->id);
         } catch (Exception $e) {
             $logger($e->getMessage());
         }
     } else {
         $logger("TBK_ORDEN_COMPRA Not Set");
     }
     // First we must check the tbk_response.
     if (isset($tbk_response)) {
         if ($tbk_response == KCC_OK_RESPONSE) {
             $logger("Response is OK");
             // Both order and cart must exist
             if (isset($order->id) && isset($cart->id)) {
                 $logger("Order Exists");
                 // Now we check the current state of the order and cart
                 if ($order->current_state == $order_state_waiting_payment) {
                     $logger("Order is Waiting Payment");
                     // The amounts must be equal
                     $total_order_amount = $getOrderTotalAmount($cart);
                     // Needed 00 at the end
                     $total_order_amount_formatted = $total_order_amount . '00';
                     if ($total_order_amount_formatted == $tbk_total_amount) {
                         $logger("Amounts are Equal");
                         // Now check the session log file
                         if (isset($tbk_session_id)) {
                             //  The log file was generated in front controller
                             $tbk_log_path = getKccLog($kccLogPath, $tbk_session_id);
                             if (file_exists($tbk_log_path)) {
                                 // Open the log file
                                 $tbk_log = fopen($tbk_log_path, 'r');
                                 // Put everything inside in a string
                                 $tbk_log_string = fgets($tbk_log);
                                 fclose($tbk_log);
                                 // $tbk_details is an array
                                 // separated by semicolon
                                 $tbk_details = explode(';', $tbk_log_string);
                                 // Details should exist
                                 if (isset($tbk_details) && isset($tbk_details[0]) && isset($tbk_details[1])) {
                                     $logger("Session File Exists");
                                     $tbk_session_total_amount = $tbk_details[0];
                                     $tbk_session_order_id = $tbk_details[1];
                                     // Session values and POST values must be equal
                                     if ($tbk_session_total_amount == $tbk_total_amount && $tbk_session_order_id == $tbk_order_id) {
                                         $logger("Session Values are Correct");
                                         // Check KCC Path
                                         if (!(is_null($kccPath) || $kccPath == '')) {
                                             // The cache file is needed for validation
                                             $tbk_cache_path = $tbk_log_path . '.cache';
                                             $tbk_cache = fopen($tbk_cache_path, 'w+');
                                             // Write all the vars to cache
                                             foreach ($_POST as $tbk_key => $tbk_value) {
                                                 fwrite($tbk_cache, "{$tbk_key}={$tbk_value}&");
                                             }
                                             fclose($tbk_cache);
                                             $logger("Cache file created");
                                             // Execute the CGI Check Script
                                             $logger("Start CGI Verification Process");
                                             if (KCC_USE_EXEC) {
                                                 $logger("Verify Using Exec");
                                                 // Store the result in $tbk_result
                                                 // executing the script with the log cache file
                                                 // as param
                                                 $command = $kccPath . KCC_CGI_CHECK . ' ' . $tbk_cache_path;
                                                 exec($command, $tbk_result);
                                             } else {
                                                 // Use perl
                                                 // TODO: Implement Perl Someday
                                                 $logger("Verify Using Perl");
                                             }
                                             // Check the result
                                             $logger("Checking the CGI Result");
                                             if (isset($tbk_result[0]) && $tbk_result[0] == KCC_VERIFICATION_OK) {
                                                 // Verification OK
                                                 // Change the order status
                                                 $logger("Transbank Verification Complete");
                                                 $current_state = $order->current_state;
                                                 try {
                                                     $order->setCurrentState($order_state_completed);
                                                     $logger("Order State Was Changed From ({$current_state}) to ({$order->current_state})");
                                                 } catch (Exception $e) {
                                                     $logger($e->getMessage());
                                                 }
                                                 // Last Check
                                                 if ($order->current_state == $order_state_completed) {
                                                     $result = KCC_ACCEPTED_RESULT;
                                                     $logger("Order state is Completed");
                                                     $isDone = true;
                                                 } else {
                                                     $result = KCC_REJECTED_RESULT;
                                                     $logger("Order State is not Completed.");
                                                 }
                                             } else {
                                                 $logger("Failed CGI Verification " . json_encode($tbk_result));
                                             }
                                         } else {
                                             $logger("KCC Path not Found");
                                         }
                                     } else {
                                         $logger("Session and Post Vars are different");
                                         $logger("Session Total : {$tbk_session_total_amount}");
                                         $logger("TBK Total: {$tbk_total_amount}");
                                         $logger("Session Order: {$tbk_session_order_id}");
                                         $logger("TBK Order Id: {$tbk_order_id}");
                                     }
                                 } else {
                                     $logger("{$tbk_log_path} does not contains valid data");
                                 }
                             } else {
                                 $logger("{$tbk_log_path} does not exist");
                             }
                         } else {
                             $logger("TBK_ID_SESION not set");
                         }
                     } else {
                         $logger("Amounts are different " . "{$total_order_amount_formatted} != {$tbk_total_amount}");
                     }
                 } else {
                     $logger("Order State is not Waiting Payment ({$order_state_waiting_payment})");
                     $logger("Current Order State is ({$order->current_state})");
                 }
             } else {
                 $logger("Order not found in DB");
             }
         } else {
             if ($tbk_response >= -8 && $tbk_response <= -1) {
                 $result = KCC_ACCEPTED_RESULT;
                 $logger("Accepted Result, but TBK_RESPUESTA != OK (0)");
             } else {
                 $logger("TBK_RESPUESTA has invalid value");
             }
         }
     } else {
         $logger("TBK_RESPUESTA not set");
     }
     // Set state to failed if not done
     if (!$isDone && isset($order->current_state)) {
         if ($order->current_state != $order_state_completed) {
             try {
                 $order->setCurrentState($order_state_failed);
                 $logger("Order State was set to Failed ({$order_state_failed})");
             } catch (Exception $e) {
                 $logger($e->getMessage());
             }
         }
     }
     // End Validation Process
     $logger("Final Result: {$result}");
     $logger("End Validation");
     $logger("#################");
     echo $result;
 }
 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);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  *
  * Get the last Kwixo tag for an order and return the correct payment status
  * 
  * @param TaglineResponse $tag
  * @param Order $order
  * @param string $tid
  * 
  */
 function manageKwixoTagline($tag, $order, $tid)
 {
     $id_order = $order->id;
     if ($tag->hasError()) {
         KwixoLogger::insertLogKwixo(__METHOD__ . " : " . __LINE__, "Appel Tagline sur commande kwixo {$id_order} échoué : " . $tag->getError());
     } else {
         //get kwixo tag and kwixo score
         $kwixo_tag = $tag->getTagValue();
         $kwixo_score = $tag->getScore();
         KwixoLogger::insertLogKwixo(__METHOD__ . ' : ' . __LINE__, 'Appel Tagline : id_order = ' . $id_order . ' | tag = ' . $kwixo_tag);
         //insert or update kwixo order for tagline action
         $this->manageKwixoOrder($id_order, $kwixo_tag, $tid, '', 'tagline');
         if (in_array($order->getCurrentState(), array((int) Configuration::get('KW_OS_WAITING'), (int) Configuration::get('KW_OS_CREDIT'), (int) Configuration::get('KW_OS_CONTROL')))) {
             switch ($kwixo_tag) {
                 //order canceled
                 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 kwixo control
                 //order under kwixo control
                 case 3:
                     $psosstatus = (int) Configuration::get('KW_OS_CONTROL');
                     break;
                 case 4:
                     //if current state is diffrent of kwixo under control
                     if (!in_array($order->getCurrentState(), array((int) Configuration::get('KW_OS_CONTROL')))) {
                         $psosstatus = (int) Configuration::get('KW_OS_WAITING');
                     } else {
                         return false;
                     }
                     break;
                     //order under credit waiting
                 //order under credit waiting
                 case 6:
                     $psosstatus = (int) Configuration::get('KW_OS_CREDIT');
                     break;
                     //order on valid status
                 //order on valid status
                 case 1:
                 case 13:
                 case 14:
                 case 10:
                     if ($kwixo_score == 'positif') {
                         $psosstatus = (int) Configuration::get('KW_OS_PAYMENT_GREEN');
                     } elseif ($kwixo_score == 'negatif') {
                         $psosstatus = (int) Configuration::get('KW_OS_PAYMENT_RED');
                     } else {
                         $psosstatus = (int) _PS_OS_PAYMENT_;
                     }
                     break;
                     //order on payment refused
                 //order on payment refused
                 case 0:
                 case 11:
                 case 12:
                 case 101:
                     $psosstatus = (int) _PS_OS_CANCELED_;
                     break;
                     //order on delivery done
                 //order on delivery done
                 case 100:
                     $psosstatus = (int) _PS_OS_PAYMENT_;
                     break;
                 default:
                     break;
             }
             //return the correct payment status
             if ($order->getCurrentState() != $psosstatus) {
                 //update order history
                 $order->setCurrentState($psosstatus);
             }
         }
     }
 }
Ejemplo n.º 6
0
 private function changeStatusOrder()
 {
     try {
         $order = new Order((int) $this->order_id);
         Context::getContext()->cart = new Cart($order->id_cart);
         // to avoid conflict with giftcard module
         $order->setCurrentState((int) $this->new_status);
     } catch (Exception $e) {
         $this->file_logger->logMessageCall('change_status_order: exception = ' . $e->getMessage(), $this->file_logger->level);
         return array('error' => $e->getMessage());
     }
     return array('success' => 'true');
 }
Ejemplo n.º 7
0
 public function validationws()
 {
     require_once _PS_MODULE_DIR_ . 'payulatam/config.php';
     $conf = new ConfPayu();
     $keysPayu = $conf->keys();
     $currency_iso_code = '';
     if ($conf->isTest()) {
         $currency_iso_code = 'USD';
     } else {
         $currency_iso_code = $params[9]['currency'];
     }
     if (!isset($_POST['sign']) && !isset($_POST['signature'])) {
         Logger::AddLog('[Payulatam] the signature is missing.', 2, null, null, null, true);
     } else {
         $token = isset($_POST['sign']) ? $_POST['sign'] : $_POST['signature'];
     }
     if (!isset($_POST['reference_sale']) && !isset($_POST['referenceCode'])) {
         Logger::AddLog('[Payulatam] the reference is missing.', 2, null, null, null, true);
     } else {
         $ref = isset($_POST['reference_sale']) ? $_POST['reference_sale'] : $_POST['referenceCode'];
     }
     if (!isset($_POST['value']) && !isset($_POST['amount'])) {
         Logger::AddLog('[Payulatam] the amount is missing.', 2, null, null, null, true);
     } else {
         $amount = isset($_POST['value']) ? $_POST['value'] : $_POST['amount'];
     }
     if (!isset($_POST['merchant_id']) && !isset($_POST['merchantId'])) {
         Logger::AddLog('[Payulatam] the merchantId is missing.', 2, null, null, null, true);
     } else {
         $merchantId = isset($_POST['merchant_id']) ? $_POST['merchant_id'] : $_POST['merchantId'];
     }
     if (!isset($_POST['lap_state']) && !isset($_POST['state_pol'])) {
         Logger::AddLog('[Payulatam] the lap_state is missing.', 2, null, null, null, true);
     } else {
         $statePol = isset($_POST['lap_state']) ? $_POST['lap_state'] : $_POST['state_pol'];
     }
     $idCart = explode('_', $ref)[2];
     $this->context->cart = new Cart((int) $idCart);
     $total_order = $this->context->cart->getOrderTotal();
     if (!$this->context->cart->OrderExists()) {
         Logger::AddLog('[Payulatam] The shopping card ' . (int) $idCart . ' doesn\'t have any order created', 2, null, null, null, true);
         return false;
     }
     if (Validate::isLoadedObject($this->context->cart)) {
         $id_orders = Db::getInstance()->ExecuteS('SELECT `id_order` FROM `' . _DB_PREFIX_ . 'orders` WHERE `id_cart` = ' . (int) $this->context->cart->id . '');
         foreach ($id_orders as $val) {
             $order = new Order((int) $val['id_order']);
             if ($this->context->cart->getOrderTotal() != $amount) {
                 Logger::AddLog('[Payulatam] The shopping card ' . (int) $idCart . ' doesn\'t have the correct amount expected during payment validation.' . $keysPayu['apiKey'] . '~' . Tools::safeOutput($keysPayu['merchantId']) . '~payU_' . Configuration::get('PS_SHOP_NAME') . '_' . (int) $this->context->cart->id . '~' . number_format((double) $this->context->cart->getOrderTotal(), 2, '.', '') . '~' . $currency->iso_code . '~' . $statePol . "---" . $amount, 2, null, null, null, true);
             } else {
                 $currency = new Currency((int) $this->context->cart->id_currency);
                 if ($token == md5($keysPayu['apiKey'] . '~' . Tools::safeOutput($keysPayu['merchantId']) . '~payU_' . Configuration::get('PS_SHOP_NAME') . '_' . (int) $this->context->cart->id . '_' . $conf->get_intentos($this->context->cart->id) . '~' . number_format((double) $total_order, 2, '.', '') . '~' . $currency_iso_code . '~' . $statePol) || $token == md5($keysPayu['apiKey'] . '~' . Tools::safeOutput($keysPayu['merchantId']) . '~payU_' . Configuration::get('PS_SHOP_NAME') . '_' . (int) $this->context->cart->id . '_' . $conf->get_intentos($this->context->cart->id) . '~' . number_format((double) $total_order, 1, '.', '') . '~' . $currency_iso_code . '~' . $statePol) || $token == md5($keysPayu['apiKey'] . '~' . Tools::safeOutput($keysPayu['merchantId']) . '~payU_' . Configuration::get('PS_SHOP_NAME') . '_' . (int) $this->context->cart->id . '_' . $conf->get_intentos($this->context->cart->id) . '~' . number_format((double) $total_order, 0, '.', '') . '~' . $currency_iso_code . '~' . $statePol)) {
                     // CUANDO SE ENVIAN # ENTEROS EN EL PAGO A PAYU, ESTE RETORNA 1 DECIMAL, CUANDO SE ENVIAN DECIMALES, PAYU RETORNA 2 DECIMALES. SE VALIDA TAMBIEN SIN DECIMALES EVG GPB
                     if ($statePol == 7) {
                         if ($order->getCurrentState() != (int) Configuration::get('PAYU_WAITING_PAYMENT')) {
                             $order->setCurrentState((int) Configuration::get('PAYU_WAITING_PAYMENT'));
                         }
                     } else {
                         if ($statePol == 4) {
                             if ($order->getCurrentState() != (int) Configuration::get('PS_OS_PAYMENT')) {
                                 $order->setCurrentState((int) Configuration::get('PS_OS_PAYMENT'));
                             }
                         } else {
                             if ($order->getCurrentState() != (int) Configuration::get('PS_OS_ERROR')) {
                                 $order->setCurrentState((int) Configuration::get('PS_OS_ERROR'));
                             }
                             Logger::AddLog('[PayU] (payulatam) The shopping card ' . (int) $idCart . ' has been rejected by PayU state pol=' . (int) $statePol, 2, null, null, null, true);
                         }
                     }
                 } else {
                     Logger::AddLog('[PayU] The shopping card ' . (int) $idCart . ' has an incorrect token given from payU during payment validation.' . $keysPayu['apiKey'] . '~' . Tools::safeOutput($keysPayu['merchantId']) . '~payU_' . Configuration::get('PS_SHOP_NAME') . '_' . (int) $this->context->cart->id . '~' . number_format((double) $total_order, 2, '.', '') . '~' . $currency->iso_code . '~' . $statePol . "--" . number_format((double) $total_order, 1, '.', '') . "--" . $token, 2, null, null, null, true);
                 }
             }
             if (_PS_VERSION_ >= 1.5) {
                 $payment = $order->getOrderPaymentCollection();
                 if (isset($payment[0])) {
                     $payment[0]->transaction_id = pSQL("payU_" . md5(Configuration::get('PS_SHOP_NAME')) . "_" . $idCart);
                     $payment[0]->save();
                 }
             }
         }
     } else {
         Logger::AddLog('[PayU] The shopping card ' . (int) $idCart . ' was not found during the payment validation step', 2, null, null, null, true);
     }
 }
 public function initOrderingContent()
 {
     // list order id by created providers
     $supply_order_created = array();
     $this->show_toolbar = true;
     $this->display = 'ordering';
     if ($this->is_1_6) {
         $this->initPageHeaderToolbar();
     }
     $this->initToolbar();
     $datas = $this->getDataGeneration();
     if (!empty($datas['data_return'])) {
         //get default currencie
         $id_default_currency = Configuration::get('PS_CURRENCY_DEFAULT');
         // get default id lang
         $id_default_lang = Configuration::get('PS_LANG_DEFAULT');
         foreach ($datas['data_return'] as $id_supplier => $products_info) {
             // Get provider datas
             $supplier = new Supplier((int) $id_supplier);
             // get warehouse datas, delivery date and tax for the provider order
             $id_warehouse_data = Tools::getValue('id_warehouse');
             $date_delivery_expected_data = Tools::getValue('date_delivery_expected');
             $tax_rate_data = Tools::getValue('tax_rate');
             $tax_rate_data = $tax_rate_data[$id_supplier];
             // id warehouse
             $id_warehouse = $id_warehouse_data[$id_supplier];
             // delivery date
             $date_delivery_expected = $date_delivery_expected_data[$id_supplier];
             // create the provider order
             $supply_order = new SupplyOrder();
             $supply_order->reference = ErpSupplyOrderClasses::getNextSupplyOrderReference();
             $supply_order->id_supplier = $id_supplier;
             $supply_order->supplier_name = $supplier->name;
             $supply_order->id_warehouse = $id_warehouse;
             $supply_order->id_currency = $id_default_currency;
             $supply_order->id_lang = $id_default_lang;
             $supply_order->id_supply_order_state = 1;
             $supply_order->id_ref_currency = (int) Currency::getDefaultCurrency()->id;
             $supply_order->date_delivery_expected = $date_delivery_expected;
             // if recording is ok, create the order lines
             if ($supply_order->add()) {
                 // get the provider id order
                 $id_supply_order = $this->getLastIdSupplyOrder();
                 $supply_order_created[] = $id_supply_order;
                 // Ajout de son historique
                 // add historical
                 $history = new SupplyOrderHistory();
                 $history->id_supply_order = $id_supply_order;
                 $history->id_state = 3;
                 $history->id_employee = (int) $this->context->employee->id;
                 $history->employee_firstname = pSQL($this->context->employee->firstname);
                 $history->employee_lastname = pSQL($this->context->employee->lastname);
                 $history->save();
                 // Create entries for provider order
                 if (!empty($products_info)) {
                     $i = 0;
                     foreach ($products_info as $item) {
                         if (!isset($item['product_id'])) {
                             continue;
                         }
                         $supply_order_detail = new SupplyOrderDetail();
                         $supply_order_detail->id_supply_order = $id_supply_order;
                         $supply_order_detail->id_currency = (int) Currency::getDefaultCurrency()->id;
                         $supply_order_detail->id_product = $item['product_id'];
                         $supply_order_detail->id_product_attribute = $item['product_attribute_id'];
                         $supply_order_detail->reference = $item['product_reference'];
                         $supply_order_detail->supplier_reference = $item['product_supplier_reference'];
                         $supply_order_detail->name = $item['product_name'];
                         $supply_order_detail->ean13 = $item['product_ean13'];
                         $supply_order_detail->upc = $item['product_upc'];
                         $supply_order_detail->quantity_expected = $item['total_product_quantity'];
                         $supply_order_detail->exchange_rate = 1;
                         $supply_order_detail->unit_price_te = $item['unit_price_tax_excl'];
                         $supply_order_detail->tax_rate = $tax_rate_data[$i];
                         $supply_order_detail->save();
                         // Get the supply order created
                         $id_supply_order_detail = $this->getLastIdSupplyOrderDetail();
                         // Record the relation between provider order and customer order
                         if (!empty($item)) {
                             foreach ($item['concerned_id_order_detail'] as $customer_link) {
                                 $supply_order_customer = new ErpSupplyOrderCustomer();
                                 $supply_order_customer->id_customer = $customer_link['id_customer'];
                                 $supply_order_customer->id_order_detail = $customer_link['id_order_detail'];
                                 $supply_order_customer->id_supply_order_detail = $id_supply_order_detail;
                                 $supply_order_customer->id_supply_order = $id_supply_order;
                                 $supply_order_customer->save();
                             }
                         }
                         $i++;
                     }
                     // Rerecording provider order data to update totals
                     $supply_order->save();
                 }
             }
         }
         // update provider order status
         if (!empty($datas['order_to_change_state'])) {
             foreach ($datas['order_to_change_state'] as $id_order) {
                 $order_change_state = new Order((int) $id_order);
                 $order_change_state->setCurrentState($this->generate_order_state_to, (int) $this->context->employee->id);
             }
         }
         $this->confirmations[] = $this->l('Order saved successfully !');
         // remove treated order in cookies
         $this->context->cookie->__unset('unselected_orders');
     } else {
         $this->errors[] = Tools::displayError($this->l('No data available for ordering ! You must select at least one order.'));
     }
     $this->context->smarty->assign(array('content' => '', 'show_toolbar ' => 'true', 'show_toolbar' => true, 'toolbar_btn' => $this->toolbar_btn, 'title' => $this->l('Supply Order : order screen'), 'toolbar_scroll' => $this->toolbar_scroll, 'token' => $this->token, 'url_post' => self::$currentIndex . '&token=' . $this->token, 'supply_order_created' => !empty($supply_order_created) ? implode(',', $supply_order_created) : ''));
     $this->createTemplate('ordering.tpl');
     $this->template = 'ordering.tpl';
 }
 /**
  * Setup the smarty variables for the confirmation form. Also if the form
  * is submitted do the desired actions (close token, order etc.)
  *
  * @return array (if not redirected)
  */
 public function paymentConfirmation($token)
 {
     $this->_checkBeforeSend();
     $tokenRow = $this->_canUseToken((int) $token);
     if (empty($token) || !$tokenRow) {
         $this->_redirectToCardForm();
     }
     // check to see if some details on cart have changed in the meanwhile
     if ($amountOfCartHasChanged = $this->_tokenDetailsHaveChanged($tokenRow)) {
         $updateAmountOnCart = $this->_updateDetailsOfToken($token);
         if ($updateAmountOnCart) {
             Tools::redirect(Context::getContext()->link->getModuleLink($this->name, 'confirm', array('token' => $token, 'msg' => 410), true));
         } else {
             $this->_redirectToCardForm();
         }
     }
     $cart = Context::getContext()->cart;
     $customer = new Customer($cart->id_customer);
     $currency = new Currency($cart->id_currency);
     $params = array('amountInteger' => (int) Tools::ps_round($cart->getOrderTotal() * 100), 'amount' => (double) $cart->getOrderTotal(), 'form_action' => Context::getContext()->link->getModuleLink($this->name, 'confirm', array('token' => $token), true), 'cart' => $cart, 'customer' => $customer, 'tokenRow' => $tokenRow);
     if (1 || Tools::isSubmit('submitConfirm')) {
         //Set the API key
         try {
             Everypay\Everypay::setApiKey($this->sk);
         } catch (Exception $e) {
             $params['message'] = $e->getMessage();
             $params['status'] = self::ERRORNEOUS;
             $this->_closeToken($params);
             Tools::redirect(Context::getContext()->link->getPageLink('order', true, NULL, "step=3"));
         }
         $evPayParams = array('token' => $tokenRow['crd_token'], 'currency' => strtoupper($currency->iso_code));
         if (!empty($tokenRow['save_customer']) && $this->configuration['EVERYPAY_CUSTOMER_MODE'] && !empty($tokenRow['crd_token'])) {
             $evPayParams = array_merge($evPayParams, array('create_customer' => 1));
             $evCusUpdateParams = array('full_name' => $customer->firstname . ' ' . $customer->lastname, 'description' => Context::getContext()->shop->name . ' - ' . $this->l('Customer') . '#' . $customer->id, 'email' => $customer->email);
         } elseif (!empty($tokenRow['save_customer']) && !$this->configuration['EVERYPAY_CUSTOMER_MODE'] && !empty($tokenRow['crd_token'])) {
             $params['message'] = $this->l('The save card option got disabled during a payment proccess');
             $params['status'] = self::ERRORNEOUS;
             $this->_closeToken($params);
             $this->_redirectToCardForm();
         } elseif (!is_null($tokenRow['id_customer_token']) && !empty($tokenRow['cus_token']) && $this->configuration['EVERYPAY_CUSTOMER_MODE']) {
             $evPayParams['token'] = $tokenRow['cus_token'];
         } elseif (!is_null($tokenRow['id_customer_token']) && !empty($tokenRow['cus_token']) && !$this->configuration['EVERYPAY_CUSTOMER_MODE']) {
             $params['message'] = $this->l('The save card option got disabled during a payment proccess');
             $params['status'] = self::ERRORNEOUS;
             $this->_closeToken($params);
             $this->_redirectToCardForm();
         }
         try {
             $evPayParams = array_merge($evPayParams, array('payee_email' => $customer->email, 'amount' => $params['amountInteger'], 'description' => Context::getContext()->shop->name . ' - ' . $this->l('Cart') . ' #' . $cart->id . ' - ' . Tools::displayPrice($cart->getOrderTotal()), 'capture' => 0));
             $evPayment = Everypay\Payment::create($evPayParams);
             //now update the customer if necessary
             if (isset($evCusUpdateParams) && isset($evPayment->customer->token)) {
                 try {
                     $evCustomer = Everypay\Customer::update($evPayment->customer->token, $evCusUpdateParams);
                     $evPayParams['token'] = $evCustomer->token;
                 } catch (Exception $e) {
                     //we didnt manage to update the customer details
                     // no big deal
                 }
             }
             //error with the payment
             if (isset($evPayment->error)) {
                 $params['message'] = $evPayment->error->message;
                 $params['status'] = self::ERRORNEOUS;
                 $this->_closeToken($params);
                 $this->_redirectToCardForm(415);
                 exit;
             }
         } catch (Exception $e) {
             $params['message'] = $e->getMessage();
             $params['status'] = self::ERRORNEOUS;
             $this->_closeToken($params);
             $this->_redirectToCardForm(415);
             exit;
         }
         $mailVars = array();
         $validateOrder = $this->validateOrder($cart->id, self::ORDER_STATUS_CAPTURE_PENDING, $params['amount'], $this->displayName, NULL, $mailVars, $params['cart']->id_currency, false, $params['customer']->secure_key);
         if ($validateOrder) {
             $params['id_order'] = $this->currentOrder;
             $params['status'] = self::SUCCESS;
             $params['pmt_token'] = $evPayment->token;
             $params['message'] = 'Success on ' . date('d/m/Y H:i:s');
             if (!is_null($tokenRow['save_customer']) && $this->configuration['EVERYPAY_CUSTOMER_MODE']) {
                 $id_customer_token = $this->_insertCardCustomer($evPayment->customer);
                 if ($id_customer_token) {
                     $params['id_customer_token'] = $id_customer_token;
                 }
             }
             $_closeToken = $this->_closeToken($params);
             $order = new Order((int) $this->currentOrder);
             //capture or die
             try {
                 $evCapture = Everypay\Payment::capture($evPayment->token);
                 $order->setCurrentState(Configuration::get('PS_OS_PAYMENT'));
                 $redirect = array('controller=order-confirmation', 'id_cart=' . (int) $params['cart']->id, 'id_module=' . (int) $this->id, 'id_order=' . (int) $this->currentOrder, 'key=' . $order->secure_key);
                 Tools::redirect('index.php?' . implode('&', $redirect));
             } catch (Exception $e) {
                 $this->_redirectToCardForm();
             }
         } else {
             try {
                 $evRefund = Everypay\Payment::refund($evPayment->token);
             } catch (Exception $e) {
                 //do nothing
             }
             $this->_redirectToCardForm();
         }
     }
     $this->context->smarty->assign($params);
     return $params;
 }
Ejemplo n.º 10
0
 protected function processOrderStateChange($new_order_state, array $payload, \Payin7\Models\OrderModel $order, &$message, &$code)
 {
     $ret = true;
     $message = null;
     $code = null;
     switch ($new_order_state) {
         case 'cancel':
             /** @var OrderCore $orderm */
             /** @noinspection PhpUndefinedClassInspection */
             $orderm = new Order($order->getOrderId());
             if (ValidateCore::isLoadedObject($orderm)) {
                 $state = $orderm->current_state;
                 if ($state == $this->module->getConfigIdOrderStatePending()) {
                     // temporarily disable updating history back to Payin7
                     $this->module->setHistoryUpdateEnabled(false);
                     $orderm->setCurrentState($this->module->getConfigIdOrderStateCancelled());
                     // reenable history
                     $this->module->setHistoryUpdateEnabled(true);
                     $message = 'Local order state set to (1): ' . $this->module->getConfigIdOrderStateCancelled();
                 }
             } else {
                 $message = 'Local order could not be loaded (2)';
                 $ret = false;
             }
             break;
         case 'active':
             $is_verified = isset($payload['is_verified']) ? (bool) $payload['is_verified'] : false;
             $is_paid = isset($payload['is_paid']) ? (bool) $payload['is_paid'] : false;
             // update the order state
             if (!$order->getPayin7OrderAccepted()) {
                 $order->setPayin7OrderAccepted(true);
                 $order->savePayin7Data();
             }
             if ($is_verified && $is_paid) {
                 /** @var OrderCore $orderm */
                 /** @noinspection PhpUndefinedClassInspection */
                 $orderm = new Order($order->getOrderId());
                 $state = $orderm->current_state;
                 if ($state == $this->module->getConfigIdOrderStatePending()) {
                     // temporarily disable updating history back to Payin7
                     $this->module->setHistoryUpdateEnabled(false);
                     $orderm->setCurrentState($this->module->getConfigIdOrderStateAccepted());
                     // reenable history
                     $this->module->setHistoryUpdateEnabled(true);
                     $message = 'Local order state set to (2): ' . $this->module->getConfigIdOrderStateAccepted();
                 }
             } else {
                 $message = 'Order not verified / paid';
                 $ret = false;
             }
             break;
     }
     return $ret;
 }
Ejemplo n.º 11
0
 public function hookAdminOrder($params)
 {
     $order = new Order((int) $params['id_order']);
     $msg = null;
     if ($this->name != $order->module) {
         return;
     }
     $cart = new Cart($order->id_cart);
     $currency = new Currency($order->id_currency);
     if (Tools::isSubmit('submitMasterPaymentRefund')) {
         $amount = (double) Tools::getValue('amount', 0);
         if ($amount > 0 && $amount <= $order->total_paid) {
             require_once dirname(__FILE__) . '/lib/api.php';
             $api = new MasterPaymentApi();
             $api->merchantName = Configuration::get('MP_MERCHANT_NAME');
             $api->secretKey = Configuration::get('MP_SECRET_KEY');
             $api->basketValue = $amount * 100;
             $api->txId = self::encodeTxID($cart);
             $comment = Tools::getValue('comment', '');
             $status = $api->refundRequest($comment);
             if ($status == MasterPaymentApi::STATUS_REFUNDED) {
                 // Update order state
                 $order->setCurrentState(Configuration::get('PS_OS_REFUND'), $this->context->employee->id);
                 // Add refund amount message
                 $msg = new Message();
                 $msg->message = $comment . ' - ' . $this->l('Refund amount') . ': ' . Tools::displayPrice($amount, $currency);
                 $msg->id_order = $order->id;
                 $msg->id_customer = $cart->id_customer;
                 $msg->private = true;
                 $msg->add();
                 // Redirect to order
                 Tools::redirectAdmin('#');
             } else {
                 $msg = '<p class="error">' . $comment . '</p>';
             }
         } else {
             $msg = '<p class="error">' . $this->l('Ivalid amount') . '</p>';
         }
     }
     $this->tplAssign('msg', $msg);
     $this->tplAssign('order', $order);
     $this->tplAssign('amount', Tools::ps_round($order->total_paid, 2));
     $this->tplAssign('currency', $currency);
     $this->_html .= $this->tplDisplay('adminOrder');
     return $this->_html;
 }
Ejemplo n.º 12
0
 /**
  * @param ShopgateOrder $order
  *
  * @return array
  * @throws ShopgateLibraryException
  */
 public function updateOrder(ShopgateOrder $order)
 {
     $paymentModel = new ShopgatePayment($this->getModule());
     $shopgateOrderItem = ShopgateOrderPrestashop::loadByOrderNumber($order->getOrderNumber());
     if (!Validate::isLoadedObject($shopgateOrderItem)) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_ORDER_NOT_FOUND, 'Order not found #' . $order->getOrderNumber(), true);
     }
     /** @var OrderCore $coreOrder */
     $coreOrder = new Order($shopgateOrderItem->id_order);
     /**
      * get order states
      */
     $changedStates = $paymentModel->getOrderStateId($order, false);
     /**
      * apply changed states
      */
     foreach ($changedStates as $changedState) {
         $coreOrder->setCurrentState($changedState);
     }
     $shopgateOrderItem->updateFromOrder($order);
     $shopgateOrderItem->save();
     return array('external_order_id' => $shopgateOrderItem->id_order, 'external_order_number' => $shopgateOrderItem->id_order);
 }
Ejemplo n.º 13
0
 public function updatePendyngOrdesConfirmation()
 {
     $orders_pendyng = $this->getPendyngOrdesConfirmation();
     foreach ($orders_pendyng as $key) {
         $order = new Order((int) $key['id_order']);
         $statePol = $this->getStatePolBymessagePol($key['message']);
         if ($statePol == 7) {
             if ($order->getCurrentState() != (int) Configuration::get('PAYU_OS_PENDING')) {
                 $order->setCurrentState((int) Configuration::get('PAYU_OS_PENDING'));
             }
         } else {
             if ($statePol == 4) {
                 if ($order->getCurrentState() != (int) Configuration::get('PS_OS_PAYMENT')) {
                     $order->setCurrentState((int) Configuration::get('PS_OS_PAYMENT'));
                 }
             } else {
                 if ($order->getCurrentState() != (int) Configuration::get('PS_OS_ERROR')) {
                     $order->setCurrentState((int) Configuration::get('PS_OS_ERROR'));
                 }
             }
         }
         if (_PS_VERSION_ >= 1.5) {
             $payment = $order->getOrderPaymentCollection();
             if (isset($payment[0])) {
                 $payment[0]->transaction_id = pSQL("payU_farmalisto_" . $key['id_cart']);
                 $payment[0]->save();
             }
         }
         echo '<br>Order: ' . $key['id_order'];
     }
 }
Ejemplo n.º 14
0
 public function changeOrderStateByInvipayPaymentId($paymentData)
 {
     $inviPayPaymentId = $paymentData->getPaymentId();
     $inviPayStatus = $paymentData->getStatus();
     $request = new InvipayPaymentRequest(InvipayPaymentRequest::getIdByPaymentId($inviPayPaymentId));
     $request->payment_status = $inviPayStatus;
     $request->save();
     $config = $this->loadConfiguration();
     Context::getContext()->controller->module->displayName = $config['PAYMENT_METHOD_TITLE'];
     $order = new Order($request->id_order);
     $order->setCurrentState(Configuration::get(constant('InvipaypaygateHelper::ORDER_STATUS_PAYMENT_' . $inviPayStatus)));
     $order->save();
 }
 public function ajaxProcessPayOrder()
 {
     $id_order = Tools::getValue('id_order');
     $order = new Order($id_order);
     $id_order_detail = Tools::getValue('id_order_detail');
     $order_detail = new AphOrderDetail($id_order_detail);
     $order_detail->id_order = $id_order;
     $order_detail->product_quantity = 0;
     $res = $order_detail->update();
     $order_payment = new OrderPayment();
     $order_payment->order_reference = $order->reference;
     $order_payment->id_currency = (int) Context::getContext()->currency->id;
     $order_payment->amount = $products_total_price;
     $order_payment->payment_method = $order->payment;
     $order_payment->conversion_rate = $order->conversion_rate;
     $order_payment->add();
     $order_details = AphOrderDetail::getList($id_order);
     if ($res && !empty($order_details) && is_array($order_details)) {
         $empty_detail = 0;
         foreach ($order_details as &$order_detail) {
             if ((int) $order_detail['product_quantity'] < 1) {
                 $empty_detail++;
             }
         }
         if ($empty_detail == sizeof($order_details)) {
             $order = new Order($id_order);
             $order->setCurrentState(Configuration::get('APH_RESERVATION_DELETED_STATUS'), (int) Context::getContext()->employee->id);
         }
     }
     die(Tools::jsonEncode(array('result' => $res)));
 }