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

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

function leerTodosCargos() {
	try {
		$todosCargos=Charge::getAll();
		foreach ($todosCargos as $cargo) {
			if (isset($cargo->payments[0]['status'])) {
				echo "Estado del pago: CONFIRMADO (ID: $cargo->id)<br>";
				echo 'Url de pago: <a href="'.$cargo->hosted_url.'" target="_blank">'.$cargo->hosted_url.'</a><br>';
			}else {
				echo "Estado del pago: IMPAGO (ID: ".$cargo['id'].")<br>";
			}
		}
	} catch (\Exception $th) {
		echo "Error: " . $th->getMessage();
	}
}

leerTodosCargos();