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