Skip to content

Instantly share code, notes, and snippets.

@alpocr
Created January 4, 2018 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alpocr/be942a0641b02d93e5991e7eb680e746 to your computer and use it in GitHub Desktop.
Save alpocr/be942a0641b02d93e5991e7eb680e746 to your computer and use it in GitHub Desktop.
<?php
//------------- PRUEBA DE AUTENTICACION API 4G PAYMENTS -----------------------
//Datos de conexion para el Api 4G
$Api_data = array("grant_type" => "client_credentials","client_id" => "[CLEINT_ID]", "client_secret" => "[CLIENT_SECRET]");
$Api_Url = "https://api.payments.4geeks.io/authentication/token/";
//------------------------------- CONEXION ------------------------------------
//Url del servicio Web consultado
$Api_curlUri = curl_init($Api_Url);
//a true, obtendremos una respuesta de la url, en otro caso,
//true si es correcto, false si no lo es
curl_setopt($Api_curlUri, CURLOPT_RETURNTRANSFER, true);
//Se establece el Verbo POST
curl_setopt($Api_curlUri, CURLOPT_CUSTOMREQUEST, "POST");
// onvertir data a JSON
$data_string = json_encode($Api_data);
//Se envia los datos, unicamente con la data en JSON
curl_setopt($Api_curlUri, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($Api_curlUri, CURLOPT_HTTPHEADER, array('Content-Type: "application/json; charset=utf-8"', 'Content-Length: ' . strlen($data_string)));
//Se obtiene la respuesta, debes enviar $Api_curlUri la variable pasada no existia.
$Api_response = json_decode(curl_exec($Api_curlUri));
//Se cierra el recurso CURL y se liberan los recursos del sistema
curl_close($Api_curl);
if(!$Api_response) {
echo "Error :(";
}else{
echo "Access Token: " . $Api_response->access_token;
}
?>
@grecadu
Copy link

grecadu commented Aug 29, 2019

Hay un error typo en la linea 33
curl_close($Api_curl); => curl_close($Api_curlUri);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment