forked from coinbase/coinbase-commerce-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoiceExample.php
More file actions
87 lines (75 loc) · 2.48 KB
/
InvoiceExample.php
File metadata and controls
87 lines (75 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
require_once __DIR__ . "/vendor/autoload.php";
use CoinbaseCommerce\ApiClient;
use CoinbaseCommerce\Resources\Invoice;
/**
* 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("API_KEY");
$invoiceObj = new Invoice(
[
'business_name' => 'Crypto Account LLC',
'customer_email' => 'customer@test.com',
'customer_name' => 'Test Customer',
'local_price' => [
'amount' => '100.00',
'currency' => 'USD'
],
'memo' => 'Taxes and Accounting Services'
]
);
try {
$invoiceObj->save();
echo sprintf("Successfully created new invoice with id: %s \n", $invoiceObj->id);
} catch (\Exception $exception) {
echo sprintf("Enable to create invoice. Error: %s \n", $exception->getMessage());
}
if ($invoiceObj->id) {
// Retrieve invoice by "id"
try {
$retrievedInvoice = Invoice::retrieve($invoiceObj->id);
echo sprintf("Successfully retrieved invoice\n");
echo $retrievedInvoice;
} catch (\Exception $exception) {
echo sprintf("Enable to retrieve invoice. Error: %s \n", $exception->getMessage());
}
}
try {
$list = Invoice::getList(["limit" => 5]);
echo sprintf("Successfully got list of invoices\n");
if (count($list)) {
echo sprintf("Invoices in list:\n");
foreach ($list as $invoice) {
echo $invoice;
}
}
echo sprintf("List's pagination:\n");
print_r($list->getPagination());
echo sprintf("Number of all invoices - %s \n", $list->countAll());
} catch (\Exception $exception) {
echo sprintf("Enable to get list of invoices. Error: %s \n", $exception->getMessage());
}
if (isset($list) && $list->hasNext()) {
// Load next page with previous settings (limit=5)
try {
$list->loadNext();
echo sprintf("Next page of invoices: \n");
foreach ($list as $invoice) {
echo $invoice;
}
} catch (\Exception $exception) {
echo sprintf("Enable to get new page of invoices. Error: %s \n", $exception->getMessage());
}
}
// Load all available invoices
try {
$allInvoice = Invoice::getAll();
echo sprintf("Successfully got all invoices:\n");
foreach ($allInvoice as $invoice) {
echo $invoice;
}
} catch (\Exception $exception) {
echo sprintf("Enable to get all invoices. Error: %s \n", $exception->getMessage());
}