Skip to content

Commit

Permalink
Merge pull request #1556 from stripe/pakrym/merge-master-beta
Browse files Browse the repository at this point in the history
Merge master into beta
  • Loading branch information
pakrym-stripe authored Aug 18, 2023
2 parents df437cc + ed8762f commit d66f376
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 151 deletions.
254 changes: 132 additions & 122 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v458
v466
7 changes: 1 addition & 6 deletions lib/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,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(),
];
}

Expand Down Expand Up @@ -406,12 +407,6 @@ function ($key) use ($params) {
}
$defaultHeaders = $this->_defaultHeaders($myApiKey, $clientUAInfo);

if ('preview' === $apiMode && !isset($headers['Stripe-Version'])) {
$headers['Stripe-Version'] = \Stripe\Util\ApiVersion::PREVIEW;
} elseif (Stripe::$apiVersion) {
$headers['Stripe-Version'] = Stripe::$apiVersion;
}

if (Stripe::$accountId) {
$defaultHeaders['Stripe-Account'] = Stripe::$accountId;
}
Expand Down
11 changes: 9 additions & 2 deletions lib/BaseStripeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BaseStripeClient implements StripeClientInterface, StripeStreamingClientIn
'api_key' => null,
'client_id' => null,
'stripe_account' => null,
'stripe_version' => null,
'stripe_version' => \Stripe\Util\ApiVersion::CURRENT,
'api_base' => self::DEFAULT_API_BASE,
'connect_base' => self::DEFAULT_CONNECT_BASE,
'files_base' => self::DEFAULT_FILES_BASE,
Expand Down Expand Up @@ -186,7 +186,14 @@ public function rawRequest($method, $path, $params = null, $opts = [])
$headers['Stripe-Context'] = $opts['stripe_context'];
unset($opts['stripe_context']);
}
$opts = $this->defaultOpts->merge($opts, true);

$defaultRawRequestOpts = $this->defaultOpts;
if ('preview' === $apiMode) {
$defaultRawRequestOpts = $defaultRawRequestOpts->merge(['stripe_version' => \Stripe\Util\ApiVersion::PREVIEW], true);
}

$opts = $defaultRawRequestOpts->merge($opts, true);

// Concatenate $headers to $opts->headers, removing duplicates.
$opts->headers = \array_merge($opts->headers, $headers);
$baseUrl = $opts->apiBase ?: $this->getApiBase();
Expand Down
3 changes: 0 additions & 3 deletions lib/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*
* @property string $id Unique identifier for the object.
* @property string $object String representing the object's type. Objects of the same type share the same value.
* @property null|\Stripe\StripeObject $alternate_statement_descriptors
* @property int $amount Amount intended to be collected by this payment. A positive integer representing how much to charge in the <a href="https://stripe.com/docs/currencies#zero-decimal">smallest currency unit</a> (e.g., 100 cents to charge $1.00 or 100 to charge ¥100, a zero-decimal currency). The minimum amount is $0.50 US or <a href="https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts">equivalent in charge currency</a>. The amount value supports up to eight digits (e.g., a value of 99999999 for a USD charge of $999,999.99).
* @property int $amount_captured Amount in cents (or local equivalent) captured (can be less than the amount attribute on the charge if a partial capture was made).
* @property int $amount_refunded Amount in cents (or local equivalent) refunded (can be less than the amount attribute on the charge if a partial refund was issued).
Expand All @@ -28,8 +27,6 @@
* @property string $currency Three-letter <a href="https://www.iso.org/iso-4217-currency-codes.html">ISO currency code</a>, in lowercase. Must be a <a href="https://stripe.com/docs/currencies">supported currency</a>.
* @property null|string|\Stripe\Customer $customer ID of the customer this charge is for if one exists.
* @property null|string $description An arbitrary string attached to the object. Often useful for displaying to users.
* @property null|string|\Stripe\Account $destination ID of an existing, connected Stripe account to transfer funds to if <code>transfer_data</code> was specified in the charge request.
* @property null|string|\Stripe\Dispute $dispute Details about the dispute if the charge has been disputed.
* @property bool $disputed Whether the charge has been disputed.
* @property null|string|\Stripe\BalanceTransaction $failure_balance_transaction ID of the balance transaction that describes the reversal of the balance on your account due to payment failure.
* @property null|string $failure_code Error code explaining reason for charge failure if available (see <a href="https://stripe.com/docs/error-codes">the errors section</a> for a list of codes).
Expand Down
3 changes: 1 addition & 2 deletions lib/Dispute.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @property null|string $network_reason_code Network-dependent reason code for the dispute.
* @property null|string|\Stripe\PaymentIntent $payment_intent ID of the PaymentIntent that was disputed.
* @property string $reason Reason given by cardholder for dispute. Possible values are <code>bank_cannot_process</code>, <code>check_returned</code>, <code>credit_not_processed</code>, <code>customer_initiated</code>, <code>debit_not_authorized</code>, <code>duplicate</code>, <code>fraudulent</code>, <code>general</code>, <code>incorrect_account_details</code>, <code>insufficient_funds</code>, <code>product_not_received</code>, <code>product_unacceptable</code>, <code>subscription_canceled</code>, or <code>unrecognized</code>. Read more about <a href="https://stripe.com/docs/disputes/categories">dispute reasons</a>.
* @property string $status Current status of dispute. Possible values are <code>warning_needs_response</code>, <code>warning_under_review</code>, <code>warning_closed</code>, <code>needs_response</code>, <code>under_review</code>, <code>charge_refunded</code>, <code>won</code>, or <code>lost</code>.
* @property string $status Current status of dispute. Possible values are <code>warning_needs_response</code>, <code>warning_under_review</code>, <code>warning_closed</code>, <code>needs_response</code>, <code>under_review</code>, <code>won</code>, or <code>lost</code>.
*/
class Dispute extends ApiResource
{
Expand All @@ -53,7 +53,6 @@ class Dispute extends ApiResource
const REASON_SUBSCRIPTION_CANCELED = 'subscription_canceled';
const REASON_UNRECOGNIZED = 'unrecognized';

const STATUS_CHARGE_REFUNDED = 'charge_refunded';
const STATUS_LOST = 'lost';
const STATUS_NEEDS_RESPONSE = 'needs_response';
const STATUS_UNDER_REVIEW = 'under_review';
Expand Down
3 changes: 0 additions & 3 deletions lib/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ class Invoice extends ApiResource
const BILLING_CHARGE_AUTOMATICALLY = 'charge_automatically';
const BILLING_SEND_INVOICE = 'send_invoice';

/** @deprecated */
const STATUS_DELETED = 'deleted';

/**
* @param null|array $params
* @param null|array|string $opts
Expand Down
3 changes: 0 additions & 3 deletions lib/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
* @property string $id Unique identifier for the object.
* @property string $object String representing the object's type. Objects of the same type share the same value.
* @property bool $active Whether the product is currently available for purchase.
* @property null|string[] $attributes A list of up to 5 attributes that each SKU can provide values for (e.g., <code>[&quot;color&quot;, &quot;size&quot;]</code>).
* @property null|string $caption A short one-line description of the product, meant to be displayable to the customer. Only applicable to products of <code>type=good</code>.
* @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
* @property null|string[] $deactivate_on An array of connect application identifiers that cannot purchase this product. Only applicable to products of <code>type=good</code>.
* @property null|string|\Stripe\Price $default_price The ID of the <a href="https://stripe.com/docs/api/prices">Price</a> object that is the default price for this product.
* @property null|string $description The product's description, meant to be displayable to the customer. Use this field to optionally store a long form explanation of the product being sold for your own rendering purposes.
* @property string[] $images A list of up to 8 URLs of images for this product, meant to be displayable to the customer.
Expand Down
2 changes: 1 addition & 1 deletion lib/SetupIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @property string $object String representing the object's type. Objects of the same type share the same value.
* @property null|string|\Stripe\StripeObject $application ID of the Connect application that created the SetupIntent.
* @property null|bool $attach_to_self <p>If present, the SetupIntent's payment method will be attached to the in-context Stripe Account.</p><p>It can only be used for this Stripe Account’s own money movement flows like InboundTransfer and OutboundTransfers. It cannot be set to true when setting up a PaymentMethod for a Customer, and defaults to false when attaching a PaymentMethod to a Customer.</p>
* @property null|\Stripe\StripeObject $automatic_payment_methods Settings for automatic payment methods compatible with this Setup Intent
* @property null|\Stripe\StripeObject $automatic_payment_methods Settings for dynamic payment methods compatible with this Setup Intent
* @property null|string $cancellation_reason Reason for cancellation of this SetupIntent, one of <code>abandoned</code>, <code>requested_by_customer</code>, or <code>duplicate</code>.
* @property null|string $client_secret <p>The client secret of this SetupIntent. Used for client-side retrieval using a publishable key.</p><p>The client secret can be used to complete payment setup from your frontend. It should not be stored, logged, or exposed to anyone other than the customer. Make sure that you have TLS enabled on any page that includes the client secret.</p>
* @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
Expand Down
7 changes: 3 additions & 4 deletions lib/Stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Util/ApiVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

class ApiVersion
{
const CURRENT = '2022-11-15';
const PREVIEW = '2023-07-13.preview-v2';
const CURRENT = '2023-08-16';
const PREVIEW = '2023-08-11.preview-v2';
}
5 changes: 5 additions & 0 deletions tests/Stripe/ApiRequestorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
25 changes: 25 additions & 0 deletions tests/Stripe/BaseStripeClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace Stripe;

use Stripe\Util\ApiVersion;

/**
* @internal
* @covers \Stripe\BaseStripeClient
*/
final class BaseStripeClientTest extends \Stripe\TestCase
{
use TestHelper;
/** @var \ReflectionProperty */
private $optsReflector;

Expand Down Expand Up @@ -208,6 +211,23 @@ public function testRequestWithOptsInParamsWarns()
static::assertSame('acct_456', $this->optsReflector->getValue($charge)->headers['Stripe-Account']);
}

public function testRequestWithNoVersionDefaultsToPinnedVersion()
{
$client = new BaseStripeClient([
'api_key' => 'sk_test_client',
'api_base' => MOCK_URL,
]);
$this->expectsRequest('get', '/v1/charges/ch_123', null, [
'Stripe-Version: ' . \Stripe\Util\ApiVersion::CURRENT,
]);
$charge = $client->request(
'get',
'/v1/charges/ch_123',
[],
[]
);
}

public function testJsonRawRequestGetWithURLParams()
{
$curlClientStub = $this->getMockBuilder(\Stripe\HttpClient\CurlClient::class)
Expand Down Expand Up @@ -238,14 +258,19 @@ public function testJsonRawRequestGetWithURLParams()
static::assertArrayNotHasKey(\CURLOPT_POST, $opts);
static::assertArrayNotHasKey(\CURLOPT_POSTFIELDS, $opts);
$content_type = null;
$stripe_version = null;
foreach ($opts[\CURLOPT_HTTPHEADER] as $header) {
if (self::headerStartsWith($header, 'Content-Type:')) {
$content_type = $header;
}
if (self::headerStartsWith($header, 'Stripe-Version:')) {
$stripe_version = $header;
}
}
// The library sends Content-Type even with no body, so assert this
// But it would be more correct to not send Content-Type
static::assertSame('Content-Type: application/x-www-form-urlencoded', $content_type);
static::assertSame('Stripe-Version: ' . ApiVersion::CURRENT, $stripe_version);
}

public function testJsonRawRequestPost()
Expand Down
2 changes: 0 additions & 2 deletions tests/TestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand Down

0 comments on commit d66f376

Please sign in to comment.