Skip to content

Commit

Permalink
Rename the request option stripeVersion to apiVersion to be consisten…
Browse files Browse the repository at this point in the history
…t with the config option and our overall terminology
  • Loading branch information
rattrayalex-stripe committed Jan 8, 2020
1 parent 52b1118 commit 20d9fa7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Stripe.prototype = {
*/
setApiVersion(version) {
emitWarning(
'`setApiVersion` is deprecated. Use the `stripeVersion` config or request option instead.'
'`setApiVersion` is deprecated. Use the `apiVersion` config or request option instead.'
);
if (version) {
this._setApiField('version', version);
Expand Down
9 changes: 5 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const OPTIONS_KEYS = [
'apiKey',
'idempotencyKey',
'stripeAccount',
'stripeVersion',
'apiVersion',
'maxNetworkRetries',
'timeout',
];
Expand All @@ -20,7 +20,8 @@ const DEPRECATED_OPTIONS = {
api_key: 'apiKey',
idempotency_key: 'idempotencyKey',
stripe_account: 'stripeAccount',
stripe_version: 'stripeVersion',
stripe_version: 'apiVersion',
stripeVersion: 'apiVersion',
};
const DEPRECATED_OPTIONS_KEYS = Object.keys(DEPRECATED_OPTIONS);

Expand Down Expand Up @@ -171,8 +172,8 @@ const utils = (module.exports = {
if (params.stripeAccount) {
opts.headers['Stripe-Account'] = params.stripeAccount;
}
if (params.stripeVersion) {
opts.headers['Stripe-Version'] = params.stripeVersion;
if (params.apiVersion) {
opts.headers['Stripe-Version'] = params.apiVersion;
}
if (Number.isInteger(params.maxNetworkRetries)) {
opts.settings.maxNetworkRetries = params.maxNetworkRetries;
Expand Down
4 changes: 2 additions & 2 deletions test/flows.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ describe('Flows', function() {
not_a_param: 'garbage, please 400',
},
{
stripeVersion: apiVersion,
apiVersion: apiVersion,
idempotencyKey: idempotencyKey,
stripeAccount: connectedAccountId,
}
Expand Down Expand Up @@ -401,7 +401,7 @@ describe('Flows', function() {
not_a_param: 'garbage, please 400',
},
{
stripeVersion: apiVersion,
apiVersion: apiVersion,
idempotencyKey: idempotencyKey,
stripeAccount: connectedAccountId,
}
Expand Down
4 changes: 2 additions & 2 deletions test/resources/EphemeralKeys.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function errorsOnNoStripeVersion() {
function sendsCorrectStripeVersion() {
stripe.ephemeralKeys.create(
{customer: 'cus_123'},
{stripeVersion: '2017-06-05'}
{apiVersion: '2017-06-05'}
);

expect(stripe.LAST_REQUEST).to.deep.equal({
Expand All @@ -33,7 +33,7 @@ describe('EphemeralKey Resource', () => {
it('Sends the correct request', () => {
stripe.ephemeralKeys.create(
{customer: 'cus_123'},
{stripeVersion: '2017-05-25'}
{apiVersion: '2017-05-25'}
);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
Expand Down
12 changes: 7 additions & 5 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('utils', () => {
});

it('parses an api version', () => {
const args = [{foo: 'bar'}, {stripeVersion: '2003-03-30'}];
const args = [{foo: 'bar'}, {apiVersion: '2003-03-30'}];
expect(utils.getOptionsFromArgs(args)).to.deep.equal({
auth: null,
headers: {'Stripe-Version': '2003-03-30'},
Expand All @@ -258,7 +258,7 @@ describe('utils', () => {
{
apiKey: 'sk_test_iiiiiiiiiiiiiiiiiiiiiiii',
idempotencyKey: 'foo',
stripeVersion: '2010-01-10',
apiVersion: '2010-01-10',
},
];
expect(utils.getOptionsFromArgs(args)).to.deep.equal({
Expand All @@ -277,7 +277,7 @@ describe('utils', () => {
{
apiKey: 'sk_test_iiiiiiiiiiiiiiiiiiiiiiii',
idempotencyKey: 'foo',
stripeVersion: 'hunter2',
apiVersion: 'hunter2',
},
];
expect(utils.getOptionsFromArgs(args)).to.deep.equal({
Expand Down Expand Up @@ -317,13 +317,15 @@ describe('utils', () => {
idempotency_key: 'key',
stripe_account: 'acct_123',
stripe_version: '2019-08-08',
stripeVersion: '2019-08-08',
},
];
const desiredWarnings = [
"Stripe: 'api_key' is deprecated; use 'apiKey' instead.",
"Stripe: 'idempotency_key' is deprecated; use 'idempotencyKey' instead.",
"Stripe: 'stripe_account' is deprecated; use 'stripeAccount' instead.",
"Stripe: 'stripe_version' is deprecated; use 'stripeVersion' instead.",
"Stripe: 'stripe_version' is deprecated; use 'apiVersion' instead.",
"Stripe: 'stripeVersion' is deprecated; use 'apiVersion' instead.",
];

const warnings = [];
Expand Down Expand Up @@ -354,7 +356,7 @@ describe('utils', () => {
{
apiKey: 'sk_test_iiiiiiiiiiiiiiiiiiiiiiii',
idempotencyKey: 'foo',
stripeVersion: '2010-01-10',
apiVersion: '2010-01-10',
fishsticks: true,
custard: true,
},
Expand Down
2 changes: 2 additions & 0 deletions types/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ declare module 'stripe' {
/**
* The [API Version](https://stripe.com/docs/upgrades) to use for a given request (e.g., '2019-12-03').
*/
apiVersion?: string;
/** @deprecated Please use apiVersion instead. */
stripeVersion?: string;
/** @deprecated Please use stripeVersion instead. */
stripe_version?: string;
Expand Down
2 changes: 1 addition & 1 deletion types/test/typescriptTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ stripe.setHost('host', 'port', 'protocol');
description: 'test',
};
const opts: Stripe.RequestOptions = {
stripeVersion: '2019-12-03',
apiVersion: '2019-12-03',
};
const customer: Stripe.Customer = await stripe.customers.create(params, opts);

Expand Down

0 comments on commit 20d9fa7

Please sign in to comment.