コード例 #1
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));
         }
     }
 }