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
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class Source |
10
|
|
|
* |
11
|
|
|
* @package Arcanedev\Stripe\Resources |
12
|
|
|
* @author ARCANEDEV <[email protected]> |
13
|
|
|
* |
14
|
|
|
* @property string type |
15
|
|
|
*/ |
16
|
|
|
class Source extends StripeResource implements SourceContract |
17
|
|
|
{ |
18
|
|
|
/* ----------------------------------------------------------------- |
19
|
|
|
| Main Methods |
20
|
|
|
| ----------------------------------------------------------------- |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* List all Sources. |
25
|
|
|
* |
26
|
|
|
* @param array|null $params |
27
|
|
|
* @param array|string|null $options |
28
|
|
|
* |
29
|
|
|
* @return \Arcanedev\Stripe\Collection|array |
30
|
|
|
*/ |
31
|
|
|
public static function all($params = [], $options = null) |
32
|
|
|
{ |
33
|
|
|
return self::scopedAll($params, $options); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Retrieve a Source. |
38
|
|
|
* |
39
|
|
|
* @param string $id |
40
|
|
|
* @param array|string|null $options |
41
|
|
|
* |
42
|
|
|
* @return self |
43
|
|
|
*/ |
44
|
18 |
|
public static function retrieve($id, $options = null) |
45
|
|
|
{ |
46
|
18 |
|
return self::scopedRetrieve($id, $options); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Create a Source. |
51
|
|
|
* |
52
|
|
|
* @param array|null $params |
53
|
|
|
* @param array|string|null $options |
54
|
|
|
* |
55
|
|
|
* @return self |
56
|
|
|
*/ |
57
|
3 |
|
public static function create($params = null, $options = null) |
58
|
|
|
{ |
59
|
3 |
|
return self::scopedCreate($params, $options); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Verify the bank account. |
64
|
|
|
* |
65
|
|
|
* @param array|null $params |
66
|
|
|
* @param array|string|null $options |
67
|
|
|
* |
68
|
|
|
* @return self |
69
|
|
|
*/ |
70
|
3 |
|
public function verify($params = null, $options = null) |
71
|
|
|
{ |
72
|
3 |
|
list($response, $opts) = $this->request('post', $this->instanceUrl() . '/verify', $params, $options); |
73
|
3 |
|
$this->refreshFrom($response, $opts); |
74
|
|
|
|
75
|
3 |
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Update a source. |
80
|
|
|
* |
81
|
|
|
* @param string $id |
82
|
|
|
* @param array|null $params |
83
|
|
|
* @param array|string|null $options |
84
|
|
|
* |
85
|
|
|
* @return self |
86
|
|
|
*/ |
87
|
|
|
public static function update($id, $params = null, $options = null) |
88
|
|
|
{ |
89
|
|
|
return self::scopedUpdate($id, $params, $options); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Save a source. |
94
|
|
|
* |
95
|
|
|
* @param array|string|null $options |
96
|
|
|
* |
97
|
|
|
* @return self |
98
|
|
|
*/ |
99
|
6 |
|
public function save($options = null) |
100
|
|
|
{ |
101
|
6 |
|
return $this->scopedSave($options); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Delete a source. |
106
|
|
|
* |
107
|
|
|
* @param array|null $params |
108
|
|
|
* @param array|string|null $options |
109
|
|
|
* |
110
|
|
|
* @return Source |
111
|
|
|
* |
112
|
|
|
* @throws \Arcanedev\Stripe\Exceptions\ApiException |
113
|
|
|
* @throws \Arcanedev\Stripe\Exceptions\InvalidRequestException |
114
|
|
|
*/ |
115
|
6 |
|
public function delete($params = null, $options = null) |
116
|
|
|
{ |
117
|
6 |
|
static::checkArguments($params, $options); |
118
|
|
|
|
119
|
6 |
|
$id = $this['id']; |
120
|
6 |
|
if ( ! $id) { |
121
|
|
|
$class = get_class($this); |
122
|
|
|
|
123
|
|
|
throw new InvalidRequestException( |
124
|
|
|
"Could not determine which URL to request: {$class} instance has invalid ID: {$id}", null |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
6 |
|
if ($this['customer']) { |
129
|
3 |
|
$base = Customer::classUrl(); |
130
|
3 |
|
$parentExtn = urlencode(str_utf8($this['customer'])); |
131
|
3 |
|
$extn = urlencode(str_utf8($id)); |
132
|
|
|
|
133
|
3 |
|
list($response, $opts) = $this->request('delete', "{$base}/{$parentExtn}/sources/{$extn}", $params, $options); |
134
|
3 |
|
$this->refreshFrom($response, $opts); |
135
|
|
|
|
136
|
3 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
3 |
|
throw new ApiException( |
140
|
|
|
'Source objects cannot be deleted, they can only be detached from customer objects. '. |
141
|
2 |
|
'This source object does not appear to be currently attached to a customer object.' |
142
|
1 |
|
); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|