diff --git a/lib/stripe.js b/lib/stripe.js index 60b82e7312..2907e49e08 100644 --- a/lib/stripe.js +++ b/lib/stripe.js @@ -148,93 +148,6 @@ Stripe.createSubtleCryptoProvider = (subtleCrypto) => { return new SubtleCryptoProvider(subtleCrypto); }; Stripe.prototype = { - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * host: 'example.com', - * port: '8080', - * protocol: 'http', - * }); - * - */ - setHost(host, port, protocol) { - emitWarning( - '`setHost` is deprecated. Use the `host` config option instead.' - ); - this._setApiField('host', host); - if (port) { - this.setPort(port); - } - if (protocol) { - this.setProtocol(protocol); - } - }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * protocol: 'http', - * }); - * - */ - setProtocol(protocol) { - emitWarning( - '`setProtocol` is deprecated. Use the `protocol` config option instead.' - ); - this._setApiField('protocol', protocol.toLowerCase()); - }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * port: 3000, - * }); - * - */ - setPort(port) { - emitWarning( - '`setPort` is deprecated. Use the `port` config option instead.' - ); - this._setApiField('port', port); - }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * apiVersion: API_VERSION, - * }); - * - */ - setApiVersion(version) { - emitWarning( - '`setApiVersion` is deprecated. Use the `apiVersion` config or request option instead.' - ); - if (version) { - this._setApiField('version', version); - } - }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY); - * - * Or, for Stripe Connect, use `stripeAccount` instead: - * - * const stripe = new Stripe(API_KEY, { - * stripeAccount: 'acct_...', - * }); - * - * Or, to use a different apiKey on a given request: - * - * stripe.customers.create(params, {apiKey: 'sk_test_...'}); - */ - setApiKey(key) { - emitWarning( - '`setApiKey` is deprecated. Use the `apiKey` request option instead.' - ); - this._setApiKey(key); - }, /** * @private */ @@ -243,37 +156,6 @@ Stripe.prototype = { this._setApiField('auth', `Bearer ${key}`); } }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * timeout: TIMEOUT_MS, - * }); - */ - setTimeout(timeout) { - emitWarning( - '`setTimeout` is deprecated. Use the `timeout` config or request option instead.' - ); - this._setApiField('timeout', timeout == null ? DEFAULT_TIMEOUT : timeout); - }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * appInfo: { - * name: 'MyPlugin', - * version: '1.4.2', - * url: 'https://myplugin.com', - * partner_id: '1234', - * }, - * }); - */ - setAppInfo(info) { - emitWarning( - '`setAppInfo` is deprecated. Use the `appInfo` config option instead.' - ); - this._setAppInfo(info); - }, /** * @private * This may be removed in the future. @@ -295,21 +177,6 @@ Stripe.prototype = { }, undefined); this._appInfo = appInfo; }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const ProxyAgent = require('https-proxy-agent'); - * const stripe = new Stripe(API_KEY, { - * httpAgent: new ProxyAgent(process.env.http_proxy), - * }); - * - */ - setHttpAgent(agent) { - emitWarning( - '`setHttpAgent` is deprecated. Use the `httpAgent` config option instead.' - ); - this._setApiField('agent', agent); - }, /** * @private * This may be removed in the future. @@ -362,17 +229,6 @@ Stripe.prototype = { getMaxNetworkRetries() { return this.getApiField('maxNetworkRetries'); }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * maxNetworkRetries: 2, - * }); - * - */ - setMaxNetworkRetries(maxNetworkRetries) { - this._setApiNumberField('maxNetworkRetries', maxNetworkRetries); - }, /** * @private * This may be removed in the future. @@ -461,20 +317,6 @@ Stripe.prototype = { } return formatted; }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * telemetry: false, - * }); - * - */ - setTelemetryEnabled(enableTelemetry) { - emitWarning( - '`setTelemetryEnabled` is deprecated. Use the `telemetry` config option instead.' - ); - this._enableTelemetry = enableTelemetry; - }, getTelemetryEnabled() { return this._enableTelemetry; }, diff --git a/src/stripe.ts b/src/stripe.ts index 5d6cb7e377..4dbb40689c 100644 --- a/src/stripe.ts +++ b/src/stripe.ts @@ -178,98 +178,6 @@ Stripe.createSubtleCryptoProvider = (subtleCrypto) => { }; Stripe.prototype = { - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * host: 'example.com', - * port: '8080', - * protocol: 'http', - * }); - * - */ - setHost(host, port, protocol) { - emitWarning( - '`setHost` is deprecated. Use the `host` config option instead.' - ); - this._setApiField('host', host); - if (port) { - this.setPort(port); - } - if (protocol) { - this.setProtocol(protocol); - } - }, - - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * protocol: 'http', - * }); - * - */ - setProtocol(protocol) { - emitWarning( - '`setProtocol` is deprecated. Use the `protocol` config option instead.' - ); - this._setApiField('protocol', protocol.toLowerCase()); - }, - - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * port: 3000, - * }); - * - */ - setPort(port) { - emitWarning( - '`setPort` is deprecated. Use the `port` config option instead.' - ); - this._setApiField('port', port); - }, - - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * apiVersion: API_VERSION, - * }); - * - */ - setApiVersion(version) { - emitWarning( - '`setApiVersion` is deprecated. Use the `apiVersion` config or request option instead.' - ); - if (version) { - this._setApiField('version', version); - } - }, - - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY); - * - * Or, for Stripe Connect, use `stripeAccount` instead: - * - * const stripe = new Stripe(API_KEY, { - * stripeAccount: 'acct_...', - * }); - * - * Or, to use a different apiKey on a given request: - * - * stripe.customers.create(params, {apiKey: 'sk_test_...'}); - */ - setApiKey(key) { - emitWarning( - '`setApiKey` is deprecated. Use the `apiKey` request option instead.' - ); - this._setApiKey(key); - }, - /** * @private */ @@ -279,39 +187,6 @@ Stripe.prototype = { } }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * timeout: TIMEOUT_MS, - * }); - */ - setTimeout(timeout) { - emitWarning( - '`setTimeout` is deprecated. Use the `timeout` config or request option instead.' - ); - this._setApiField('timeout', timeout == null ? DEFAULT_TIMEOUT : timeout); - }, - - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * appInfo: { - * name: 'MyPlugin', - * version: '1.4.2', - * url: 'https://myplugin.com', - * partner_id: '1234', - * }, - * }); - */ - setAppInfo(info) { - emitWarning( - '`setAppInfo` is deprecated. Use the `appInfo` config option instead.' - ); - this._setAppInfo(info); - }, - /** * @private * This may be removed in the future. @@ -343,22 +218,6 @@ Stripe.prototype = { this._appInfo = appInfo; }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const ProxyAgent = require('https-proxy-agent'); - * const stripe = new Stripe(API_KEY, { - * httpAgent: new ProxyAgent(process.env.http_proxy), - * }); - * - */ - setHttpAgent(agent) { - emitWarning( - '`setHttpAgent` is deprecated. Use the `httpAgent` config option instead.' - ); - this._setApiField('agent', agent); - }, - /** * @private * This may be removed in the future. @@ -417,18 +276,6 @@ Stripe.prototype = { return this.getApiField('maxNetworkRetries'); }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * maxNetworkRetries: 2, - * }); - * - */ - setMaxNetworkRetries(maxNetworkRetries) { - this._setApiNumberField('maxNetworkRetries', maxNetworkRetries); - }, - /** * @private * This may be removed in the future. @@ -533,21 +380,6 @@ Stripe.prototype = { return formatted; }, - /** - * @deprecated will be removed in a future major version. Use the config object instead: - * - * const stripe = new Stripe(API_KEY, { - * telemetry: false, - * }); - * - */ - setTelemetryEnabled(enableTelemetry) { - emitWarning( - '`setTelemetryEnabled` is deprecated. Use the `telemetry` config option instead.' - ); - this._enableTelemetry = enableTelemetry; - }, - getTelemetryEnabled() { return this._enableTelemetry; }, diff --git a/test/StripeResource.spec.js b/test/StripeResource.spec.js index 78b999aedb..5b7217d2f2 100644 --- a/test/StripeResource.spec.js +++ b/test/StripeResource.spec.js @@ -1023,8 +1023,6 @@ describe('StripeResource', () => { describe('Request Timeout', () => { it('should allow the setting of a request timeout on a per-request basis', (done) => { - stripe.setTimeout(1000); - stripe.charges.create({}); expect(stripe.LAST_REQUEST.settings).to.deep.equal({}); diff --git a/test/resources/EphemeralKeys.spec.js b/test/resources/EphemeralKeys.spec.js index 2a64f5a978..e77866ea29 100644 --- a/test/resources/EphemeralKeys.spec.js +++ b/test/resources/EphemeralKeys.spec.js @@ -1,9 +1,9 @@ 'use strict'; -const stripe = require('../../testUtils').getSpyableStripe(); +const getSpyableStripe = require('../../testUtils').getSpyableStripe; const expect = require('chai').expect; -function errorsOnNoStripeVersion() { +function errorsOnNoStripeVersion(stripe) { return expect( stripe.ephemeralKeys.create({customer: 'cus_123'}) ).to.be.eventually.rejectedWith( @@ -11,7 +11,7 @@ function errorsOnNoStripeVersion() { ); } -function sendsCorrectStripeVersion() { +function sendsCorrectStripeVersion(stripe) { stripe.ephemeralKeys.create( {customer: 'cus_123'}, {apiVersion: '2017-06-05'} @@ -32,6 +32,8 @@ function sendsCorrectStripeVersion() { describe('EphemeralKey Resource', () => { describe('create', () => { + const stripe = getSpyableStripe(); + it('Sends the correct request', () => { stripe.ephemeralKeys.create( {customer: 'cus_123'}, @@ -51,43 +53,35 @@ describe('EphemeralKey Resource', () => { }); describe('when an api version is set', () => { - beforeEach(function() { - this.oldVersion = stripe.getApiField('version'); - stripe.setApiVersion('2017-05-25'); - }); - - afterEach(function() { - stripe.setApiVersion(this.oldVersion); + const stripe = getSpyableStripe({ + apiVersion: '2017-05-25', }); it('Errors if no stripe-version is specified', () => - errorsOnNoStripeVersion()); + errorsOnNoStripeVersion(stripe)); it('Sends the correct stripe-version', () => { - sendsCorrectStripeVersion(); + sendsCorrectStripeVersion(stripe); }); }); describe('when no api version is set', () => { - beforeEach(function() { - this.oldVersion = stripe.getApiField('version'); - stripe.setApiVersion(null); - }); - - afterEach(function() { - stripe.setApiVersion(this.oldVersion); + const stripe = getSpyableStripe({ + apiVersion: null, }); it('Errors if no stripe-version is specified', () => - errorsOnNoStripeVersion()); + errorsOnNoStripeVersion(stripe)); it('Sends the correct stripe-version', () => { - sendsCorrectStripeVersion(); + sendsCorrectStripeVersion(stripe); }); }); }); describe('delete', () => { + const stripe = getSpyableStripe(); + it('Sends the correct request', () => { stripe.ephemeralKeys.del('ephkey_123'); expect(stripe.LAST_REQUEST).to.deep.equal({ diff --git a/test/stripe.spec.js b/test/stripe.spec.js index c2111b39b1..f3d4c3b9c4 100644 --- a/test/stripe.spec.js +++ b/test/stripe.spec.js @@ -111,8 +111,8 @@ describe('Stripe Module', function() { }); cases.forEach((item) => { - const stripe = Stripe(testUtils.getUserStripeKey(), item); - expect(stripe.getApiField('version')).to.equal(null); + const newStripe = Stripe(testUtils.getUserStripeKey(), item); + expect(newStripe.getApiField('version')).to.equal(null); }); }); @@ -178,22 +178,22 @@ describe('Stripe Module', function() { it('Should include whether typescript: true was passed, respecting reinstantiations', () => { return new Promise((resolve) => resolve()) .then(() => { - const stripe = new Stripe('sk_test_123', { + const newStripe = new Stripe('sk_test_123', { typescript: true, }); return expect( new Promise((resolve, reject) => { - stripe.getClientUserAgent((c) => { + newStripe.getClientUserAgent((c) => { resolve(JSON.parse(c)); }); }) ).to.eventually.have.property('typescript', 'true'); }) .then(() => { - const stripe = new Stripe('sk_test_123', {}); + const newStripe = new Stripe('sk_test_123', {}); return expect( new Promise((resolve, reject) => { - stripe.getClientUserAgent((c) => { + newStripe.getClientUserAgent((c) => { resolve(JSON.parse(c)); }); }) @@ -276,25 +276,28 @@ describe('Stripe Module', function() { }); }); - describe('setTimeout', () => { + describe('timeout config', () => { const defaultTimeout = 80000; it('Should define a default of 80000', () => { expect(stripe.getApiField('timeout')).to.equal(defaultTimeout); }); it('Should allow me to set a custom timeout', () => { - stripe.setTimeout(900); - expect(stripe.getApiField('timeout')).to.equal(900); + const newStripe = Stripe('sk_test', { + timeout: 900, + }); + expect(newStripe.getApiField('timeout')).to.equal(900); }); it('Should allow me to set null, to reset to the default', () => { - stripe.setTimeout(null); - expect(stripe.getApiField('timeout')).to.equal(defaultTimeout); + const newStripe = Stripe('sk_test', { + timeout: null, + }); + expect(newStripe.getApiField('timeout')).to.equal(defaultTimeout); }); }); - describe('setAppInfo', () => { + describe('appInfo config', () => { describe('when given nothing or an empty object', () => { it('should unset stripe._appInfo', () => { - stripe.setAppInfo(); expect(stripe._appInfo).to.be.undefined; }); }); @@ -308,7 +311,9 @@ describe('Stripe Module', function() { describe('when given a non-object variable', () => { it('should throw an error', () => { expect(() => { - stripe.setAppInfo('foo'); + Stripe('sk_test', { + appInfo: 'foo', + }); }).to.throw(/AppInfo must be an object./); }); }); @@ -316,18 +321,24 @@ describe('Stripe Module', function() { describe('when given an object with no `name`', () => { it('should throw an error', () => { expect(() => { - stripe.setAppInfo({}); + Stripe('sk_test', { + appInfo: {}, + }); }).to.throw(/AppInfo.name is required/); expect(() => { - stripe.setAppInfo({ - version: '1.2.3', + Stripe('sk_test', { + appInfo: { + version: '1.2.3', + }, }); }).to.throw(/AppInfo.name is required/); expect(() => { - stripe.setAppInfo({ - cats: '42', + Stripe('sk_test', { + appInfo: { + cats: '42', + }, }); }).to.throw(/AppInfo.name is required/); }); @@ -335,50 +346,60 @@ describe('Stripe Module', function() { describe('when given at least a `name`', () => { it('should set name, partner ID, url, and version of stripe._appInfo', () => { - stripe.setAppInfo({ - name: 'MyAwesomeApp', + let newStripe = Stripe('sk_test', { + appInfo: { + name: 'MyAwesomeApp', + }, }); - expect(stripe._appInfo).to.eql({ + expect(newStripe._appInfo).to.eql({ name: 'MyAwesomeApp', }); - stripe.setAppInfo({ - name: 'MyAwesomeApp', - version: '1.2.345', + newStripe = Stripe('sk_test', { + appInfo: { + name: 'MyAwesomeApp', + version: '1.2.345', + }, }); - expect(stripe._appInfo).to.eql({ + expect(newStripe._appInfo).to.eql({ name: 'MyAwesomeApp', version: '1.2.345', }); - stripe.setAppInfo({ - name: 'MyAwesomeApp', - url: 'https://myawesomeapp.info', + newStripe = Stripe('sk_test', { + appInfo: { + name: 'MyAwesomeApp', + url: 'https://myawesomeapp.info', + }, }); - expect(stripe._appInfo).to.eql({ + expect(newStripe._appInfo).to.eql({ name: 'MyAwesomeApp', url: 'https://myawesomeapp.info', }); - stripe.setAppInfo({ - name: 'MyAwesomeApp', - partner_id: 'partner_1234', + newStripe = Stripe('sk_test', { + appInfo: { + name: 'MyAwesomeApp', + partner_id: 'partner_1234', + }, }); - expect(stripe._appInfo).to.eql({ + expect(newStripe._appInfo).to.eql({ name: 'MyAwesomeApp', partner_id: 'partner_1234', }); }); it('should ignore any invalid properties', () => { - stripe.setAppInfo({ - name: 'MyAwesomeApp', - partner_id: 'partner_1234', - version: '1.2.345', - url: 'https://myawesomeapp.info', - countOfRadishes: 512, + const newStripe = Stripe('sk_test', { + appInfo: { + name: 'MyAwesomeApp', + partner_id: 'partner_1234', + version: '1.2.345', + url: 'https://myawesomeapp.info', + countOfRadishes: 512, + }, }); - expect(stripe._appInfo).to.eql({ + expect(newStripe._appInfo).to.eql({ name: 'MyAwesomeApp', partner_id: 'partner_1234', version: '1.2.345', @@ -394,12 +415,14 @@ describe('Stripe Module', function() { url: 'https://myawesomeapp.info', }; - stripe.setAppInfo(appInfo); + const newStripe = Stripe('sk_test', { + appInfo, + }); - stripe.getClientUserAgent((uaString) => { + newStripe.getClientUserAgent((uaString) => { expect(JSON.parse(uaString).application).to.eql(appInfo); - expect(stripe.getAppInfoAsString()).to.eql( + expect(newStripe.getAppInfoAsString()).to.eql( `${appInfo.name}/${appInfo.version} (${appInfo.url})` ); @@ -496,7 +519,6 @@ describe('Stripe Module', function() { describe('errors', () => { it('Exports errors as types', () => { - const Stripe = require('../lib/stripe'); expect( new Stripe.errors.StripeInvalidRequestError({ message: 'error', diff --git a/test/telemetry.spec.js b/test/telemetry.spec.js index f408c92c60..c73650ac34 100644 --- a/test/telemetry.spec.js +++ b/test/telemetry.spec.js @@ -58,10 +58,14 @@ describe('Client Telemetry', () => { }, (host, port) => { const stripe = require('../lib/stripe')( - 'sk_test_FEiILxKZwnmmocJDUjUNO6pa' + 'sk_test_FEiILxKZwnmmocJDUjUNO6pa', + { + telemetry: false, + host, + port, + protocol: 'http', + } ); - stripe.setTelemetryEnabled(false); - stripe.setHost(host, port, 'http'); stripe.balance .retrieve() @@ -104,10 +108,14 @@ describe('Client Telemetry', () => { }, (host, port) => { const stripe = require('../lib/stripe')( - 'sk_test_FEiILxKZwnmmocJDUjUNO6pa' + 'sk_test_FEiILxKZwnmmocJDUjUNO6pa', + { + telemetry: true, + host, + port, + protocol: 'http', + } ); - stripe.setTelemetryEnabled(true); - stripe.setHost(host, port, 'http'); stripe.balance .retrieve() @@ -152,10 +160,14 @@ describe('Client Telemetry', () => { }, (host, port) => { const stripe = require('../lib/stripe')( - 'sk_test_FEiILxKZwnmmocJDUjUNO6pa' + 'sk_test_FEiILxKZwnmmocJDUjUNO6pa', + { + telemetry: true, + host, + port, + protocol: 'http', + } ); - stripe.setTelemetryEnabled(true); - stripe.setHost(host, port, 'http'); Promise.all([stripe.balance.retrieve(), stripe.balance.retrieve()]) .then(() => diff --git a/testUtils/index.js b/testUtils/index.js index f527a44765..4e090fc4c1 100644 --- a/testUtils/index.js +++ b/testUtils/index.js @@ -58,12 +58,12 @@ const utils = (module.exports = { return key; }, - getSpyableStripe: () => { + getSpyableStripe: (config) => { // Provide a testable stripe instance // That is, with mock-requests built in and hookable const stripe = require('../lib/stripe'); - const stripeInstance = stripe('fakeAuthToken'); + const stripeInstance = stripe('fakeAuthToken', config); stripeInstance.REQUESTS = []; diff --git a/types/2022-08-01/index.d.ts b/types/2022-08-01/index.d.ts index bd8c1c27ef..57f7591dde 100644 --- a/types/2022-08-01/index.d.ts +++ b/types/2022-08-01/index.d.ts @@ -134,8 +134,6 @@ declare module 'stripe' { constructor(apiKey: string, config?: Stripe.StripeConfig); - setAppInfo(info: Stripe.AppInfo): void; - StripeResource: Stripe.StripeResource; /** @@ -281,27 +279,6 @@ declare module 'stripe' { event: 'response', handler: (event: Stripe.ResponseEvent) => void ): void; - - setProtocol(protocol: string): void; - - /** @deprecated Please use the StripeConfig object instead. */ - setHost(host: string, port?: string | number, protocol?: string): void; - - /** @deprecated Please use the StripeConfig object instead. */ - setPort(port: string | number): void; - /** @deprecated Please use the StripeConfig object instead. */ - setApiVersion(version: Stripe.LatestApiVersion): void; - /** @deprecated Please use the StripeConfig object instead. */ - setApiKey(key: string): void; - - /** @deprecated Please use the StripeConfig object instead. */ - setTimeout(timeout?: number): void; - /** @deprecated Please use the StripeConfig object instead. */ - setMaxNetworkRetries(maxNetworkRetries: number): void; - /** @deprecated Please use the StripeConfig object instead. */ - setTelemetryEnabled(enabled: boolean): void; - /** @deprecated Please use the StripeConfig object instead. */ - setHttpAgent(agent: Stripe.HttpAgent): void; } export default Stripe; diff --git a/types/test/typescriptTest.ts b/types/test/typescriptTest.ts index ebd0b7da64..42d0fec726 100644 --- a/types/test/typescriptTest.ts +++ b/types/test/typescriptTest.ts @@ -35,15 +35,11 @@ stripe = new Stripe('sk_test_123', { port: 123, telemetry: true, httpClient: Stripe.createNodeHttpClient(), + appInfo: { + name: 'my-wordpress-plugin', + }, }); -stripe.setTimeout(3000); -stripe.setAppInfo({ - name: 'my-wordpress-plugin', -}); - -stripe.setHost('host', 'port', 'protocol'); - (async (): Promise => { const params: Stripe.CustomerCreateParams = { description: 'test',