<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Negocios {

    function obtemcliente($email) {

        $ch = curl_init();
        //Chaves de acesso  API enviadas via POST
        $post = array(
            'chave' => OPAYT_CHAVE,
            'token' => OPAYT_TOKEN,
            'aluno' => $email
        );
        
        curl_setopt($ch, CURLOPT_URL, URL_NEGOCIOS . 'obtemconta');
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $requisicao = curl_exec($ch);
        
        $result = json_decode($requisicao);
        
        return $result;
        
        curl_close($ch);
    }
    
    function consomesaldo($valor, $pedido) {
         $ch = curl_init();
        //Chaves de acesso  API enviadas via POST
        $post = array(
           'token' => OPAYT_TOKEN,
           'chave' => OPAYT_CHAVE, 
           'id_aluno' => usuario('id_aluno'),
           'valor'  => $valor,
           'pedido' => $pedido
        );
        
        curl_setopt($ch, CURLOPT_URL, URL_NEGOCIOS .'consumirsaldo');
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        
        $requisicao = curl_exec($ch);
        
        $result = json_decode($requisicao);
        
        return $result;
        
        curl_close($ch);
 
    }
    
    function adicionasaldo($valor, $email, $id_aluno, $pedido) {
         
        $ch = curl_init();
        //Chaves de acesso  API enviadas via POST
        $post = array(
           'chave' => OPAYT_CHAVE,
           'token' => OPAYT_TOKEN,
           'email' => $email,
           'cliente' => $id_aluno, 
           'valor' => $valor,
           'pedido' => $pedido
        );
        
        curl_setopt($ch, CURLOPT_URL, URL_NEGOCIOS .'adicaosaldo');
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $requisicao = curl_exec($ch);
        
        $result = json_decode($requisicao);
       
        if ($result->status == 1) {
            return array('status' => 1);
        } else {
            return array('status' => 3, 'mensagem' => $result->mensagem);
        }
        curl_close($ch);
    }

}
