1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This software may be modified and distributed under the terms |
7
|
|
|
* of the MIT license. See the LICENSE file for details. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Shapin\Stripe; |
11
|
|
|
|
12
|
|
|
use Shapin\Stripe\Hydrator\ModelHydrator; |
13
|
|
|
use Shapin\Stripe\Hydrator\Hydrator; |
14
|
|
|
use Http\Client\HttpClient; |
15
|
|
|
|
16
|
|
|
final class StripeClient |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var HttpClient |
20
|
|
|
*/ |
21
|
|
|
private $httpClient; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Hydrator |
25
|
|
|
*/ |
26
|
|
|
private $hydrator; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var RequestBuilder |
30
|
|
|
*/ |
31
|
|
|
private $requestBuilder; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The constructor accepts already configured HTTP clients. |
35
|
|
|
* Use the configure method to pass a configuration to the Client and create an HTTP Client. |
36
|
|
|
*/ |
37
|
28 |
|
public function __construct( |
38
|
|
|
HttpClient $httpClient, |
39
|
|
|
Hydrator $hydrator = null, |
40
|
|
|
RequestBuilder $requestBuilder = null |
41
|
|
|
) { |
42
|
28 |
|
$this->httpClient = $httpClient; |
43
|
28 |
|
$this->hydrator = $hydrator ?: new ModelHydrator(); |
44
|
28 |
|
$this->requestBuilder = $requestBuilder ?: new RequestBuilder(); |
45
|
28 |
|
} |
46
|
|
|
|
47
|
|
|
public static function configure( |
48
|
|
|
HttpClientConfigurator $httpClientConfigurator, |
49
|
|
|
Hydrator $hydrator = null, |
50
|
|
|
RequestBuilder $requestBuilder = null |
51
|
|
|
): self { |
52
|
|
|
$httpClient = $httpClientConfigurator->createConfiguredClient(); |
53
|
|
|
|
54
|
|
|
return new self($httpClient, $hydrator, $requestBuilder); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public static function create(string $apiKey): self |
58
|
|
|
{ |
59
|
|
|
$httpClientConfigurator = (new HttpClientConfigurator())->setApiKey($apiKey); |
60
|
|
|
|
61
|
|
|
return self::configure($httpClientConfigurator); |
62
|
|
|
} |
63
|
|
|
|
64
|
3 |
|
public function balances(): Api\Balance |
65
|
|
|
{ |
66
|
3 |
|
return new Api\Balance($this->httpClient, $this->hydrator, $this->requestBuilder); |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
public function charges(): Api\Charge |
70
|
|
|
{ |
71
|
1 |
|
return new Api\Charge($this->httpClient, $this->hydrator, $this->requestBuilder); |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
public function refunds(): Api\Refund |
75
|
|
|
{ |
76
|
2 |
|
return new Api\Refund($this->httpClient, $this->hydrator, $this->requestBuilder); |
77
|
|
|
} |
78
|
|
|
|
79
|
2 |
|
public function cards(): Api\Card |
80
|
|
|
{ |
81
|
2 |
|
return new Api\Card($this->httpClient, $this->hydrator, $this->requestBuilder); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function bankAccounts(): Api\BankAccount |
85
|
|
|
{ |
86
|
|
|
return new Api\BankAccount($this->httpClient, $this->hydrator, $this->requestBuilder); |
87
|
|
|
} |
88
|
|
|
|
89
|
2 |
|
public function accounts(): Api\Account |
90
|
|
|
{ |
91
|
2 |
|
return new Api\Account($this->httpClient, $this->hydrator, $this->requestBuilder); |
92
|
|
|
} |
93
|
|
|
|
94
|
1 |
|
public function sources(): Api\Source |
95
|
|
|
{ |
96
|
1 |
|
return new Api\Source($this->httpClient, $this->hydrator, $this->requestBuilder); |
97
|
|
|
} |
98
|
|
|
|
99
|
2 |
|
public function transfers(): Api\Transfer |
100
|
|
|
{ |
101
|
2 |
|
return new Api\Transfer($this->httpClient, $this->hydrator, $this->requestBuilder); |
102
|
|
|
} |
103
|
|
|
|
104
|
2 |
|
public function products(): Api\Product |
105
|
|
|
{ |
106
|
2 |
|
return new Api\Product($this->httpClient, $this->hydrator, $this->requestBuilder); |
107
|
|
|
} |
108
|
|
|
|
109
|
2 |
|
public function customers(): Api\Customer |
110
|
|
|
{ |
111
|
2 |
|
return new Api\Customer($this->httpClient, $this->hydrator, $this->requestBuilder); |
112
|
|
|
} |
113
|
|
|
|
114
|
3 |
|
public function subscriptions(): Api\Subscription |
115
|
|
|
{ |
116
|
3 |
|
return new Api\Subscription($this->httpClient, $this->hydrator, $this->requestBuilder); |
117
|
|
|
} |
118
|
|
|
|
119
|
2 |
|
public function plans(): Api\Plan |
120
|
|
|
{ |
121
|
2 |
|
return new Api\Plan($this->httpClient, $this->hydrator, $this->requestBuilder); |
122
|
|
|
} |
123
|
|
|
|
124
|
2 |
|
public function invoices(): Api\Invoice |
125
|
|
|
{ |
126
|
2 |
|
return new Api\Invoice($this->httpClient, $this->hydrator, $this->requestBuilder); |
127
|
|
|
} |
128
|
|
|
|
129
|
2 |
|
public function coupons(): Api\Coupon |
130
|
|
|
{ |
131
|
2 |
|
return new Api\Coupon($this->httpClient, $this->hydrator, $this->requestBuilder); |
132
|
|
|
} |
133
|
|
|
|
134
|
2 |
|
public function paymentIntents(): Api\PaymentIntent |
135
|
|
|
{ |
136
|
2 |
|
return new Api\PaymentIntent($this->httpClient, $this->hydrator, $this->requestBuilder); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|