/**
  * Executes a request to the PaynetEasy server
  * to start the payment process.
  *
  * If the request is successful, redirects the
  * customer to the PaynetEasy payment form.
  *
  * If the request is made with an error,
  * displays an error message.
  */
 public function display()
 {
     $payment_aggregate = new PaymentAggregate($this->module);
     $prestashop_cart = $this->context->cart;
     $return_url = $this->context->link->getModuleLink('payneteasy', 'finishsale', array('id_cart' => $prestashop_cart->id), true);
     try {
         $paynet_response = $payment_aggregate->startSale($prestashop_cart, $return_url);
         $this->savePaynetPayment($paynet_response, $prestashop_cart);
     } catch (Exception $ex) {
         $this->createOrderWithErrorPayment($prestashop_cart, $ex->getMessage());
         return $this->displayTechnicalError($ex);
     }
     Tools::redirectLink($paynet_response->getRedirectUrl());
 }
 /**
  * Validates response from PaynetEasy server.
  *
  * Creates the order if the payment was successful
  * and redirect customer to result page with success message.
  *
  * If the payment is made with an error,
  * displays an error message.
  */
 public function display()
 {
     $payment_aggregate = new PaymentAggregate($this->module);
     $prestashop_cart = new Cart(Tools::getValue('id_cart'));
     $paynet_response = new CallbackResponse($_REQUEST);
     try {
         $this->validatePaymentData($prestashop_cart, $paynet_response);
         if ($prestashop_cart->orderExists()) {
             $this->successRedirect();
         }
         $paynet_response = $payment_aggregate->finishSale($prestashop_cart, $paynet_response);
     } catch (Exception $ex) {
         $this->logException($ex);
         $this->createOrderWithErrorPayment($prestashop_cart, $paynet_response, $ex->getMessage());
         return $this->displayError('Invalid payment data received.');
     }
     if (!$paynet_response->isApproved()) {
         $this->createOrderWithErrorPayment($prestashop_cart, $paynet_response);
         return $this->displayError('Payment not passed');
     }
     $this->createOrderWithSuccessPayment($prestashop_cart, $paynet_response);
     $this->successRedirect();
 }