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 |
|
\Stripe\Stripe::setApiKey($stripeSecretKey); |
15
|
1 |
|
\Stripe\Stripe::setApiVersion(STRIPE_API_VERSION); |
|
|
|
|
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function getSubscription($args) { |
19
|
|
|
return \Stripe\Subscription::retrieve($args); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getUpcomingInvoice($args) { |
23
|
|
|
return \Stripe\Invoice::upcoming($args); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function createCustomer($args) { |
27
|
|
|
return \Stripe\Customer::create($args); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function updateCustomer($id, $args) { |
31
|
|
|
return \Stripe\Customer::update($id, $args); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function createSubscription($args) { |
35
|
|
|
return \Stripe\Subscription::create($args); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getInvoices($args) { |
39
|
|
|
return \Stripe\Invoice::all($args); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function createSchedule($id) { |
43
|
|
|
return \Stripe\SubscriptionSchedule::create(['from_subscription' => $id]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function updateSchedule($id, $phases) { |
47
|
|
|
return \Stripe\SubscriptionSchedule::update($id, ['phases' => $phases]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function releaseSchedule($id) { |
51
|
|
|
\Stripe\SubscriptionSchedule::release($id); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function updateSubscription($id, $args) { |
55
|
|
|
\Stripe\Subscription::update($id, $args); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|