diff --git a/lib/Account.php b/lib/Account.php index 0c0b0810d4..7a68c42e5d 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. @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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; - } } 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/CreditNote.php b/lib/CreditNote.php index 22ed919f2d..c9782d10ed 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,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 @@ -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 diff --git a/lib/Customer.php b/lib/Customer.php index baae723d4c..3858733f39 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,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 @@ -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 @@ -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 diff --git a/lib/EphemeralKey.php b/lib/EphemeralKey.php index d100d2f6cf..1b7fd82da5 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 4ad0347a3f..0421ad4098 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 \Stripe\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 lines. + * @param array|null $params + * @param array|string|null $opts + * + * @throws StripeExceptionApiErrorException if the request fails + * + * @return \Stripe\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 \Stripe\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 lines. - * @param array|null $params - * @param array|string|null $opts - * - * @throws \Stripe\Exception\ApiErrorException if the request fails - * - * @return \Stripe\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 b68190d2d4..c1e49dd45a 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 \Stripe\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 \Stripe\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/PaymentMethod.php b/lib/PaymentMethod.php index df78105066..c0312024d8 100644 --- a/lib/PaymentMethod.php +++ b/lib/PaymentMethod.php @@ -13,6 +13,7 @@ * @property \Stripe\StripeObject $card_present * @property int $created * @property string|null $customer + * @property \Stripe\StripeObject $fpx * @property \Stripe\StripeObject $ideal * @property bool $livemode * @property \Stripe\StripeObject $metadata diff --git a/lib/Source.php b/lib/Source.php index 1a72fc365f..a85a8aeb55 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..defc046a93 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; @@ -85,7 +86,7 @@ public static function getSavedNestedResources() * * @throws \Stripe\Exception\ApiErrorException if the request fails * - * @return Subscription The deleted subscription. + * @return \Stripe\Subscription The deleted subscription. */ public function cancel($params = null, $opts = null) { @@ -98,7 +99,7 @@ public function cancel($params = null, $opts = null) * * @throws \Stripe\Exception\ApiErrorException if the request fails * - * @return Subscription The updated subscription. + * @return \Stripe\Subscription The updated subscription. */ public function deleteDiscount($params = null, $opts = null) { diff --git a/lib/SubscriptionItem.php b/lib/SubscriptionItem.php index 35acaadf61..3c490e6d6e 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,8 @@ 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 1431a22a91..98f5d80df6 100644 --- a/lib/SubscriptionSchedule.php +++ b/lib/SubscriptionSchedule.php @@ -12,8 +12,8 @@ * @property int $created * @property \Stripe\StripeObject|null $current_phase * @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..f9a0147535 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,8 @@ 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