<?php

class ModelTotalWirecard extends Model
{
  public function getTotal(&$total_data, &$total)
  {

    if (isset($this->session->data['payment_method']) &&
      ($this->session->data['payment_method']['code'] == Type_WirecardConfigs::Tp_NameModule)) {

      $this->language->load('total/wirecard');
      $this->load->helper('ftr_geral');
      $desconto = false;

      switch ($this->session->data['payment_method']['code_type']) {
        case Type_PaymentOption::Tp_Billet:
          if ($this->config->get('wirecard_billet')) {
            $wirecard_billet = $this->config->get('wirecard_billet');
            $desconto = ftr_geral::getPaymentDiscount($wirecard_billet, $total, $this->cart->getTotal());
            $title = $this->language->get('text_dicount_billit');
          }
          break;
        case Type_PaymentOption::Tp_BankTransfer:
          if ($this->config->get('wirecard_bank_transfer')) {
            $wirecard_bank_transfer = $this->config->get('wirecard_bank_transfer');
            $desconto = ftr_geral::getPaymentDiscount($wirecard_bank_transfer, $total, $this->cart->getTotal());
            $title = $this->language->get('text_dicount_bank_transfer');
          }
          break;
        default:
          return false;
      }

      if (!$desconto) {
        return false;
      }

      $total -= ($desconto * -1);

      $total_data[] = array(
        'code' => 'wirecard',
        'title' => $title,
        'text' => $this->currency->format($desconto),
        'value' => $desconto,
        'sort_order' => $this->config->get('wirecard_discount_order')
      );

    }else{
      return false;
    }

  }

}
