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

class Bank extends CI_Controller {

	public function __construct(){
        parent::__construct();
		$this->load->model('token_model');
    }
	public function transfer()
    {
	
		## METHODE ACCEPTE
		$this->token_model->valideMethod('POST');

		## AUTHENTIFICATION 
		$this->token_model->valideToken();

		## RECUPERATION DES DONNEES 
		$this->token_model->getData('JSON');
       
        $json = $this->token_model->Data;
        uses_class('finance');
        $finance = new finance();//
        $finance->TypeService = 'bank';
        $finance->Type = 'bankin';
        $finance->agent_id = $this->token_model->user_id;
        $finance->setData($json);
        if($finance->getProvider())
        {
            $finance->BankTransfert();
           if(!empty($finance->Return['reponse'])) $result['data'] = $finance->Return['reponse'];
           elseif(!empty($finance->Return['error'])) $result['error'] = $finance->Return['error'];
        }
        else
        {
            header('HTTP/1.0 404 Resource not found');
            if(!empty($finance->Return['error'])) $result['error'] = $finance->Return['error'];
            else $result['error'] =apiError(400,$finance->Error);
			local_json($result);
        }
        
        local_json($result);
    }

}