Account.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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 requirements or if the account is
  7. * enabled to make live charges or receive payouts.
  8. *
  9. * For accounts where <a href="/api/accounts/object#account_object-controller-requirement_collection">controller.requirement_collection</a>
  10. * is <code>application</code>, which includes Custom accounts, the properties below are always
  11. * returned.
  12. *
  13. * For accounts where <a href="/api/accounts/object#account_object-controller-requirement_collection">controller.requirement_collection</a>
  14. * is <code>stripe</code>, which includes Standard and Express accounts, some properties are only returned
  15. * until you create an <a href="/api/account_links">Account Link</a> or <a href="/api/account_sessions">Account Session</a>
  16. * to start Connect Onboarding. Learn about the <a href="/connect/accounts">differences between accounts</a>.
  17. *
  18. * @property string $id Unique identifier for the object.
  19. * @property string $object String representing the object's type. Objects of the same type share the same value.
  20. * @property null|\Stripe\StripeObject $business_profile Business information about the account.
  21. * @property null|string $business_type The business type. After you create an <a href="/api/account_links">Account Link</a> or <a href="/api/account_sessions">Account Session</a>, this property is only returned for accounts where <a href="/api/accounts/object#account_object-controller-requirement_collection">controller.requirement_collection</a> is <code>application</code>, which includes Custom accounts.
  22. * @property null|\Stripe\StripeObject $capabilities
  23. * @property null|bool $charges_enabled Whether the account can create live charges.
  24. * @property null|\Stripe\StripeObject $company
  25. * @property null|\Stripe\StripeObject $controller
  26. * @property null|string $country The account's country.
  27. * @property null|int $created Time at which the account was connected. Measured in seconds since the Unix epoch.
  28. * @property null|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>.
  29. * @property null|bool $details_submitted Whether account details have been submitted. Accounts with Stripe Dashboard access, which includes Standard accounts, cannot receive payouts before this is true. Accounts where this is false should be directed to <a href="/connect/onboarding">an onboarding flow</a> to finish submitting account details.
  30. * @property null|string $email An email address associated with the account. It's not used for authentication and Stripe doesn't market to this field without explicit approval from the platform.
  31. * @property null|\Stripe\Collection<\Stripe\BankAccount|\Stripe\Card> $external_accounts External accounts (bank accounts and debit cards) currently attached to this account. External accounts are only returned for requests where <code>controller[is_controller]</code> is true.
  32. * @property null|\Stripe\StripeObject $future_requirements
  33. * @property null|\Stripe\Person $individual <p>This is an object representing a person associated with a Stripe account.</p><p>A platform cannot access a person for an account where <a href="/api/accounts/object#account_object-controller-requirement_collection">account.controller.requirement_collection</a> is <code>stripe</code>, which includes Standard and Express accounts, after creating an Account Link or Account Session to start Connect onboarding.</p><p>See the <a href="/connect/standard-accounts">Standard onboarding</a> or <a href="/connect/express-accounts">Express onboarding</a> documentation for information about prefilling information and account onboarding steps. Learn more about <a href="/connect/handling-api-verification#person-information">handling identity verification with the API</a>.</p>
  34. * @property null|\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.
  35. * @property null|bool $payouts_enabled Whether Stripe can send payouts to this account.
  36. * @property null|\Stripe\StripeObject $requirements
  37. * @property null|\Stripe\StripeObject $settings Options for customizing how the account functions within Stripe.
  38. * @property null|\Stripe\StripeObject $tos_acceptance
  39. * @property null|string $type The Stripe account type. Can be <code>standard</code>, <code>express</code>, <code>custom</code>, or <code>none</code>.
  40. */
  41. class Account extends ApiResource
  42. {
  43. const OBJECT_NAME = 'account';
  44. use ApiOperations\NestedResource;
  45. use ApiOperations\Update;
  46. const BUSINESS_TYPE_COMPANY = 'company';
  47. const BUSINESS_TYPE_GOVERNMENT_ENTITY = 'government_entity';
  48. const BUSINESS_TYPE_INDIVIDUAL = 'individual';
  49. const BUSINESS_TYPE_NON_PROFIT = 'non_profit';
  50. const TYPE_CUSTOM = 'custom';
  51. const TYPE_EXPRESS = 'express';
  52. const TYPE_NONE = 'none';
  53. const TYPE_STANDARD = 'standard';
  54. /**
  55. * With <a href="/docs/connect">Connect</a>, you can create Stripe accounts for
  56. * your users. To do this, you’ll first need to <a
  57. * href="https://dashboard.stripe.com/account/applications/settings">register your
  58. * platform</a>.
  59. *
  60. * If you’ve already collected information for your connected accounts, you <a
  61. * href="/docs/connect/best-practices#onboarding">can prefill that information</a>
  62. * when creating the account. Connect Onboarding won’t ask for the prefilled
  63. * information during account onboarding. You can prefill any information on the
  64. * account.
  65. *
  66. * @param null|array $params
  67. * @param null|array|string $options
  68. *
  69. * @throws \Stripe\Exception\ApiErrorException if the request fails
  70. *
  71. * @return \Stripe\Account the created resource
  72. */
  73. public static function create($params = null, $options = null)
  74. {
  75. self::_validateParams($params);
  76. $url = static::classUrl();
  77. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  78. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  79. $obj->setLastResponse($response);
  80. return $obj;
  81. }
  82. /**
  83. * With <a href="/connect">Connect</a>, you can delete accounts you manage.
  84. *
  85. * Test-mode accounts can be deleted at any time.
  86. *
  87. * Live-mode accounts where Stripe is responsible for negative account balances
  88. * cannot be deleted, which includes Standard accounts. Live-mode accounts where
  89. * your platform is liable for negative account balances, which includes Custom and
  90. * Express accounts, can be deleted when all <a
  91. * href="/api/balance/balanace_object">balances</a> are zero.
  92. *
  93. * If you want to delete your own account, use the <a
  94. * href="https://dashboard.stripe.com/settings/account">account information tab in
  95. * your account settings</a> instead.
  96. *
  97. * @param null|array $params
  98. * @param null|array|string $opts
  99. *
  100. * @throws \Stripe\Exception\ApiErrorException if the request fails
  101. *
  102. * @return \Stripe\Account the deleted resource
  103. */
  104. public function delete($params = null, $opts = null)
  105. {
  106. self::_validateParams($params);
  107. $url = $this->instanceUrl();
  108. list($response, $opts) = $this->_request('delete', $url, $params, $opts);
  109. $this->refreshFrom($response, $opts);
  110. return $this;
  111. }
  112. /**
  113. * Returns a list of accounts connected to your platform via <a
  114. * href="/docs/connect">Connect</a>. If you’re not a platform, the list is empty.
  115. *
  116. * @param null|array $params
  117. * @param null|array|string $opts
  118. *
  119. * @throws \Stripe\Exception\ApiErrorException if the request fails
  120. *
  121. * @return \Stripe\Collection<\Stripe\Account> of ApiResources
  122. */
  123. public static function all($params = null, $opts = null)
  124. {
  125. $url = static::classUrl();
  126. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  127. }
  128. /**
  129. * Updates a <a href="/connect/accounts">connected account</a> by setting the
  130. * values of the parameters passed. Any parameters not provided are left unchanged.
  131. *
  132. * For accounts where <a
  133. * href="/api/accounts/object#account_object-controller-requirement_collection">controller.requirement_collection</a>
  134. * is <code>application</code>, which includes Custom accounts, you can update any
  135. * information on the account.
  136. *
  137. * For accounts where <a
  138. * href="/api/accounts/object#account_object-controller-requirement_collection">controller.requirement_collection</a>
  139. * is <code>stripe</code>, which includes Standard and Express accounts, you can
  140. * update all information until you create an <a href="/api/account_links">Account
  141. * Link</a> or <a href="/api/account_sessions">Account Session</a> to start Connect
  142. * onboarding, after which some properties can no longer be updated.
  143. *
  144. * To update your own account, use the <a
  145. * href="https://dashboard.stripe.com/settings/account">Dashboard</a>. Refer to our
  146. * <a href="/docs/connect/updating-accounts">Connect</a> documentation to learn
  147. * more about updating accounts.
  148. *
  149. * @param string $id the ID of the resource to update
  150. * @param null|array $params
  151. * @param null|array|string $opts
  152. *
  153. * @throws \Stripe\Exception\ApiErrorException if the request fails
  154. *
  155. * @return \Stripe\Account the updated resource
  156. */
  157. public static function update($id, $params = null, $opts = null)
  158. {
  159. self::_validateParams($params);
  160. $url = static::resourceUrl($id);
  161. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  162. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  163. $obj->setLastResponse($response);
  164. return $obj;
  165. }
  166. use ApiOperations\Retrieve {
  167. retrieve as protected _retrieve;
  168. }
  169. public static function getSavedNestedResources()
  170. {
  171. static $savedNestedResources = null;
  172. if (null === $savedNestedResources) {
  173. $savedNestedResources = new Util\Set([
  174. 'external_account',
  175. 'bank_account',
  176. ]);
  177. }
  178. return $savedNestedResources;
  179. }
  180. public function instanceUrl()
  181. {
  182. if (null === $this['id']) {
  183. return '/v1/account';
  184. }
  185. return parent::instanceUrl();
  186. }
  187. /**
  188. * @param null|array|string $id the ID of the account to retrieve, or an
  189. * options array containing an `id` key
  190. * @param null|array|string $opts
  191. *
  192. * @throws \Stripe\Exception\ApiErrorException if the request fails
  193. *
  194. * @return \Stripe\Account
  195. */
  196. public static function retrieve($id = null, $opts = null)
  197. {
  198. if (!$opts && \is_string($id) && 'sk_' === \substr($id, 0, 3)) {
  199. $opts = $id;
  200. $id = null;
  201. }
  202. return self::_retrieve($id, $opts);
  203. }
  204. public function serializeParameters($force = false)
  205. {
  206. $update = parent::serializeParameters($force);
  207. if (isset($this->_values['legal_entity'])) {
  208. $entity = $this['legal_entity'];
  209. if (isset($entity->_values['additional_owners'])) {
  210. $owners = $entity['additional_owners'];
  211. $entityUpdate = isset($update['legal_entity']) ? $update['legal_entity'] : [];
  212. $entityUpdate['additional_owners'] = $this->serializeAdditionalOwners($entity, $owners);
  213. $update['legal_entity'] = $entityUpdate;
  214. }
  215. }
  216. if (isset($this->_values['individual'])) {
  217. $individual = $this['individual'];
  218. if (($individual instanceof Person) && !isset($update['individual'])) {
  219. $update['individual'] = $individual->serializeParameters($force);
  220. }
  221. }
  222. return $update;
  223. }
  224. private function serializeAdditionalOwners($legalEntity, $additionalOwners)
  225. {
  226. if (isset($legalEntity->_originalValues['additional_owners'])) {
  227. $originalValue = $legalEntity->_originalValues['additional_owners'];
  228. } else {
  229. $originalValue = [];
  230. }
  231. if (($originalValue) && (\count($originalValue) > \count($additionalOwners))) {
  232. throw new Exception\InvalidArgumentException(
  233. 'You cannot delete an item from an array, you must instead set a new array'
  234. );
  235. }
  236. $updateArr = [];
  237. foreach ($additionalOwners as $i => $v) {
  238. $update = ($v instanceof StripeObject) ? $v->serializeParameters() : $v;
  239. if ([] !== $update) {
  240. if (!$originalValue
  241. || !\array_key_exists($i, $originalValue)
  242. || ($update !== $legalEntity->serializeParamsValue($originalValue[$i], null, false, true))) {
  243. $updateArr[$i] = $update;
  244. }
  245. }
  246. }
  247. return $updateArr;
  248. }
  249. /**
  250. * @param null|array $clientId
  251. * @param null|array|string $opts
  252. *
  253. * @throws \Stripe\Exception\ApiErrorException if the request fails
  254. *
  255. * @return \Stripe\StripeObject object containing the response from the API
  256. */
  257. public function deauthorize($clientId = null, $opts = null)
  258. {
  259. $params = [
  260. 'client_id' => $clientId,
  261. 'stripe_user_id' => $this->id,
  262. ];
  263. return OAuth::deauthorize($params, $opts);
  264. }
  265. /**
  266. * @param null|array $params
  267. * @param null|array|string $opts
  268. *
  269. * @throws \Stripe\Exception\ApiErrorException if the request fails
  270. *
  271. * @return \Stripe\Account the rejected account
  272. */
  273. public function reject($params = null, $opts = null)
  274. {
  275. $url = $this->instanceUrl() . '/reject';
  276. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  277. $this->refreshFrom($response, $opts);
  278. return $this;
  279. }
  280. const PATH_CAPABILITIES = '/capabilities';
  281. /**
  282. * @param string $id the ID of the account on which to retrieve the capabilities
  283. * @param null|array $params
  284. * @param null|array|string $opts
  285. *
  286. * @throws \Stripe\Exception\ApiErrorException if the request fails
  287. *
  288. * @return \Stripe\Collection<\Stripe\Capability> the list of capabilities
  289. */
  290. public static function allCapabilities($id, $params = null, $opts = null)
  291. {
  292. return self::_allNestedResources($id, static::PATH_CAPABILITIES, $params, $opts);
  293. }
  294. /**
  295. * @param string $id the ID of the account to which the capability belongs
  296. * @param string $capabilityId the ID of the capability to retrieve
  297. * @param null|array $params
  298. * @param null|array|string $opts
  299. *
  300. * @throws \Stripe\Exception\ApiErrorException if the request fails
  301. *
  302. * @return \Stripe\Capability
  303. */
  304. public static function retrieveCapability($id, $capabilityId, $params = null, $opts = null)
  305. {
  306. return self::_retrieveNestedResource($id, static::PATH_CAPABILITIES, $capabilityId, $params, $opts);
  307. }
  308. /**
  309. * @param string $id the ID of the account to which the capability belongs
  310. * @param string $capabilityId the ID of the capability to update
  311. * @param null|array $params
  312. * @param null|array|string $opts
  313. *
  314. * @throws \Stripe\Exception\ApiErrorException if the request fails
  315. *
  316. * @return \Stripe\Capability
  317. */
  318. public static function updateCapability($id, $capabilityId, $params = null, $opts = null)
  319. {
  320. return self::_updateNestedResource($id, static::PATH_CAPABILITIES, $capabilityId, $params, $opts);
  321. }
  322. const PATH_EXTERNAL_ACCOUNTS = '/external_accounts';
  323. /**
  324. * @param string $id the ID of the account on which to retrieve the external accounts
  325. * @param null|array $params
  326. * @param null|array|string $opts
  327. *
  328. * @throws \Stripe\Exception\ApiErrorException if the request fails
  329. *
  330. * @return \Stripe\Collection<\Stripe\BankAccount|\Stripe\Card> the list of external accounts (BankAccount or Card)
  331. */
  332. public static function allExternalAccounts($id, $params = null, $opts = null)
  333. {
  334. return self::_allNestedResources($id, static::PATH_EXTERNAL_ACCOUNTS, $params, $opts);
  335. }
  336. /**
  337. * @param string $id the ID of the account on which to create the external account
  338. * @param null|array $params
  339. * @param null|array|string $opts
  340. *
  341. * @throws \Stripe\Exception\ApiErrorException if the request fails
  342. *
  343. * @return \Stripe\BankAccount|\Stripe\Card
  344. */
  345. public static function createExternalAccount($id, $params = null, $opts = null)
  346. {
  347. return self::_createNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $params, $opts);
  348. }
  349. /**
  350. * @param string $id the ID of the account to which the external account belongs
  351. * @param string $externalAccountId the ID of the external account to delete
  352. * @param null|array $params
  353. * @param null|array|string $opts
  354. *
  355. * @throws \Stripe\Exception\ApiErrorException if the request fails
  356. *
  357. * @return \Stripe\BankAccount|\Stripe\Card
  358. */
  359. public static function deleteExternalAccount($id, $externalAccountId, $params = null, $opts = null)
  360. {
  361. return self::_deleteNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
  362. }
  363. /**
  364. * @param string $id the ID of the account to which the external account belongs
  365. * @param string $externalAccountId the ID of the external account to retrieve
  366. * @param null|array $params
  367. * @param null|array|string $opts
  368. *
  369. * @throws \Stripe\Exception\ApiErrorException if the request fails
  370. *
  371. * @return \Stripe\BankAccount|\Stripe\Card
  372. */
  373. public static function retrieveExternalAccount($id, $externalAccountId, $params = null, $opts = null)
  374. {
  375. return self::_retrieveNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
  376. }
  377. /**
  378. * @param string $id the ID of the account to which the external account belongs
  379. * @param string $externalAccountId the ID of the external account to update
  380. * @param null|array $params
  381. * @param null|array|string $opts
  382. *
  383. * @throws \Stripe\Exception\ApiErrorException if the request fails
  384. *
  385. * @return \Stripe\BankAccount|\Stripe\Card
  386. */
  387. public static function updateExternalAccount($id, $externalAccountId, $params = null, $opts = null)
  388. {
  389. return self::_updateNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
  390. }
  391. const PATH_LOGIN_LINKS = '/login_links';
  392. /**
  393. * @param string $id the ID of the account on which to create the login link
  394. * @param null|array $params
  395. * @param null|array|string $opts
  396. *
  397. * @throws \Stripe\Exception\ApiErrorException if the request fails
  398. *
  399. * @return \Stripe\LoginLink
  400. */
  401. public static function createLoginLink($id, $params = null, $opts = null)
  402. {
  403. return self::_createNestedResource($id, static::PATH_LOGIN_LINKS, $params, $opts);
  404. }
  405. const PATH_PERSONS = '/persons';
  406. /**
  407. * @param string $id the ID of the account on which to retrieve the persons
  408. * @param null|array $params
  409. * @param null|array|string $opts
  410. *
  411. * @throws \Stripe\Exception\ApiErrorException if the request fails
  412. *
  413. * @return \Stripe\Collection<\Stripe\Person> the list of persons
  414. */
  415. public static function allPersons($id, $params = null, $opts = null)
  416. {
  417. return self::_allNestedResources($id, static::PATH_PERSONS, $params, $opts);
  418. }
  419. /**
  420. * @param string $id the ID of the account on which to create the person
  421. * @param null|array $params
  422. * @param null|array|string $opts
  423. *
  424. * @throws \Stripe\Exception\ApiErrorException if the request fails
  425. *
  426. * @return \Stripe\Person
  427. */
  428. public static function createPerson($id, $params = null, $opts = null)
  429. {
  430. return self::_createNestedResource($id, static::PATH_PERSONS, $params, $opts);
  431. }
  432. /**
  433. * @param string $id the ID of the account to which the person belongs
  434. * @param string $personId the ID of the person to delete
  435. * @param null|array $params
  436. * @param null|array|string $opts
  437. *
  438. * @throws \Stripe\Exception\ApiErrorException if the request fails
  439. *
  440. * @return \Stripe\Person
  441. */
  442. public static function deletePerson($id, $personId, $params = null, $opts = null)
  443. {
  444. return self::_deleteNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
  445. }
  446. /**
  447. * @param string $id the ID of the account to which the person belongs
  448. * @param string $personId the ID of the person to retrieve
  449. * @param null|array $params
  450. * @param null|array|string $opts
  451. *
  452. * @throws \Stripe\Exception\ApiErrorException if the request fails
  453. *
  454. * @return \Stripe\Person
  455. */
  456. public static function retrievePerson($id, $personId, $params = null, $opts = null)
  457. {
  458. return self::_retrieveNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
  459. }
  460. /**
  461. * @param string $id the ID of the account to which the person belongs
  462. * @param string $personId the ID of the person to update
  463. * @param null|array $params
  464. * @param null|array|string $opts
  465. *
  466. * @throws \Stripe\Exception\ApiErrorException if the request fails
  467. *
  468. * @return \Stripe\Person
  469. */
  470. public static function updatePerson($id, $personId, $params = null, $opts = null)
  471. {
  472. return self::_updateNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
  473. }
  474. }