function piKlarnaCheckPendingOrders(){ $piKlarnaPendingId=piKlarnaGetPendingStatusId(); $sql = "SELECT transactionID, ordernumber FROM s_order WHERE cleared = ?"; $piKlarnaPendingOrders = Shopware()->Db()->fetchAll($sql, array((int)$piKlarnaPendingId)); $cleared = $piKlarnaPendingId; for ($i = 0; $i < sizeof($piKlarnaPendingOrders); $i++) { try { $k = piKlarnaCreateKlarnaInstance($piKlarnaPendingOrders[$i]['ordernumber']); $result = $k->checkOrderStatus($piKlarnaPendingOrders[$i]['transactionID'],0); if ($result == KlarnaFlags::ACCEPTED) { $cleared=piKlarnaGetAcceptedStatusId(); } else if ($result == KlarnaFlags::DENIED) { $cleared=piKlarnaGetDeclinedStatusId(); } // otherwise use the default value $sql = "UPDATE s_order SET cleared = ? WHERE transactionID = ?"; Shopware()->Db()->query($sql, array((int)$cleared,$piKlarnaPendingOrders[$i]['transactionID'])); } catch (Exception $e) { $cleared=piKlarnaGetDeclinedStatusId(); $sql = "UPDATE s_order SET cleared = ? WHERE transactionID = ?"; Shopware()->Db()->query($sql, array((int)$cleared,$piKlarnaPendingOrders[$i]['transactionID'])); } } }
/** * add rates to Productlistings * * @param Enlight_Event_EventArgs $piKlarnaArgs */ public static function piKlarnaOnPostDispatchListing(Enlight_Event_EventArgs $piKlarnaArgs) { $piKlarnaConfig = array(); Shopware()->Template()->addTemplateDir(dirname(__FILE__) . '/Views/Frontend/'); $piKlarnaConfig = Shopware()->Plugins()->Frontend()->PigmbhKlarnaPayment()->Config(); $klarnaShopLang = checkKlarnaCountryCurrencys(); if ($klarnaShopLang == 'de') $klarnaShopLang = Shopware()->Locale()->getLanguage(); if ($piKlarnaConfig->pi_klarna_rate_listing && $piKlarnaConfig->pi_klarna_active && checkKlarnaCountrys($klarnaShopLang)) { $piKlarnaArticlePrice = array(); $piKlarnaView = $piKlarnaArgs->getSubject()->View(); $piKlarnaView->KlarnaJS = true; if (sizeof($piKlarnaView->sArticles) > 0) { $piKlarnaView->piKlarnaArticles = true; foreach($piKlarnaView->sArticles as $key => $article) { $piKlarnaArticlePrice[$key] = str_replace(",", ".", $article['price']); } } else { $piKlarnaArticlePrice[0] = 0; $piKlarnaView->piKlarnaOffers = true; foreach($piKlarnaView->sOffers as $key => $article) { $piKlarnaArticlePrice[$key] = str_replace(",", ".", $article['price']); } } $counter = array(); $pi_klarna_value = array(); //for ($i = 0; $i < sizeof($piKlarnaArticlePrice); $i++) { $i = 0; foreach($piKlarnaArticlePrice as $key=>$price) { if($price){ $k = piKlarnaCreateKlarnaInstance(); $k->setCountry($klarnaShopLang); if ($k->getCheapestPClass($price, KlarnaFlags::PRODUCT_PAGE)){ $pi_klarna_value[$key] = number_format(KlarnaCalc::calc_monthly_cost($piKlarnaArticlePrice[$key], $k->getCheapestPClass($piKlarnaArticlePrice[$key], KlarnaFlags::PRODUCT_PAGE), KlarnaFlags::PRODUCT_PAGE), 2, ',', '.'); } $counter[$key] = $key; } $i++; } $piKlarnaView->pi_klarna_counter = $counter; $piKlarnaView->pi_klarna_rate = $pi_klarna_value; $piKlarnaView->pi_klarna_sum = $piKlarnaView->extendsTemplate('listing/box_article.tpl'); } }
/** * Advises Klarna to send the invoice per post to the customer. * * @see templates/backend/plugins/PigmbhKlarnaPayment/index.php * @throws KlarnaException */ public function sendInvoicePostAction() { $this->View()->setTemplate(); $piKlarnaOrderNumber = $this->Request()->ordernumber; $piKlarnaInvoice = $this->Request()->invoice; $result= array(); $k = piKlarnaCreateKlarnaInstance($piKlarnaOrderNumber); try { $result = $k->sendInvoice($piKlarnaInvoice); } catch (Exception $e) { echo $e->getMessage() . " (#" . $e->getCode() . ")"; } echo json_encode(array("total" => count($result), "items" => $result)); }
/** Customer cancels reservation * * @param Enlight_Event_EventArgs $piKlarnaArgs * @return void */ public function stornoOrderAction(Enlight_Event_EventArgs $piKlarnaArgs) { $piKlarnaUrl = $_SERVER['PHP_SELF']; $substr = substr( $piKlarnaUrl, strlen('Pi_Klarna,') + strpos($piKlarnaUrl, 'Pi_Klarna,'), (strlen($piKlarnaUrl) - strpos($piKlarnaUrl, '15719816655')) * (-1) ); $sql = "SELECT transactionid FROM Pi_klarna_payment_order_data WHERE order_number = ?"; $piKlarnaTransactionId = Shopware()->Db()->fetchOne($sql, array($substr)); $k = piKlarnaCreateKlarnaInstance(); try { $k->cancelReservation($piKlarnaTransactionId); $piKlarnaCompleteCancelStatusId=piKlarnaGetCompleteCancelStatusId(); $piKlarnaReserverationCanceledStatusId=piKlarnaGetReserverationCanceledStatusId(); $sql = "UPDATE Pi_klarna_payment_order_detail SET versandstatus = ? WHERE ordernumber = ?"; Shopware()->Db()->query($sql, array((int)$piKlarnaCompleteCancelStatusId, $substr)); $sql = "UPDATE s_order SET cleared = ?, status = ? WHERE ordernumber = ?"; Shopware()->Db()->query($sql, array( (int)$piKlarnaReserverationCanceledStatusId, (int)$piKlarnaCompleteCancelStatusId, $substr )); } catch (Exception $e) { $this->view->sPaymentError = $e->getMessage() . " (#" . $e->getCode() . ")"; } return $this->forward('orders', 'account'); }