Exemplo n.º 1
0
 function checkOrderStatus()
 {
     if (!class_exists('VirtueMartModelOrders')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php';
     }
     $payment_methodid = JRequest::getInt('payment_methodid');
     $invNo = JRequest::getInt('invNo');
     $orderNumber = JRequest::getString('order_number');
     $orderPass = JRequest::getString('order_pass');
     if (!($method = $this->getVmPluginMethod($payment_methodid))) {
         return NULL;
         // Another method was selected, do nothing
     }
     $modelOrder = VmModel::getModel('orders');
     // If the user is not logged in, we will check the order number and order pass
     $orderId = $modelOrder->getOrderIdByOrderPass($orderNumber, $orderPass);
     if (empty($orderId)) {
         VmError('Invalid order_number/password ' . JText::_('COM_VIRTUEMART_RESTRICTED_ACCESS'));
         return 0;
     }
     $country = $this->getCountryCodeByOrderID($orderId);
     $settings = KlarnaHandler::countryData($method, $country);
     $mode = KlarnaHandler::getKlarnaMode($method);
     $klarna_order_status = KlarnaHandler::checkOrderStatus($settings, $mode, $invNo);
     if ($klarna_order_status == KlarnaFlags::ACCEPTED) {
         /* if Klarna's order status is pending: add it in the history */
         /* The order is under manual review and will be accepted or denied at a later stage.
         		 Use cronjob with checkOrderStatus() or visit Klarna Online to check to see if the status has changed.
         		 You should still show it to the customer as it was accepted, to avoid further attempts to fraud. */
         $order['order_status'] = $method->status_success;
         $order['comments'] = JText::_('VMPAYMENT_KLARNA_PAYMENT_ACCEPTED');
         $order['customer_notified'] = 0;
         $dbValues['klarna_log'] = JText::_('VMPAYMENT_KLARNA_PAYMENT_ACCEPTED');
     } elseif ($klarna_order_status == KlarnaFlags::DENIED) {
         $order['order_status'] = $method->status_canceled;
         $order['customer_notified'] = 0;
         $dbValues['klarna_log'] = JText::_('VMPAYMENT_KLARNA_PAYMENT_NOT_ACCEPTED');
     } else {
         $dbValues['klarna_log'] = $klarna_order_status;
         $order['comments'] = $klarna_order_status;
         $order['customer_notified'] = 0;
     }
     $dbValues['order_number'] = $orderNumber;
     $dbValues['virtuemart_order_id'] = $orderId;
     $dbValues['virtuemart_paymentmethod_id'] = $payment_methodid;
     $dbValues['klarna_invoice_no'] = $invNo;
     $this->storePSPluginInternalData($dbValues);
     $modelOrder->updateStatusForOneOrder($orderId, $order, true);
     $app = JFactory::getApplication();
     $app->redirect('index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id=' . $orderId);
     // 	jexit();
 }