forked from coinbase/coinbase-commerce-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventExample.php
56 lines (47 loc) · 1.53 KB
/
EventExample.php
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
<?php
require_once __DIR__ . "/vendor/autoload.php";
use CoinbaseCommerce\ApiClient;
use CoinbaseCommerce\Resources\Event;
/**
* 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");
try {
$list = Event::getList(["limit" => 5]);
echo sprintf("Successfully got list of events\n");
if (count($list)) {
echo sprintf("Events in list:\n");
foreach ($list as $event) {
echo $event;
}
}
echo sprintf("List\"s pagination:\n");
print_r($list->getPagination());
echo sprintf("Number of all events - %s \n", $list->countAll());
} catch (\Exception $exception) {
echo sprintf("Enable to get list of events. Error: %s \n", $exception->getMessage());
}
if ($list && $list->hasNext()) {
// Load next page with previous settings (limit=5)
try {
$list->loadNext();
echo sprintf("Next page of events: \n");
foreach ($list as $event) {
echo $event;
}
} catch (\Exception $exception) {
echo sprintf("Enable to get new page of events. Error: %s \n", $exception->getMessage());
}
}
// Load all events in array page by page
try {
$allCharge = Event::getAll();
echo sprintf("Successfully got all events:\n");
foreach ($allCharge as $event) {
echo $event;
}
} catch (\Exception $exception) {
echo sprintf("Enable to get all events. Error: %s \n", $exception->getMessage());
}