1
|
|
|
<?php namespace Arcanedev\Stripe\Bases; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Stripe\Exceptions\ApiException; |
4
|
|
|
use Arcanedev\Stripe\Exceptions\InvalidRequestException; |
5
|
|
|
use Arcanedev\Stripe\Resources; |
6
|
|
|
use Arcanedev\Stripe\StripeResource; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class ExternalAccount |
10
|
|
|
* |
11
|
|
|
* @package Arcanedev\Stripe\Bases |
12
|
|
|
* @author ARCANEDEV <[email protected]> |
13
|
|
|
* |
14
|
|
|
* @property string id |
15
|
|
|
* @property bool|null deleted |
16
|
|
|
*/ |
17
|
|
|
abstract class ExternalAccount extends StripeResource |
18
|
|
|
{ |
19
|
|
|
/* ------------------------------------------------------------------------------------------------ |
20
|
|
|
| Getters & Setters |
21
|
|
|
| ------------------------------------------------------------------------------------------------ |
22
|
|
|
*/ |
23
|
|
|
/** |
24
|
|
|
* Get The instance URL for this resource. |
25
|
|
|
* It needs to be special cased because it doesn't fit into the standard resource pattern. |
26
|
|
|
* |
27
|
|
|
* @throws InvalidRequestException |
28
|
|
|
* |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
20 |
|
public function instanceUrl() |
32
|
|
|
{ |
33
|
20 |
|
$id = $this['id']; |
34
|
|
|
|
35
|
20 |
|
if ( ! $id) { |
36
|
2 |
|
$class = get_class($this); |
37
|
2 |
|
throw new InvalidRequestException( |
38
|
2 |
|
"Could not determine which URL to request: $class instance has invalid ID: $id", null |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
18 |
|
if ($this['account']) { |
43
|
|
|
$parent = $this['account']; |
44
|
|
|
$class = Resources\Account::class; |
45
|
|
|
$path = 'external_accounts'; |
46
|
|
|
} |
47
|
18 |
|
elseif ($this['customer']) { |
48
|
14 |
|
$parent = $this['customer']; |
49
|
14 |
|
$class = Resources\Customer::class; |
50
|
14 |
|
$path = 'sources'; |
51
|
|
|
} |
52
|
6 |
|
elseif ($this['recipient']) { |
53
|
6 |
|
$parent = $this['recipient']; |
54
|
6 |
|
$class = 'Arcanedev\\Stripe\\Resources\\Recipient'; |
55
|
6 |
|
$path = 'cards'; |
56
|
|
|
} |
57
|
|
|
else { |
58
|
2 |
|
return null; |
59
|
|
|
} |
60
|
|
|
|
61
|
18 |
|
return implode('/', [ |
62
|
18 |
|
self::classUrl($class), |
63
|
18 |
|
urlencode(str_utf8($parent)), |
64
|
18 |
|
$path, |
65
|
18 |
|
str_utf8($id), |
66
|
|
|
]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/* ------------------------------------------------------------------------------------------------ |
70
|
|
|
| Main Functions |
71
|
|
|
| ------------------------------------------------------------------------------------------------ |
72
|
|
|
*/ |
73
|
|
|
/** |
74
|
|
|
* Delete an external account. |
75
|
|
|
* |
76
|
|
|
* @param array|null $params |
77
|
|
|
* @param array|string|null $options |
78
|
|
|
* |
79
|
|
|
* @return self |
80
|
|
|
*/ |
81
|
6 |
|
public function delete($params = [], $options = null) |
82
|
|
|
{ |
83
|
6 |
|
return $this->scopedDelete($params, $options); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Save an external account. |
88
|
|
|
* |
89
|
|
|
* @param array|string|null $options |
90
|
|
|
* |
91
|
|
|
* @return self |
92
|
|
|
*/ |
93
|
6 |
|
public function save($options = null) |
94
|
|
|
{ |
95
|
6 |
|
return $this->scopedSave($options); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Verify the external account. |
100
|
|
|
* |
101
|
|
|
* @param array|null $params |
102
|
|
|
* @param array|string|null $options |
103
|
|
|
* |
104
|
|
|
* @return self |
105
|
|
|
* |
106
|
|
|
* @throws \Arcanedev\Stripe\Exceptions\ApiException |
107
|
|
|
*/ |
108
|
|
|
public function verify($params = [], $options = null) |
109
|
|
|
{ |
110
|
|
|
if ( ! $this['customer']) |
111
|
|
|
throw new ApiException('Only customer external accounts can be verified in this manner.'); |
112
|
|
|
|
113
|
|
|
$url = $this->instanceUrl() . '/verify'; |
114
|
|
|
list($response, $options) = $this->request('post', $url, $params, $options); |
115
|
|
|
$this->refreshFrom($response, $options); |
116
|
|
|
|
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|