PHP Coinbase Callback POST

1

2

I've a problem with the callback. The post data is not right, because the users cents is not update.

My Code:

    public function bitcoin($secret) {
        if($secret == App::Config(ROW_CONFIG_COINBASE_SC)) {
            if($_POST) {
                $total = User::Get($_POST["custom"], FIELD_USERS_CENT) + $_POST["total_native"];
                User::Set($_POST["custom"], FIELD_USERS_CENT, $total);
            }
        } else {
            die("error");
        }
    }

the post data:

{
    "order {
        "total_btc":{"cents":269800,"currency_iso":"BTC"},
        "total_native":{"cents":100,"currency_iso":"EUR"},
        "total_payout":{"cents":0,"currency_iso":"USD"},
    }
}

user3803645

Posted 2014-09-10T16:20:32.323

Reputation: 11

Answers

1

You're not accessing the post data correctly.

$data = json_decode(file_get_contents("php://input"))['order'];
$total = User::Get($data['custom'], FIELD_USERS_CENT) + $data['total_native']['cents'];
User::Set($data['custom'], FIELD_USERS_CENT, $total);

See also.

Nick ODell

Posted 2014-09-10T16:20:32.323

Reputation: 26 536