Completed
Push — master ( 8e0025...04518a )
by
05:55
created

Charge::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the PhpMob package.
5
 *
6
 * (c) Ishmael Doss <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhpMob\Omise\Api;
13
14
use PhpMob\Omise\Api;
15
use PhpMob\Omise\Domain\Charge as Domain;
16
use PhpMob\Omise\Domain\Pagination;
17
18
/**
19
 * @author Ishmael Doss <[email protected]>
20
 *
21
 * @see https://www.omise.co/charges-api
22
 */
23
final class Charge extends Api
24
{
25
    /**
26
     * @param array $parameters
27
     *
28
     * @return Pagination
29
     */
30
    public function all(array $parameters = [])
31
    {
32
        return $this->doRequest('GET', '/charges', $parameters);
33
    }
34
35
    /**
36
     * @param string $id
37
     *
38
     * @return Domain
39
     */
40
    public function find($id)
41
    {
42
        self::assertNotEmpty($id);
43
44
        return $this->doRequest('GET', '/charges/'.$id);
45
    }
46
47
    /**
48
     * @param Domain $charge
49
     */
50
    public function refresh(Domain $charge)
51
    {
52
        $charge->updateStore($this->find($charge->id)->toArray());
53
    }
54
55
    /**
56
     * @param Domain $charge
57
     */
58
    public function create(Domain $charge)
59
    {
60
        $charge->updateStore($this->doRequest('POST', '/charges', $charge->getCreateData())->toArray());
61
    }
62
63
    /**
64
     * @param Domain $charge
65
     */
66
    public function createUsingToken(Domain $charge)
67
    {
68
        self::assertNotEmpty(@$charge->card->id, 'Card token can not be empty.');
69
70
        $this->create($charge);
71
    }
72
73
    /**
74
     * @param Domain $charge
75
     */
76
    public function createUsingCustomer(Domain $charge)
77
    {
78
        self::assertNotEmpty(@$charge->customer->id, 'Customer id can not be empty.');
79
80
        $this->create($charge);
81
    }
82
83
    /**
84
     * @param Domain $charge
85
     */
86
    public function createUsingCustomerAndCard(Domain $charge)
87
    {
88
        self::assertNotEmpty(@$charge->customer->id && @$charge->card->id, 'Require `customer` and `card`.');
89
90
        $this->create($charge);
91
    }
92
93
    /**
94
     * @param Domain $charge
95
     */
96
    public function update(Domain $charge)
97
    {
98
        self::assertNotEmpty($charge->id);
99
100
        $charge->updateStore($this->doRequest('PATCH', '/charges/'.$charge->id, $charge->getUpdateData())->toArray());
101
    }
102
103
    /**
104
     * @param Domain $charge
105
     */
106
    public function capture(Domain $charge)
107
    {
108
        self::assertNotEmpty($charge->id);
109
110
        $charge->updateStore($this->doRequest('POST', '/charges/'.$charge->id.'/capture')->toArray());
111
    }
112
113
    /**
114
     * @param Domain $charge
115
     */
116
    public function reverse(Domain $charge)
117
    {
118
        self::assertNotEmpty($charge->id);
119
120
        $charge->updateStore($this->doRequest('POST', '/charges/'.$charge->id.'/reverse')->toArray());
121
    }
122
}
123