diff --git a/lib/ApiRequestor.php b/lib/ApiRequestor.php index e8f653438..2672ef35e 100644 --- a/lib/ApiRequestor.php +++ b/lib/ApiRequestor.php @@ -348,6 +348,7 @@ private static function _defaultHeaders($apiKey, $clientInfo = null) 'X-Stripe-Client-User-Agent' => \json_encode($ua), 'User-Agent' => $uaString, 'Authorization' => 'Bearer ' . $apiKey, + 'Stripe-Version' => Stripe::getApiVersion(), ]; } @@ -393,9 +394,6 @@ function ($key) use ($params) { $absUrl = $this->_apiBase . $url; $params = self::_encodeObjects($params); $defaultHeaders = $this->_defaultHeaders($myApiKey, $clientUAInfo); - if (Stripe::$apiVersion) { - $defaultHeaders['Stripe-Version'] = Stripe::$apiVersion; - } if (Stripe::$accountId) { $defaultHeaders['Stripe-Account'] = Stripe::$accountId; diff --git a/lib/BaseStripeClient.php b/lib/BaseStripeClient.php index aa6a59a37..60c7c5a5f 100644 --- a/lib/BaseStripeClient.php +++ b/lib/BaseStripeClient.php @@ -18,6 +18,7 @@ class BaseStripeClient implements StripeClientInterface, StripeStreamingClientIn 'api_key' => null, 'client_id' => null, 'stripe_account' => null, + // Note, even if null, ApiRequestor will default this to Stripe::$apiVersion 'stripe_version' => null, 'api_base' => self::DEFAULT_API_BASE, 'connect_base' => self::DEFAULT_CONNECT_BASE, diff --git a/lib/Stripe.php b/lib/Stripe.php index 504b13ec8..335f9316e 100644 --- a/lib/Stripe.php +++ b/lib/Stripe.php @@ -22,8 +22,8 @@ class Stripe /** @var string The base URL for the Stripe API uploads endpoint. */ public static $apiUploadBase = 'https://files.stripe.com'; - /** @var null|string The version of the Stripe API to use for requests. */ - public static $apiVersion = null; + /** @var string The version of the Stripe API to use for requests. */ + public static $apiVersion = \Stripe\Util\ApiVersion::CURRENT; /** @var null|string The account ID for connected accounts requests. */ public static $accountId = null; @@ -119,8 +119,7 @@ public static function setClientId($clientId) } /** - * @return string The API version used for requests. null if we're using the - * latest version. + * @return string the API version used for requests */ public static function getApiVersion() { diff --git a/tests/Stripe/ApiRequestorTest.php b/tests/Stripe/ApiRequestorTest.php index 6615b12a6..5fbdfa945 100644 --- a/tests/Stripe/ApiRequestorTest.php +++ b/tests/Stripe/ApiRequestorTest.php @@ -82,6 +82,11 @@ public function testDefaultHeaders() 'Stripe/v1 PhpBindings/' . Stripe::VERSION . ' MyTestApp/1.2.34 (https://mytestapp.example)' ); + static::assertSame( + $headers['Stripe-Version'], + Stripe::getApiVersion() + ); + static::assertSame($headers['Authorization'], 'Bearer ' . $apiKey); } diff --git a/tests/TestHelper.php b/tests/TestHelper.php index 95e4ec64b..06319c7c0 100644 --- a/tests/TestHelper.php +++ b/tests/TestHelper.php @@ -43,7 +43,6 @@ protected function setUpConfig() Stripe::$apiUploadBase = \defined('MOCK_URL') ? MOCK_URL : 'http://localhost:12111'; Stripe::setApiKey('sk_test_123'); Stripe::setClientId('ca_123'); - Stripe::setApiVersion(null); Stripe::setAccountId(null); // Set up the HTTP client mocker @@ -63,7 +62,6 @@ protected function tearDownConfig() Stripe::setEnableTelemetry(false); Stripe::setApiKey($this->origApiKey); Stripe::setClientId($this->origClientId); - Stripe::setApiVersion($this->origApiVersion); Stripe::setAccountId($this->origAccountId); }