-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgocardless.php
75 lines (63 loc) · 1.79 KB
/
gocardless.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
if (date_default_timezone_get() == null) {
// So default osx install doesn't explode with warnings.
date_default_timezone_set('Europe/London');
}
require_once __DIR__ . '/vendor/autoload.php';
class GoCardlessAPI
{
public function __construct()
{
$loader = new Twig_Loader_Filesystem(__DIR__ + '/templates');
$this->twig = new Twig_Environment($loader);
$this->client = new GoCardlessPro\Client(array(
'access_token' => getenv('GC_TOKEN'),
'environment' => \GoCardlessPro\Environment::SANDBOX
));
}
public function getCustomer($id)
{
return $this->client->customers()->get($id);
}
public function listPayments($cid)
{
return $this->client->payments()->list(array(
'customer' => $cid
));
}
public function getCustomerMandates($id)
{
return $this->client->mandates()->list(array(
'customer' => $id,
'limit' => 1
));
}
public function chargeCustomer($cid, $mid, $amount)
{
$newPayment = $this->client->payments()->create(array(
'amount' => $amount * 100,
'currency' => 'GBP',
'description' => 'lunch',
'links' => array(
'mandate' => $mid
)
));
return $newPayment;
}
public function getCurrentUser()
{
if ($this->currentUser) {
return $this->currentUser;
}
$this->currentUser = $this->client->creditors()->list()->records()[0];
return $this->currentUser;
}
public function listCustomers()
{
return $this->client->customers()->list()->records();
}
public function listUsers()
{
return $this->client->creditors()->list()->records();
}
}