What I am trying to do is to create a json file and submit to API via CURL
PHP CURL EXAMPLE:
//API Url
$url = 'https://example.com/api';
//Initiate cURL.
$ch = curl_init($url);
//The JSON data.
$jsonData = array(
'username' => 'MyUsername',
'password' => 'MyPassword'
);
//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Execute the request
$result = curl_exec($ch);
?>
The problem is I need a json format like this:
THE JSON FORMAT I NEED TO SEND VIA POST:
{
"transaction-request": {
"version": "1.0.0",
"verification": {
"merchantId": "*****",
"merchantKey": "*****"
},
"sale": {
"order": {
"reference": "123456789",
"totalAmount": "50000"
},
"payment": {
"acquirer": "1",
"method": "1",
"amount": "10000",
"currency": "986",
"country": "BRA",
"numberOfPayments": "1",
"groupNumber": "0",
"flag": "mastercard",
"cardHolder": "Jose da Silva",
"cardNumber": "*****",
"cardSecurityCode": "123",
"cardExpirationDate": "201805",
"saveCreditCard": "true",
"generateToken": "false",
"departureTax": "0"
},
"billing": {
"customerIdentity": "1",
"name": "Fulano de Tal",
"address": "Av. Federativa, 230",
"address2": "10 Andar",
"city": "Mogi das Cruzes",
"state": "SP",
"postalCode": "20031170",
"country": "BR",
"phone": "*****",
"email": "*****"
},
"urlReturn": "http://loja.exemplo.com.br",
"fraud": "false"
}
}
}
How to create this json format in my php CURL example?