9 * @property string $object
10 * @property string $business_logo
11 * @property string $business_name
12 * @property string $business_primary_color
13 * @property string $business_url
14 * @property bool $charges_enabled
15 * @property string $country
16 * @property int $created
17 * @property bool $debit_negative_balances
18 * @property mixed $decline_charge_on
19 * @property string $default_currency
20 * @property bool $details_submitted
21 * @property string $display_name
22 * @property string $email
23 * @property Collection $external_accounts
24 * @property mixed $legal_entity
25 * @property StripeObject $metadata
26 * @property mixed $payout_schedule
27 * @property string $payout_statement_descriptor
28 * @property bool $payouts_enabled
29 * @property string $product_description
30 * @property string $statement_descriptor
31 * @property mixed $support_address
32 * @property string $support_email
33 * @property string $support_phone
34 * @property string $support_url
35 * @property string $timezone
36 * @property mixed $tos_acceptance
37 * @property string $type
38 * @property mixed $verification
42 class Account
extends ApiResource
45 const OBJECT_NAME
= "account";
47 use ApiOperations\All
;
48 use ApiOperations\Create
;
49 use ApiOperations\Delete
;
50 use ApiOperations\NestedResource
;
51 use ApiOperations\Retrieve
{
52 retrieve
as protected _retrieve
;
54 use ApiOperations\Update
;
56 public static function getSavedNestedResources()
58 static $savedNestedResources = null;
59 if ($savedNestedResources === null) {
60 $savedNestedResources = new Util\
Set([
65 return $savedNestedResources;
68 const PATH_EXTERNAL_ACCOUNTS
= '/external_accounts';
69 const PATH_LOGIN_LINKS
= '/login_links';
71 public function instanceUrl()
73 if ($this['id'] === null) {
76 return parent
::instanceUrl();
81 * @param array|string|null $id The ID of the account to retrieve, or an
82 * options array containing an `id` key.
83 * @param array|string|null $opts
87 public static function retrieve($id = null, $opts = null)
89 if (!$opts && is_string($id) && substr($id, 0, 3) === 'sk_') {
93 return self
::_retrieve($id, $opts);
97 * @param array|null $params
98 * @param array|string|null $opts
100 * @return Account The rejected account.
102 public function reject($params = null, $opts = null)
104 $url = $this->instanceUrl() . '/reject';
105 list($response, $opts) = $this->_request('post', $url, $params, $opts);
106 $this->refreshFrom($response, $opts);
111 * @param array|null $clientId
112 * @param array|string|null $opts
114 * @return StripeObject Object containing the response from the API.
116 public function deauthorize($clientId = null, $opts = null)
119 'client_id' => $clientId,
120 'stripe_user_id' => $this->id
,
122 return OAuth
::deauthorize($params, $opts);
126 * @param array|null $id The ID of the account on which to create the external account.
127 * @param array|null $params
128 * @param array|string|null $opts
130 * @return BankAccount|Card
132 public static function createExternalAccount($id, $params = null, $opts = null)
134 return self
::_createNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS
, $params, $opts);
138 * @param array|null $id The ID of the account to which the external account belongs.
139 * @param array|null $externalAccountId The ID of the external account to retrieve.
140 * @param array|null $params
141 * @param array|string|null $opts
143 * @return BankAccount|Card
145 public static function retrieveExternalAccount($id, $externalAccountId, $params = null, $opts = null)
147 return self
::_retrieveNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS
, $externalAccountId, $params, $opts);
151 * @param array|null $id The ID of the account to which the external account belongs.
152 * @param array|null $externalAccountId The ID of the external account to update.
153 * @param array|null $params
154 * @param array|string|null $opts
156 * @return BankAccount|Card
158 public static function updateExternalAccount($id, $externalAccountId, $params = null, $opts = null)
160 return self
::_updateNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS
, $externalAccountId, $params, $opts);
164 * @param array|null $id The ID of the account to which the external account belongs.
165 * @param array|null $externalAccountId The ID of the external account to delete.
166 * @param array|null $params
167 * @param array|string|null $opts
169 * @return BankAccount|Card
171 public static function deleteExternalAccount($id, $externalAccountId, $params = null, $opts = null)
173 return self
::_deleteNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS
, $externalAccountId, $params, $opts);
177 * @param array|null $id The ID of the account on which to retrieve the external accounts.
178 * @param array|null $params
179 * @param array|string|null $opts
181 * @return BankAccount|Card
183 public static function allExternalAccounts($id, $params = null, $opts = null)
185 return self
::_allNestedResources($id, static::PATH_EXTERNAL_ACCOUNTS
, $params, $opts);
189 * @param array|null $id The ID of the account on which to create the login link.
190 * @param array|null $params
191 * @param array|string|null $opts
195 public static function createLoginLink($id, $params = null, $opts = null)
197 return self
::_createNestedResource($id, static::PATH_LOGIN_LINKS
, $params, $opts);
200 public function serializeParameters($force = false)
202 $update = parent
::serializeParameters($force);
203 if (isset($this->_values
['legal_entity'])) {
204 $entity = $this['legal_entity'];
205 if (isset($entity->_values
['additional_owners'])) {
206 $owners = $entity['additional_owners'];
207 $entityUpdate = isset($update['legal_entity']) ?
$update['legal_entity'] : [];
208 $entityUpdate['additional_owners'] = $this->serializeAdditionalOwners($entity, $owners);
209 $update['legal_entity'] = $entityUpdate;
215 private function serializeAdditionalOwners($legalEntity, $additionalOwners)
217 if (isset($legalEntity->_originalValues
['additional_owners'])) {
218 $originalValue = $legalEntity->_originalValues
['additional_owners'];
222 if (($originalValue) && (count($originalValue) > count($additionalOwners))) {
223 throw new \
InvalidArgumentException(
224 "You cannot delete an item from an array, you must instead set a new array"
229 foreach ($additionalOwners as $i => $v) {
230 $update = ($v instanceof StripeObject
) ?
$v->serializeParameters() : $v;
232 if ($update !== []) {
233 if (!$originalValue ||
($update != $legalEntity->serializeParamsValue($originalValue[$i], null, false, true))) {
234 $updateArr[$i] = $update;