<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Ep extends App_Controller
{
    public function confirm()
    {
        $this->load->library('payment/euplatesc');

        $this->euplatesc->set_mid($this->euplatesc_gateway->merchant_code());
        $this->euplatesc->set_key($this->euplatesc_gateway->secret_key());

        $this->euplatesc->response();
        $response = $this->euplatesc->get_response();
        $errors = $this->euplatesc->get_errors();

        if (isset($response['order_id'])) {
            /*if($order['order_status'] == 2){
                //already paid
                $do_order_confirm = false;
            }else{
                $do_order_confirm = true;
            }*/
        } else {

        }
        $do_order_confirm = true;
        if (!isset($response['status'])) {
            $do_order_confirm = false;
        }


        if ($do_order_confirm) {
            switch ($response['status']) {
                case 'success':
                    $this->load->model('invoices_model');
                    $invoice = $this->invoices_model->get($response['order_id']);

                    $this->mobilpay_gateway->addPayment(
                        [
                            'amount' => $invoice->total,
                            'invoiceid' => $response['order_id'],
                            'transactionid' => $response['order_id'],
                            'paymentmethod' => 'Credit card',
                        ]
                    );
                    break;
                case 'failed':

                    break;
                default:

                    break;

            }
        }

    }
}
