Ejemplo n.º 1
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param  ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see AtosCurrency::setDeleted()
  * @see AtosCurrency::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(AtosCurrencyTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildAtosCurrencyQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Ejemplo n.º 2
0
Archivo: Atos.php Proyecto: bibich/Atos
 /**
  *
  *  Method used by payment gateway.
  *
  *  If this method return a \Thelia\Core\HttpFoundation\Response instance, this response is send to the
  *  browser.
  *
  *  In many cases, it's necessary to send a form to the payment gateway.
  *  On your response you can return this form already completed, ready to be sent
  *
  * @param  \Thelia\Model\Order                       $order processed order
  * @return null|\Thelia\Core\HttpFoundation\Response
  */
 public function pay(Order $order)
 {
     $pathBin = self::getBinDirectory() . 'request';
     $atosCurrency = AtosCurrencyQuery::create()->findPk($order->getCurrency()->getCode());
     if (null == $atosCurrency) {
         throw new \InvalidArgumentException(sprintf("Atos does not supprot this currency : %s", $order->getCurrency()->getCode()));
     }
     $amount = $order->getTotalAmount();
     $amount = number_format($amount, $atosCurrency->getDecimals(), '', '');
     $transactionId = $this->generateTransactionID();
     $order->setTransactionRef($transactionId)->save();
     $router = $this->getContainer()->get('router.atos');
     $this->addParam('pathfile', self::getPathfilePath())->addParam('merchant_id', self::getConfigValue('atos_merchantId'))->addParam('customer_email', $order->getCustomer()->getEmail())->addParam('currency_code', $atosCurrency->getAtosCode())->addParam('amount', $amount)->addParam('language', $order->getLang()->getCode())->addParam('transaction_id', $transactionId)->addParam('order_id', $order->getId())->addParam('automatic_response_url', URL::getInstance()->absoluteUrl($router->generate('atos.payment.confirmation')))->addParam('cancel_return_url', $this->getPaymentFailurePageUrl($order->getId(), Translator::getInstance()->trans('you cancel the payment', [], Atos::MODULE_DOMAIN)))->addParam('normal_return_url', $this->getPaymentSuccessPageUrl($order->getId()));
     $encrypt = exec(sprintf("%s %s", $pathBin, $this->getParameters()));
     if (!empty($encrypt)) {
         $datas = explode('!', $encrypt);
         if ($datas[1] == '' && $datas[2] == '') {
             throw new \RuntimeException(Translator::getInstance()->trans('Request binary not found in "%path"', ['%path' => $pathBin]));
         } elseif ($datas[1] != 0) {
             throw new \RuntimeException($datas[2]);
         } else {
             $parser = $this->getContainer()->get('thelia.parser');
             $parser->setTemplateDefinition($parser->getTemplateHelper()->getActiveFrontTemplate());
             $content = $parser->renderString(file_get_contents(__DIR__ . DS . 'templates' . DS . 'atos' . DS . 'payment.html'), ['site_name' => self::getConfigValue('store_name'), 'form' => $datas[3]]);
             return Response::create($content);
         }
     } else {
         throw new \RuntimeException(Translator::getInstance()->trans('Empty response recevied from Atos binary "%path". Please check path and permissions.', ['%path' => $pathBin], self::MODULE_DOMAIN));
         // FIXME : show something to the customer
     }
 }