|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MySociety\TheyWorkForYou; |
|
4
|
|
|
|
|
5
|
|
|
class Stripe { |
|
6
|
|
|
private static $instance; |
|
7
|
|
|
|
|
8
|
1 |
|
public function __construct($stripeSecretKey = "") { |
|
9
|
1 |
|
if (self::$instance) { |
|
10
|
|
|
throw new \RuntimeException('Stripe could not be instantiate more than once. Check PHP implementation : https://github.com/stripe/stripe-php'); |
|
11
|
|
|
} |
|
12
|
1 |
|
self::$instance = $this; |
|
13
|
|
|
|
|
14
|
1 |
|
# Not present in testing |
|
15
|
1 |
|
if ($stripeSecretKey) { |
|
16
|
|
|
$this->client = new \Stripe\StripeClient([ |
|
|
|
|
|
|
17
|
|
|
"api_key" => $stripeSecretKey, |
|
18
|
|
|
"stripe_version" => STRIPE_API_VERSION, |
|
|
|
|
|
|
19
|
|
|
]); |
|
20
|
|
|
} |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function getSubscription($id, $args = []) { |
|
24
|
|
|
return $this->client->subscriptions->retrieve($id, $args); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function getUpcomingInvoice($args) { |
|
28
|
|
|
return $this->client->invoices->upcoming($args); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function createCustomer($args) { |
|
32
|
|
|
return $this->client->customers->create($args); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function updateCustomer($id, $args) { |
|
36
|
|
|
return $this->client->customers->update($id, $args); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function createSubscription($args) { |
|
40
|
|
|
return $this->client->subscriptions->create($args); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getInvoices($args) { |
|
44
|
|
|
return $this->client->invoices->all($args); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function createSchedule($id) { |
|
48
|
|
|
return $this->client->subscriptionSchedules->create(['from_subscription' => $id]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function updateSchedule($id, $phases) { |
|
52
|
|
|
return $this->client->subscriptionSchedules->update($id, ['phases' => $phases]); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function releaseSchedule($id) { |
|
56
|
|
|
$this->client->subscriptionSchedules->release($id); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function updateSubscription($id, $args) { |
|
60
|
|
|
$this->client->subscriptions->update($id, $args); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|