Skip to content

Commit

Permalink
Autogen from 8a03cf8cfb6b31
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Jan 23, 2020
1 parent 19cc7cf commit ca12071
Show file tree
Hide file tree
Showing 43 changed files with 497 additions and 370 deletions.
239 changes: 141 additions & 98 deletions lib/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
*
* @property string $id
* @property string $object
* @property mixed|null $business_profile
* @property \Stripe\StripeObject|null $business_profile
* @property string|null $business_type
* @property mixed $capabilities
* @property \Stripe\StripeObject $capabilities
* @property bool $charges_enabled
* @property mixed $company
* @property \Stripe\StripeObject $company
* @property string $country
* @property int $created
* @property string $default_currency
* @property bool $details_submitted
* @property string|null $email
* @property \Stripe\Collection $external_accounts
* @property mixed $individual
* @property \Stripe\Person $individual
* @property \Stripe\StripeObject $metadata
* @property bool $payouts_enabled
* @property mixed $requirements
* @property mixed|null $settings
* @property mixed $tos_acceptance
* @property \Stripe\StripeObject $requirements
* @property \Stripe\StripeObject|null $settings
* @property \Stripe\StripeObject $tos_acceptance
* @property string $type
*
* @package Stripe
Expand All @@ -36,10 +36,11 @@ class Account extends ApiResource
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\NestedResource;
use ApiOperations\Update;

use ApiOperations\Retrieve {
retrieve as protected _retrieve;
}
use ApiOperations\Update;

/**
* Possible string representations of an account's business type.
Expand Down Expand Up @@ -85,11 +86,6 @@ public static function getSavedNestedResources()
return $savedNestedResources;
}

const PATH_CAPABILITIES = '/capabilities';
const PATH_EXTERNAL_ACCOUNTS = '/external_accounts';
const PATH_LOGIN_LINKS = '/login_links';
const PATH_PERSONS = '/persons';

public function instanceUrl()
{
if ($this['id'] === null) {
Expand All @@ -99,6 +95,55 @@ public function instanceUrl()
}
}

public function serializeParameters($force = false)
{
$update = parent::serializeParameters($force);
if (isset($this->_values['legal_entity'])) {
$entity = $this['legal_entity'];
if (isset($entity->_values['additional_owners'])) {
$owners = $entity['additional_owners'];
$entityUpdate = isset($update['legal_entity']) ? $update['legal_entity'] : [];
$entityUpdate['additional_owners'] = $this->serializeAdditionalOwners($entity, $owners);
$update['legal_entity'] = $entityUpdate;
}
}
if (isset($this->_values['individual'])) {
$individual = $this['individual'];
if (($individual instanceof Person) && !isset($update['individual'])) {
$update['individual'] = $individual->serializeParameters($force);
}
}
return $update;
}

private function serializeAdditionalOwners($legalEntity, $additionalOwners)
{
if (isset($legalEntity->_originalValues['additional_owners'])) {
$originalValue = $legalEntity->_originalValues['additional_owners'];
} else {
$originalValue = [];
}
if (($originalValue) && (count($originalValue) > count($additionalOwners))) {
throw new Exception\InvalidArgumentException(
"You cannot delete an item from an array, you must instead set a new array"
);
}

$updateArr = [];
foreach ($additionalOwners as $i => $v) {
$update = ($v instanceof StripeObject) ? $v->serializeParameters() : $v;

if ($update !== []) {
if (!$originalValue ||
!array_key_exists($i, $originalValue) ||
($update != $legalEntity->serializeParamsValue($originalValue[$i], null, false, true))) {
$updateArr[$i] = $update;
}
}
}
return $updateArr;
}

/**
* @param array|string|null $id The ID of the account to retrieve, or an
* options array containing an `id` key.
Expand All @@ -117,22 +162,6 @@ public static function retrieve($id = null, $opts = null)
return self::_retrieve($id, $opts);
}

/**
* @param array|null $params
* @param array|string|null $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return Account The rejected account.
*/
public function reject($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/reject';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}

/**
* @param array|null $clientId
* @param array|string|null $opts
Expand All @@ -150,13 +179,31 @@ public function deauthorize($clientId = null, $opts = null)
return OAuth::deauthorize($params, $opts);
}

/**
* @param array|null $params
* @param array|string|null $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return Account The rejected account.
*/
public function reject($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/reject';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}

/*
* Capabilities methods
* We can not add the capabilities() method today as the Account object already has a
* capabilities property which is a hash and not the sub-list of capabilities.
*/


const PATH_CAPABILITIES = '/capabilities';

/**
* @param string $id The ID of the account to which the capability belongs.
* @param string $capabilityId The ID of the capability to retrieve.
Expand All @@ -167,8 +214,12 @@ public function deauthorize($clientId = null, $opts = null)
*
* @return Capability
*/
public static function retrieveCapability($id, $capabilityId, $params = null, $opts = null)
{
public static function retrieveCapability(
$id,
$capabilityId,
$params = null,
$opts = null
) {
return self::_retrieveNestedResource($id, static::PATH_CAPABILITIES, $capabilityId, $params, $opts);
}

Expand All @@ -182,8 +233,12 @@ public static function retrieveCapability($id, $capabilityId, $params = null, $o
*
* @return Capability
*/
public static function updateCapability($id, $capabilityId, $params = null, $opts = null)
{
public static function updateCapability(
$id,
$capabilityId,
$params = null,
$opts = null
) {
return self::_updateNestedResource($id, static::PATH_CAPABILITIES, $capabilityId, $params, $opts);
}

Expand All @@ -201,6 +256,8 @@ public static function allCapabilities($id, $params = null, $opts = null)
return self::_allNestedResources($id, static::PATH_CAPABILITIES, $params, $opts);
}

const PATH_EXTERNAL_ACCOUNTS = '/external_accounts';

/**
* @param string $id The ID of the account on which to create the external account.
* @param array|null $params
Expand All @@ -210,8 +267,11 @@ public static function allCapabilities($id, $params = null, $opts = null)
*
* @return BankAccount|Card
*/
public static function createExternalAccount($id, $params = null, $opts = null)
{
public static function createExternalAccount(
$id,
$params = null,
$opts = null
) {
return self::_createNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $params, $opts);
}

Expand All @@ -225,8 +285,12 @@ public static function createExternalAccount($id, $params = null, $opts = null)
*
* @return BankAccount|Card
*/
public static function retrieveExternalAccount($id, $externalAccountId, $params = null, $opts = null)
{
public static function retrieveExternalAccount(
$id,
$externalAccountId,
$params = null,
$opts = null
) {
return self::_retrieveNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
}

Expand All @@ -240,8 +304,12 @@ public static function retrieveExternalAccount($id, $externalAccountId, $params
*
* @return BankAccount|Card
*/
public static function updateExternalAccount($id, $externalAccountId, $params = null, $opts = null)
{
public static function updateExternalAccount(
$id,
$externalAccountId,
$params = null,
$opts = null
) {
return self::_updateNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
}

Expand All @@ -255,8 +323,12 @@ public static function updateExternalAccount($id, $externalAccountId, $params =
*
* @return BankAccount|Card
*/
public static function deleteExternalAccount($id, $externalAccountId, $params = null, $opts = null)
{
public static function deleteExternalAccount(
$id,
$externalAccountId,
$params = null,
$opts = null
) {
return self::_deleteNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
}

Expand All @@ -269,11 +341,16 @@ public static function deleteExternalAccount($id, $externalAccountId, $params =
*
* @return Collection The list of external accounts (BankAccount or Card).
*/
public static function allExternalAccounts($id, $params = null, $opts = null)
{
public static function allExternalAccounts(
$id,
$params = null,
$opts = null
) {
return self::_allNestedResources($id, static::PATH_EXTERNAL_ACCOUNTS, $params, $opts);
}

const PATH_LOGIN_LINKS = '/login_links';

/**
* @param string $id The ID of the account on which to create the login link.
* @param array|null $params
Expand All @@ -288,6 +365,8 @@ public static function createLoginLink($id, $params = null, $opts = null)
return self::_createNestedResource($id, static::PATH_LOGIN_LINKS, $params, $opts);
}

const PATH_PERSONS = '/persons';

/**
* @param array|null $params
* @param array|string|null $opts
Expand All @@ -305,6 +384,7 @@ public function persons($params = null, $opts = null)
return $obj;
}


/**
* @param string $id The ID of the account on which to create the person.
* @param array|null $params
Expand All @@ -329,8 +409,12 @@ public static function createPerson($id, $params = null, $opts = null)
*
* @return Person
*/
public static function retrievePerson($id, $personId, $params = null, $opts = null)
{
public static function retrievePerson(
$id,
$personId,
$params = null,
$opts = null
) {
return self::_retrieveNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
}

Expand All @@ -344,8 +428,12 @@ public static function retrievePerson($id, $personId, $params = null, $opts = nu
*
* @return Person
*/
public static function updatePerson($id, $personId, $params = null, $opts = null)
{
public static function updatePerson(
$id,
$personId,
$params = null,
$opts = null
) {
return self::_updateNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
}

Expand All @@ -359,8 +447,12 @@ public static function updatePerson($id, $personId, $params = null, $opts = null
*
* @return Person
*/
public static function deletePerson($id, $personId, $params = null, $opts = null)
{
public static function deletePerson(
$id,
$personId,
$params = null,
$opts = null
) {
return self::_deleteNestedResource($id, static::PATH_PERSONS, $personId, $params, $opts);
}

Expand All @@ -377,53 +469,4 @@ public static function allPersons($id, $params = null, $opts = null)
{
return self::_allNestedResources($id, static::PATH_PERSONS, $params, $opts);
}

public function serializeParameters($force = false)
{
$update = parent::serializeParameters($force);
if (isset($this->_values['legal_entity'])) {
$entity = $this['legal_entity'];
if (isset($entity->_values['additional_owners'])) {
$owners = $entity['additional_owners'];
$entityUpdate = isset($update['legal_entity']) ? $update['legal_entity'] : [];
$entityUpdate['additional_owners'] = $this->serializeAdditionalOwners($entity, $owners);
$update['legal_entity'] = $entityUpdate;
}
}
if (isset($this->_values['individual'])) {
$individual = $this['individual'];
if (($individual instanceof Person) && !isset($update['individual'])) {
$update['individual'] = $individual->serializeParameters($force);
}
}
return $update;
}

private function serializeAdditionalOwners($legalEntity, $additionalOwners)
{
if (isset($legalEntity->_originalValues['additional_owners'])) {
$originalValue = $legalEntity->_originalValues['additional_owners'];
} else {
$originalValue = [];
}
if (($originalValue) && (count($originalValue) > count($additionalOwners))) {
throw new Exception\InvalidArgumentException(
"You cannot delete an item from an array, you must instead set a new array"
);
}

$updateArr = [];
foreach ($additionalOwners as $i => $v) {
$update = ($v instanceof StripeObject) ? $v->serializeParameters() : $v;

if ($update !== []) {
if (!$originalValue ||
!array_key_exists($i, $originalValue) ||
($update != $legalEntity->serializeParamsValue($originalValue[$i], null, false, true))) {
$updateArr[$i] = $update;
}
}
}
return $updateArr;
}
}
Loading

0 comments on commit ca12071

Please sign in to comment.