firecasey firecasey - 8 months ago 61
JSON Question

Using json encode in php array with cURL

I am very much a please go easy :)

I need to replicate this json using a php json encode:

"payment": {
"amount": 10.00,
"memo": "Client x paid with $10.00 of nickles"

Here is what I am doing, but it doesn't seem to work. I think it has to do with the "payment" key possibly not being represented somehow in the following code?

$params = array(
'payment' => "",
'amount' => $paymentAmount,
'memo' => $memo

$content = json_encode($params);

// send to chargify
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

$json_response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

 $params = array(
                  'payment' => array(
                       'amount'   => $paymentAmount,
                        'memo'    => $memo