Test Failed
Push — master ( 020fe5...ff9a8e )
by
01:58
created

Charge::createUsingSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
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
declare(strict_types=1);
13
14
namespace PhpMob\Omise\Api;
15
16
use PhpMob\Omise\Api;
17
use PhpMob\Omise\Domain\Charge as Domain;
18
use PhpMob\Omise\Domain\Pagination;
19
20
/**
21
 * @author Ishmael Doss <[email protected]>
22
 *
23
 * @see https://www.omise.co/charges-api
24
 */
25
final class Charge extends Api
26
{
27
    /**
28
     * @param array $parameters
29
     *
30
     * @return Pagination
31
     */
32 1
    public function all(array $parameters = [])
33
    {
34 1
        return $this->doRequest('GET', '/charges', $parameters);
35
    }
36
37
    /**
38
     * @param string $id
39
     *
40
     * @return Domain
41
     */
42 6
    public function find($id)
43
    {
44 6
        self::assertNotEmpty($id);
45
46 5
        return $this->doRequest('GET', '/charges/' . $id);
47
    }
48
49
    /**
50
     * @param Domain $charge
51
     */
52 1
    public function refresh(Domain $charge)
53
    {
54 1
        $charge->updateStore($this->find($charge->id)->toArray());
55 1
    }
56
57
    /**
58
     * @param Domain $charge
59
     */
60 4
    public function create(Domain $charge)
61
    {
62 4
        $charge->updateStore($this->doRequest('POST', '/charges', $charge->getCreateData($this->countryCode))->toArray());
63 4
    }
64
65
    /**
66
     * @param Domain $charge
67
     */
68
    public function createUsingSource(Domain $charge)
69
    {
70
        self::assertNotEmpty($charge->source, 'Source can not be empty.');
71
72
        $charge->updateStore($this->doRequest('POST', '/charges', $charge->getCreateUsingSourceData($this->countryCode))->toArray());
73
    }
74
75
    /**
76
     * @param Domain $charge
77
     */
78
    public function createUsingToken(Domain $charge)
79
    {
80
        self::assertNotEmpty($charge->cardToken, 'Card token can not be empty.');
81
82
        $charge->updateStore($this->doRequest('POST', '/charges', $charge->getCreateUsingTokenData($this->countryCode))->toArray());
83
    }
84
85
    /**
86
     * @param Domain $charge
87
     */
88
    public function createUsingCustomer(Domain $charge)
89
    {
90
        self::assertNotEmpty(@$charge->customer->id, 'Customer id can not be empty.');
91
92
        $this->create($charge);
93
    }
94
95
    /**
96
     * @param Domain $charge
97
     */
98 1
    public function createUsingCustomerAndCard(Domain $charge)
99
    {
100 1
        self::assertNotEmpty(@$charge->customer->id && @$charge->card->id, 'Require `customer` and `card`.');
101
102 1
        $this->create($charge);
103 1
    }
104
105
    /**
106
     * @param Domain $charge
107
     */
108 1
    public function update(Domain $charge)
109
    {
110 1
        self::assertNotEmpty($charge->id);
111
112 1
        $charge->updateStore($this->doRequest('PATCH', '/charges/' . $charge->id, $charge->getUpdateData())->toArray());
113 1
    }
114
115
    /**
116
     * @param Domain $charge
117
     */
118 1
    public function capture(Domain $charge)
119
    {
120 1
        self::assertNotEmpty($charge->id);
121
122 1
        $charge->updateStore($this->doRequest('POST', '/charges/' . $charge->id . '/capture')->toArray());
123 1
    }
124
125
    /**
126
     * @param Domain $charge
127
     */
128
    public function reverse(Domain $charge)
129
    {
130
        self::assertNotEmpty($charge->id);
131
132
        $charge->updateStore($this->doRequest('POST', '/charges/' . $charge->id . '/reverse')->toArray());
133
    }
134
}
135