I’m trying to receive a JSON POST on a payment interface website, but I can’t decode it.
When I print :
echo $_POST;
I get:
Array
I get nothing when I try this:
if ( $_POST ) {
foreach ( $_POST as $key => $value ) {
echo "llave: ".$key."- Valor:".$value."<br />";
}
}
I get nothing when I try this:
$string = $_POST['operation'];
$var = json_decode($string);
echo $var;
I get NULL when I try this:
$data = json_decode( file_get_contents('php://input') );
var_dump( $data->operation );
When I do:
$data = json_decode(file_get_contents('php://input'), true);
var_dump($data);
I get:
NULL
The JSON format is (according to payment site documentation):
{
"operacion": {
"tok": "[generated token]",
"shop_id": "12313",
"respuesta": "S",
"respuesta_details": "respuesta S",
"extended_respuesta_description": "respuesta extendida",
"moneda": "PYG",
"monto": "10100.00",
"authorization_number": "123456",
"ticket_number": "123456789123456",
"response_code": "00",
"response_description": "Transacción aprobada.",
"security_information": {
"customer_ip": "123.123.123.123",
"card_source": "I",
"card_country": "Croacia",
"version": "0.3",
"risk_index": "0"
}
}
}
The payment site log says everything is OK. What’s the problem?
var_dump($_POST)
say? Is it an empty array? – Leastwisevar_dump($_POST);
what you get? – Gerenuk<?php echo '<pre>'; print_r($_POST); echo '</pre>'; ?>
What does that show? – Utilityjson_decode
it. But maybe the service sends data in request body, that's a different story and yes,file_get_contents('php://input')
should work then. – Leastwisevar_dump($_POST)
I get array(0) { }. When I doecho '<pre>'; print_r($_POST); echo '</pre>';
I get Array ( ) And yes, documentation says "we will make post request sending json in request body" When I do$entityBody = file_get_contents('php://input'); var_dump($entityBody);
I get string(0) – Marciamarciano$data = json_decode(file_get_contents('php://input'), true); var_dump($data);
I getNULL
– Marciamarciano