Completed
Push — master ( bdfee2...e6cd81 )
by Olivier
02:17
created

Plan::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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\Plan\Plan as PlanModel;
15
use Shapin\Stripe\Model\Plan\PlanCollection;
16
use Symfony\Component\Config\Definition\Processor;
17
18
final class Plan extends HttpApi
19
{
20
    /**
21
     * @throws Exception
22
     */
23 1
    public function get(string $id)
24
    {
25 1
        $response = $this->httpGet("/v1/plans/$id");
26
27 1
        return $this->hydrator->hydrate($response, PlanModel::class);
28
    }
29
30
    /**
31
     * @throws Exception
32
     */
33 1
    public function all(array $params = [])
34
    {
35 1
        $response = $this->httpGet('/v1/plans', $params);
36
37 1
        return $this->hydrator->hydrate($response, PlanCollection::class);
38
    }
39
40
    /**
41
     * @throws Exception
42
     */
43
    public function create(array $params)
44
    {
45
        $processor = new Processor();
46
        $params = $processor->processConfiguration(new Configuration\PlanCreate(), [$params]);
47
48
        if (isset($params['existing_product'])) {
49
            $params['product'] = $params['existing_product'];
50
            unset($params['existing_product']);
51
        }
52
53
        $response = $this->httpPost('/v1/plans', $params);
54
55
        return $this->hydrator->hydrate($response, PlanModel::class);
56
    }
57
58
    /**
59
     * @throws Exception
60
     */
61
    public function update(string $id, array $params)
62
    {
63
        $processor = new Processor();
64
        $processor->processConfiguration(new Configuration\PlanUpdate(), [$params]);
65
66
        $response = $this->httpPost("/v1/plans/$id", $params);
67
68
        return $this->hydrator->hydrate($response, PlanModel::class);
69
    }
70
}
71