Просмотр исходного кода

#423 Update Stripe Library from 3.4.0 to 3.23.0

Alex Trofimov 10 лет назад
Родитель
Сommit
49b11fcf63
51 измененных файлов с 5389 добавлено и 3313 удалено
  1. 116 0
      plugins/stripe/CHANGELOG.md
  2. 60 18
      plugins/stripe/README.md
  3. 1 1
      plugins/stripe/VERSION
  4. 3863 3227
      plugins/stripe/data/ca-certificates.crt
  5. 7 0
      plugins/stripe/init.php
  6. 59 1
      plugins/stripe/lib/Account.php
  7. 5 0
      plugins/stripe/lib/AlipayAccount.php
  8. 60 17
      plugins/stripe/lib/ApiRequestor.php
  9. 51 7
      plugins/stripe/lib/ApiResource.php
  10. 32 0
      plugins/stripe/lib/ApiResponse.php
  11. 65 0
      plugins/stripe/lib/ApplePayDomain.php
  12. 19 3
      plugins/stripe/lib/ApplicationFee.php
  13. 5 0
      plugins/stripe/lib/ApplicationFeeRefund.php
  14. 7 1
      plugins/stripe/lib/AttachedObject.php
  15. 10 0
      plugins/stripe/lib/Balance.php
  16. 20 0
      plugins/stripe/lib/BalanceTransaction.php
  17. 18 1
      plugins/stripe/lib/BankAccount.php
  18. 5 0
      plugins/stripe/lib/BitcoinReceiver.php
  19. 5 0
      plugins/stripe/lib/BitcoinTransaction.php
  20. 5 0
      plugins/stripe/lib/Card.php
  21. 48 0
      plugins/stripe/lib/Charge.php
  22. 31 0
      plugins/stripe/lib/Collection.php
  23. 44 0
      plugins/stripe/lib/CountrySpec.php
  24. 17 0
      plugins/stripe/lib/Coupon.php
  25. 34 2
      plugins/stripe/lib/Customer.php
  26. 32 1
      plugins/stripe/lib/Dispute.php
  27. 11 0
      plugins/stripe/lib/Error/Card.php
  28. 15 0
      plugins/stripe/lib/Event.php
  29. 24 0
      plugins/stripe/lib/ExternalAccount.php
  30. 12 0
      plugins/stripe/lib/FileUpload.php
  31. 121 7
      plugins/stripe/lib/HttpClient/CurlClient.php
  32. 20 1
      plugins/stripe/lib/Invoice.php
  33. 17 0
      plugins/stripe/lib/InvoiceItem.php
  34. 27 0
      plugins/stripe/lib/Order.php
  35. 33 0
      plugins/stripe/lib/OrderReturn.php
  36. 17 0
      plugins/stripe/lib/Plan.php
  37. 28 0
      plugins/stripe/lib/Product.php
  38. 17 0
      plugins/stripe/lib/Recipient.php
  39. 29 0
      plugins/stripe/lib/Refund.php
  40. 28 0
      plugins/stripe/lib/SKU.php
  41. 5 0
      plugins/stripe/lib/SingletonApiResource.php
  42. 44 0
      plugins/stripe/lib/Source.php
  43. 53 1
      plugins/stripe/lib/Stripe.php
  44. 34 5
      plugins/stripe/lib/StripeObject.php
  45. 56 18
      plugins/stripe/lib/Subscription.php
  46. 25 0
      plugins/stripe/lib/ThreeDSecure.php
  47. 15 0
      plugins/stripe/lib/Token.php
  48. 45 1
      plugins/stripe/lib/Transfer.php
  49. 14 0
      plugins/stripe/lib/TransferReversal.php
  50. 61 0
      plugins/stripe/lib/Util/AutoPagingIterator.php
  51. 19 1
      plugins/stripe/lib/Util/Util.php

+ 116 - 0
plugins/stripe/CHANGELOG.md

@@ -1,3 +1,119 @@
+### 3.23.0 2016-09-15
+
+* Add support for Apple Pay domains
+
+### 3.22.0 2016-09-13
+
+* Add `Stripe::setAppInfo` to allow plugins to register user agent information
+
+### 3.21.0 2016-08-25
+
+* Add `Source` model for generic payment sources
+
+### 3.20.0 2016-08-08
+
+* Add `getDeclineCode` to card errors
+
+### 3.19.0 2016-07-29
+
+* Opt requests directly into TLS 1.2 where OpenSSL >= 1.0.1 (see #277 for context)
+
+### 3.18.0 2016-07-28
+
+* Add new `STATUS_` constants for subscriptions
+
+### 3.17.1 2016-07-28
+
+* Fix auto-paging iterator so that it plays nicely with `iterator_to_array`
+
+### 3.17.0 2016-07-14
+
+* Add field annotations to model classes for better editor hinting
+
+### 3.16.0 2016-07-12
+
+* Add `ThreeDSecure` model for 3-D secure payments
+
+### 3.15.0 2016-06-29
+
+* Add static `update` method to all resources that can be changed.
+
+### 3.14.3 2016-06-20
+
+* Make sure that cURL never sends `Expects: 100-continue`, even on large request bodies
+
+### 3.14.2 2016-06-03
+
+* Add `inventory` under `SKU` to list of keys that have nested data and can be updated
+
+### 3.14.1 2016-05-27
+
+* Fix some inconsistencies in PHPDoc
+
+### 3.14.0 2016-05-25
+
+* Add support for returning Relay orders
+
+### 3.13.0 2016-05-04
+
+* Add `list`, `create`, `update`, `retrieve`, and `delete` methods to the Subscription class
+
+### 3.12.1 2016-04-07
+
+* Additional check on value arrays for some extra safety
+
+### 3.12.0 2016-03-31
+
+* Fix bug `refreshFrom` on `StripeObject` would not take an `$opts` array
+* Fix bug where `$opts` not passed to parent `save` method in `Account`
+* Fix bug where non-existent variable was referenced in `reverse` in `Transfer`
+* Update CA cert bundle for compatibility with OpenSSL versions below 1.0.1
+
+### 3.11.0 2016-03-22
+
+* Allow `CurlClient` to be initialized with default `CURLOPT_*` options
+
+### 3.10.1 2016-03-22
+
+* Fix bug where request params and options were ignored in `ApplicationFee`'s `refund.`
+
+### 3.10.0 2016-03-15
+
+* Add `reject` on `Account` to support the new API feature
+
+### 3.9.2 2016-03-04
+
+* Fix error when an object's metadata is set more than once
+
+### 3.9.1 2016-02-24
+
+* Fix encoding behavior of nested arrays for requests (see #227)
+
+### 3.9.0 2016-02-09
+
+* Add automatic pagination mechanism with `autoPagingIterator()`
+* Allow global account ID to be set with `Stripe::setAccountId()`
+
+### 3.8.0 2016-02-08
+
+* Add `CountrySpec` model for looking up country payment information
+
+### 3.7.1 2016-02-01
+
+* Update bundled CA certs
+
+### 3.7.0 2016-01-27
+
+* Support deleting Relay products and SKUs
+
+### 3.6.0 2016-01-05
+
+* Allow configuration of HTTP client timeouts
+
+### 3.5.0 2015-12-01
+
+* Add a verification routine for external accounts
+
 ### 3.4.0 2015-09-14
 
 * Products, SKUs, and Orders -- https://stripe.com/relay

+ 60 - 18
plugins/stripe/README.md

@@ -14,20 +14,10 @@ PHP 5.3.3 and later.
 
 ## Composer
 
-You can install the bindings via [Composer](http://getcomposer.org/). Add this to your `composer.json`:
-
-```json
-{
-  "require": {
-    "stripe/stripe-php": "3.*"
-  }
-}
-```
-
-Then install via:
+You can install the bindings via [Composer](http://getcomposer.org/). Run the following command:
 
 ```bash
-composer install
+composer require stripe/stripe-php
 ```
 
 To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/00-intro.md#autoloading):
@@ -44,13 +34,23 @@ If you do not wish to use Composer, you can download the [latest release](https:
 require_once('/path/to/stripe-php/init.php');
 ```
 
+## Dependencies
+
+The bindings require the following extension in order to work properly:
+
+- [`curl`](https://secure.php.net/manual/en/book.curl.php), although you can use your own non-cURL client if you prefer
+- [`json`](https://secure.php.net/manual/en/book.json.php)
+- [`mbstring`](https://secure.php.net/manual/en/book.mbstring.php) (Multibyte String)
+
+If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.
+
 ## Getting Started
 
 Simple usage looks like:
 
 ```php
 \Stripe\Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249');
-$myCard = array('number' => '4242424242424242', 'exp_month' => 5, 'exp_year' => 2015);
+$myCard = array('number' => '4242424242424242', 'exp_month' => 8, 'exp_year' => 2018);
 $charge = \Stripe\Charge::create(array('card' => $myCard, 'amount' => 2000, 'currency' => 'usd'));
 echo $charge;
 ```
@@ -67,21 +67,63 @@ This legacy version may be included via `require_once("/path/to/stripe-php/lib/S
 
 ```php
 Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249');
-$myCard = array('number' => '4242424242424242', 'exp_month' => 5, 'exp_year' => 2015);
+$myCard = array('number' => '4242424242424242', 'exp_month' => 8, 'exp_year' => 2018);
 $charge = Stripe_Charge::create(array('card' => $myCard, 'amount' => 2000, 'currency' => 'usd'));
 echo $charge;
 ```
 
+## Custom Request Timeouts
+
+*NOTE:* We do not recommend decreasing the timeout for non-read-only calls (e.g. charge creation), since even if you locally timeout, the request on Stripe's side can still complete. If you are decreasing timeouts on these calls, make sure to use [idempotency tokens](https://stripe.com/docs/api/php#idempotent_requests) to avoid executing the same transaction twice as a result of timeout retry logic.
+
+To modify request timeouts (connect or total, in seconds) you'll need to tell the API client to use a CurlClient other than its default. You'll set the timeouts in that CurlClient.
+
+```php
+// set up your tweaked Curl client
+$curl = new \Stripe\HttpClient\CurlClient();
+$curl->setTimeout(10); // default is \Stripe\HttpClient\CurlClient::DEFAULT_TIMEOUT
+$curl->setConnectTimeout(5); // default is \Stripe\HttpClient\CurlClient::DEFAULT_CONNECT_TIMEOUT
+
+echo $curl->getTimeout(); // 10
+echo $curl->getConnectTimeout(); // 5
+
+// tell Stripe to use the tweaked client
+\Stripe\ApiRequestor::setHttpClient($curl);
+
+// use the Stripe API client as you normally would
+```
+
+## Custom cURL Options (e.g. proxies)
+
+Need to set a proxy for your requests? Pass in the requisite `CURLOPT_*` array to the CurlClient constructor, using the same syntax as `curl_stopt_array()`. This will set the default cURL options for each HTTP request made by the SDK, though many more common options (e.g. timeouts; see above on how to set those) will be overridden by the client even if set here.
+
+```php
+// set up your tweaked Curl client
+$curl = new \Stripe\HttpClient\CurlClient(array(CURLOPT_PROXY => 'proxy.local:80'));
+// tell Stripe to use the tweaked client
+\Stripe\ApiRequestor::setHttpClient($curl);
+```
+
+Alternately, a callable can be passed to the CurlClient constructor that returns the above array based on request inputs. See `testDefaultOptions()` in `tests/CurlClientTest.php` for an example of this behavior. Note that the callable is called at the beginning of every API request, before the request is sent.
+
+## Development
+
+Install dependencies:
+
+``` bash
+composer install
+```
+
 ## Tests
 
-In order to run tests first install [PHPUnit](http://packagist.org/packages/phpunit/phpunit) via [Composer](http://getcomposer.org/):
+Install dependencies as mentioned above (which will resolve [PHPUnit](http://packagist.org/packages/phpunit/phpunit)), then you can run the test suite:
 
 ```bash
-composer update --dev
+./vendor/bin/phpunit
 ```
 
-To run the test suite:
+Or to run an individual test file:
 
 ```bash
-./vendor/bin/phpunit
+./vendor/bin/phpunit tests/UtilTest.php
 ```

+ 1 - 1
plugins/stripe/VERSION

@@ -1 +1 @@
-3.4.0
+3.23.0

Разница между файлами не показана из-за своего большого размера
+ 3863 - 3227
plugins/stripe/data/ca-certificates.crt


+ 7 - 0
plugins/stripe/init.php

@@ -4,6 +4,7 @@
 require(dirname(__FILE__) . '/lib/Stripe.php');
 
 // Utilities
+require(dirname(__FILE__) . '/lib/Util/AutoPagingIterator.php');
 require(dirname(__FILE__) . '/lib/Util/RequestOptions.php');
 require(dirname(__FILE__) . '/lib/Util/Set.php');
 require(dirname(__FILE__) . '/lib/Util/Util.php');
@@ -22,6 +23,7 @@ require(dirname(__FILE__) . '/lib/Error/InvalidRequest.php');
 require(dirname(__FILE__) . '/lib/Error/RateLimit.php');
 
 // Plumbing
+require(dirname(__FILE__) . '/lib/ApiResponse.php');
 require(dirname(__FILE__) . '/lib/JsonSerializable.php');
 require(dirname(__FILE__) . '/lib/StripeObject.php');
 require(dirname(__FILE__) . '/lib/ApiRequestor.php');
@@ -33,6 +35,7 @@ require(dirname(__FILE__) . '/lib/ExternalAccount.php');
 // Stripe API Resources
 require(dirname(__FILE__) . '/lib/Account.php');
 require(dirname(__FILE__) . '/lib/AlipayAccount.php');
+require(dirname(__FILE__) . '/lib/ApplePayDomain.php');
 require(dirname(__FILE__) . '/lib/ApplicationFee.php');
 require(dirname(__FILE__) . '/lib/ApplicationFeeRefund.php');
 require(dirname(__FILE__) . '/lib/Balance.php');
@@ -43,6 +46,7 @@ require(dirname(__FILE__) . '/lib/BitcoinTransaction.php');
 require(dirname(__FILE__) . '/lib/Card.php');
 require(dirname(__FILE__) . '/lib/Charge.php');
 require(dirname(__FILE__) . '/lib/Collection.php');
+require(dirname(__FILE__) . '/lib/CountrySpec.php');
 require(dirname(__FILE__) . '/lib/Coupon.php');
 require(dirname(__FILE__) . '/lib/Customer.php');
 require(dirname(__FILE__) . '/lib/Dispute.php');
@@ -51,12 +55,15 @@ require(dirname(__FILE__) . '/lib/FileUpload.php');
 require(dirname(__FILE__) . '/lib/Invoice.php');
 require(dirname(__FILE__) . '/lib/InvoiceItem.php');
 require(dirname(__FILE__) . '/lib/Order.php');
+require(dirname(__FILE__) . '/lib/OrderReturn.php');
 require(dirname(__FILE__) . '/lib/Plan.php');
 require(dirname(__FILE__) . '/lib/Product.php');
 require(dirname(__FILE__) . '/lib/Recipient.php');
 require(dirname(__FILE__) . '/lib/Refund.php');
 require(dirname(__FILE__) . '/lib/SKU.php');
+require(dirname(__FILE__) . '/lib/Source.php');
 require(dirname(__FILE__) . '/lib/Subscription.php');
+require(dirname(__FILE__) . '/lib/ThreeDSecure.php');
 require(dirname(__FILE__) . '/lib/Token.php');
 require(dirname(__FILE__) . '/lib/Transfer.php');
 require(dirname(__FILE__) . '/lib/TransferReversal.php');

+ 59 - 1
plugins/stripe/lib/Account.php

@@ -2,6 +2,38 @@
 
 namespace Stripe;
 
+/**
+ * Class Account
+ *
+ * @property string $id
+ * @property string $object
+ * @property mixed $business_logo
+ * @property string $business_name
+ * @property mixed $business_url
+ * @property bool $charges_enabled
+ * @property string $country
+ * @property bool $debit_negative_balances
+ * @property mixed $decline_charge_on
+ * @property string $default_currency
+ * @property bool $details_submitted
+ * @property string $display_name
+ * @property string $email
+ * @property mixed $external_accounts
+ * @property mixed $legal_entity
+ * @property bool $managed
+ * @property mixed $product_description
+ * @property mixed $statement_descriptor
+ * @property mixed $support_email
+ * @property mixed $support_phone
+ * @property string $timezone
+ * @property mixed $tos_acceptance
+ * @property mixed $transfer_schedule
+ * @property bool $transfers_enabled
+ * @property mixed $verification
+ * @property mixed $keys
+ *
+ * @package Stripe
+ */
 class Account extends ApiResource
 {
     public function instanceUrl()
@@ -39,6 +71,18 @@ class Account extends ApiResource
         return self::_create($params, $opts);
     }
 
+    /**
+     * @param string $id The ID of the account to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Account The updated account.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|string|null $opts
      *
@@ -46,7 +90,7 @@ class Account extends ApiResource
      */
     public function save($opts = null)
     {
-        return $this->_save();
+        return $this->_save($opts);
     }
 
     /**
@@ -60,6 +104,20 @@ class Account extends ApiResource
         return $this->_delete($params, $opts);
     }
 
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @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 $params
      * @param array|string|null $opts

+ 5 - 0
plugins/stripe/lib/AlipayAccount.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class AlipayAccount
+ *
+ * @package Stripe
+ */
 class AlipayAccount extends ExternalAccount
 {
 

+ 60 - 17
plugins/stripe/lib/ApiRequestor.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class ApiRequestor
+ *
+ * @package Stripe
+ */
 class ApiRequestor
 {
     private $_apiKey;
@@ -44,7 +49,7 @@ class ApiRequestor
      * @param array|null $params
      * @param array|null $headers
      *
-     * @return array An array whose first element is the response and second
+     * @return array An array whose first element is an API response and second
      *    element is the API key used to make the request.
      */
     public function request($method, $url, $params = null, $headers = null)
@@ -57,7 +62,8 @@ class ApiRequestor
         }
         list($rbody, $rcode, $rheaders, $myApiKey) =
         $this->_requestRaw($method, $url, $params, $headers);
-        $resp = $this->_interpretResponse($rbody, $rcode, $rheaders);
+        $json = $this->_interpretResponse($rbody, $rcode, $rheaders);
+        $resp = new ApiResponse($rbody, $rcode, $rheaders, $json);
         return array($resp, $myApiKey);
     }
 
@@ -91,7 +97,7 @@ class ApiRequestor
 
         switch ($rcode) {
             case 400:
-                // 'rate_limit' code is depreciated, but left here for backwards compatibility
+                // 'rate_limit' code is deprecated, but left here for backwards compatibility
                 // for API versions earlier than 2015-09-08
                 if ($code == 'rate_limit') {
                     throw new Error\RateLimit($msg, $param, $rcode, $rbody, $resp, $rheaders);
@@ -111,6 +117,51 @@ class ApiRequestor
         }
     }
 
+    private static function _formatAppInfo($appInfo)
+    {
+        if ($appInfo !== null) {
+            $string = $appInfo['name'];
+            if ($appInfo['version'] !== null) {
+                $string .= '/' . $appInfo['version'];
+            }
+            if ($appInfo['url'] !== null) {
+                $string .= ' (' . $appInfo['url'] . ')';
+            }
+            return $string;
+        } else {
+            return null;
+        }
+    }
+
+    private static function _defaultHeaders($apiKey)
+    {
+        $appInfo = Stripe::getAppInfo();
+
+        $uaString = 'Stripe/v1 PhpBindings/' . Stripe::VERSION;
+
+        $langVersion = phpversion();
+        $uname = php_uname();
+        $appInfo = Stripe::getAppInfo();
+        $ua = array(
+            'bindings_version' => Stripe::VERSION,
+            'lang' => 'php',
+            'lang_version' => $langVersion,
+            'publisher' => 'stripe',
+            'uname' => $uname,
+        );
+        if ($appInfo !== null) {
+            $uaString .= ' ' . self::_formatAppInfo($appInfo);
+            $ua['application'] = $appInfo;
+        }
+
+        $defaultHeaders = array(
+            'X-Stripe-Client-User-Agent' => json_encode($ua),
+            'User-Agent' => $uaString,
+            'Authorization' => 'Bearer ' . $apiKey,
+        );
+        return $defaultHeaders;
+    }
+
     private function _requestRaw($method, $url, $params, $headers)
     {
         $myApiKey = $this->_apiKey;
@@ -128,23 +179,15 @@ class ApiRequestor
 
         $absUrl = $this->_apiBase.$url;
         $params = self::_encodeObjects($params);
-        $langVersion = phpversion();
-        $uname = php_uname();
-        $ua = array(
-            'bindings_version' => Stripe::VERSION,
-            'lang' => 'php',
-            'lang_version' => $langVersion,
-            'publisher' => 'stripe',
-            'uname' => $uname,
-        );
-        $defaultHeaders = array(
-            'X-Stripe-Client-User-Agent' => json_encode($ua),
-            'User-Agent' => 'Stripe/v1 PhpBindings/' . Stripe::VERSION,
-            'Authorization' => 'Bearer ' . $myApiKey,
-        );
+        $defaultHeaders = $this->_defaultHeaders($myApiKey);
         if (Stripe::$apiVersion) {
             $defaultHeaders['Stripe-Version'] = Stripe::$apiVersion;
         }
+
+        if (Stripe::$accountId) {
+            $defaultHeaders['Stripe-Account'] = Stripe::$accountId;
+        }
+
         $hasFile = false;
         $hasCurlFile = class_exists('\CURLFile', false);
         foreach ($params as $k => $v) {

+ 51 - 7
plugins/stripe/lib/ApiResource.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class ApiResource
+ *
+ * @package Stripe
+ */
 abstract class ApiResource extends StripeObject
 {
     private static $HEADERS_TO_PERSIST = array('Stripe-Account' => true, 'Stripe-Version' => true);
@@ -25,7 +30,8 @@ abstract class ApiResource extends StripeObject
             $this->_retrieveOptions,
             $this->_opts->headers
         );
-        $this->refreshFrom($response, $this->_opts);
+        $this->setLastResponse($response);
+        $this->refreshFrom($response->json, $this->_opts);
         return $this;
     }
 
@@ -63,11 +69,10 @@ abstract class ApiResource extends StripeObject
     }
 
     /**
-     * @return string The full API URL for this API resource.
+     * @return string The instance endpoint URL for the given class.
      */
-    public function instanceUrl()
+    public static function resourceUrl($id)
     {
-        $id = $this['id'];
         if ($id === null) {
             $class = get_called_class();
             $message = "Could not determine which URL to request: "
@@ -80,6 +85,14 @@ abstract class ApiResource extends StripeObject
         return "$base/$extn";
     }
 
+    /**
+     * @return string The full API URL for this API resource.
+     */
+    public function instanceUrl()
+    {
+        return static::resourceUrl($this['id']);
+    }
+
     private static function _validateParams($params = null)
     {
         if ($params && !is_array($params)) {
@@ -95,7 +108,9 @@ abstract class ApiResource extends StripeObject
     protected function _request($method, $url, $params = array(), $options = null)
     {
         $opts = $this->_opts->merge($options);
-        return static::_staticRequest($method, $url, $params, $opts);
+        list($resp, $options) = static::_staticRequest($method, $url, $params, $opts);
+        $this->setLastResponse($resp);
+        return array($resp->json, $options);
     }
 
     protected static function _staticRequest($method, $url, $params, $options)
@@ -125,7 +140,15 @@ abstract class ApiResource extends StripeObject
         $url = static::classUrl();
 
         list($response, $opts) = static::_staticRequest('get', $url, $params, $options);
-        return Util\Util::convertToStripeObject($response, $opts);
+        $obj = Util\Util::convertToStripeObject($response->json, $opts);
+        if (!is_a($obj, 'Stripe\\Collection')) {
+            $class = get_class($obj);
+            $message = "Expected type \"Stripe\\Collection\", got \"$class\" instead";
+            throw new Error\Api($message);
+        }
+        $obj->setLastResponse($response);
+        $obj->setRequestParams($params);
+        return $obj;
     }
 
     protected static function _create($params = null, $options = null)
@@ -135,7 +158,28 @@ abstract class ApiResource extends StripeObject
         $url = static::classUrl();
 
         list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
-        return Util\Util::convertToStripeObject($response, $opts);
+        $obj = Util\Util::convertToStripeObject($response->json, $opts);
+        $obj->setLastResponse($response);
+        return $obj;
+    }
+
+    /**
+     * @param string $id The ID of the API resource to update.
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return ApiResource the updated API resource
+     */
+    protected static function _update($id, $params = null, $options = null)
+    {
+        self::_validateParams($params);
+        $base = static::baseUrl();
+        $url = static::resourceUrl($id);
+
+        list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
+        $obj = Util\Util::convertToStripeObject($response->json, $opts);
+        $obj->setLastResponse($response);
+        return $obj;
     }
 
     protected function _save($options = null)

+ 32 - 0
plugins/stripe/lib/ApiResponse.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace Stripe;
+
+/**
+ * Class ApiResponse
+ *
+ * @package Stripe
+ */
+class ApiResponse
+{
+    public $headers;
+    public $body;
+    public $json;
+    public $code;
+
+    /**
+     * @param string $body
+     * @param integer $code
+     * @param array|null $headers
+     * @param array|null $json
+     *
+     * @return obj An APIResponse
+     */
+    public function __construct($body, $code, $headers, $json)
+    {
+        $this->body = $body;
+        $this->code = $code;
+        $this->headers = $headers;
+        $this->json = $json;
+    }
+}

+ 65 - 0
plugins/stripe/lib/ApplePayDomain.php

@@ -0,0 +1,65 @@
+<?php
+
+namespace Stripe;
+
+/**
+ * Class ApplePayDomain
+ *
+ * @package Stripe
+ */
+class ApplePayDomain extends ApiResource
+{
+    
+    /**
+     * @return string The class URL for this resource. It needs to be special
+     *    cased because it doesn't fit into the standard resource pattern.
+     */
+    public static function classUrl()
+    {
+        return '/v1/apple_pay/domains';
+    }
+
+    /**
+     * @param string $id The ID of the domain to retrieve.
+     * @param array|string|null $opts
+     *
+     * @return ApplePayDomain
+     */
+    public static function retrieve($id, $opts = null)
+    {
+        return self::_retrieve($id, $opts);
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return ApplePayDomain The created domain.
+     */
+    public static function create($params = null, $opts = null)
+    {
+        return self::_create($params, $opts);
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return ApplePayDomain The deleted domain.
+     */
+    public function delete($params = null, $opts = null)
+    {
+        return $this->_delete($params, $opts);
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return Collection of ApplePayDomains
+     */
+    public static function all($params = null, $opts = null)
+    {
+        return self::_all($params, $opts);
+    }
+}

+ 19 - 3
plugins/stripe/lib/ApplicationFee.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class ApplicationFee
+ *
+ * @package Stripe
+ */
 class ApplicationFee extends ApiResource
 {
     /**
@@ -26,6 +31,18 @@ class ApplicationFee extends ApiResource
         return self::_retrieve($id, $opts);
     }
 
+    /**
+     * @param string $id The ID of the application fee to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return ApplicationFee The updated application fee.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|null $params
      * @param array|string|null $opts
@@ -45,9 +62,8 @@ class ApplicationFee extends ApiResource
      */
     public function refund($params = null, $opts = null)
     {
-        $url = $this->instanceUrl() . '/refund';
-        list($response, $opts) = $this->_request('post', $url, $params, $opts);
-        $this->refreshFrom($response, $opts);
+        $this->refunds->create($params, $opts);
+        $this->refresh();
         return $this;
     }
 }

+ 5 - 0
plugins/stripe/lib/ApplicationFeeRefund.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class ApplicationFeeRefund
+ *
+ * @package Stripe
+ */
 class ApplicationFeeRefund extends ApiResource
 {
     /**

+ 7 - 1
plugins/stripe/lib/AttachedObject.php

@@ -2,7 +2,13 @@
 
 namespace Stripe;
 
-// e.g. metadata on Stripe objects.
+/**
+ * Class AttachedObject
+ *
+ * e.g. metadata on Stripe objects.
+ *
+ * @package Stripe
+ */
 class AttachedObject extends StripeObject
 {
     /**

+ 10 - 0
plugins/stripe/lib/Balance.php

@@ -2,6 +2,16 @@
 
 namespace Stripe;
 
+/**
+ * Class Balance
+ *
+ * @param string $object
+ * @param mixed $available
+ * @param bool $livedmode
+ * @param mixed $pending
+ *
+ * @package Stripe
+ */
 class Balance extends SingletonApiResource
 {
     /**

+ 20 - 0
plugins/stripe/lib/BalanceTransaction.php

@@ -2,6 +2,26 @@
 
 namespace Stripe;
 
+/**
+ * Class BalanceTransaction
+ *
+ * @property string $id
+ * @property string $object
+ * @property int $amount
+ * @property int $available_on
+ * @property int $created
+ * @property string $currency
+ * @property string $description
+ * @property int $fee
+ * @property mixed $fee_details
+ * @property int $net
+ * @property string $source
+ * @property mixed $sourced_transfers
+ * @property string $status
+ * @property string $type
+ *
+ * @package Stripe
+ */
 class BalanceTransaction extends ApiResource
 {
     /**

+ 18 - 1
plugins/stripe/lib/BankAccount.php

@@ -2,7 +2,24 @@
 
 namespace Stripe;
 
+/**
+ * Class BankAccount
+ *
+ * @package Stripe
+ */
 class BankAccount extends ExternalAccount
 {
-
+    /**
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return BankAccount The verified bank account.
+     */
+    public function verify($params = null, $options = null)
+    {
+        $url = $this->instanceUrl() . '/verify';
+        list($response, $opts) = $this->_request('post', $url, $params, $options);
+        $this->refreshFrom($response, $opts);
+        return $this;
+    }
 }

+ 5 - 0
plugins/stripe/lib/BitcoinReceiver.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class BitcoinReceiver
+ *
+ * @package Stripe
+ */
 class BitcoinReceiver extends ExternalAccount
 {
     /**

+ 5 - 0
plugins/stripe/lib/BitcoinTransaction.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class BitcoinTransaction
+ *
+ * @package Stripe
+ */
 class BitcoinTransaction extends ApiResource
 {
 

+ 5 - 0
plugins/stripe/lib/Card.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class Card
+ *
+ * @package Stripe
+ */
 class Card extends ExternalAccount
 {
 

+ 48 - 0
plugins/stripe/lib/Charge.php

@@ -2,6 +2,42 @@
 
 namespace Stripe;
 
+/**
+ * Class Charge
+ *
+ * @property string $id
+ * @property string $object
+ * @property int $amount
+ * @property int $amount_refunded
+ * @property mixed $application_fee
+ * @property string $balance_transaction
+ * @property bool $captured
+ * @property int $created
+ * @property string $currency
+ * @property string $customer
+ * @property mixed $description
+ * @property mixed $destination
+ * @property mixed $dispute
+ * @property mixed $failure_code
+ * @property mixed $failure_message
+ * @property mixed $fraud_details
+ * @property mixed $invoice
+ * @property bool $livemode
+ * @property mixed $metadata
+ * @property mixed $order
+ * @property bool $paid
+ * @property mixed $receipt_email
+ * @property mixed $receipt_number
+ * @property bool $refunded
+ * @property mixed $refunds
+ * @property mixed $shipping
+ * @property mixed $source
+ * @property mixed $source_transfer
+ * @property mixed $statement_descriptor
+ * @property string $status
+ *
+ * @package Stripe
+ */
 class Charge extends ApiResource
 {
     /**
@@ -37,6 +73,18 @@ class Charge extends ApiResource
         return self::_create($params, $options);
     }
 
+    /**
+     * @param string $id The ID of the charge to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Charge The updated charge.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|string|null $options
      *

+ 31 - 0
plugins/stripe/lib/Collection.php

@@ -2,13 +2,31 @@
 
 namespace Stripe;
 
+/**
+ * Class Collection
+ *
+ * @param string $object
+ * @param string $url
+ * @param bool $has_more
+ * @param mixed $data
+ *
+ * @package Stripe
+ */
 class Collection extends ApiResource
 {
+    protected $_requestParams = array();
+
+    public function setRequestParams($params)
+    {
+        $this->_requestParams = $params;
+    }
+
     public function all($params = null, $opts = null)
     {
         list($url, $params) = $this->extractPathAndUpdateParams($params);
 
         list($response, $opts) = $this->_request('get', $url, $params, $opts);
+        $this->_requestParams = $params;
         return Util\Util::convertToStripeObject($response, $opts);
     }
 
@@ -17,6 +35,7 @@ class Collection extends ApiResource
         list($url, $params) = $this->extractPathAndUpdateParams($params);
 
         list($response, $opts) = $this->_request('post', $url, $params, $opts);
+        $this->_requestParams = $params;
         return Util\Util::convertToStripeObject($response, $opts);
     }
 
@@ -32,9 +51,21 @@ class Collection extends ApiResource
             $params,
             $opts
         );
+        $this->_requestParams = $params;
         return Util\Util::convertToStripeObject($response, $opts);
     }
 
+    /**
+     * @return AutoPagingIterator An iterator that can be used to iterate
+     *    across all objects across all pages. As page boundaries are
+     *    encountered, the next page will be fetched automatically for
+     *    continued iteration.
+     */
+    public function autoPagingIterator()
+    {
+        return new Util\AutoPagingIterator($this, $this->_requestParams);
+    }
+
     private function extractPathAndUpdateParams($params)
     {
         $url = parse_url($this->url);

+ 44 - 0
plugins/stripe/lib/CountrySpec.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace Stripe;
+
+/**
+ * Class CountrySpec
+ *
+ * @package Stripe
+ */
+class CountrySpec extends ApiResource
+{
+    /**
+     * This is a special case because the country specs endpoint has an
+     *    underscore in it. The parent `className` function strips underscores.
+     *
+     * @return string The name of the class.
+     */
+    public static function className()
+    {
+        return 'country_spec';
+    }
+
+    /**
+     * @param string $country The ISO country code of the country we retrieve the CountrySpec for.
+     * @param array|string|null $opts
+     *
+     * @return CountrySpec
+     */
+    public static function retrieve($country, $opts = null)
+    {
+        return self::_retrieve($country, $opts);
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return Collection of CountrySpecs
+     */
+    public static function all($params = null, $opts = null)
+    {
+        return self::_all($params, $opts);
+    }
+}

+ 17 - 0
plugins/stripe/lib/Coupon.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class Coupon
+ *
+ * @package Stripe
+ */
 class Coupon extends ApiResource
 {
     /**
@@ -26,6 +31,18 @@ class Coupon extends ApiResource
         return self::_create($params, $opts);
     }
 
+    /**
+     * @param string $id The ID of the coupon to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Coupon The updated coupon.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|null $params
      * @param array|string|null $opts

+ 34 - 2
plugins/stripe/lib/Customer.php

@@ -2,6 +2,28 @@
 
 namespace Stripe;
 
+/**
+ * Class Customer
+ *
+ * @property string $id
+ * @property string $object
+ * @property int $account_balance
+ * @property string $business_vat_id
+ * @property string $created
+ * @property string $currency
+ * @property string $default_source
+ * @property bool $delinquent
+ * @property string $description
+ * @property mixed $discount
+ * @property string $email
+ * @property bool $livemode
+ * @property array $metadata
+ * @property mixed $shipping
+ * @property Collection $sources
+ * @property Collection $subscriptions
+ *
+ * @package Stripe
+ */
 class Customer extends ApiResource
 {
     /**
@@ -37,6 +59,18 @@ class Customer extends ApiResource
         return self::_create($params, $opts);
     }
 
+    /**
+     * @param string $id The ID of the customer to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Customer The updated customer.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|string|null $opts
      *
@@ -145,8 +179,6 @@ class Customer extends ApiResource
     }
 
     /**
-     * @param array|null $params
-     *
      * @return Customer The updated customer.
      */
     public function deleteDiscount()

+ 32 - 1
plugins/stripe/lib/Dispute.php

@@ -2,6 +2,26 @@
 
 namespace Stripe;
 
+/**
+ * Class Dispute
+ *
+ * @property string $id
+ * @property string $object
+ * @property int $amount
+ * @property mixed $balance_transactions
+ * @property string $charge
+ * @property int $created
+ * @property string $currency
+ * @property mixed $evidence
+ * @property mixed $evidence_details
+ * @property bool $is_charge_refundable
+ * @property bool $livemode
+ * @property mixed $metadata
+ * @property string $reason
+ * @property string $status
+ *
+ * @package Stripe
+ */
 class Dispute extends ApiResource
 {
     /**
@@ -26,6 +46,18 @@ class Dispute extends ApiResource
         return self::_all($params, $options);
     }
 
+    /**
+     * @param string $id The ID of the dispute to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Dispute The updated dispute.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|string|null $options
      *
@@ -37,7 +69,6 @@ class Dispute extends ApiResource
     }
 
     /**
-     * @param array|null $params
      * @param array|string|null $options
      *
      * @return Dispute The closed dispute.

+ 11 - 0
plugins/stripe/lib/Error/Card.php

@@ -16,6 +16,17 @@ class Card extends Base
         parent::__construct($message, $httpStatus, $httpBody, $jsonBody, $httpHeaders);
         $this->stripeParam = $stripeParam;
         $this->stripeCode = $stripeCode;
+
+        // This one is not like the others because it was added later and we're
+        // trying to do our best not to change the public interface of this class'
+        // constructor. We should consider changing its implementation on the
+        // next major version bump of this library.
+        $this->declineCode = isset($jsonBody["error"]["decline_code"]) ? $jsonBody["error"]["decline_code"] : null;
+    }
+
+    public function getDeclineCode()
+    {
+        return $this->declineCode;
     }
 
     public function getStripeCode()

+ 15 - 0
plugins/stripe/lib/Event.php

@@ -2,6 +2,21 @@
 
 namespace Stripe;
 
+/**
+ * Class Event
+ *
+ * @property string $id
+ * @property string $object
+ * @property string $api_version
+ * @property int $created
+ * @property mixed $data
+ * @property bool $livemode
+ * @property int $pending_webhooks
+ * @property string $request
+ * @property string $type
+ *
+ * @package Stripe
+ */
 class Event extends ApiResource
 {
     /**

+ 24 - 0
plugins/stripe/lib/ExternalAccount.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class ExternalAccount
+ *
+ * @package Stripe
+ */
 abstract class ExternalAccount extends ApiResource
 {
     /**
@@ -62,4 +67,23 @@ abstract class ExternalAccount extends ApiResource
     {
         return $this->_save($opts);
     }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return ExternalAccount The verified (or not) external account.
+     */
+    public function verify($params = null, $opts = null)
+    {
+        if ($this['customer']) {
+            $url = $this->instanceUrl() . '/verify';
+            list($response, $options) = $this->_request('post', $url, $params, $opts);
+            $this->refreshFrom($response, $options);
+            return $this;
+        } else {
+            $message = 'Only customer external accounts can be verified in this manner.';
+            throw new Error\Api($message);
+        }
+    }
 }

+ 12 - 0
plugins/stripe/lib/FileUpload.php

@@ -2,6 +2,18 @@
 
 namespace Stripe;
 
+/**
+ * Class FileUpload
+ *
+ * @property string $id
+ * @property string $object
+ * @property int $created
+ * @property string $purpose
+ * @property int $size
+ * @property string $type
+ *
+ * @package Stripe
+ */
 class FileUpload extends ApiResource
 {
     public static function baseUrl()

+ 121 - 7
plugins/stripe/lib/HttpClient/CurlClient.php

@@ -18,11 +18,78 @@ class CurlClient implements ClientInterface
         return self::$instance;
     }
 
+    protected $defaultOptions;
+
+    /**
+     * CurlClient constructor.
+     *
+     * Pass in a callable to $defaultOptions that returns an array of CURLOPT_* values to start
+     * off a request with, or an flat array with the same format used by curl_setopt_array() to
+     * provide a static set of options. Note that many options are overridden later in the request
+     * call, including timeouts, which can be set via setTimeout() and setConnectTimeout().
+     *
+     * Note that request() will silently ignore a non-callable, non-array $defaultOptions, and will
+     * throw an exception if $defaultOptions returns a non-array value.
+     *
+     * @param array|callable|null $defaultOptions
+     */
+    public function __construct($defaultOptions = null)
+    {
+        $this->defaultOptions = $defaultOptions;
+    }
+
+    public function getDefaultOptions()
+    {
+        return $this->defaultOptions;
+    }
+
+    // USER DEFINED TIMEOUTS
+
+    const DEFAULT_TIMEOUT = 80;
+    const DEFAULT_CONNECT_TIMEOUT = 30;
+
+    private $timeout = self::DEFAULT_TIMEOUT;
+    private $connectTimeout = self::DEFAULT_CONNECT_TIMEOUT;
+
+    public function setTimeout($seconds)
+    {
+        $this->timeout = (int) max($seconds, 0);
+        return $this;
+    }
+
+    public function setConnectTimeout($seconds)
+    {
+        $this->connectTimeout = (int) max($seconds, 0);
+        return $this;
+    }
+
+    public function getTimeout()
+    {
+        return $this->timeout;
+    }
+
+    public function getConnectTimeout()
+    {
+        return $this->connectTimeout;
+    }
+
+    // END OF USER DEFINED TIMEOUTS
+
     public function request($method, $absUrl, $headers, $params, $hasFile)
     {
         $curl = curl_init();
         $method = strtolower($method);
+
         $opts = array();
+        if (is_callable($this->defaultOptions)) { // call defaultOptions callback, set options to return value
+            $opts = call_user_func_array($this->defaultOptions, func_get_args());
+            if (!is_array($opts)) {
+                throw new Error\Api("Non-array value returned by defaultOptions CurlClient callback");
+            }
+        } elseif (is_array($this->defaultOptions)) { // set default curlopts from array
+            $opts = $this->defaultOptions;
+        }
+
         if ($method == 'get') {
             if ($hasFile) {
                 throw new Error\Api(
@@ -59,18 +126,63 @@ class CurlClient implements ClientInterface
             return strlen($header_line);
         };
 
+        // By default for large request body sizes (> 1024 bytes), cURL will
+        // send a request without a body and with a `Expect: 100-continue`
+        // header, which gives the server a chance to respond with an error
+        // status code in cases where one can be determined right away (say
+        // on an authentication problem for example), and saves the "large"
+        // request body from being ever sent.
+        //
+        // Unfortunately, the bindings don't currently correctly handle the
+        // success case (in which the server sends back a 100 CONTINUE), so
+        // we'll error under that condition. To compensate for that problem
+        // for the time being, override cURL's behavior by simply always
+        // sending an empty `Expect:` header.
+        array_push($headers, 'Expect: ');
+
         $absUrl = Util\Util::utf8($absUrl);
         $opts[CURLOPT_URL] = $absUrl;
         $opts[CURLOPT_RETURNTRANSFER] = true;
-        $opts[CURLOPT_CONNECTTIMEOUT] = 30;
-        $opts[CURLOPT_TIMEOUT] = 80;
-        $opts[CURLOPT_RETURNTRANSFER] = true;
+        $opts[CURLOPT_CONNECTTIMEOUT] = $this->connectTimeout;
+        $opts[CURLOPT_TIMEOUT] = $this->timeout;
         $opts[CURLOPT_HEADERFUNCTION] = $headerCallback;
         $opts[CURLOPT_HTTPHEADER] = $headers;
         if (!Stripe::$verifySslCerts) {
             $opts[CURLOPT_SSL_VERIFYPEER] = false;
         }
 
+        // @codingStandardsIgnoreStart
+        // PSR2 requires all constants be upper case. Sadly, the CURL_SSLVERSION
+        // constants to not abide by those rules.
+        //
+        // Explicitly set a TLS version for cURL to use now that we're starting
+        // to block 1.0 and 1.1 requests.
+        //
+        // If users are on OpenSSL >= 1.0.1, we know that they support TLS 1.2,
+        // so set that explicitly because on some older Linux distros, clients may
+        // default to TLS 1.0 even when they have TLS 1.2 available.
+        //
+        // For users on much older versions of OpenSSL, set a valid range of
+        // TLS 1.0 to 1.2 (CURL_SSLVERSION_TLSv1). Note that this may result in
+        // their requests being blocked unless they're specially flagged into
+        // being able to use an old TLS version.
+        //
+        // Note: The int on the right is pulled from the source of OpenSSL 1.0.1a.
+        if (OPENSSL_VERSION_NUMBER >= 0x1000100f) {
+            if (!defined('CURL_SSLVERSION_TLSv1_2')) {
+                // Note the value 6 comes from its position in the enum that
+                // defines it in cURL's source code.
+                define('CURL_SSLVERSION_TLSv1_2', 6); // constant not defined in PHP < 5.5
+            }
+            $opts[CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_2;
+        } else {
+            if (!defined('CURL_SSLVERSION_TLSv1')) {
+                define('CURL_SSLVERSION_TLSv1', 1); // constant not defined in PHP < 5.5
+            }
+            $opts[CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1;
+        }
+        // @codingStandardsIgnoreEnd
+
         curl_setopt_array($curl, $opts);
         $rbody = curl_exec($curl);
 
@@ -163,10 +275,12 @@ class CurlClient implements ClientInterface
                 continue;
             }
 
-            if ($prefix && $k && !is_int($k)) {
-                $k = $prefix."[".$k."]";
-            } elseif ($prefix) {
-                $k = $prefix."[]";
+            if ($prefix) {
+                if ($k !== null && (!is_int($k) || is_array($v))) {
+                    $k = $prefix."[".$k."]";
+                } else {
+                    $k = $prefix."[]";
+                }
             }
 
             if (is_array($v)) {

+ 20 - 1
plugins/stripe/lib/Invoice.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class Invoice
+ *
+ * @package Stripe
+ */
 class Invoice extends ApiResource
 {
     /**
@@ -37,6 +42,18 @@ class Invoice extends ApiResource
         return self::_all($params, $opts);
     }
 
+    /**
+     * @param string $id The ID of the invoice to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Invoice The updated invoice.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|null $params
      * @param array|string|null $opts
@@ -47,7 +64,9 @@ class Invoice extends ApiResource
     {
         $url = static::classUrl() . '/upcoming';
         list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
-        return Util\Util::convertToStripeObject($response, $opts);
+        $obj = Util\Util::convertToStripeObject($response->json, $opts);
+        $obj->setLastResponse($response);
+        return $obj;
     }
 
     /**

+ 17 - 0
plugins/stripe/lib/InvoiceItem.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class InvoiceItem
+ *
+ * @package Stripe
+ */
 class InvoiceItem extends ApiResource
 {
     /**
@@ -37,6 +42,18 @@ class InvoiceItem extends ApiResource
         return self::_create($params, $opts);
     }
 
+    /**
+     * @param string $id The ID of the invoice item to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return InvoiceItem The updated invoice item.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|string|null $opts
      *

+ 27 - 0
plugins/stripe/lib/Order.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class Order
+ *
+ * @package Stripe
+ */
 class Order extends ApiResource
 {
     /**
@@ -26,6 +31,18 @@ class Order extends ApiResource
         return self::_create($params, $opts);
     }
 
+    /**
+     * @param string $id The ID of the order to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Order The updated order.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|string|null $opts
      *
@@ -57,4 +74,14 @@ class Order extends ApiResource
         $this->refreshFrom($response, $opts);
         return $this;
     }
+
+    /**
+     * @return OrderReturn The newly created return.
+     */
+    public function returnOrder($params = null, $opts = null)
+    {
+        $url = $this->instanceUrl() . '/returns';
+        list($response, $opts) = $this->_request('post', $url, $params, $opts);
+        return Util\Util::convertToStripeObject($response, $opts);
+    }
 }

+ 33 - 0
plugins/stripe/lib/OrderReturn.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace Stripe;
+
+/**
+ * Class OrderReturn
+ *
+ * @package Stripe
+ */
+class OrderReturn extends ApiResource
+{
+    /**
+     * @param string $id The ID of the OrderReturn to retrieve.
+     * @param array|string|null $opts
+     *
+     * @return Order
+     */
+    public static function retrieve($id, $opts = null)
+    {
+        return self::_retrieve($id, $opts);
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return Collection of OrderReturns
+     */
+    public static function all($params = null, $opts = null)
+    {
+        return self::_all($params, $opts);
+    }
+}

+ 17 - 0
plugins/stripe/lib/Plan.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class Plan
+ *
+ * @package Stripe
+ */
 class Plan extends ApiResource
 {
     /**
@@ -26,6 +31,18 @@ class Plan extends ApiResource
         return self::_create($params, $opts);
     }
 
+    /**
+     * @param string $id The ID of the plan to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Plan The updated plan.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|null $params
      * @param array|string|null $opts

+ 28 - 0
plugins/stripe/lib/Product.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class Product
+ *
+ * @package Stripe
+ */
 class Product extends ApiResource
 {
     /**
@@ -26,6 +31,18 @@ class Product extends ApiResource
         return self::_create($params, $opts);
     }
 
+    /**
+     * @param string $id The ID of the product to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Product The updated product.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|string|null $opts
      *
@@ -46,4 +63,15 @@ class Product extends ApiResource
     {
         return self::_all($params, $opts);
     }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return Product The deleted product.
+     */
+    public function delete($params = null, $opts = null)
+    {
+        return $this->_delete($params, $opts);
+    }
 }

+ 17 - 0
plugins/stripe/lib/Recipient.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class Recipient
+ *
+ * @package Stripe
+ */
 class Recipient extends ApiResource
 {
     /**
@@ -37,6 +42,18 @@ class Recipient extends ApiResource
         return self::_create($params, $opts);
     }
 
+    /**
+     * @param string $id The ID of the recipient to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Recipient The updated recipient.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|string|null $opts
      *

+ 29 - 0
plugins/stripe/lib/Refund.php

@@ -2,6 +2,23 @@
 
 namespace Stripe;
 
+/**
+ * Class Refund
+ *
+ * @property string $id
+ * @property string $object
+ * @property int $amount
+ * @property mixed $balance_transaction
+ * @property string $charge
+ * @property int $created
+ * @property string $currency
+ * @property mixed $metadata
+ * @property mixed $reason
+ * @property mixed $receipt_number
+ * @property string $status
+ *
+ * @package Stripe
+ */
 class Refund extends ApiResource
 {
 
@@ -16,6 +33,18 @@ class Refund extends ApiResource
         return self::_retrieve($id, $options);
     }
 
+    /**
+     * @param string $id The ID of the refund to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Refund The updated refund.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|null $params
      * @param array|string|null $options

+ 28 - 0
plugins/stripe/lib/SKU.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class SKU
+ *
+ * @package Stripe
+ */
 class SKU extends ApiResource
 {
     /**
@@ -26,6 +31,18 @@ class SKU extends ApiResource
         return self::_create($params, $opts);
     }
 
+    /**
+     * @param string $id The ID of the SKU to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return SKU The updated SKU.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @param array|string|null $opts
      *
@@ -46,4 +63,15 @@ class SKU extends ApiResource
     {
         return self::_all($params, $opts);
     }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return SKU The deleted sku.
+     */
+    public function delete($params = null, $opts = null)
+    {
+        return $this->_delete($params, $opts);
+    }
 }

+ 5 - 0
plugins/stripe/lib/SingletonApiResource.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class SingletonApiResource
+ *
+ * @package Stripe
+ */
 abstract class SingletonApiResource extends ApiResource
 {
     protected static function _singletonRetrieve($options = null)

+ 44 - 0
plugins/stripe/lib/Source.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace Stripe;
+
+/**
+ * Class Source
+ *
+ * @package Stripe
+ */
+class Source extends ApiResource
+{
+    /**
+     * @param string $id The ID of the Source to retrieve.
+     * @param array|string|null $opts
+     *
+     * @return Source
+     */
+    public static function retrieve($id, $opts = null)
+    {
+        return self::_retrieve($id, $opts);
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return Collection of Sources
+     */
+    public static function all($params = null, $opts = null)
+    {
+        return self::_all($params, $opts);
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return Source The created Source.
+     */
+    public static function create($params = null, $opts = null)
+    {
+        return self::_create($params, $opts);
+    }
+}

+ 53 - 1
plugins/stripe/lib/Stripe.php

@@ -2,6 +2,11 @@
 
 namespace Stripe;
 
+/**
+ * Class Stripe
+ *
+ * @package Stripe
+ */
 class Stripe
 {
     // @var string The Stripe API key to be used for requests.
@@ -16,10 +21,16 @@ class Stripe
     // @var string|null The version of the Stripe API to use for requests.
     public static $apiVersion = null;
 
+    // @var string|null The account ID for connected accounts requests.
+    public static $accountId = null;
+
     // @var boolean Defaults to true.
     public static $verifySslCerts = true;
 
-    const VERSION = '3.4.0';
+    // @var array The application's information (name, version, URL)
+    public static $appInfo = null;
+
+    const VERSION = '3.23.0';
 
     /**
      * @return string The API key used for requests.
@@ -71,4 +82,45 @@ class Stripe
     {
         self::$verifySslCerts = $verify;
     }
+
+    /**
+     * @return string | null The Stripe account ID for connected account
+     *   requests.
+     */
+    public static function getAccountId()
+    {
+        return self::$accountId;
+    }
+
+    /**
+     * @param string $accountId The Stripe account ID to set for connected
+     *   account requests.
+     */
+    public static function setAccountId($accountId)
+    {
+        self::$accountId = $accountId;
+    }
+
+    /**
+     * @return array | null The application's information
+     */
+    public static function getAppInfo()
+    {
+        return self::$appInfo;
+    }
+
+    /**
+     * @param string $appName The application's name
+     * @param string $appVersion The application's version
+     * @param string $appUrl The application's URL
+     */
+    public static function setAppInfo($appName, $appVersion = null, $appUrl = null)
+    {
+        if (self::$appInfo === null) {
+            self::$appInfo = array();
+        }
+        self::$appInfo['name'] = $appName;
+        self::$appInfo['version'] = $appVersion;
+        self::$appInfo['url'] = $appUrl;
+    }
 }

+ 34 - 5
plugins/stripe/lib/StripeObject.php

@@ -5,6 +5,11 @@ namespace Stripe;
 use ArrayAccess;
 use InvalidArgumentException;
 
+/**
+ * Class StripeObject
+ *
+ * @package Stripe
+ */
 class StripeObject implements ArrayAccess, JsonSerializable
 {
     /**
@@ -25,15 +30,35 @@ class StripeObject implements ArrayAccess, JsonSerializable
             'metadata', 'legal_entity', 'address', 'dob', 'transfer_schedule', 'verification',
             'tos_acceptance', 'personal_address',
             // will make the array into an AttachedObject: weird, but works for now
-            'additional_owners', 0, 1, 2, 3, 4 // Max 3, but leave the 4th so errors work properly
+            'additional_owners', 0, 1, 2, 3, 4, // Max 3, but leave the 4th so errors work properly
+            'inventory'
         ));
     }
 
+    /**
+     * @return object The last response from the Stripe API
+     */
+    public function getLastResponse()
+    {
+        return $this->_lastResponse;
+    }
+
+    /**
+     * @param ApiResponse
+     *
+     * @return void Set the last response from the Stripe API
+     */
+    public function setLastResponse($resp)
+    {
+        $this->_lastResponse = $resp;
+    }
+
     protected $_opts;
     protected $_values;
     protected $_unsavedValues;
     protected $_transientValues;
     protected $_retrieveOptions;
+    protected $_lastResponse;
 
     public function __construct($id = null, $opts = null)
     {
@@ -69,7 +94,7 @@ class StripeObject implements ArrayAccess, JsonSerializable
         }
 
         if (self::$nestedUpdatableAttributes->includes($k)
-                && isset($this->$k) && is_array($v)) {
+                && isset($this->$k) && $this->$k instanceof AttachedObject && is_array($v)) {
             $this->$k->replaceWith($v);
         } else {
             // TODO: may want to clear from $_transientValues (Won't be user-visible).
@@ -94,9 +119,9 @@ class StripeObject implements ArrayAccess, JsonSerializable
     {
         // function should return a reference, using $nullval to return a reference to null
         $nullval = null;
-        if (array_key_exists($k, $this->_values)) {
+        if (!empty($this->_values) && array_key_exists($k, $this->_values)) {
             return $this->_values[$k];
-        } else if ($this->_transientValues->includes($k)) {
+        } else if (!empty($this->_transientValues) && $this->_transientValues->includes($k)) {
             $class = get_class($this);
             $attrs = join(', ', array_keys($this->_values));
             $message = "Stripe Notice: Undefined property of $class instance: $k. "
@@ -158,11 +183,15 @@ class StripeObject implements ArrayAccess, JsonSerializable
      * Refreshes this object using the provided values.
      *
      * @param array $values
-     * @param array $opts
+     * @param array|Util\RequestOptions $opts
      * @param boolean $partial Defaults to false.
      */
     public function refreshFrom($values, $opts, $partial = false)
     {
+        if (is_array($opts)) {
+            $opts = Util\RequestOptions::parse($opts);
+        }
+
         $this->_opts = $opts;
 
         // Wipe old state before setting new.  This is useful for e.g. updating a

+ 56 - 18
plugins/stripe/lib/Subscription.php

@@ -2,29 +2,67 @@
 
 namespace Stripe;
 
+/**
+ * Class Subscription
+ *
+ * @package Stripe
+ */
 class Subscription extends ApiResource
 {
     /**
-     * @return string The API URL for this Stripe subscription.
+     * These constants are possible representations of the status field.
+     *
+     * @link https://stripe.com/docs/api#subscription_object-status
+     */
+    const STATUS_ACTIVE = 'active';
+    const STATUS_CANCELED = 'canceled';
+    const STATUS_PAST_DUE = 'past_due';
+    const STATUS_TRIALING = 'trialing';
+    const STATUS_UNPAID = 'unpaid';
+
+    /**
+     * @param string $id The ID of the subscription to retrieve.
+     * @param array|string|null $opts
+     *
+     * @return Subscription
+     */
+    public static function retrieve($id, $opts = null)
+    {
+        return self::_retrieve($id, $opts);
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return Collection of Subscriptions
+     */
+    public static function all($params = null, $opts = null)
+    {
+        return self::_all($params, $opts);
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return Subscription The created subscription.
+     */
+    public static function create($params = null, $opts = null)
+    {
+        return self::_create($params, $opts);
+    }
+
+    /**
+     * @param string $id The ID of the subscription to retrieve.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Subscription The updated subscription.
      */
-    public function instanceUrl()
+    public static function update($id, $params = null, $options = null)
     {
-        $id = $this['id'];
-        $customer = $this['customer'];
-        if (!$id) {
-            throw new Error\InvalidRequest(
-                "Could not determine which URL to request: " .
-                "class instance has invalid ID: $id",
-                null
-            );
-        }
-        $id = Util\Util::utf8($id);
-        $customer = Util\Util::utf8($customer);
-
-        $base = Customer::classUrl();
-        $customerExtn = urlencode($customer);
-        $extn = urlencode($id);
-        return "$base/$customerExtn/subscriptions/$extn";
+        return self::_update($id, $params, $options);
     }
 
     /**

+ 25 - 0
plugins/stripe/lib/ThreeDSecure.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace Stripe;
+
+class ThreeDSecure extends ApiResource
+{
+    /**
+     * @return string The endpoint URL for the given class.
+     */
+    public static function classUrl()
+    {
+        return "/v1/3d_secure";
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return ThreeDSecure The created 3D Secure object.
+     */
+    public static function create($params = null, $opts = null)
+    {
+        return self::_create($params, $opts);
+    }
+}

+ 15 - 0
plugins/stripe/lib/Token.php

@@ -2,6 +2,21 @@
 
 namespace Stripe;
 
+/**
+ * Class Token
+ *
+ * @property string $id
+ * @property string $object
+ * @property mixed $bank_account
+ * @property mixed $card
+ * @property mixed $client_ip
+ * @property int $created
+ * @property bool $livemode
+ * @property string $type
+ * @property bool $used
+ *
+ * @package Stripe
+ */
 class Token extends ApiResource
 {
     /**

+ 45 - 1
plugins/stripe/lib/Transfer.php

@@ -2,6 +2,38 @@
 
 namespace Stripe;
 
+/**
+ * Class Transfer
+ *
+ * @property string $id
+ * @property string $object
+ * @property int $amount
+ * @property int $amount_reversed
+ * @property mixed $application_fee
+ * @property string $balance_transaction
+ * @property int $created
+ * @property string $currency
+ * @property int $date
+ * @property mixed $description
+ * @property mixed $destination
+ * @property mixed $destination_payment
+ * @property mixed $failure_code
+ * @property mixed $failure_message
+ * @property mixed $fraud_details
+ * @property mixed $invoice
+ * @property bool $livemode
+ * @property mixed $metadata
+ * @property mixed $recipient
+ * @property mixed $reversals
+ * @property bool $reversed
+ * @property mixed $source_transaction
+ * @property string $source_type
+ * @property mixed $statement_descriptor
+ * @property string $status
+ * @property string $type
+ *
+ * @package Stripe
+ */
 class Transfer extends ApiResource
 {
     /**
@@ -37,13 +69,25 @@ class Transfer extends ApiResource
         return self::_create($params, $opts);
     }
 
+    /**
+     * @param string $id The ID of the transfer to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Transfer The updated transfer.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
     /**
      * @return TransferReversal The created transfer reversal.
      */
     public function reverse($params = null, $opts = null)
     {
         $url = $this->instanceUrl() . '/reversals';
-        list($response, $opts) = $this->_request('post', $url, $params, $options);
+        list($response, $opts) = $this->_request('post', $url, $params, $opts);
         $this->refreshFrom($response, $opts);
         return $this;
     }

+ 14 - 0
plugins/stripe/lib/TransferReversal.php

@@ -2,6 +2,20 @@
 
 namespace Stripe;
 
+/**
+ * Class TransferReversal
+ *
+ * @property string $id
+ * @property string $object
+ * @property int $amount
+ * @property string $balance_transaction
+ * @property int $created
+ * @property string $currency
+ * @property mixed $metadata
+ * @property string $transfer
+ *
+ * @package Stripe
+ */
 class TransferReversal extends ApiResource
 {
     /**

+ 61 - 0
plugins/stripe/lib/Util/AutoPagingIterator.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace Stripe\Util;
+
+class AutoPagingIterator implements \Iterator
+{
+    private $lastId = null;
+    private $page = null;
+    private $pageOffset = 0;
+    private $params = array();
+
+    public function __construct($collection, $params)
+    {
+        $this->page = $collection;
+        $this->params = $params;
+    }
+
+    public function rewind()
+    {
+        // Actually rewinding would require making a copy of the original page.
+    }
+
+    public function current()
+    {
+        $item = current($this->page->data);
+        $this->lastId = $item !== false ? $item['id'] : null;
+
+        return $item;
+    }
+
+    public function key()
+    {
+        return key($this->page->data) + $this->pageOffset;
+    }
+
+    public function next()
+    {
+        $item = next($this->page->data);
+        if ($item === false) {
+            // If we've run out of data on the current page, try to fetch another one
+            // and increase the offset the new page would start at
+            $this->pageOffset += count($this->page->data);
+            if ($this->page['has_more']) {
+                $this->params = array_merge(
+                    $this->params ? $this->params : array(),
+                    array('starting_after' => $this->lastId)
+                );
+                $this->page = $this->page->all($this->params);
+            } else {
+                return false;
+            }
+        }
+    }
+
+    public function valid()
+    {
+        $key = key($this->page->data);
+        $valid = ($key !== null && $key !== false);
+        return $valid;
+    }
+}

+ 19 - 1
plugins/stripe/lib/Util/Util.php

@@ -6,6 +6,8 @@ use Stripe\StripeObject;
 
 abstract class Util
 {
+    private static $isMbstringAvailable = null;
+
     /**
      * Whether the provided array (or other) is a list rather than a dictionary.
      *
@@ -64,10 +66,12 @@ abstract class Util
         $types = array(
             'account' => 'Stripe\\Account',
             'alipay_account' => 'Stripe\\AlipayAccount',
+            'apple_pay_domain' => 'Stripe\\ApplePayDomain',
             'bank_account' => 'Stripe\\BankAccount',
             'balance_transaction' => 'Stripe\\BalanceTransaction',
             'card' => 'Stripe\\Card',
             'charge' => 'Stripe\\Charge',
+            'country_spec' => 'Stripe\\CountrySpec',
             'coupon' => 'Stripe\\Coupon',
             'customer' => 'Stripe\\Customer',
             'dispute' => 'Stripe\\Dispute',
@@ -79,12 +83,15 @@ abstract class Util
             'token' => 'Stripe\\Token',
             'transfer' => 'Stripe\\Transfer',
             'order' => 'Stripe\\Order',
+            'order_return' => 'Stripe\\OrderReturn',
             'plan' => 'Stripe\\Plan',
             'product' => 'Stripe\\Product',
             'recipient' => 'Stripe\\Recipient',
             'refund' => 'Stripe\\Refund',
             'sku' => 'Stripe\\SKU',
+            'source' => 'Stripe\\Source',
             'subscription' => 'Stripe\\Subscription',
+            'three_d_secure' => 'Stripe\\ThreeDSecure',
             'fee_refund' => 'Stripe\\ApplicationFeeRefund',
             'bitcoin_receiver' => 'Stripe\\BitcoinReceiver',
             'bitcoin_transaction' => 'Stripe\\BitcoinTransaction',
@@ -115,7 +122,18 @@ abstract class Util
      */
     public static function utf8($value)
     {
-        if (is_string($value) && mb_detect_encoding($value, "UTF-8", true) != "UTF-8") {
+        if (self::$isMbstringAvailable === null) {
+            self::$isMbstringAvailable = function_exists('mb_detect_encoding');
+
+            if (!self::$isMbstringAvailable) {
+                trigger_error("It looks like the mbstring extension is not enabled. " .
+                    "UTF-8 strings will not properly be encoded. Ask your system " .
+                    "administrator to enable the mbstring extension, or write to " .
+                    "support@stripe.com if you have any questions.", E_USER_WARNING);
+            }
+        }
+
+        if (is_string($value) && self::$isMbstringAvailable && mb_detect_encoding($value, "UTF-8", true) != "UTF-8") {
             return utf8_encode($value);
         } else {
             return $value;

Некоторые файлы не были показаны из-за большого количества измененных файлов