<?php
    header("Content-Type:application/json");
    include("../../../settings/dbconn.php");
    include("../../../settings/utils.php");
    
    
    $out = new stdClass();
    // Llamamos a la api primerito
    /*
    $request = array(
        'telefonoCobrador'=>$phoneAFX,
        'banco'=>'0138',
        'id'=>'V13408527',
        'telefonoPagador'=>'4249999990',
        'monto'=>(float)10000,
        'token'=>'703263',
        'motivo'=>'Deposito',
        'origen'=>'12'
    );
    //$request = new stdClass();
    
    $nonce = generateNonce();
    
    echo("/".$BP_VERSION."/pagos/c2p".$nonce.json_encode($request));
    echo("\n\n");
    echo json_encode($request);
    echo("\n\n");
    $headers = array(
        "Content-Type: application/json",
        "api-key:".$BP_C2P_KEY, 
        "api-signature: ".
        (
        generateApiSignature("/".$BP_VERSION."/pagos/c2p".$nonce.json_encode($request),$BP_C2P_KEY_SECRET)
        ),
        "nonce:".$nonce,
    );
    
    echo(var_dump($headers));
    
    //die();

    // obtenemos respuesta
    $rest = queryApiBP($BP_URL_QA, "pagos/c2p", $BP_VERSION, "POST", $headers, $request);
    echo(var_dump($rest['bodyres']->referencia));
    echo("\n\n");
    echo(var_dump($rest));
    die();
    /*
    
    $nonce = generateNonce();
    
    // Llamamos a la api primerito
    $request = array();
    
    $headers = array('Content-Type:application/json', 
        "api-key: $BP_C2P_KEY", 
        "api-signature: ".
        (
            generateApiSignature("/".$BP_VERSION."/pagos/c2p".$nonce, $BP_C2P_KEY_SECRET)
        ),
        "nonce: ".$nonce,
    );
    
    // obtenemos respuesta
    $rest = queryApiBP($BP_URL_QA, "pagos/c2p/J302522030", $BP_VERSION, "GET", $headers, $request);
    
    echo(json_encode($rest));
    
    die();*/
    
    // formateamos el telefono para quitarle el zero
    //$cinumbers = preg_replace('/\D/', '', $ci);
    
    $phone = "0424-2032143";
    $phoneReg = preg_replace('/^0?/', '', $phone);
    $phoneReg = "58".preg_replace('/\D/','', $phoneReg);
    
    $out->phone = $phoneReg;
    
    header("HTTP/1.1 200");
    echo(json_encode($out));
    die();
    
?>