Пример #1
0
 /**
  * singleton accessor
  * 
  * @return type 
  */
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new Mopt_PayoneMain();
     }
     return self::$instance;
 }
Пример #2
0
 /**
  * Recurring payment action method.
  */
 public function recurringAction()
 {
     if (!$this->getAmount() || $this->getOrderNumber()) {
         $this->redirect(array('controller' => 'checkout'));
         return;
     }
     $orderId = $this->Request()->getParam('orderId');
     Shopware()->Session()->moptPayment = $this->getPaymentDataFromOrder($orderId);
     if ($this->moptPayonePaymentHelper->isPayoneCreditcard($this->getPaymentShortName())) {
         Shopware()->Session()->moptOverwriteEcommerceMode = Payone_Api_Enum_Ecommercemode::INTERNET;
     }
     $action = 'mopt_payone__' . $this->moptPayonePaymentHelper->getActionFromPaymentName($this->getPaymentShortName());
     $response = $this->{$action}();
     $errorMessage = false;
     if ($response->isRedirect()) {
         $errorMessage = 'Tried to use redirect payment for abo order';
     }
     $session = Shopware()->Session();
     if ($response->getStatus() == 'ERROR') {
         $errorMessage = $response->getErrorcode();
     }
     if (!$errorMessage) {
         //extract possible clearing data
         $clearingData = $this->moptPayoneMain->getPaymentHelper()->extractClearingDataFromResponse($response);
         //save order
         $orderNr = $this->saveOrder($response->getTxid(), $session->paymentReference);
         //get order id
         $sql = 'SELECT `id` FROM `s_order` WHERE ordernumber = ?';
         $orderId = Shopware()->Db()->fetchOne($sql, $orderNr);
         if ($clearingData) {
             $sql = 'UPDATE `s_order_attributes`' . 'SET mopt_payone_txid=?, mopt_payone_is_authorized=?, ' . 'mopt_payone_clearing_data=? WHERE orderID = ?';
             Shopware()->Db()->query($sql, array($response->getTxid(), $session->moptIsAuthorized, json_encode($clearingData), $orderId));
         } else {
             $sql = 'UPDATE `s_order_attributes`' . 'SET mopt_payone_txid=?, mopt_payone_is_authorized=? WHERE orderID = ?';
             Shopware()->Db()->query($sql, array($response->getTxid(), $session->moptIsAuthorized, $orderId));
         }
         if (Shopware()->Session()->moptPayment) {
             $this->saveTransactionPaymentData($orderId, Shopware()->Session()->moptPayment);
         }
         unset($session->moptPayment);
         unset($session->moptIsAuthorized);
     }
     if ($this->Request()->isXmlHttpRequest()) {
         if ($errorMessage) {
             $data = array('success' => false, 'message' => $errorMessage);
         } else {
             $data = array('success' => true, 'data' => array(array('orderNumber' => $orderNr, 'transactionId' => $response->getTxid())));
         }
         echo Zend_Json::encode($data);
     } else {
         if ($errorMessage) {
             $this->View()->errormessage = $this->moptPayoneMain->getPaymentHelper()->moptGetErrorMessageFromErrorCodeViaSnippet(false, $response->getErrorcode());
             $this->forward('error');
         } else {
             $this->redirect(array('controller' => 'checkout', 'action' => 'finish', 'sUniqueID' => $session->paymentReference));
         }
     }
 }
Пример #3
0
 public function moptPayoneCaptureOrderAction()
 {
     $request = $this->Request();
     try {
         $orderId = $request->getParam('id');
         if (!($order = Shopware()->Models()->getRepository('Shopware\\Models\\Order\\Order')->find($orderId))) {
             $message = Shopware()->Snippets()->getNamespace('backend/MoptPaymentPayone/errorMessages')->get('orderNotFound', 'Bestellung nicht gefunden', true);
             throw new Exception($message);
         }
         if (!$this->moptPayone_isOrderCapturable($order)) {
             $errorMessage = Shopware()->Snippets()->getNamespace('backend/MoptPaymentPayone/errorMessages')->get('captureNotPossibleGeneral', 'Capture nicht möglich.', true);
             throw new Exception($errorMessage);
         }
         $payment = $order->getPayment();
         $paymentName = $payment->getName();
         if ($request->getParam('includeShipment') === 'true') {
             $includeShipment = true;
         } else {
             $includeShipment = false;
         }
         $config = Mopt_PayoneMain::getInstance()->getPayoneConfig($payment->getId());
         //positions ?
         $positionIds = $request->get('positionIds') ? json_decode($request->get('positionIds')) : array();
         //covert finalize param
         $finalize = $request->get('finalize') == "true" ? true : false;
         //fetch params
         $params = $this->moptPayone__main->getParamBuilder()->buildOrderCapture($order, $positionIds, $finalize, $includeShipment);
         if ($config['submitBasket'] || $this->moptPayone__main->getPaymentHelper()->isPayoneBillsafe($paymentName)) {
             $invoicing = $this->moptPayone__main->getParamBuilder()->getInvoicingFromOrder($order, $positionIds, $finalize, false, $includeShipment);
         }
         //call capture service
         $response = $this->moptPayone_callCaptureService($params, $invoicing);
         if ($response->getStatus() == Payone_Api_Enum_ResponseType::APPROVED) {
             //increase sequence
             $this->moptPayoneUpdateSequenceNumber($order, true);
             //mark / fill positions as captured
             $this->moptPayoneMarkPositionsAsCaptured($order, $positionIds, $includeShipment);
             //extract and save clearing data
             $clearingData = $this->moptPayone__paymentHelper->extractClearingDataFromResponse($response);
             if ($clearingData) {
                 $this->moptPayoneSaveClearingData($order, $clearingData);
             }
             $response = array('success' => true);
         } else {
             $errorMessage = Shopware()->Snippets()->getNamespace('backend/MoptPaymentPayone/errorMessages')->get('captureNotPossibleNow', 'Capture (zur Zeit) nicht möglich.', true);
             $response = array('success' => false, 'error_message' => $errorMessage);
         }
     } catch (Exception $e) {
         $response = array('success' => false, 'error_message' => $e->getMessage());
     }
     $this->View()->assign($response);
 }
 /**
  * returns auth-parameters for API-calls
  *
  * @param string $paymentId
  * @return array 
  */
 protected function getAuthParameters($paymentId = 0)
 {
     $this->payoneConfig = Mopt_PayoneMain::getInstance()->getPayoneConfig($paymentId);
     $authParameters = array();
     $authParameters['mid'] = $this->payoneConfig['merchantId'];
     $authParameters['portalid'] = $this->payoneConfig['portalId'];
     $authParameters['key'] = $this->payoneConfig['apiKey'];
     $authParameters['aid'] = $this->payoneConfig['subaccountId'];
     $authParameters['solution_name'] = 'mediaopt';
     $authParameters['solution_version'] = Shopware()->Plugins()->Frontend()->MoptPaymentPayone()->getVersion();
     $authParameters['integrator_name'] = 'shopware';
     $authParameters['integrator_version'] = Shopware()->Config()->Version;
     if ($this->payoneConfig['liveMode'] == 1) {
         $authParameters['mode'] = Payone_Enum_Mode::LIVE;
     } else {
         $authParameters['mode'] = Payone_Enum_Mode::TEST;
     }
     $authParameters['encoding'] = 'UTF-8';
     // optional param default is: ISO-8859-1
     return $authParameters;
 }
Пример #5
0
 /**
  * Creates and returns the payone builder for an event.
  *
  * @param \Enlight_Event_EventArgs $args
  * @return \Shopware_Components_Payone_Builder
  */
 public function onInitResourcePayoneMain(\Enlight_Event_EventArgs $args)
 {
     $moptPayoneMain = Mopt_PayoneMain::getInstance();
     return $moptPayoneMain;
 }