Completed
Push — master ( 30588a...b49168 )
by ARCANEDEV
15s
created

Source::sourceTransactions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Arcanedev\Stripe\Resources;
2
3
use Arcanedev\Stripe\Contracts\Resources\Source as SourceContract;
4
use Arcanedev\Stripe\Exceptions\ApiException;
5
use Arcanedev\Stripe\Exceptions\InvalidRequestException;
6
use Arcanedev\Stripe\StripeResource;
7
use Arcanedev\Stripe\Utilities\Util;
8
9
/**
10
 * Class     Source
11
 *
12
 * @package  Arcanedev\Stripe\Resources
13
 * @author   ARCANEDEV <[email protected]>
14
 *
15
 * @property  string  type
16
 */
17
class Source extends StripeResource implements SourceContract
18
{
19
    /* -----------------------------------------------------------------
20
     |  Main Methods
21
     | -----------------------------------------------------------------
22
     */
23
24
    /**
25
     * List all Sources.
26
     *
27
     * @param  array|null         $params
28
     * @param  array|string|null  $options
29
     *
30
     * @return \Arcanedev\Stripe\Collection|array
31
     */
32
    public static function all($params = [], $options = null)
33
    {
34
        return self::scopedAll($params, $options);
35
    }
36
37
    /**
38
     * Retrieve a Source.
39
     *
40
     * @param  string             $id
41
     * @param  array|string|null  $options
42
     *
43
     * @return self
44
     */
45 8
    public static function retrieve($id, $options = null)
46
    {
47 8
        return self::scopedRetrieve($id, $options);
48
    }
49
50
    /**
51
     * Create a Source.
52
     *
53
     * @param  array|null         $params
54
     * @param  array|string|null  $options
55
     *
56
     * @return self
57
     */
58 2
    public static function create($params = null, $options = null)
59
    {
60 2
        return self::scopedCreate($params, $options);
61
    }
62
63
    /**
64
     * Verify the bank account.
65
     *
66
     * @param  array|null         $params
67
     * @param  array|string|null  $options
68
     *
69
     * @return self
70
     */
71 2
    public function verify($params = null, $options = null)
72
    {
73 2
        list($response, $opts) = $this->request('post', $this->instanceUrl() . '/verify', $params, $options);
74 2
        $this->refreshFrom($response, $opts);
75
76 2
        return $this;
77
    }
78
79
    /**
80
     * Update a source.
81
     *
82
     * @param  string             $id
83
     * @param  array|null         $params
84
     * @param  array|string|null  $options
85
     *
86
     * @return self
87
     */
88
    public static function update($id, $params = null, $options = null)
89
    {
90
        return self::scopedUpdate($id, $params, $options);
91
    }
92
93
    /**
94
     * Save a source.
95
     *
96
     * @param array|string|null $options
97
     *
98
     * @return self
99
     */
100 4
    public function save($options = null)
101
    {
102 4
        return $this->scopedSave($options);
103
    }
104
105
    /**
106
     * Detach a source.
107
     *
108
     * @param  array|null         $params
109
     * @param  array|string|null  $options
110
     *
111
     * @return self
112
     *
113
     * @throws \Arcanedev\Stripe\Exceptions\ApiException
114
     * @throws \Arcanedev\Stripe\Exceptions\InvalidRequestException
115
     */
116 4
    public function detach($params = null, $options = null)
117
    {
118 4
        static::checkArguments($params, $options);
119
120 4
        $id = $this['id'];
121 4
        if ( ! $id) {
122
            $class = get_class($this);
123
124
            throw new InvalidRequestException(
125
                "Could not determine which URL to request: {$class} instance has invalid ID: {$id}", null
126
            );
127
        }
128
129 4
        if ($this['customer']) {
130 2
            $base       = Customer::classUrl();
131 2
            $parentExtn = urlencode(str_utf8($this['customer']));
132 2
            $extn       = urlencode(str_utf8($id));
133
134 2
            list($response, $opts) = $this->request('delete', "{$base}/{$parentExtn}/sources/{$extn}", $params, $options);
135 2
            $this->refreshFrom($response, $opts);
136
137 2
            return $this;
138
        }
139
140 2
        throw new ApiException(
141 2
            'This source object does not appear to be currently attached to a customer object.'
142
        );
143
    }
144
145
    /**
146
     * Delete a source.
147
     *
148
     * @deprecated Use the `detach` method instead.
149
     *
150
     * @param  array|null         $params
151
     * @param  array|string|null  $options
152
     *
153
     * @return self
154
     */
155
    public function delete($params = null, $options = null)
156
    {
157
        return $this->detach($params, $options);
158
    }
159
160
    /**
161
     * Get the source transactions.
162
     *
163
     * @param  array|null         $params
164
     * @param  array|string|null  $options
165
     *
166
     * @return \Arcanedev\Stripe\Collection
167
     */
168 2
    public function sourceTransactions($params = null, $options = null)
169
    {
170 2
        list($response, $opts) = static::staticRequest(
171 2
            'get', $this->instanceUrl().'/source_transactions', $params, $options
172
        );
173
174
        /** @var  \Arcanedev\Stripe\Http\Response  $response */
175 2
        return Util::convertToStripeObject($response->getJson(), $opts)
0 ignored issues
show
Bug introduced by
It seems like $response->getJson() targeting Arcanedev\Stripe\Http\Response::getJson() can also be of type null; however, Arcanedev\Stripe\Utiliti...convertToStripeObject() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
176 2
                   ->setLastResponse($response);
177
    }
178
}
179