예제 #1
0
 function plgVmOnCancelPayment($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;
     }
     // Status code is === 3==> active invoice. Cannot be be deleted
     // the invoice is active
     //if ($order->order_status == $method->status_success) {
     if ($invNo = $this->_getKlarnaInvoiceNo($payments)) {
         //vmDebug('order',$order);return;
         $country = $this->getCountryCodeByOrderId($order->virtuemart_order_id);
         $klarna = new Klarna_virtuemart();
         $cData = KlarnaHandler::countryData($method, $country);
         $mode = KlarnaHandler::getKlarnaMode($method);
         $klarna->config($cData['eid'], $cData['secret'], $cData['country_code'], NULL, $cData['currency_code'], $mode);
         try {
             //remove a passive invoice from Klarna.
             $result = $klarna->deleteInvoice($invNo);
             if ($result) {
                 $message = Jtext::_('VMPAYMENT_KLARNA_INVOICE_DELETED', $invNo);
             } else {
                 $message = Jtext::_('VMPAYMENT_KLARNA_INVOICE_NOT_DELETED', $invNo);
             }
             $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'] = 0;
             // it has been deleted
             $dbValues['klarna_pdf_invoice'] = 0;
             // it has been deleted
             $dbValues['klarna_log'] = $message;
             $dbValues['klarna_eid'] = $cData['eid'];
             $this->storePSPluginInternalData($dbValues);
             VmInfo($message);
         } catch (Exception $e) {
             $log = $e->getMessage() . " (#" . $e->getCode() . ")";
             $this->_updateKlarnaInternalData($order, $log, $invNo);
             VmError($e->getMessage() . " (#" . $e->getCode() . ")");
             if ($e->getCode() == '8113') {
                 VmError('invoice_not_passive');
             }
             return false;
         }
     }
     return true;
 }