I am implementing a payment service on my website, and one of the last ones is to make a request http
with curl
, but I don't fully understand how to do it.
The documentation says that the request must have the following form:
https://sandbox.affirm.com/api/v2/charges
-X POST
-u "<public_api_key>:<private_api_key>"
-H "Content-Type: application/json"
-d '{"checkout_token": "<checkout_token>","order_id": "JKLM4321"}'
The way I have to do this with curl would be the following:
// Iniciar curl
$curl = curl_init();
$headers[] = 'Content-Type: application/json';
// Agregar las opciones y datos
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://sandbox.affirm.com/api/v2/charges',
CURLOPT_POST => 1,
CURLOPT_HEADER => $headers,
CURLOPT_POSTFIELDS => [
checkout_token => 'value',
order_id => 'value2'
]
]);
// Enviar la petición y obtener la respuesta
$resp = curl_exec($curl);
// Cerrar la peticion
curl_close($curl);
But, as you can see, I have no idea how to include the public and private keys (which I already have, that's NOT the problem) in the request with curl
, and I don't know what that "-u" they describe in the documentation means either. Any ideas?
The
u
one you ask for corresponds to the optionCURLOPT_USERPWD
,cURL
as you can verify in the code example below.On the API page you have an example of PHP code using
cURL
:Just uncomment and change this to your actual credentials and it should work: