Alex Trofimov 9 лет назад
Родитель
Сommit
7e9509ad7c

+ 30 - 0
plugins/stripe/CHANGELOG.md

@@ -1,3 +1,33 @@
+### 4.4.0 2017-01-18
+
+* Add support for updating sources
+
+### 4.3.0 2016-11-30
+
+* Add support for verifying sources
+
+### 4.2.0 2016-11-21
+
+* Add retrieve method for 3-D Secure resources
+
+### 4.1.1 2016-10-21
+
+* Add docblock with model properties for `Plan`
+
+### 4.1.0 2016-10-18
+
+* Support for 403 status codes (permission denied)
+
+### 4.0.1 2016-10-17
+
+* Fix transfer reversal materialization
+* Fixes for some property definitions in docblocks
+
+### 4.0.0 2016-09-28
+
+* Support for subscription items
+* Drop attempt to force TLS 1.2: please note that this could be breaking if you're using old OS distributions or packages and upgraded recently (so please make sure to test your integration!)
+
 ### 3.23.0 2016-09-15
 
 * Add support for Apple Pay domains

+ 25 - 0
plugins/stripe/README.md

@@ -106,6 +106,17 @@ $curl = new \Stripe\HttpClient\CurlClient(array(CURLOPT_PROXY => 'proxy.local:80
 
 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.
 
+### SSL / TLS compatibility issues
+
+Stripe's API now requires that [all connections use TLS 1.2](https://stripe.com/blog/upgrading-tls). Some systems (most notably some older CentOS and RHEL versions) are capable of using TLS 1.2 but will use TLS 1.0 or 1.1 by default. In this case, you'd get an `invalid_request_error` with the following error message: "Stripe no longer supports API requests made with TLS 1.0. Please initiate HTTPS connections with TLS 1.2 or later. You can learn more about this at [https://stripe.com/blog/upgrading-tls](https://stripe.com/blog/upgrading-tls).".
+
+The recommended course of action is to [upgrade your cURL and OpenSSL packages](https://support.stripe.com/questions/how-do-i-upgrade-my-stripe-integration-from-tls-1-0-to-tls-1-2#php) so that TLS 1.2 is used by default, but if that is not possible, you might be able to solve the issue by setting the `CURLOPT_SSLVERSION` option to either `CURL_SSLVERSION_TLSv1` or `CURL_SSLVERSION_TLSv1_2`:
+
+```php
+$curl = new \Stripe\HttpClient\CurlClient(array(CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1));
+\Stripe\ApiRequestor::setHttpClient($curl);
+```
+
 ## Development
 
 Install dependencies:
@@ -127,3 +138,17 @@ Or to run an individual test file:
 ```bash
 ./vendor/bin/phpunit tests/UtilTest.php
 ```
+
+## Attention plugin developers
+
+Are you writing a plugin that integrates Stripe and embeds our library? Then please use the `setAppInfo` function to identify your plugin. For example:
+
+```php
+\Stripe\Stripe::setAppInfo("MyAwesomePlugin", "1.2.34", "https://myawesomeplugin.info");
+```
+
+The method should be called once, before any request is sent to the API. The second and third parameters are optional.
+
+### SSL / TLS configuration option
+
+See the "SSL / TLS compatibility issues" paragraph above for full context. If you want to ensure that your plugin can be used on all systems, you should add a configuration option to let your users choose between different values for `CURLOPT_SSLVERSION`: none (default), `CURL_SSLVERSION_TLSv1` and `CURL_SSLVERSION_TLSv1_2`.

+ 1 - 1
plugins/stripe/VERSION

@@ -1 +1 @@
-3.23.0
+4.4.0

+ 2 - 0
plugins/stripe/init.php

@@ -20,6 +20,7 @@ require(dirname(__FILE__) . '/lib/Error/ApiConnection.php');
 require(dirname(__FILE__) . '/lib/Error/Authentication.php');
 require(dirname(__FILE__) . '/lib/Error/Card.php');
 require(dirname(__FILE__) . '/lib/Error/InvalidRequest.php');
+require(dirname(__FILE__) . '/lib/Error/Permission.php');
 require(dirname(__FILE__) . '/lib/Error/RateLimit.php');
 
 // Plumbing
@@ -63,6 +64,7 @@ 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/SubscriptionItem.php');
 require(dirname(__FILE__) . '/lib/ThreeDSecure.php');
 require(dirname(__FILE__) . '/lib/Token.php');
 require(dirname(__FILE__) . '/lib/Transfer.php');

+ 7 - 0
plugins/stripe/lib/ApiRequestor.php

@@ -76,6 +76,8 @@ class ApiRequestor
      * @throws Error\InvalidRequest if the error is caused by the user.
      * @throws Error\Authentication if the error is caused by a lack of
      *    permissions.
+     * @throws Error\Permission if the error is caused by insufficient
+     *    permissions.
      * @throws Error\Card if the error is the error code is 402 (payment
      *    required)
      * @throws Error\RateLimit if the error is caused by too many requests
@@ -110,6 +112,8 @@ class ApiRequestor
                 throw new Error\Authentication($msg, $rcode, $rbody, $resp, $rheaders);
             case 402:
                 throw new Error\Card($msg, $param, $code, $rcode, $rbody, $resp, $rheaders);
+            case 403:
+                throw new Error\Permission($msg, $rcode, $rbody, $resp, $rheaders);
             case 429:
                 throw new Error\RateLimit($msg, $param, $rcode, $rbody, $resp, $rheaders);
             default:
@@ -141,6 +145,7 @@ class ApiRequestor
 
         $langVersion = phpversion();
         $uname = php_uname();
+        $curlVersion = curl_version();
         $appInfo = Stripe::getAppInfo();
         $ua = array(
             'bindings_version' => Stripe::VERSION,
@@ -148,6 +153,8 @@ class ApiRequestor
             'lang_version' => $langVersion,
             'publisher' => 'stripe',
             'uname' => $uname,
+            'httplib' => 'curl ' . $curlVersion['version'],
+            'ssllib' => $curlVersion['ssl_version'],
         );
         if ($appInfo !== null) {
             $uaString .= ' ' . self::_formatAppInfo($appInfo);

+ 0 - 2
plugins/stripe/lib/ApiResource.php

@@ -154,7 +154,6 @@ abstract class ApiResource extends StripeObject
     protected static function _create($params = null, $options = null)
     {
         self::_validateParams($params);
-        $base = static::baseUrl();
         $url = static::classUrl();
 
         list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
@@ -173,7 +172,6 @@ abstract class ApiResource extends StripeObject
     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);

+ 4 - 4
plugins/stripe/lib/Balance.php

@@ -5,10 +5,10 @@ namespace Stripe;
 /**
  * Class Balance
  *
- * @param string $object
- * @param mixed $available
- * @param bool $livedmode
- * @param mixed $pending
+ * @property string $object
+ * @property mixed $available
+ * @property bool $livedmode
+ * @property mixed $pending
  *
  * @package Stripe
  */

+ 4 - 4
plugins/stripe/lib/Collection.php

@@ -5,10 +5,10 @@ namespace Stripe;
 /**
  * Class Collection
  *
- * @param string $object
- * @param string $url
- * @param bool $has_more
- * @param mixed $data
+ * @property string $object
+ * @property string $url
+ * @property bool $has_more
+ * @property mixed $data
  *
  * @package Stripe
  */

+ 7 - 0
plugins/stripe/lib/Error/Permission.php

@@ -0,0 +1,7 @@
+<?php
+
+namespace Stripe\Error;
+
+class Permission extends Base
+{
+}

+ 16 - 32
plugins/stripe/lib/HttpClient/CurlClient.php

@@ -6,6 +6,22 @@ use Stripe\Stripe;
 use Stripe\Error;
 use Stripe\Util;
 
+// cURL constants are not defined in PHP < 5.5
+
+// @codingStandardsIgnoreStart
+// PSR2 requires all constants be upper case. Sadly, the CURL_SSLVERSION
+// constants do not abide by those rules.
+
+// Note the values 1 and 6 come from their position in the enum that
+// defines them in cURL's source code.
+if (!defined('CURL_SSLVERSION_TLSv1')) {
+    define('CURL_SSLVERSION_TLSv1', 1);
+}
+if (!defined('CURL_SSLVERSION_TLSv1_2')) {
+    define('CURL_SSLVERSION_TLSv1_2', 6);
+}
+// @codingStandardsIgnoreEnd
+
 class CurlClient implements ClientInterface
 {
     private static $instance;
@@ -151,38 +167,6 @@ class CurlClient implements ClientInterface
             $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);
 

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

@@ -6,6 +6,19 @@ namespace Stripe;
  * Class Plan
  *
  * @package Stripe
+ *
+ * @property $id
+ * @property $object
+ * @property $amount
+ * @property $created
+ * @property $currency
+ * @property $interval
+ * @property $interval_count
+ * @property $livemode
+ * @property AttachedObject $metadata
+ * @property $name
+ * @property $statement_descriptor
+ * @property $trial_period_days
  */
 class Plan extends ApiResource
 {

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

@@ -41,4 +41,40 @@ class Source extends ApiResource
     {
         return self::_create($params, $opts);
     }
+
+    /**
+     * @param string $id The ID of the source to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return Source The updated source.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
+    /**
+     * @param array|string|null $opts
+     *
+     * @return Source The saved source.
+     */
+    public function save($opts = null)
+    {
+        return $this->_save($opts);
+    }
+
+    /**
+     * @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;
+    }
 }

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

@@ -30,7 +30,7 @@ class Stripe
     // @var array The application's information (name, version, URL)
     public static $appInfo = null;
 
-    const VERSION = '3.23.0';
+    const VERSION = '4.4.0';
 
     /**
      * @return string The API key used for requests.

+ 88 - 0
plugins/stripe/lib/SubscriptionItem.php

@@ -0,0 +1,88 @@
+<?php
+
+namespace Stripe;
+
+/**
+ * Class SubscriptionItem
+ *
+ * @package Stripe
+ */
+class SubscriptionItem extends ApiResource
+{
+    /**
+     * This is a special case because the subscription items endpoint has an
+     *    underscore in it. The parent `className` function strips underscores.
+     *
+     * @return string The name of the class.
+     */
+    public static function className()
+    {
+        return 'subscription_item';
+    }
+
+    /**
+     * @param string $id The ID of the subscription item to retrieve.
+     * @param array|string|null $opts
+     *
+     * @return SubscriptionItem
+     */
+    public static function retrieve($id, $opts = null)
+    {
+        return self::_retrieve($id, $opts);
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return Collection of SubscriptionItems
+     */
+    public static function all($params = null, $opts = null)
+    {
+        return self::_all($params, $opts);
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return SubscriptionItem The created subscription item.
+     */
+    public static function create($params = null, $opts = null)
+    {
+        return self::_create($params, $opts);
+    }
+
+    /**
+     * @param string $id The ID of the subscription item to update.
+     * @param array|null $params
+     * @param array|string|null $options
+     *
+     * @return SubscriptionItem The updated subscription item.
+     */
+    public static function update($id, $params = null, $options = null)
+    {
+        return self::_update($id, $params, $options);
+    }
+
+    /**
+     * @param array|string|null $opts
+     *
+     * @return SubscriptionItem The saved subscription item.
+     */
+    public function save($opts = null)
+    {
+        return $this->_save($opts);
+    }
+
+    /**
+     * @param array|null $params
+     * @param array|string|null $opts
+     *
+     * @return SubscriptionItem The deleted subscription item.
+     */
+    public function delete($params = null, $opts = null)
+    {
+        return $this->_delete($params, $opts);
+    }
+}

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

@@ -12,6 +12,17 @@ class ThreeDSecure extends ApiResource
         return "/v1/3d_secure";
     }
 
+    /**
+     * @param string $id The ID of the 3DS auth to retrieve.
+     * @param array|string|null $options
+     *
+     * @return ThreeDSecure
+     */
+    public static function retrieve($id, $options = null)
+    {
+        return self::_retrieve($id, $options);
+    }
+
     /**
      * @param array|null $params
      * @param array|string|null $opts

+ 2 - 0
plugins/stripe/lib/Util/Util.php

@@ -82,6 +82,7 @@ abstract class Util
             'file' => 'Stripe\\FileUpload',
             'token' => 'Stripe\\Token',
             'transfer' => 'Stripe\\Transfer',
+            'transfer_reversal' => 'Stripe\\TransferReversal',
             'order' => 'Stripe\\Order',
             'order_return' => 'Stripe\\OrderReturn',
             'plan' => 'Stripe\\Plan',
@@ -91,6 +92,7 @@ abstract class Util
             'sku' => 'Stripe\\SKU',
             'source' => 'Stripe\\Source',
             'subscription' => 'Stripe\\Subscription',
+            'subscription_item' => 'Stripe\\SubscriptionItem',
             'three_d_secure' => 'Stripe\\ThreeDSecure',
             'fee_refund' => 'Stripe\\ApplicationFeeRefund',
             'bitcoin_receiver' => 'Stripe\\BitcoinReceiver',