コード例 #1
0
 /**
  * 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
 /**
  * Gets settings and creates API object.
  *
  * @return Barzahlen_Api
  */
 function createApi()
 {
     $sandbox = MODULE_PAYMENT_BARZAHLEN_SANDBOX == 'True' ? true : false;
     $debug = MODULE_PAYMENT_BARZAHLEN_SANDBOX == 'True' ? true : false;
     $api = new Barzahlen_Api(MODULE_PAYMENT_BARZAHLEN_SHOPID, MODULE_PAYMENT_BARZAHLEN_PAYMENTKEY, $sandbox);
     $api->setDebug($debug, $this->logFile);
     $api->setUserAgent('Gambio ' . $this->getGambioVersion() . ' / Plugin v' . $this->version);
     return $api;
 }
 /**
  * Prepares a Barzahlen API object for the payment request.
  *
  * @param integer $iOrderLang order language id
  * @return Barzahlen_Api
  */
 protected function _getBarzahlenApi($iOrderLang)
 {
     $oxConfig = $this->getConfig();
     $sShopId = $oxConfig->getShopId();
     $sModule = oxConfig::OXMODULE_MODULE_PREFIX . $this->_sModuleId;
     $sBzShopId = $oxConfig->getShopConfVar('bzShopId', $sShopId, $sModule);
     $sPaymentKey = $oxConfig->getShopConfVar('bzPaymentKey', $sShopId, $sModule);
     $blSandbox = $oxConfig->getShopConfVar('bzSandbox', $sShopId, $sModule);
     $blDebug = $oxConfig->getShopConfVar('bzDebug', $sShopId, $sModule);
     $oApi = new Barzahlen_Api($sBzShopId, $sPaymentKey, $blSandbox);
     $oApi->setDebug($blDebug, self::LOGFILE);
     $oApi->setLanguage($this->_getOrderLanguage($iOrderLang));
     $oApi->setUserAgent('OXID v' . $oxConfig->getVersion() . ' / Plugin v1.2.1');
     return $oApi;
 }
コード例 #4
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);
             }
         }
     }
 }