/**
  * @param OrderPayment $orderPayment
  * @return \SecurionPay\Response\Charge
  */
 protected function createRefundRequest($orderPayment)
 {
     $currencyObject = new Currency((int) $orderPayment['id_currency']);
     $currency = $currencyObject->iso_code;
     $total = (double) $orderPayment['amount'];
     $amount = CurrencyUtils::toMinorUnits($total, $currency);
     try {
         $refundRequest = new \SecurionPay\Request\RefundRequest();
         $refundRequest->amount($amount)->chargeId($orderPayment['transaction_id']);
         return $this->module->gateway->refundCharge($refundRequest);
     } catch (Exception $e) {
         $this->errors[] = Tools::displayError('Refund exception: ' . $e->getMessage());
     }
 }
 /**
  * @param \SecurionPay\Response\Charge $charge
  * @param string $customerSecureKey
  * @param integer $cartId
  */
 protected function validateOrder($charge, $customerSecureKey, $cartId)
 {
     $currency = $this->context->currency;
     $total = CurrencyUtils::fromMinorUnits($charge->getAmount(), $charge->getCurrency());
     $extraVars = array('transaction_id' => $charge->getId());
     $paymentMethod = $this->module->l('Card payment', 'payment');
     // confirm order and mark it as paid
     $this->module->validateOrder($cartId, Configuration::get('PS_OS_PAYMENT'), $total, $paymentMethod, null, $extraVars, (int) $currency->id, false, $customerSecureKey);
 }
 /**
  * @param array $params
  * @return Response
  */
 public function hookPayment($params)
 {
     if (!$this->active) {
         return;
     }
     $cart = $this->context->cart;
     $currencyObject = new Currency((int) $cart->id_currency);
     $currency = $currencyObject->iso_code;
     $total = (double) $cart->getOrderTotal(true, Cart::BOTH);
     $amount = CurrencyUtils::toMinorUnits($total, $currency);
     $signedCheckoutRequest = $this->createSecurionPayCharge($amount, $currency);
     $this->context->smarty->assign(array('publicKey' => $this->getPublicKey(), 'email' => $this->getCurrentUserEmail(), 'checkoutFirstLine' => Configuration::get(self::CHECKOUT_FIRST_LINE), 'checkoutSecondLine' => Configuration::get(self::CHECKOUT_SECOND_LINE), 'checkoutPaymentButton' => Configuration::get(self::CHECKOUT_PAYMENT_BUTTON), 'checkoutRequest' => $signedCheckoutRequest, 'version' => (double) _PS_VERSION_));
     if ((double) _PS_VERSION_ >= '1.6') {
         $this->context->controller->addCSS(_MODULE_DIR_ . $this->name . '/views/css/securionpay.css');
     }
     return $this->display(__FILE__, 'payment.tpl');
 }