<?php
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS');
    header('Access-Control-Allow-Headers: token, Content-Type');
    header('Access-Control-Max-Age: 1728000');
    header('Content-Length: 0');
    header('Content-Type: text/plain');
    die();
}

header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
class Api_pagos extends Controller{
    public function __construct()
    {
        $this->ModelApi_pago = $this->model('Api_pago');
    }

    public function index(){
      $data = json_decode(file_get_contents("php://input"));
        //var_dump($data);
        //exit;

            //make sure error are empty
            $resp=$this->ModelApi_pago->index();
            echo json_encode($resp);


    }

    public function guardar(){
/*header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST, GET, PUT, DELETE");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
*/
        $data = json_decode(file_get_contents("php://input"));
        //var_dump($data);
        //exit;
/*
            //valide name
            if(empty($data->nombres)){
                //$data['name_err'] = 'Please enter name';
                echo json_encode(["message" => "Nombres Obligatotios..."]);
                exit;
            }

            //validate email
            if(empty($data->correo)){
                $data['email_err'] = 'Please enter email';
            }
*/
//$_SESSION['data']=;
            //make sure error are empty
            $resp=$this->ModelApi_pago->guardar($data);
            //print_r($resp);
                if($resp['res']=='ok'){
                echo json_encode(["message" => $resp['msg']]);
                exit;
                }else{
                echo json_encode(["message" => $resp['msg']]);
                //print_r($resp);
                exit;
                }

    }
    public function actualizar(){
     $data = json_decode(file_get_contents("php://input"));
        //var_dump($data);
        //exit;

            //valide name
            if(empty($data->nombres)){
                //$data['name_err'] = 'Please enter name';
                echo json_encode(["message" => "Nombres Obligatotios..."]);
                exit;
            }

            //validate email
            if(empty($data->correo)){
                $data['email_err'] = 'Please enter email';
            }


            //make sure error are empty
            $resp=$this->userModel->actualizar($data);
            //print_r($resp);
                if($resp['res']=='ok'){
                echo json_encode(["message" => $resp['msg']]);
                exit;
                }else{
                echo json_encode(["message" => $resp['msg']]);
                //print_r($resp);
                exit;
                }

    }

    public function eliminar(){
        $data = json_decode(file_get_contents("php://input"));
        //var_dump($data);
        //exit;




            //make sure error are empty
            $resp=$this->ModelApi_pago->eliminar($data);
            //print_r($resp);
                if($resp['res']=='ok'){
                echo json_encode(["message" => $resp['msg']]);
                exit;
                }else{
                echo json_encode(["message" => $resp['msg']]);
                //print_r($resp);
                exit;
                }

    }

}