Skip to content

Commit

Permalink
Autogen
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Jan 30, 2020
1 parent 6a58162 commit 5dbc6b1
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 163 deletions.
146 changes: 75 additions & 71 deletions lib/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,14 +95,63 @@ 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.
* @param array|string|null $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return Account
* @return \Stripe\Account
*/
public static function retrieve($id = null, $opts = null)
{
Expand All @@ -118,44 +163,48 @@ public static function retrieve($id = null, $opts = null)
}

/**
* @param array|null $params
* @param array|null $clientId
* @param array|string|null $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return Account The rejected account.
* @return \Stripe\StripeObject Object containing the response from the API.
*/
public function reject($params = null, $opts = null)
public function deauthorize($clientId = null, $opts = null)
{
$url = $this->instanceUrl() . '/reject';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
$params = [
'client_id' => $clientId,
'stripe_user_id' => $this->id,
];
return OAuth::deauthorize($params, $opts);
}

/**
* @param array|null $clientId
* @param array|null $params
* @param array|string|null $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return StripeObject Object containing the response from the API.
* @return Account The rejected account.
*/
public function deauthorize($clientId = null, $opts = null)
public function reject($params = null, $opts = null)
{
$params = [
'client_id' => $clientId,
'stripe_user_id' => $this->id,
];
return OAuth::deauthorize($params, $opts);
$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 on which to retrieve the capabilities.
* @param array|null $params
Expand Down Expand Up @@ -199,6 +248,7 @@ public static function updateCapability($id, $capabilityId, $params = null, $opt
{
return self::_updateNestedResource($id, static::PATH_CAPABILITIES, $capabilityId, $params, $opts);
}
const PATH_EXTERNAL_ACCOUNTS = '/external_accounts';

/**
* @param string $id The ID of the account on which to retrieve the external accounts.
Expand Down Expand Up @@ -272,6 +322,7 @@ public static function updateExternalAccount($id, $externalAccountId, $params =
{
return self::_updateNestedResource($id, static::PATH_EXTERNAL_ACCOUNTS, $externalAccountId, $params, $opts);
}
const PATH_LOGIN_LINKS = '/login_links';

/**
* @param string $id The ID of the account on which to create the login link.
Expand All @@ -286,6 +337,7 @@ 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
Expand All @@ -304,6 +356,7 @@ public function persons($params = null, $opts = null)
return $obj;
}


/**
* @param string $id The ID of the account on which to retrieve the persons.
* @param array|null $params
Expand Down Expand Up @@ -376,53 +429,4 @@ public static function updatePerson($id, $personId, $params = null, $opts = null
{
return self::_updateNestedResource($id, static::PATH_PERSONS, $personId, $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;
}
}
1 change: 1 addition & 0 deletions lib/ApplicationFee.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ApplicationFee extends ApiResource
use ApiOperations\NestedResource;
use ApiOperations\Retrieve;


const PATH_REFUNDS = '/refunds';

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ class Balance extends SingletonApiResource
{
const OBJECT_NAME = 'balance';


/**
* @param array|string|null $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return Balance
* @return \Stripe\Balance
*/
public static function retrieve($opts = null)
{
Expand Down
9 changes: 5 additions & 4 deletions lib/CreditNote.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class CreditNote extends ApiResource

use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\NestedResource;
use ApiOperations\Retrieve;
use ApiOperations\Update;
use ApiOperations\NestedResource;

/**
* Possible string representations of the credit note reason.
Expand All @@ -65,8 +65,6 @@ class CreditNote extends ApiResource
const TYPE_POST_PAYMENT = 'post_payment';
const TYPE_PRE_PAYMENT = 'pre_payment';

const PATH_LINES = '/lines';

/**
* @param array|null $params
* @param array|string|null $opts
Expand Down Expand Up @@ -100,8 +98,11 @@ public function voidCreditNote($params = null, $opts = null)
return $this;
}


const PATH_LINES = '/lines';

/**
* @param string $id The ID of the credit note on which to retrieve the lines.
* @param string $id The ID of the credit note on which to retrieve the credit note line items.
* @param array|null $params
* @param array|string|null $opts
*
Expand Down

0 comments on commit 5dbc6b1

Please sign in to comment.