Comment on page
Autenticación
Este es un standard ampliamente documentado para cualquier lenguaje de programación y la mayor parte de lenguajes ya cuentan con librerías que facilitan la implementación del OAuth 2.0. Algunos ejemplos:
C#
PHP
JAVA
cURL
var client = new RestClient("https://id.wompi.sv/connect/token");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", "grant_type=client_credentials&client_id=%24%7Baccount.clientId%7D&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://id.wompi.sv/connect/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id=%24%7Baccount.clientId%7D&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER",
CURLOPT_HTTPHEADER => array(
"content-type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
HttpResponse<String> response = Unirest.post("https://id.wompi.sv/connect/token")
.header("content-type", "application/x-www-form-urlencoded")
.body("grant_type=client_credentials&client_id=%24%7Baccount.clientId%7D&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER")
.asString();
curl --request POST \
--url 'https://YOUR_DOMAIN/oauth/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--data grant_type=client_credentials \
--data 'client_id=YOUR_CLIENT_ID' \
--data client_secret=YOUR_CLIENT_SECRET \
--data audience=YOUR_API_IDENTIFIER
Url para extraer token: https://id.wompi.sv/connect/token
- grant_type: Dejar siempre client_credentials.
- audience: Dejar siempre "wompi_api"
- client_id: El client id del aplicativo de wompi bajo el cual desea ejecutar la acción en el api
- client_secret: Es la llave secreta del aplicativo de wompi bajo el cual desea ejecutar la acción en el api
{
"access_token":"eyJz93a...k4laUWw",
"expires_in": 3600,
"token_type": "Bearer",
"scope": "wompi_api"
}
Donde:
- access_token: contiene el token de autenticación
- expires_in: la duración del token en segundos (no es necesario obtener un token para cada petición)
Como se menciono anteriormente los únicos dos parámetros que no son fijos necesarios para hacer la petición son:
- client_id: El client id del aplicativo de wompi bajo el cual desea ejecutar la acción en el api
- client_secret: Es la llave secreta del aplicativo de wompi bajo el cual desea ejecutar la acción en el api

Ingresar al listado de aplicativos y editar el aplicativo deseado

Detalle aplicatico
Una vez en el detalle del aplicativo el App ID corresponde a client_id y API Secret a client_secret de la petición OAuth
Para utilizar el token solo hay que agregar un header HTTP en todas las peticiones al API:
- Nombre header: authorization
- Valor Header: Bearer ACCESS_TOKEN
Donde "ACCESS_TOKEN" es la token regresada en el proceso de autenticación mencionado previamente
C#
PHP
Java
cURL
var client = new RestClient("https://api.wompi.sv/EnlacePago");
var request = new RestRequest(Method.GET);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "Bearer ACCESS_TOKEN");
IRestResponse response = client.Execute(request);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.wompi.sv/EnlacePago",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer ACCESS_TOKEN",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
HttpResponse<String> response = Unirest.get("https://api.wompi.sv/EnlacePago")
.header("content-type", "application/json")
.header("authorization", "Bearer ACCESS_TOKEN")
.asString();
curl --request GET \
--url https://api.wompi.sv/EnlacePago \
--header 'authorization: Bearer ACCESS_TOKEN' \
--header 'content-type: application/json'
Last modified 3yr ago