<pre><code>$data = json_decode(file_get_contents('php://input'), TRUE);
$text = print_r($data,true);
file_put_contents('coinbase.txt', $text);
</code></pre>

<p>This actually sends the following information to a text file:</p>

<pre><code>Array
(
    [order] =&gt; Array
        (
            [id] =&gt; 
            [created_at] =&gt; 
            [status] =&gt; new
            [total_btc] =&gt; Array
                (
                    [cents] =&gt; 100000000
                    [currency_iso] =&gt; BTC
                )

            [total_native] =&gt; Array
                (
                    [cents] =&gt; 2270
                    [currency_iso] =&gt; USD
                )

            [custom] =&gt; 123456789
            [button] =&gt; Array
                (
                    [type] =&gt; buy_now
                    [name] =&gt; Test Item
                    [description] =&gt; 
                    [id] =&gt; 
                )

            [transaction] =&gt; Array
                (
                    [hash] =&gt; 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
                    [confirmations] =&gt; 0
                )

        )

)
</code></pre>

CC BY-SA 3.0
2013-02-09T06:53:53.030Z
2013-02-09T06:53:53.030Z
fwho
<p>I have never used JSON before and am trying to retrieve the values POSTed to my site from coinbase. But I have no idea how to.</p>

<p>Information about the IPN and callback can be found here: <a href="https://coinbase.com/docs/merchant_tools/callbacks" rel="nofollow">https://coinbase.com/docs/merchant_tools/callbacks</a></p>

<p>To be more specific, what I understand so far is that I can use json_decode($jsonData); to turn the JSON data into PHP data. But how do I set the variable $jsonData?</p>

<p>This is the response that is supposed to be sent:</p>

<pre><code>{"order":{"id":null,"created_at":null,"status":"new","total_btc":
{"cents":100000000,"currency_iso":"BTC"},"total_native":
{"cents":2263,"currency_iso":"USD"},"custom":"123456789","button":
{"type":"buy_now","name":"Test Item","description":null,"id":null},"transaction":
{"hash":"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b","confirmations":0}}}
</code></pre>

CC BY-SA 3.0
2013-02-08T02:22:32.193Z
Could you put `var_dump($_POST);` in your callback and post the output?
Nick ODell
CC BY-SA 3.0
2013-02-08T02:32:33.393Z
I just tried
    $data = var_dump($_POST);
    file_put_contents('coinbase.txt', $data);
with no luck.
fwho
CC BY-SA 3.0
2013-02-08T02:34:35.123Z
Ah, of course. It's been a while since I've done any php. Try `$data = print_r($_POST, TRUE); file_put_contents('coinbase.txt', $data);`
Nick ODell
CC BY-SA 3.0
2013-02-08T02:40:28.993Z
I got Array
(
)
It is a step forward though!
fwho
CC BY-SA 3.0
2013-02-08T04:36:53.903Z
Do you have a shell on this computer? If so, you could do `nc -l 8080`, then set the callback url to `http://yoursite.com:8080/` to see *exactly* what it's sending.
Nick ODell
CC BY-SA 3.0
2013-02-08T17:09:03.393Z
I have no idea how to do that to be honest.
fwho
CC BY-SA 3.0
2013-02-08T18:24:12.903Z
If print_r is displaying "Array ()" then the array returned is is empty.
Highly Irregular
CC BY-SA 3.0
2013-02-08T20:48:56.907Z
I added the data that I am told is being sent. I believe the data is an array nested within an array in JSON format.
fwho
<coinbase.com><commercial><php><merchant-services>
How to retrieve POST data that contains JSON
fwho
# How to retrieve POST data that contains JSON

(Asked by: username_0 on 2013-02-08)

I have never used JSON before and am trying to retrieve the values POSTed to my site from coinbase. But I have no idea how to.
Information about the IPN and callback can be found here: https://coinbase.com/docs/merchant_tools/callbacks
To be more specific, what I understand so far is that I can use json_decode($jsonData); to turn the JSON data into PHP data. But how do I set the variable $jsonData?
This is the response that is supposed to be sent:
{"order":{"id":null,"created_at":null,"status":"new","total_btc":
{"cents":100000000,"currency_iso":"BTC"},"total_native":
{"cents":2263,"currency_iso":"USD"},"custom":"123456789","button":
{"type":"buy_now","name":"Test Item","description":null,"id":null},"transaction":
{"hash":"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b","confirmations":0}}}

**Tags:** coinbase.com, commercial, php, merchant-services

> **Comments:**
> **username_1**: Could you put `var_dump($_POST);` in your callback and post the output?  
> **username_0**: I just tried     $data = var_dump($_POST);     file_put_contents('coinbase.txt', $data); with no luck.  
> **username_1**: Ah, of course. It's been a while since I've done any php. Try `$data = print_r($_POST, TRUE); file_put_contents('coinbase.txt', $data);`  
> **username_0**: I got Array ( ) It is a step forward though!  
> **username_1**: Do you have a shell on this computer? If so, you could do `nc -l 8080`, then set the callback url to `http://yoursite.com:8080/` to see *exactly* what it's sending.  
> **username_0**: I have no idea how to do that to be honest.  
> **username_2**: If print_r is displaying "Array ()" then the array returned is is empty.  
> **username_0**: I added the data that I am told is being sent. I believe the data is an array nested within an array in JSON format.  

---

## 1 answers

### Answer by username_0 on 2013-02-09. Score: 0 | Accepted answer

$data = json_decode(file_get_contents('php://input'), TRUE);
$text = print_r($data,true);
file_put_contents('coinbase.txt', $text);

This actually sends the following information to a text file:
Array
(
    [order] => Array
        (
            [id] => 
            [created_at] => 
            [status] => new
            [total_btc] => Array
                (
                    [cents] => 100000000
                    [currency_iso] => BTC
                )

            [total_native] => Array
                (
                    [cents] => 2270
                    [currency_iso] => USD
                )

            [custom] => 123456789
            [button] => Array
                (
                    [type] => buy_now
                    [name] => Test Item
                    [description] => 
                    [id] => 
                )

            [transaction] => Array
                (
                    [hash] => 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
                    [confirmations] => 0
                )

        )

)


---

