Skip to content

Commit

Permalink
Autogen
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Jan 31, 2020
1 parent 4402181 commit cb5ba60
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 133 deletions.
147 changes: 76 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,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,12 +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 on which to retrieve the capabilities.
* @param array|null $params
Expand Down Expand Up @@ -200,6 +248,8 @@ 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.
* @param array|null $params
Expand Down Expand Up @@ -273,6 +323,8 @@ 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.
* @param array|null $params
Expand All @@ -287,6 +339,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 Down Expand Up @@ -376,53 +430,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
6 changes: 3 additions & 3 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,6 +98,8 @@ 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 credit note line items.
* @param array|null $params
Expand Down
10 changes: 6 additions & 4 deletions lib/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ public static function getSavedNestedResources()
return $savedNestedResources;
}

const PATH_BALANCE_TRANSACTIONS = '/balance_transactions';
const PATH_SOURCES = '/sources';
const PATH_TAX_IDS = '/tax_ids';

/**
* @param array|null $params
* @param array|string|null $opts
Expand All @@ -78,6 +74,8 @@ public function deleteDiscount($params = null, $opts = null)
$this->refreshFrom(['discount' => null], $opts, true);
}

const PATH_BALANCE_TRANSACTIONS = '/balance_transactions';

/**
* @param string $id The ID of the customer on which to retrieve the customer balance transactions.
* @param array|null $params
Expand Down Expand Up @@ -136,6 +134,8 @@ public static function updateBalanceTransaction($id, $balanceTransactionId, $par
return self::_updateNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts);
}

const PATH_SOURCES = '/sources';

/**
* @param string $id The ID of the customer on which to retrieve the payment sources.
* @param array|null $params
Expand Down Expand Up @@ -209,6 +209,8 @@ public static function updateSource($id, $sourceId, $params = null, $opts = null
return self::_updateNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
}

const PATH_TAX_IDS = '/tax_ids';

/**
* @param string $id The ID of the customer on which to retrieve the tax ids.
* @param array|null $params
Expand Down
3 changes: 2 additions & 1 deletion lib/EphemeralKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class EphemeralKey extends ApiResource
{
const OBJECT_NAME = 'ephemeral_key';

use ApiOperations\Delete;

use ApiOperations\Create {
create as protected _create;
}
use ApiOperations\Delete;

/**
* @param array|null $params
Expand Down
10 changes: 6 additions & 4 deletions lib/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@
*/
class File extends ApiResource
{
const OBJECT_NAME = 'file';

use ApiOperations\All;
use ApiOperations\Retrieve;

// This resource can have two different object names. In latter API
// versions, only `file` is used, but since stripe-php may be used with
// any API version, we need to support deserializing the older
// `file_upload` object into the same class.
const OBJECT_NAME = 'file';
const OBJECT_NAME_ALT = "file_upload";
const OBJECT_NAME_ALT = 'file_upload';

use ApiOperations\All;
use ApiOperations\Create {
create as protected _create;
}
use ApiOperations\Retrieve;

public static function classUrl()
{
Expand Down
Loading

0 comments on commit cb5ba60

Please sign in to comment.