<?php

$loader = $this->registry->get('load');
$loader->controller('payment/payment_default');

class ControllerPaymentBankTransfer extends ControllerPaymentPaymentDefault
{
    protected function index()
    {
        parent::index();
        $this->app();
        $this->language->load('payment/bank_transfer');

        // Not being used in ecommerce but it's necessary because customer app 
        $this->data['text_instruction'] = $this->language->get('text_instruction');
        $this->data['text_description'] = $this->language->get('text_description');
        $this->data['text_payment'] = $this->language->get('text_payment');
        $this->data['bank'] = nl2br($this->config->get('bank_transfer_bank_' . $this->config->get('config_language_id')));

        $this->render('payment/bank_transfer');
    }

    public function app() {
        parent::app();
    }

    public function confirm() {

        $json = array();
        $json['error'] = $this->validate();

        if (!$json['error']) {
            $this->language->load('payment/bank_transfer');
            $this->load->dmodel('checkout/order');

            $comment = $this->language->get('text_instruction') . "\n\n";
            $comment .= $this->config->get('bank_transfer_bank_' . $this->config->get('config_language_id')) . "\n\n";
            $comment .= $this->language->get('text_payment');

            $this->dmodel_checkout_order->confirm($this->session->data['order_id'], $this->config->get('bank_transfer_order_status_id'), $comment);
        }

        $this->response->setOutput(json_encode($json));
    }

    public function validate() {
        return parent::validate();
    }

    public function success() {
        
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/success/bank_transfer.twig')) {
			$this->template = $this->config->get('config_template') . '/template/success/bank_transfer.twig';     
		}	

        $this->language->load('payment/bank_transfer');
        $this->data['text_instruction'] = $this->language->get('text_instruction');
        $this->data['text_description'] = $this->language->get('text_description');
        $this->data['text_payment'] = $this->language->get('text_payment');
        $this->data['bank'] = nl2br($this->config->get('bank_transfer_bank_' . $this->config->get('config_language_id')));

        $this->response->setOutput($this->render());
    }
}
