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\Subscription\Item; |
15
|
|
|
use Shapin\Stripe\Model\Subscription\Subscription as SubscriptionModel; |
16
|
|
|
use Shapin\Stripe\Model\Subscription\SubscriptionCollection; |
17
|
|
|
use Symfony\Component\Config\Definition\Processor; |
18
|
|
|
|
19
|
|
|
final class Subscription extends HttpApi |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @throws Exception |
23
|
|
|
*/ |
24
|
1 |
|
public function get(string $id) |
25
|
|
|
{ |
26
|
1 |
|
$response = $this->httpGet("subscriptions/$id"); |
27
|
|
|
|
28
|
1 |
|
return $this->hydrator->hydrate($response, SubscriptionModel::class); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @throws Exception |
33
|
|
|
*/ |
34
|
1 |
|
public function all(array $params = []) |
35
|
|
|
{ |
36
|
1 |
|
$response = $this->httpGet('subscriptions', $params); |
37
|
|
|
|
38
|
1 |
|
return $this->hydrator->hydrate($response, SubscriptionCollection::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @throws Exception |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function create(array $params) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$processor = new Processor(); |
47
|
|
|
$params = $processor->processConfiguration(new Configuration\SubscriptionCreate(), [$params]); |
48
|
|
|
|
49
|
|
|
$response = $this->httpPost('subscriptions', $params); |
50
|
|
|
|
51
|
|
|
return $this->hydrator->hydrate($response, SubscriptionModel::class); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @throws Exception |
56
|
|
|
*/ |
57
|
|
View Code Duplication |
public function cancel(string $id, array $params = []) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$processor = new Processor(); |
60
|
|
|
$params = $processor->processConfiguration(new Configuration\SubscriptionCancel(), [$params]); |
61
|
|
|
|
62
|
|
|
$response = $this->httpDelete("subscriptions/$id", $params); |
63
|
|
|
|
64
|
|
|
return $this->hydrator->hydrate($response, SubscriptionModel::class); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @throws Exception |
69
|
|
|
*/ |
70
|
1 |
|
public function getItem(string $id) |
71
|
|
|
{ |
72
|
1 |
|
$response = $this->httpGet("subscription_items/$id"); |
73
|
|
|
|
74
|
1 |
|
return $this->hydrator->hydrate($response, Item::class); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @throws Exception |
79
|
|
|
*/ |
80
|
|
View Code Duplication |
public function update(string $id, array $params) |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
$processor = new Processor(); |
83
|
|
|
$params = $processor->processConfiguration(new Configuration\SubscriptionUpdate(), [$params]); |
84
|
|
|
|
85
|
|
|
$response = $this->httpPost("subscriptions/$id", $params); |
86
|
|
|
|
87
|
|
|
return $this->hydrator->hydrate($response, SubscriptionModel::class); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.