Example #1
0
 /**
  * Save updated order data to the method specific table
  *
  * @param array $order Form data
  * @return mixed, True on success, false on failures (the rest of the save-process will be
  * skipped!), or null when this method is not actived.
  */
 public function plgVmOnUpdateOrderPayment(&$order, $old_order_status)
 {
     if (!$this->selectedThisByMethodId($order->virtuemart_paymentmethod_id)) {
         return NULL;
         // Another method was selected, do nothing
     }
     if (!($method = $this->getVmPluginMethod($order->virtuemart_paymentmethod_id))) {
         return NULL;
         // Another method was selected, do nothing
     }
     if (!($payments = $this->_getKlarnaInternalData($order->virtuemart_order_id))) {
         vmError(JText::sprintf('VMPAYMENT_KLARNA_ERROR_NO_DATA', $order->virtuemart_order_id));
         return NULL;
     }
     if (!($invNo = $this->_getKlarnaInvoiceNo($payments))) {
         return NULL;
     }
     // to actiavte the order
     if ($order->order_status == $method->status_shipped) {
         $country = $this->getCountryCodeByOrderId($order->virtuemart_order_id);
         $klarna = new Klarna_virtuemart();
         $cData = KlarnaHandler::countryData($method, $country);
         /*
          * The activateInvoice function is used to activate a passive invoice.
          * Please note that this function call cannot activate an invoice created in test mode.
          * It is however possible to manually activate that type of invoices.
          */
         $mode = KlarnaHandler::getKlarnaMode($method);
         $klarna->config($cData['eid'], $cData['secret'], $cData['country_code'], NULL, $cData['currency_code'], $mode);
         try {
             //You can specify a new pclass ID if the customer wanted to change it before you activate.
             $invoice_url = $klarna->activateInvoice($invNo);
             $this->copyInvoice($invoice_url, $vm_invoice_name);
             $dbValues['order_number'] = $order->order_number;
             $dbValues['virtuemart_order_id'] = $order->virtuemart_order_id;
             $dbValues['virtuemart_paymentmethod_id'] = $order->virtuemart_paymentmethod_id;
             $dbValues['klarna_invoice_no'] = $invNo;
             $dbValues['klarna_log'] = Jtext::_('VMPAYMENT_KLARNA_ACTIVATE_INVOICE', $invNo);
             $dbValues['klarna_eid'] = $cData['eid'];
             //$dbValues['klarna_status_code'] = KLARNA_INVOICE_ACTIVE; // Invoice is active
             //$dbValues['klarna_status_text'] = '';
             $dbValues['klarna_pdf_invoice'] = $vm_invoice_name;
             $this->storePSPluginInternalData($dbValues);
             //The url points to a PDF file for the invoice.
             //Invoice activated, proceed accordingly.
         } catch (Exception $e) {
             $log = $e->getMessage() . " (#" . $e->getCode() . ")";
             $this->_updateKlarnaInternalData($order, $log);
             VmError($e->getMessage() . " (#" . $e->getCode() . ")");
             return false;
         }
         return true;
     }
     return NULL;
 }