<?php
require_once 'vendor/autoload.php';
use CoinbaseCommerce\ApiClient;
use CoinbaseCommerce\Resources\Charge;

ApiClient::init('4c514d38-f187-41c7-ba1e-9bf449d5345e');

$cargo = new Charge([
	'name' => 'Test Product',
	'description' => 'A description for the test product',
	'local_price' => [
		'amount' => '1.00',
		'currency' => 'USD'
	],
	'metadata' => [
		'customer_id' => 'id_1005',
		'customer_name' => 'Satoshi Nakamoto',
		'order_id' => 'oid_1005'
	],
	'pricing_type' => 'fixed_price'
]);

try {
	$cargo->save();
	echo "Id de compra: ".$cargo->id."<br>"; // ID of the created charge
	echo "URL de pago: <a href='".$cargo->hosted_url."' target='_blank'>PAGAR</a><br>"; // URL to the checkout page
	echo "URL de parámetros: <a href='leerCargoID.php?id=".$cargo->id."' target='_blank'>Ver</a>"; // URL to the checkout page
} catch (\Exception $th) {
	echo "Error: " . $th->getMessage();
}
