/**
  * Order information are gather and send to Barzahlen to request a payment
  * slip. If the request was successful, the order is saved and the order id
  * will be updated.
  */
 public function gatewayAction()
 {
     // check if payment request is already processing
     if (!isset(Shopware()->Session()->BarzahlenProcess)) {
         Shopware()->Session()->BarzahlenProcess = true;
         $config = Shopware()->Plugins()->Frontend()->ZerintPaymentBarzahlen()->Config();
         $paymentUniqueId = $this->createPaymentUniqueId();
         $shopId = $config->barzahlenShopId;
         $paymentKey = $config->barzahlenPaymentKey;
         $sandbox = $config->barzahlenSandbox;
         $api = new Barzahlen_Api($shopId, $paymentKey, $sandbox);
         $api->setDebug($config->barzahlenDebug, self::LOGFILE);
         $api->setUserAgent('Shopware v' . Shopware::VERSION . ' / Plugin v1.0.7');
         $userinfo = $this->getUser();
         if (!$userinfo) {
             Shopware()->Session()->BarzahlenPaymentError = "Es gab einen Fehler bei der Datenübertragung. Bitte versuchen Sie es erneut oder wählen Sie eine andere Zahlungsmethode.";
             $this->redirect(array('controller' => 'checkout', 'action' => 'confirm'));
         }
         $customerEmail = $userinfo["additional"]["user"]["email"];
         $customerStreetNr = $userinfo["billingaddress"]["street"] . ' ' . $userinfo["billingaddress"]["streetnumber"];
         $customerZipcode = $userinfo["billingaddress"]["zipcode"];
         $customerCity = $userinfo["billingaddress"]["city"];
         $customerCountry = $userinfo["additional"]["country"]["countryiso"];
         $amount = $this->getAmount();
         $currency = $this->getCurrencyShortName();
         $payment = new Barzahlen_Request_Payment($customerEmail, $customerStreetNr, $customerZipcode, $customerCity, $customerCountry, $amount, $currency);
         try {
             $api->handleRequest($payment);
         } catch (Exception $e) {
             $this->_logError($e);
         }
         if ($payment->isValid()) {
             $orderId = $this->saveOrder($payment->getTransactionId(), $paymentUniqueId, NULL, true);
             $update = new Barzahlen_Request_Update($payment->getTransactionId(), $orderId);
             try {
                 $api->handleRequest($update);
             } catch (Exception $e) {
                 $this->_logError($e);
             }
             Shopware()->Session()->BarzahlenResponse = $payment->getXmlArray();
             $this->redirect(array('controller' => 'checkout', 'action' => 'finish'));
         } else {
             Shopware()->Session()->BarzahlenPaymentError = "Es gab einen Fehler bei der Datenübertragung. Bitte versuchen Sie es erneut oder wählen Sie eine andere Zahlungsmethode.";
             $this->redirect(array('controller' => 'checkout', 'action' => 'confirm'));
         }
     } else {
         // if there is already a payment process wait for the results
         while (!isset(Shopware()->Session()->BarzahlenResponse) && !isset(Shopware()->Session()->BarzahlenPaymentError)) {
             sleep(1);
         }
         if (isset(Shopware()->Session()->BarzahlenResponse)) {
             $this->redirect(array('controller' => 'checkout', 'action' => 'finish'));
         }
         if (isset(Shopware()->Session()->BarzahlenPaymentError)) {
             $this->redirect(array('controller' => 'checkout', 'action' => 'confirm'));
         }
     }
 }
Пример #2
0
 /**
  * Cancels payment slip before order is deleted.
  *
  * @param Enlight_Event_EventArgs $args
  */
 public function onGetOrderControllerPreDispatch(Enlight_Event_EventArgs $args)
 {
     if ($args->getRequest()->getActionName() === 'delete') {
         $id = $args->getSubject()->Request()->getParam('id', null);
         $order = Shopware()->Models()->getRepository('Shopware\\Models\\Order\\Order')->find($id);
         if ($order->getPayment()->getName() === 'barzahlen') {
             $transactionId = $order->getTransactionId();
             $cancel = new Barzahlen_Request_Cancel($transactionId);
             $config = $this->Config();
             $shopId = $config->barzahlenShopId;
             $paymentKey = $config->barzahlenPaymentKey;
             $sandbox = $config->barzahlenSandbox;
             $api = new Barzahlen_Api($shopId, $paymentKey, $sandbox);
             $api->setDebug($config->barzahlenDebug, self::LOGFILE);
             try {
                 $api->handleRequest($cancel);
             } catch (Exception $e) {
                 $this->_logError($e);
             }
         }
     }
 }