Completed
Push — master ( 301374...1d98cc )
by Olivier
01:46
created

Customer::delete()   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\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