XenForo Input - JSON

Robust

Well-known member
Hey,

I'm doing a Coinbase implementation into XenForo, and looking at the callback they send back (https://developers.coinbase.com/docs/merchants/callbacks) shows this:

Code:
{
"order": {
  "id": "5RTQNACF",
  "created_at": "2012-12-09T21:23:41-08:00",
  "status": "completed",
  "event": {
    "type": "completed"
  },
  "total_btc": {
    "cents": 100000000,
    "currency_iso": "BTC"
  },
  "total_native": {
    "cents": 1253,
    "currency_iso": "USD"
  },
  "total_payout": {
    "cents": 2345,
    "currency_iso": "USD"
  },
  "custom": "order1234",
  "receive_address": "1NhwPYPgoPwr5hynRAsto5ZgEcw1LzM3My",
  "button": {
    "type": "buy_now",
    "name": "Alpaca Socks",
    "description": "The ultimate in lightweight footwear",
    "id": "5d37a3b61914d6d0ad15b5135d80c19f"
  },
  "transaction": {
    "id": "514f18b7a5ea3d630a00000f",
    "hash": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
    "confirmations": 0
  },
  "refund_address": "1HcmQZarSgNuGYz4r7ZkjYumiU4PujrNYk"
},
"customer": {
  "email": "coinbase@example.com",
  "shipping_address": [
    "John Smith",
    "123 Main St.",
    "Springfield, OR 97477",
    "United States"
  ]
}
}

So I'm filtering the data from the callback using XenForo_Input. I'm assuming this isn't as simple as 'order' => XenForo_Input::JSON_ARRAY. I'm guessing I should perhaps be doing something else?

Right now I have:

Code:
($request = Zend_Controller_Request_Http sent into function)

        $this->_input = new XenForo_Input($request);

        $this->_filtered = $this->_input->filter(array(
// filter the array
        ));
 
Ok if you have the Zend_Controller_Request_Http done correctly then you can use:
PHP:
$test = new Zend_Filter_Decrypt(array('adapter' => 'mcrypt', 'key' => VARIABLE OR KEY IF REQUIRED BY COINBASE));
$test->setVector(VARIABLE YOUR PASSING);
$filtered = $test->filter(VARIABLE PASSING);

That is what I used for doing a XenForo token check.

You can also use the following:
PHP:
$link = 'some link';
$open = curl_init();
curl_setopt($open, CURLOPT_URL, $link);
curl_setopt($open, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($open, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($open, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070319 Firefox/2.0.0.3");
$data = curl_exec($open);
curl_close($open);

$decodedData = json_decode($data, true);

Then you can grab any data it has return.

The first open is not tested for your case so you would need some playing with data. The second option isn't used too often as it requires a lot more lines of code and probably adds about 0.0003 secs onto your load time which isn't bad.
 
Back
Top Bottom