Account.php 16 KB

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