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\Api; |
11
|
|
|
|
12
|
|
|
use Shapin\Stripe\Configuration; |
13
|
|
|
use Shapin\Stripe\Exception; |
14
|
|
|
use Shapin\Stripe\Model\Customer\Customer as CustomerModel; |
15
|
|
|
use Shapin\Stripe\Model\Customer\CustomerCollection; |
16
|
|
|
use Symfony\Component\Config\Definition\Processor; |
17
|
|
|
|
18
|
|
|
final class Customer extends HttpApi |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @throws Exception |
22
|
|
|
*/ |
23
|
1 |
|
public function get(string $customerId) |
24
|
|
|
{ |
25
|
1 |
|
$response = $this->httpGet("/v1/customers/$customerId"); |
26
|
|
|
|
27
|
1 |
|
if (200 !== $response->getStatusCode()) { |
28
|
|
|
$this->handleErrors($response); |
29
|
|
|
} |
30
|
|
|
|
31
|
1 |
|
return $this->hydrator->hydrate($response, CustomerModel::class); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @throws Exception |
36
|
|
|
*/ |
37
|
1 |
|
public function all(array $params = []) |
38
|
|
|
{ |
39
|
1 |
|
$response = $this->httpGet('/v1/customers', $params); |
40
|
|
|
|
41
|
1 |
|
if (200 !== $response->getStatusCode()) { |
42
|
|
|
$this->handleErrors($response); |
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
return $this->hydrator->hydrate($response, CustomerCollection::class); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @throws Exception |
50
|
|
|
*/ |
51
|
|
|
public function create(array $params) |
52
|
|
|
{ |
53
|
|
|
$processor = new Processor(); |
54
|
|
|
$params = $processor->processConfiguration(new Configuration\CustomerCreate(), [$params]); |
55
|
|
|
|
56
|
|
|
$response = $this->httpPost('/v1/customers', $params); |
57
|
|
|
|
58
|
|
|
if (200 !== $response->getStatusCode()) { |
59
|
|
|
$this->handleErrors($response); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this->hydrator->hydrate($response, CustomerModel::class); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @throws Exception |
67
|
|
|
*/ |
68
|
|
|
public function update(string $id, array $params) |
69
|
|
|
{ |
70
|
|
|
$processor = new Processor(); |
71
|
|
|
$params = $processor->processConfiguration(new Configuration\CustomerUpdate(), [$params]); |
72
|
|
|
|
73
|
|
|
$response = $this->httpPost("/v1/customers/$id", $params); |
74
|
|
|
|
75
|
|
|
if (200 !== $response->getStatusCode()) { |
76
|
|
|
$this->handleErrors($response); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $this->hydrator->hydrate($response, CustomerModel::class); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|