Account.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * This is an object representing a Stripe account. You can retrieve it to see
  6. * properties on the account like its current e-mail address or if the account is
  7. * enabled yet to make live charges.
  8. *
  9. * Some properties, marked below, are available only to platforms that want to <a
  10. * href="https://stripe.com/docs/connect/accounts">create and manage Express or
  11. * Custom accounts</a>.
  12. *
  13. * @property string $id Unique identifier for the object.
  14. * @property string $object String representing the object's type. Objects of the same type share the same value.
  15. * @property null|\Stripe\StripeObject $business_profile Business information about the account.
  16. * @property null|string $business_type The business type.
  17. * @property \Stripe\StripeObject $capabilities
  18. * @property bool $charges_enabled Whether the account can create live charges.
  19. * @property \Stripe\StripeObject $company
  20. * @property \Stripe\StripeObject $controller
  21. * @property string $country The account's country.
  22. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  23. * @property string $default_currency Three-letter ISO currency code representing the default currency for the account. This must be a currency that <a href="https://stripe.com/docs/payouts">Stripe supports in the account's country</a>.
  24. * @property bool $details_submitted Whether account details have been submitted. Standard accounts cannot receive payouts before this is true.
  25. * @property null|string $email An email address associated with the account. You can treat this as metadata: it is not used for authentication or messaging account holders.
  26. * @property \Stripe\Collection<\Stripe\BankAccount|\Stripe\Card> $external_accounts External accounts (bank accounts and debit cards) currently attached to this account
  27. * @property \Stripe\StripeObject $future_requirements
  28. * @property \Stripe\Person $individual <p>This is an object representing a person associated with a Stripe account.</p><p>A platform cannot access a Standard or Express account's persons after the account starts onboarding, such as after generating an account link for the account. See the <a href="https://stripe.com/docs/connect/standard-accounts">Standard onboarding</a> or <a href="https://stripe.com/docs/connect/express-accounts">Express onboarding documentation</a> for information about platform pre-filling and account onboarding steps.</p><p>Related guide: <a href="https://stripe.com/docs/connect/identity-verification-api#person-information">Handling Identity Verification with the API</a>.</p>
  29. * @property \Stripe\StripeObject $metadata Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
  30. * @property bool $payouts_enabled Whether Stripe can send payouts to this account.
  31. * @property \Stripe\StripeObject $requirements
  32. * @property null|\Stripe\StripeObject $settings Options for customizing how the account functions within Stripe.
  33. * @property \Stripe\StripeObject $tos_acceptance
  34. * @property string $type The Stripe account type. Can be <code>standard</code>, <code>express</code>, or <code>custom</code>.
  35. */
  36. class Account extends ApiResource
  37. {
  38. const OBJECT_NAME = 'account';
  39. use ApiOperations\All;
  40. use ApiOperations\Create;
  41. use ApiOperations\Delete;
  42. use ApiOperations\NestedResource;
  43. use ApiOperations\Update;
  44. const BUSINESS_TYPE_COMPANY = 'company';
  45. const BUSINESS_TYPE_GOVERNMENT_ENTITY = 'government_entity';
  46. const BUSINESS_TYPE_INDIVIDUAL = 'individual';
  47. const BUSINESS_TYPE_NON_PROFIT = 'non_profit';
  48. const CAPABILITY_CARD_PAYMENTS = 'card_payments';
  49. const CAPABILITY_LEGACY_PAYMENTS = 'legacy_payments';
  50. const CAPABILITY_PLATFORM_PAYMENTS = 'platform_payments';
  51. const CAPABILITY_TRANSFERS = 'transfers';
  52. const CAPABILITY_STATUS_ACTIVE = 'active';
  53. const CAPABILITY_STATUS_INACTIVE = 'inactive';
  54. const CAPABILITY_STATUS_PENDING = 'pending';
  55. const TYPE_CUSTOM = 'custom';
  56. const TYPE_EXPRESS = 'express';
  57. const TYPE_STANDARD = 'standard';
  58. use ApiOperations\Retrieve {
  59. retrieve as protected _retrieve;
  60. }
  61. public static function getSavedNestedResources()
  62. {
  63. static $savedNestedResources = null;
  64. if (null === $savedNestedResources) {
  65. $savedNestedResources = new Util\Set([
  66. 'external_account',
  67. 'bank_account',
  68. ]);
  69. }
  70. return $savedNestedResources;
  71. }
  72. public function instanceUrl()
  73. {
  74. if (null === $this['id']) {
  75. return '/v1/account';
  76. }
  77. return parent::instanceUrl();
  78. }
  79. public function serializeParameters($force = false)
  80. {
  81. $update = parent::serializeParameters($force);
  82. if (isset($this->_values['legal_entity'])) {
  83. $entity = $this['legal_entity'];
  84. if (isset($entity->_values['additional_owners'])) {
  85. $owners = $entity['additional_owners'];
  86. $entityUpdate = isset($update['legal_entity']) ? $update['legal_entity'] : [];
  87. $entityUpdate['additional_owners'] = $this->serializeAdditionalOwners($entity, $owners);
  88. $update['legal_entity'] = $entityUpdate;
  89. }
  90. }
  91. if (isset($this->_values['individual'])) {
  92. $individual = $this['individual'];
  93. if (($individual instanceof Person) && !isset($update['individual'])) {
  94. $update['individual'] = $individual->serializeParameters($force);
  95. }
  96. }
  97. return $update;
  98. }
  99. private function serializeAdditionalOwners($legalEntity, $additionalOwners)
  100. {
  101. if (isset($legalEntity->_originalValues['additional_owners'])) {
  102. $originalValue = $legalEntity->_originalValues['additional_owners'];
  103. } else {
  104. $originalValue = [];
  105. }
  106. if (($originalValue) && (\count($originalValue) > \count($additionalOwners))) {
  107. throw new Exception\InvalidArgumentException(
  108. 'You cannot delete an item from an array, you must instead set a new array'
  109. );
  110. }
  111. $updateArr = [];
  112. foreach ($additionalOwners as $i => $v) {
  113. $update = ($v instanceof StripeObject) ? $v->serializeParameters() : $v;
  114. if ([] !== $update) {
  115. if (!$originalValue
  116. || !\array_key_exists($i, $originalValue)
  117. || ($update !== $legalEntity->serializeParamsValue($originalValue[$i], null, false, true))) {
  118. $updateArr[$i] = $update;
  119. }
  120. }
  121. }
  122. return $updateArr;
  123. }
  124. /**
  125. * @param null|array|string $id the ID of the account to retrieve, or an
  126. * options array containing an `id` key
  127. * @param null|array|string $opts
  128. *
  129. * @throws \Stripe\Exception\ApiErrorException if the request fails
  130. *
  131. * @return \Stripe\Account
  132. */
  133. public static function retrieve($id = null, $opts = null)
  134. {
  135. if (!$opts && \is_string($id) && 'sk_' === \substr($id, 0, 3)) {
  136. $opts = $id;
  137. $id = null;
  138. }
  139. return self::_retrieve($id, $opts);
  140. }
  141. /**
  142. * @param null|array $clientId
  143. * @param null|array|string $opts
  144. *
  145. * @throws \Stripe\Exception\ApiErrorException if the request fails
  146. *
  147. * @return \Stripe\StripeObject object containing the response from the API
  148. */
  149. public function deauthorize($clientId = null, $opts = null)
  150. {
  151. $params = [
  152. 'client_id' => $clientId,
  153. 'stripe_user_id' => $this->id,
  154. ];
  155. return OAuth::deauthorize($params, $opts);
  156. }
  157. /**
  158. * @param null|array $params
  159. * @param null|array|string $opts
  160. *
  161. * @throws \Stripe\Exception\ApiErrorException if the request fails
  162. *
  163. * @return \Stripe\Collection<\Stripe\Person> the list of persons
  164. */
  165. public function persons($params = null, $opts = null)
  166. {
  167. $url = $this->instanceUrl() . '/persons';
  168. list($response, $opts) = $this->_request('get', $url, $params, $opts);
  169. $obj = Util\Util::convertToStripeObject($response, $opts);
  170. $obj->setLastResponse($response);
  171. return $obj;
  172. }
  173. /**
  174. * @param null|array $params
  175. * @param null|array|string $opts
  176. *
  177. * @throws \Stripe\Exception\ApiErrorException if the request fails
  178. *
  179. * @return \Stripe\Account the rejected account
  180. */
  181. public function reject($params = null, $opts = null)
  182. {
  183. $url = $this->instanceUrl() . '/reject';
  184. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  185. $this->refreshFrom($response, $opts);
  186. return $this;
  187. }
  188. /*
  189. * Capabilities methods
  190. * We can not add the capabilities() method today as the Account object already has a
  191. * capabilities property which is a hash and not the sub-list of capabilities.
  192. */
  193. const PATH_CAPABILITIES = '/capabilities';
  194. /**
  195. * @param string $id the ID of the account on which to retrieve the capabilities
  196. * @param null|array $params
  197. * @param null|array|string $opts
  198. *
  199. * @throws \Stripe\Exception\ApiErrorException if the request fails
  200. *
  201. * @return \Stripe\Collection<\Stripe\Capability> the list of capabilities
  202. */
  203. public static function allCapabilities($id, $params = null, $opts = null)
  204. {
  205. return self::_allNestedResources($id, static::PATH_CAPABILITIES, $params, $opts);
  206. }
  207. /**
  208. * @param string $id the ID of the account to which the capability belongs
  209. * @param string $capabilityId the ID of the capability to retrieve
  210. * @param null|array $params
  211. * @param null|array|string $opts
  212. *
  213. * @throws \Stripe\Exception\ApiErrorException if the request fails
  214. *
  215. * @return \Stripe\Capability
  216. */
  217. public static function retrieveCapability($id, $capabilityId, $params = null, $opts = null)
  218. {
  219. return self::_retrieveNestedResource($id, static::PATH_CAPABILITIES, $capabilityId, $params, $opts);
  220. }
  221. /**
  222. * @param string $id the ID of the account to which the capability belongs
  223. * @param string $capabilityId the ID of the capability to update
  224. * @param null|array $params
  225. * @param null|array|string $opts
  226. *
  227. * @throws \Stripe\Exception\ApiErrorException if the request fails
  228. *
  229. * @return \Stripe\Capability
  230. */
  231. public static function updateCapability($id, $capabilityId, $params = null, $opts = null)
  232. {
  233. return self::_updateNestedResource($id, static::PATH_CAPABILITIES, $capabilityId, $params, $opts);
  234. }
  235. const PATH_EXTERNAL_ACCOUNTS = '/external_accounts';
  236. /**
  237. * @param string $id the ID of the account on which to retrieve the external accounts
  238. * @param null|array $params
  239. * @param null|array|string $opts
  240. *
  241. * @throws \Stripe\Exception\ApiErrorException if the request fails
  242. *
  243. * @return \Stripe\Collection<\Stripe\BankAccount|\Stripe\Card> the list of external accounts (BankAccount or Card)
  244. */
  245. public static function allExternalAccounts($id, $params = null, $opts = null)
  246. {
  247. return self::_allNestedResources($id, static::PATH_EXTERNAL_ACCOUNTS, $params, $opts);
  248. }
  249. /**
  250. * @param string $id the ID of the account on which to create the external account
  251. * @param null|array $params
  252. * @param null|array|string $opts
  253. *
  254. * @throws \Stripe\Exception\ApiErrorException if the request fails
  255. *
  256. * @return \Stripe\BankAccount|\Stripe\Card
  257. */
  258. public static function createExternalAccount($id, $params = null, $opts = null)
  259. {
  260. return self::_createNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $params, $opts);
  261. }
  262. /**
  263. * @param string $id the ID of the account to which the external account belongs
  264. * @param string $externalAccountId the ID of the external account to delete
  265. * @param null|array $params
  266. * @param null|array|string $opts
  267. *
  268. * @throws \Stripe\Exception\ApiErrorException if the request fails
  269. *
  270. * @return \Stripe\BankAccount|\Stripe\Card
  271. */
  272. public static function deleteExternalAccount($id, $externalAccountId, $params = null, $opts = null)
  273. {
  274. return self::_deleteNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
  275. }
  276. /**
  277. * @param string $id the ID of the account to which the external account belongs
  278. * @param string $externalAccountId the ID of the external account to retrieve
  279. * @param null|array $params
  280. * @param null|array|string $opts
  281. *
  282. * @throws \Stripe\Exception\ApiErrorException if the request fails
  283. *
  284. * @return \Stripe\BankAccount|\Stripe\Card
  285. */
  286. public static function retrieveExternalAccount($id, $externalAccountId, $params = null, $opts = null)
  287. {
  288. return self::_retrieveNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
  289. }
  290. /**
  291. * @param string $id the ID of the account to which the external account belongs
  292. * @param string $externalAccountId the ID of the external account to update
  293. * @param null|array $params
  294. * @param null|array|string $opts
  295. *
  296. * @throws \Stripe\Exception\ApiErrorException if the request fails
  297. *
  298. * @return \Stripe\BankAccount|\Stripe\Card
  299. */
  300. public static function updateExternalAccount($id, $externalAccountId, $params = null, $opts = null)
  301. {
  302. return self::_updateNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
  303. }
  304. const PATH_LOGIN_LINKS = '/login_links';
  305. /**
  306. * @param string $id the ID of the account on which to create the login link
  307. * @param null|array $params
  308. * @param null|array|string $opts
  309. *
  310. * @throws \Stripe\Exception\ApiErrorException if the request fails
  311. *
  312. * @return \Stripe\LoginLink
  313. */
  314. public static function createLoginLink($id, $params = null, $opts = null)
  315. {
  316. return self::_createNestedResource($id, static::PATH_LOGIN_LINKS, $params, $opts);
  317. }
  318. const PATH_PERSONS = '/persons';
  319. /**
  320. * @param string $id the ID of the account on which to retrieve the persons
  321. * @param null|array $params
  322. * @param null|array|string $opts
  323. *
  324. * @throws \Stripe\Exception\ApiErrorException if the request fails
  325. *
  326. * @return \Stripe\Collection<\Stripe\Person> the list of persons
  327. */
  328. public static function allPersons($id, $params = null, $opts = null)
  329. {
  330. return self::_allNestedResources($id, static::PATH_PERSONS, $params, $opts);
  331. }
  332. /**
  333. * @param string $id the ID of the account on which to create the person
  334. * @param null|array $params
  335. * @param null|array|string $opts
  336. *
  337. * @throws \Stripe\Exception\ApiErrorException if the request fails
  338. *
  339. * @return \Stripe\Person
  340. */
  341. public static function createPerson($id, $params = null, $opts = null)
  342. {
  343. return self::_createNestedResource($id, static::PATH_PERSONS, $params, $opts);
  344. }
  345. /**
  346. * @param string $id the ID of the account to which the person belongs
  347. * @param string $personId the ID of the person to delete
  348. * @param null|array $params
  349. * @param null|array|string $opts
  350. *
  351. * @throws \Stripe\Exception\ApiErrorException if the request fails
  352. *
  353. * @return \Stripe\Person
  354. */
  355. public static function deletePerson($id, $personId, $params = null, $opts = null)
  356. {
  357. return self::_deleteNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
  358. }
  359. /**
  360. * @param string $id the ID of the account to which the person belongs
  361. * @param string $personId the ID of the person to retrieve
  362. * @param null|array $params
  363. * @param null|array|string $opts
  364. *
  365. * @throws \Stripe\Exception\ApiErrorException if the request fails
  366. *
  367. * @return \Stripe\Person
  368. */
  369. public static function retrievePerson($id, $personId, $params = null, $opts = null)
  370. {
  371. return self::_retrieveNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
  372. }
  373. /**
  374. * @param string $id the ID of the account to which the person belongs
  375. * @param string $personId the ID of the person to update
  376. * @param null|array $params
  377. * @param null|array|string $opts
  378. *
  379. * @throws \Stripe\Exception\ApiErrorException if the request fails
  380. *
  381. * @return \Stripe\Person
  382. */
  383. public static function updatePerson($id, $personId, $params = null, $opts = null)
  384. {
  385. return self::_updateNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
  386. }
  387. }