简体   繁体   中英

Get value from coinbase commerce API Response

I am trying to retrieve the status of a coinbase invoice previously created with the API. The response given by the API is an "ArrayObject", and I would like to convert this to json to be able to retrieve the value "status". Thank you in advance for your answers.

Response from the API : https://i.stack.imgur.com/q03sT.png

<?php
 
require_once("../vendor/autoload.php");
 
use CoinbaseCommerce\ApiClient;
use CoinbaseCommerce\Resources\Charge;
 
/**
 * Init ApiClient with your Api Key
 * Your Api Keys are available in the Coinbase Commerce Dashboard.
 * Make sure you don't store your API Key in your source code!
 */
ApiClient::init("XXXX-XXXXX-XXXX-XXXX-XXXXX");
 
$chargeData = [
    'name' => 'CloudPay - Recharge 10€',
    'description' => 'wwww.CloudPay.fr | Rechargez votre solde CloudPay de 10€',
    'local_price' => [
        'amount' => '10.00',
        'currency' => 'EUR'
    ],
    'pricing_type' => 'fixed_price',
    'redirect_url' => "https://cloudpay.fr/paiement?status=success",
    'cancel_url' => "https://cloudpay.fr/paiement?error=crypto_canceled"
];
$chargeObj = Charge::create($chargeData);
 
 
 
echo ("id : ");
echo $chargeObj->id;
echo ("<br><br>");
echo ("url : ");
echo $chargeObj->hosted_url;
 
echo ("<br><br><br>");
 
 
    // Retrieve charge by "id"
    try {
        $retrievedCharge = Charge::retrieve($chargeObj->id);
        echo sprintf("Successfully retrieved charge\n");
        echo ('<br><br>');
        echo $retrievedCharge;
        echo ('<br><br><br><br>');
        // here I want to get the status of the invoice
    } catch (\Exception $exception) {
        echo sprintf("Enable to retrieve charge. Error: %s \n", $exception->getMessage());
    }
 
 
?>
$chargeObj->timeline[0]["status"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM