I creatint a charge first then retrieving address but it comes with authorization error I have used my valid Api key
$apikey = “*********************************”;
$apiVersion = ‘2018-03-22’;
$currency = ‘USDT’;
$amount = 100;
$metadata = array(
‘customer_id’ => ‘123’,
‘customer_name’ => ‘John Doe’
);
// Create the charge
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ‘https://api.commerce.coinbase.com/charges’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
‘name’ => ‘Deposit’,
‘description’ => ‘Product Description’,
‘pricing_type’ => ‘fixed_price’,
‘local_price’ => array(
‘amount’ => $amount,
‘currency’ => $currency
),
‘metadata’ => $metadata
)));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
'X-CC-Api-Key: '.$apiKey,
'X-CC-Version: '.$apiVersion
));
$result = curl_exec($ch);
$json = json_decode($result);
// Check if there is an error
if (curl_errno($ch)) {
echo 'Error: ’ . curl_error($ch);
} else if (isset($json->error)) {
echo 'Error: ’ . $json->error->message;
} else {
$chargeId = $json->data->id;
// Retrieve the deposit address
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.commerce.coinbase.com/charges/'.$chargeId.'/addresses');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'X-CC-Api-Key: '.$apiKey,
'X-CC-Version: '.$apiVersion
));
$result = curl_exec($ch);
$json = json_decode($result);
// Check if there is an error
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
} else if (isset($json->error)) {
echo 'Error: ' . $json->error->message;
} else {
$address = $json->data->$currency;
echo 'Deposit address: '.$address;
}
}
curl_close($ch);