/** * 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; }
/** * Return pclasses stored in json file. */ public static function getPClasses($type = NULL, $mode, $settings) { //$settings = self::countryData($method, $country); try { $klarna = new Klarna_virtuemart(); $klarna->config($settings['eid'], $settings['secret'], $settings['country'], $settings['language'], $settings['currency'], $mode, VMKLARNA_PC_TYPE, KlarnaHandler::getKlarna_pc_type(), TRUE); return $klarna->getPClasses($type); } catch (Exception $e) { } }
$total = 0; if (!class_exists('VmModel')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'vmmodel.php'; } $model = VmModel::getModel('paymentmethod'); $payment = $model->getPayment(); if (!class_exists('vmParameters')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'parameterparser.php'; } $parameters = new vmParameters($payment, $payment->payment_element, 'plugin', 'vmpayment'); $data = $parameters->getParamByName('data'); //vmdebug('pclasses',$data); $eid_array = KlarnaHandler::getEidSecretArray($data); foreach ($eid_array as $country => $eid_data) { try { $klarna = new Klarna_virtuemart(); $klarna->config($eid_data['eid'], $eid_data['secret'], null, null, null, $data->klarna_mode, VMKLARNA_PC_TYPE, KlarnaHandler::getKlarna_pc_type(), $data->klarna_mode == 'klarna_live'); $klarna->setCountry($country); $pclasses = $klarna->getPClasses(); $total = $total + count($pclasses); if (!count($pclasses) == 0) { ?> <table class="klarna_pclasses"> <thead class="klarna_pclasses_header"> <td class="pclass_id"><?php echo JText::_('VMPAYMENT_KLARNA_PCLASS_ID'); ?> </td> <td class="pclass_description"><?php echo JText::_('VMPAYMENT_KLARNA_PCLASS_DESCRIPTION'); ?>
/** * */ function cancelReservation($order, $payments) { $rno = $this->getReservationNumber($payments); if (!$rno) { return; // error already sent } $this->initKlarnaParams($this->method); $klarna = new Klarna_virtuemart(); $klarna->config($this->merchantid, $this->sharedsecret, $this->country_code_3, NULL, $this->currency_code_3, $this->mode, VMKLARNA_PC_TYPE, KlarnaHandler::getKlarna_pc_type(), $this->ssl); $modelOrder = VmModel::getModel('orders'); try { $result = $klarna->cancelReservation($rno); $info = vmText::sprintf('VMPAYMENT_KLARNACHECKOUT_RESERVATION_CANCELED', $rno); VmInfo($info); $history = array(); $history['customer_notified'] = 1; //$history['order_status'] = $this->method->checkout_complete; $history['comments'] = $info; // $order['details']['BT']->order_number); $modelOrder->updateStatusForOneOrder($order->virtuemart_paymentmethod_id, $history, TRUE); $dbValues['order_number'] = $payments[0]->order_number; $dbValues['payment_name'] = ''; $dbValues['virtuemart_paymentmethod_id'] = $payments[0]->virtuemart_paymentmethod_id; $dbValues['action'] = 'cancelReservation'; $dbValues['klarna_status'] = 'cancelReservation'; $dbValues['data'] = $info; $this->debugLog($dbValues, 'storePSPluginInternalData cancelReservation', 'debug'); $values = $this->storePSPluginInternalData($dbValues, $this->_tablepkey); } catch (Exception $e) { $error = $e->getMessage(); VmError($e->getMessage(), vmText::sprintf('VMPAYMENT_KLARNACHECKOUT_ERROR_OCCURRED', $this->method->payment_name)); $this->debugLog($e->getMessage(), 'cancelReservation', 'error'); return FALSE; } //$dbValues['data'] = $vm_invoice_name; return true; }
/** * */ function cancelReservation($order, $payments) { $rno = $this->getReservationNumber($payments); if (!$rno) { return; // error already sent } $klarna = new Klarna_virtuemart(); $klarna->config($this->_currentMethod->merchantid, $this->_currentMethod->sharedsecret, $this->country_code_3, NULL, $this->currency_code_3, $this->mode, VMKLARNA_PC_TYPE, KlarnaHandler::getKlarna_pc_type(), $this->ssl); $modelOrder = tmsModel::getModel('orders'); try { $result = $klarna->cancelReservation($rno); $info = tsmText::sprintf('VMPAYMENT_KLARNACHECKOUT_RESERVATION_CANCELED', $rno); VmInfo($info); $history = array(); $history['customer_notified'] = 1; //$history['order_status'] = $this->_currentMethod->checkout_complete; $history['comments'] = $info; // $order['details']['BT']->order_number); $modelOrder->updateStatusForOneOrder($order->virtuemart_order_id, $history, TRUE); } catch (Exception $e) { $error = $e->getMessage(); $this->KlarnacheckoutError($e->getMessage(), tsmText::sprintf('VMPAYMENT_KLARNACHECKOUT_ERROR_OCCURRED', $this->_currentMethod->payment_name)); return FALSE; } //$dbValues['data'] = $vm_invoice_name; return $result; }