Example #1
0
 public function saveStatusToOrder($order, $byjuno_status, Byjuno_Cdp_Helper_Api_Classes_ByjunoResponse $ByjunoResponse)
 {
     $order->addStatusHistoryComment('<b>Byjuno status: ' . $this->valueToStatus($byjuno_status) . '</b><br/>Credit rating: ' . $ByjunoResponse->getCustomerCreditRating() . '<br/>Credit rating level: ' . $ByjunoResponse->getCustomerCreditRatingLevel() . '<br/>Status code: ' . $byjuno_status . '</b>');
     $order->setByjunoStatus($byjuno_status);
     $order->setByjunoCreditRating($ByjunoResponse->getCustomerCreditRating());
     $order->setByjunoCreditLevel($ByjunoResponse->getCustomerCreditRatingLevel());
     $order->save();
 }
Example #2
0
 public function getOrderPlaceRedirectUrl()
 {
     $session = Mage::getSingleton('checkout/session');
     /* @var $quote Mage_Sales_Model_Quote */
     $quote = Mage::getSingleton('checkout/cart')->getQuote();
     /* @var $order Mage_Sales_Model_Order */
     /* @var $ordSess Mage_Sales_Model_Order */
     $ordSess = Mage::getModel('sales/order');
     $order = $ordSess->loadByIncrementId($quote->getReservedOrderId());
     $payment = $order->getPayment();
     $paymentMethod = $payment->getMethod();
     $request = $this->getHelper()->CreateMagentoShopRequestOrder($order, $paymentMethod);
     $ByjunoRequestName = "Order request";
     if ($request->getCompanyName1() != '' && Mage::getStoreConfig('payment/cdp/businesstobusiness', Mage::app()->getStore()) == 'enable') {
         $ByjunoRequestName = "Order request for Company";
         $xml = $request->createRequestCompany();
     } else {
         $xml = $request->createRequest();
     }
     $byjunoCommunicator = new Byjuno_Cdp_Helper_Api_Classes_ByjunoCommunicator();
     $mode = Mage::getStoreConfig('payment/cdp/currentmode', Mage::app()->getStore());
     if ($mode == 'production') {
         $byjunoCommunicator->setServer('live');
     } else {
         $byjunoCommunicator->setServer('test');
     }
     $response = $byjunoCommunicator->sendRequest($xml, (int) Mage::getStoreConfig('payment/cdp/timeout', Mage::app()->getStore()));
     $status = 0;
     $byjunoResponse = new Byjuno_Cdp_Helper_Api_Classes_ByjunoResponse();
     if ($response) {
         $byjunoResponse->setRawResponse($response);
         $byjunoResponse->processResponse();
         $status = (int) $byjunoResponse->getCustomerRequestStatus();
         $this->getHelper()->saveLog($quote, $request, $xml, $response, $status, $ByjunoRequestName);
         if (intval($status) > 15) {
             $status = 0;
         }
     } else {
         $this->getHelper()->saveLog($quote, $request, $xml, "empty response", "0", $ByjunoRequestName);
     }
     if ($status == 2) {
         $return = "http://magento-checkout-byjuno-ch/confirm?req=" . $byjunoResponse->getTransactionNumber() . "&res=" . $byjunoResponse->getResponseId() . "&lang=de&method=BYJUNO-INVOICE&redirectURL=" . Mage::getUrl('cdp/standard/result');
         return $return;
         // var_dump($byjunoResponse);
         // exit();
         return "http://ext-test-checkout.byjuno.ch/confirm?Req=" . $byjunoResponse->getTransactionNumber() . "&Res=" . $byjunoResponse->getResponseId() . "&lang=de&method=BYJUNO-INVOICE&redirectURL=" . Mage::getUrl('cdp/standard/result');
     } else {
         if ($status == 0) {
             $session->addError("Gateway timeout. Please try again later");
             return Mage::getUrl('cdp/standard/cancel');
         } else {
             $session->addError("You are not allowed to pay with this payment method");
             return Mage::getUrl('cdp/standard/cancel');
         }
     }
 }
Example #3
0
 public function sales_order_payment_place_end(Varien_Event_Observer $observer)
 {
     if (Mage::getStoreConfig('byjuno/api/pluginenabled', Mage::app()->getStore()) == 'disable') {
         return;
     }
     $order_id = $observer->getData('order_ids');
     /* @var $order Mage_Sales_Model_Order */
     $order = Mage::getModel('sales/order')->load($order_id);
     $incrementId = $order->getIncrementId();
     if (empty($incrementId)) {
         return;
     }
     $payment = $order->getPayment();
     $quote = Mage::getSingleton('checkout/type_onepage')->getQuote();
     $paymentMethod = $payment->getMethod();
     $request = $this->getHelper()->CreateMagentoShopRequestPaid($order, $paymentMethod);
     $ByjunoRequestName = "Order paid";
     if ($request->getCompanyName1() != '' && Mage::getStoreConfig('byjuno/api/businesstobusiness', Mage::app()->getStore()) == 'enable') {
         $ByjunoRequestName = "Order paid for Company";
         $xml = $request->createRequestCompany();
     } else {
         $xml = $request->createRequest();
     }
     $byjunoCommunicator = new Byjuno_Cdp_Helper_Api_Classes_ByjunoCommunicator();
     $mode = Mage::getStoreConfig('byjuno/api/currentmode', Mage::app()->getStore());
     if ($mode == 'production') {
         $byjunoCommunicator->setServer('live');
     } else {
         $byjunoCommunicator->setServer('test');
     }
     $response = $byjunoCommunicator->sendRequest($xml, (int) Mage::getStoreConfig('byjuno/api/timeout', Mage::app()->getStore()));
     $status = 0;
     if ($response) {
         $byjunoResponse = new Byjuno_Cdp_Helper_Api_Classes_ByjunoResponse();
         $byjunoResponse->setRawResponse($response);
         $byjunoResponse->processResponse();
         $status = (int) $byjunoResponse->getCustomerRequestStatus();
         if (intval($status) > 15) {
             $status = 0;
         }
         $this->getHelper()->saveLog($quote, $request, $xml, $response, $status, $ByjunoRequestName);
         $statusToPayment = Mage::getSingleton('checkout/session')->getData('ByjunoCDPStatus');
         $ByjunoResponseSession = Mage::getSingleton('checkout/session')->getData('ByjunoResponse');
         if (!empty($statusToPayment) && !empty($ByjunoResponseSession)) {
             $this->getHelper()->saveStatusToOrder($order, $statusToPayment, unserialize($ByjunoResponseSession));
         }
     } else {
         $this->getHelper()->saveLog($quote, $request, $xml, "empty response", "0", $ByjunoRequestName);
     }
 }