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