From 155586146de8c57f166c3a365a4044c843dfdbfd Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Wed, 29 Jan 2020 15:51:39 -0800 Subject: [PATCH] Autogen --- lib/Account.php | 146 ++++++++++++++++++----------------- lib/ApplicationFee.php | 1 + lib/Balance.php | 1 + lib/CreditNote.php | 11 +-- lib/Customer.php | 47 +++++------ lib/EphemeralKey.php | 3 +- lib/File.php | 10 ++- lib/Invoice.php | 63 +++++++-------- lib/Order.php | 18 ++--- lib/Source.php | 3 +- lib/Subscription.php | 7 +- lib/SubscriptionItem.php | 4 +- lib/SubscriptionSchedule.php | 1 - lib/Transfer.php | 5 +- 14 files changed, 168 insertions(+), 152 deletions(-) diff --git a/lib/Account.php b/lib/Account.php index c9c4646094..fc2e165422 100644 --- a/lib/Account.php +++ b/lib/Account.php @@ -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. @@ -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) { @@ -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. @@ -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 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 @@ -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. @@ -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. @@ -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 @@ -293,7 +345,7 @@ public static function createLoginLink($id, $params = null, $opts = null) * * @throws \Stripe\Exception\ApiErrorException if the request fails * - * @return \Stripe\Collection The list of persons. + * @return Collection The list of persons. */ public function persons($params = null, $opts = null) { @@ -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 @@ -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; - } } diff --git a/lib/ApplicationFee.php b/lib/ApplicationFee.php index 1e7c3006a5..9eb193f583 100644 --- a/lib/ApplicationFee.php +++ b/lib/ApplicationFee.php @@ -30,6 +30,7 @@ class ApplicationFee extends ApiResource use ApiOperations\NestedResource; use ApiOperations\Retrieve; + const PATH_REFUNDS = '/refunds'; /** diff --git a/lib/Balance.php b/lib/Balance.php index e7578bdff2..0c7749eaf4 100644 --- a/lib/Balance.php +++ b/lib/Balance.php @@ -17,6 +17,7 @@ class Balance extends SingletonApiResource { const OBJECT_NAME = 'balance'; + /** * @param array|string|null $opts * diff --git a/lib/CreditNote.php b/lib/CreditNote.php index 33bb792994..e8815d61f5 100644 --- a/lib/CreditNote.php +++ b/lib/CreditNote.php @@ -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. @@ -65,15 +65,13 @@ 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 * * @throws \Stripe\Exception\ApiErrorException if the request fails * - * @return \Stripe\CreditNote The previewed credit note. + * @return CreditNote The previewed credit note. */ public static function preview($params = null, $opts = null) { @@ -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 * diff --git a/lib/Customer.php b/lib/Customer.php index eaf22b1109..dbf7c9884a 100644 --- a/lib/Customer.php +++ b/lib/Customer.php @@ -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 @@ -78,14 +74,17 @@ 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 balance transactions. + * @param string $id The ID of the customer on which to retrieve the customer balance transactions. * @param array|null $params * @param array|string|null $opts * * @throws \Stripe\Exception\ApiErrorException if the request fails * - * @return \Stripe\Collection The list of balance transactions. + * @return \Stripe\Collection The list of customer balance transactions. */ public static function allBalanceTransactions($id, $params = null, $opts = null) { @@ -93,13 +92,13 @@ public static function allBalanceTransactions($id, $params = null, $opts = null) } /** - * @param string $id The ID of the customer on which to create the balance transaction. + * @param string $id The ID of the customer on which to create the customer balance transaction. * @param array|null $params * @param array|string|null $opts * * @throws \Stripe\Exception\ApiErrorException if the request fails * - * @return \Stripe\BalanceTransaction + * @return \Stripe\CustomerBalanceTransaction */ public static function createBalanceTransaction($id, $params = null, $opts = null) { @@ -107,14 +106,14 @@ public static function createBalanceTransaction($id, $params = null, $opts = nul } /** - * @param string $id The ID of the customer to which the balance transaction belongs. - * @param string $balanceTransactionId The ID of the balance transaction to retrieve. + * @param string $id The ID of the customer to which the customer balance transaction belongs. + * @param string $balanceTransactionId The ID of the customer balance transaction to retrieve. * @param array|null $params * @param array|string|null $opts * * @throws \Stripe\Exception\ApiErrorException if the request fails * - * @return \Stripe\BalanceTransaction + * @return \Stripe\CustomerBalanceTransaction */ public static function retrieveBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null) { @@ -122,28 +121,29 @@ public static function retrieveBalanceTransaction($id, $balanceTransactionId, $p } /** - * @param string $id The ID of the customer to which the balance transaction belongs. - * @param string $balanceTransactionId The ID of the balance transaction to update. + * @param string $id The ID of the customer to which the customer balance transaction belongs. + * @param string $balanceTransactionId The ID of the customer balance transaction to update. * @param array|null $params * @param array|string|null $opts * * @throws \Stripe\Exception\ApiErrorException if the request fails * - * @return \Stripe\BalanceTransaction + * @return \Stripe\CustomerBalanceTransaction */ public static function updateBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null) { 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 sources. + * @param string $id The ID of the customer on which to retrieve the payment sources. * @param array|null $params * @param array|string|null $opts * * @throws \Stripe\Exception\ApiErrorException if the request fails * - * @return \Stripe\Collection The list of sources. + * @return \Stripe\Collection The list of payment sources (AlipayAccount, BankAccount, BitcoinReceiver, Card or Source). */ public static function allSources($id, $params = null, $opts = null) { @@ -151,7 +151,7 @@ public static function allSources($id, $params = null, $opts = null) } /** - * @param string $id The ID of the customer on which to create the source. + * @param string $id The ID of the customer on which to create the payment source. * @param array|null $params * @param array|string|null $opts * @@ -165,8 +165,8 @@ public static function createSource($id, $params = null, $opts = null) } /** - * @param string $id The ID of the customer to which the source belongs. - * @param string $sourceId The ID of the source to delete. + * @param string $id The ID of the customer to which the payment source belongs. + * @param string $sourceId The ID of the payment source to delete. * @param array|null $params * @param array|string|null $opts * @@ -180,8 +180,8 @@ public static function deleteSource($id, $sourceId, $params = null, $opts = null } /** - * @param string $id The ID of the customer to which the source belongs. - * @param string $sourceId The ID of the source to retrieve. + * @param string $id The ID of the customer to which the payment source belongs. + * @param string $sourceId The ID of the payment source to retrieve. * @param array|null $params * @param array|string|null $opts * @@ -195,8 +195,8 @@ public static function retrieveSource($id, $sourceId, $params = null, $opts = nu } /** - * @param string $id The ID of the customer to which the source belongs. - * @param string $sourceId The ID of the source to update. + * @param string $id The ID of the customer to which the payment source belongs. + * @param string $sourceId The ID of the payment source to update. * @param array|null $params * @param array|string|null $opts * @@ -208,6 +208,7 @@ 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. diff --git a/lib/EphemeralKey.php b/lib/EphemeralKey.php index 4479ebe412..f7895ce502 100644 --- a/lib/EphemeralKey.php +++ b/lib/EphemeralKey.php @@ -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 diff --git a/lib/File.php b/lib/File.php index a4f8b1900e..6e14ef6927 100644 --- a/lib/File.php +++ b/lib/File.php @@ -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() { diff --git a/lib/Invoice.php b/lib/Invoice.php index 1cb73e36f3..8a09efe637 100644 --- a/lib/Invoice.php +++ b/lib/Invoice.php @@ -77,6 +77,7 @@ class Invoice extends ApiResource use ApiOperations\Delete; use ApiOperations\Retrieve; use ApiOperations\Update; + use ApiOperations\NestedResource; /** @@ -118,6 +119,37 @@ class Invoice extends ApiResource const PATH_LINES = '/lines'; + /** + * @param array|null $params + * @param array|string|null $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return Invoice The upcoming invoice. + */ + public static function upcoming($params = null, $opts = null) + { + $url = static::classUrl() . '/upcoming'; + list($response, $opts) = static::_staticRequest('get', $url, $params, $opts); + $obj = Util\Util::convertToStripeObject($response->json, $opts); + $obj->setLastResponse($response); + return $obj; + } + + /** + * @param string $id The ID of the invoice on which to retrieve the lins. + * @param array|null $params + * @param array|string|null $opts + * + * @throws StripeExceptionApiErrorException if the request fails + * + * @return Collection The list of lines (InvoiceLineItem). + */ + public static function allLines($id, $params = null, $opts = null) + { + return self::_allNestedResources($id, static::PATH_LINES, $params, $opts); + } + /** * @param array|null $params * @param array|string|null $opts @@ -182,23 +214,6 @@ public function sendInvoice($params = null, $opts = null) return $this; } - /** - * @param array|null $params - * @param array|string|null $opts - * - * @throws \Stripe\Exception\ApiErrorException if the request fails - * - * @return Invoice The upcoming invoice. - */ - public static function upcoming($params = null, $opts = null) - { - $url = static::classUrl() . '/upcoming'; - list($response, $opts) = static::_staticRequest('get', $url, $params, $opts); - $obj = Util\Util::convertToStripeObject($response->json, $opts); - $obj->setLastResponse($response); - return $obj; - } - /** * @param array|null $params * @param array|string|null $opts @@ -214,18 +229,4 @@ public function voidInvoice($params = null, $opts = null) $this->refreshFrom($response, $opts); return $this; } - - /** - * @param string $id The ID of the invoice on which to retrieve the lins. - * @param array|null $params - * @param array|string|null $opts - * - * @throws \Stripe\Exception\ApiErrorException if the request fails - * - * @return Collection The list of lines (InvoiceLineItem). - */ - public static function allLines($id, $params = null, $opts = null) - { - return self::_allNestedResources($id, static::PATH_LINES, $params, $opts); - } } diff --git a/lib/Order.php b/lib/Order.php index db9993d8f2..834e343b42 100644 --- a/lib/Order.php +++ b/lib/Order.php @@ -46,14 +46,13 @@ class Order extends ApiResource * * @throws \Stripe\Exception\ApiErrorException if the request fails * - * @return Order The paid order. + * @return OrderReturn The newly created return. */ - public function pay($params = null, $opts = null) + public function returnOrder($params = null, $opts = null) { - $url = $this->instanceUrl() . '/pay'; + $url = $this->instanceUrl() . '/returns'; list($response, $opts) = $this->_request('post', $url, $params, $opts); - $this->refreshFrom($response, $opts); - return $this; + return Util\Util::convertToStripeObject($response, $opts); } /** @@ -62,12 +61,13 @@ public function pay($params = null, $opts = null) * * @throws \Stripe\Exception\ApiErrorException if the request fails * - * @return OrderReturn The newly created return. + * @return Order The paid order. */ - public function returnOrder($params = null, $opts = null) + public function pay($params = null, $opts = null) { - $url = $this->instanceUrl() . '/returns'; + $url = $this->instanceUrl() . '/pay'; list($response, $opts) = $this->_request('post', $url, $params, $opts); - return Util\Util::convertToStripeObject($response, $opts); + $this->refreshFrom($response, $opts); + return $this; } } diff --git a/lib/Source.php b/lib/Source.php index 5345499f50..56ca8f34c4 100644 --- a/lib/Source.php +++ b/lib/Source.php @@ -51,10 +51,11 @@ class Source extends ApiResource const OBJECT_NAME = 'source'; use ApiOperations\Create; - use ApiOperations\NestedResource; use ApiOperations\Retrieve; use ApiOperations\Update; + use ApiOperations\NestedResource; + /** * Possible string representations of source flows. * @link https://stripe.com/docs/api#source_object-flow diff --git a/lib/Subscription.php b/lib/Subscription.php index db8a2cc1d5..82e9deaf5d 100644 --- a/lib/Subscription.php +++ b/lib/Subscription.php @@ -49,9 +49,6 @@ class Subscription extends ApiResource use ApiOperations\All; use ApiOperations\Create; - use ApiOperations\Delete { - delete as protected _delete; - } use ApiOperations\Retrieve; use ApiOperations\Update; @@ -68,6 +65,10 @@ class Subscription extends ApiResource const STATUS_INCOMPLETE = 'incomplete'; const STATUS_INCOMPLETE_EXPIRED = 'incomplete_expired'; + use ApiOperations\Delete { + delete as protected _delete; + } + public static function getSavedNestedResources() { static $savedNestedResources = null; diff --git a/lib/SubscriptionItem.php b/lib/SubscriptionItem.php index de31c595bc..595438eb06 100644 --- a/lib/SubscriptionItem.php +++ b/lib/SubscriptionItem.php @@ -29,7 +29,6 @@ class SubscriptionItem extends ApiResource use ApiOperations\Update; const PATH_USAGE_RECORDS = '/usage_records'; - const PATH_USAGE_RECORD_SUMMARIES = '/usage_record_summaries'; /** * @param string|null $id The ID of the subscription item on which to create the usage record. @@ -64,6 +63,9 @@ public function usageRecordSummaries($params = null, $opts = null) return $obj; } + + const PATH_USAGE_RECORD_SUMMARIES = '/usage_record_summaries'; + /** * @param string $id The ID of the subscription item on which to retrieve the usage record summaries. * @param array|null $params diff --git a/lib/SubscriptionSchedule.php b/lib/SubscriptionSchedule.php index 6bb8f5529e..98f5d80df6 100644 --- a/lib/SubscriptionSchedule.php +++ b/lib/SubscriptionSchedule.php @@ -14,7 +14,6 @@ * @property string $customer * @property \Stripe\StripeObject $default_settings * @property string $end_behavior - * @property mixed|null $invoice_settings * @property bool $livemode * @property \Stripe\StripeObject|null $metadata * @property \Stripe\StripeObject[] $phases diff --git a/lib/Transfer.php b/lib/Transfer.php index ce49c5f02b..a613134ccc 100644 --- a/lib/Transfer.php +++ b/lib/Transfer.php @@ -35,8 +35,6 @@ class Transfer extends ApiResource use ApiOperations\Retrieve; use ApiOperations\Update; - const PATH_REVERSALS = '/reversals'; - /** * Possible string representations of the source type of the transfer. * @link https://stripe.com/docs/api/transfers/object#transfer_object-source_type @@ -62,6 +60,9 @@ public function cancel($params = null, $opts = null) return $this; } + + const PATH_REVERSALS = '/reversals'; + /** * @param string $id The ID of the transfer on which to retrieve the transfer reversals. * @param array|null $params