Skip to content

Commit

Permalink
Merge pull request #1806 from stripe/richardm-fix-retry-bug
Browse files Browse the repository at this point in the history
Allow request-level options to disable retries
  • Loading branch information
richardm-stripe authored Jun 2, 2023
2 parents ba2568b + ffd6a87 commit ac9661b
Show file tree
Hide file tree
Showing 39 changed files with 691 additions and 1,060 deletions.
5 changes: 4 additions & 1 deletion .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ const config = {
// Recurse through all tests in the test directory.
recursive: true,
extension: ["js", "ts"],
require: "ts-node/register/transpile-only",
require: "ts-node/register/transpile-only,./test/setup",
};

if (process.argv.find(a => a.includes('WebStorm'))) {
// Parallel doesn't work correctly when running from JetBrains WebStorm
config.parallel = false;
}

// Ensure we are using the 'as promised' libs before any tests are run:
require('chai').use(require('chai-as-promised'));

module.exports = config;
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 12.8.0 - 2023-06-01
* [#1799](https://github.com/stripe/stripe-node/pull/1799) Update generated code
* Add support for `numeric` and `text` on `CheckoutSessionCreateParams.custom_fields[]`, `PaymentLinkCreateParams.custom_fields[]`, and `PaymentLinkUpdateParams.custom_fields[]`
* Add support for new values `aba` and `swift` on enums `Checkout.Session.payment_method_options.customer_balance.bank_transfer.requested_address_types[]`, `CheckoutSessionCreateParams.payment_method_options.customer_balance.bank_transfer.requested_address_types[]`, `PaymentIntent.payment_method_options.customer_balance.bank_transfer.requested_address_types[]`, `PaymentIntentConfirmParams.payment_method_options.customer_balance.bank_transfer.requested_address_types[]`, `PaymentIntentCreateParams.payment_method_options.customer_balance.bank_transfer.requested_address_types[]`, and `PaymentIntentUpdateParams.payment_method_options.customer_balance.bank_transfer.requested_address_types[]`
* Add support for new value `us_bank_transfer` on enums `Checkout.Session.payment_method_options.customer_balance.bank_transfer.type`, `CheckoutSessionCreateParams.payment_method_options.customer_balance.bank_transfer.type`, `CustomerCreateFundingInstructionsParams.bank_transfer.type`, `PaymentIntent.next_action.display_bank_transfer_instructions.type`, `PaymentIntent.payment_method_options.customer_balance.bank_transfer.type`, `PaymentIntentConfirmParams.payment_method_options.customer_balance.bank_transfer.type`, `PaymentIntentCreateParams.payment_method_options.customer_balance.bank_transfer.type`, and `PaymentIntentUpdateParams.payment_method_options.customer_balance.bank_transfer.type`
* Add support for `maximum_length` and `minimum_length` on `Checkout.Session.custom_fields[].numeric` and `Checkout.Session.custom_fields[].text`
* Add support for `preferred_locales` on `Issuing.Cardholder`, `IssuingCardholderCreateParams`, and `IssuingCardholderUpdateParams`
* Add support for `description`, `iin`, and `issuer` on `PaymentMethod.card_present` and `PaymentMethod.interac_present`
* Add support for `payer_email` on `PaymentMethod.paypal`

## 12.7.0 - 2023-05-25
* [#1797](https://github.com/stripe/stripe-node/pull/1797) Update generated code
* Add support for `zip_payments` on `Account.capabilities`, `AccountCreateParams.capabilities`, and `AccountUpdateParams.capabilities`
Expand Down
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v354
v369
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.7.0
12.8.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stripe",
"version": "12.7.0",
"version": "12.8.0",
"description": "Stripe API wrapper",
"keywords": [
"stripe",
Expand Down
2 changes: 1 addition & 1 deletion src/stripe.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function createStripe(
platformFunctions: PlatformFunctions,
requestSender: RequestSenderFactory = defaultRequestSenderFactory
): typeof Stripe {
Stripe.PACKAGE_VERSION = '12.7.0';
Stripe.PACKAGE_VERSION = '12.8.0';
Stripe.USER_AGENT = {
bindings_version: Stripe.PACKAGE_VERSION,
lang: 'node',
Expand Down
22 changes: 15 additions & 7 deletions test/Integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as childProcess from 'child_process';
const testUtils = require('./testUtils.js');
import {FAKE_API_KEY} from './testUtils.js';

const nodeVersion = parseInt(process.versions.node.split('.')[0], 10);

Expand All @@ -8,25 +8,30 @@ describe('Integration test', function() {
const testExec = (cmd: string): Promise<void> => {
const child = childProcess.exec(cmd);

child.stdout?.on('data', console.debug);
child.stderr?.on('data', console.debug);
let out = '';
child.stdout?.on('data', (chunk) => {
out += chunk;
});
child.stderr?.on('data', (chunk) => {
out += chunk;
});

return new Promise((resolve, reject) => {
child.on('exit', (code) => {
if (code == 0) {
resolve();
} else {
reject(new Error('Test failed'));
reject(new Error('Test failed: ' + out));
}
});
});
};
const runTestProject = (projectName: string): Promise<void> => {
return testExec(`
cd testProjects/${projectName} &&
cd testProjects/${projectName} && rm -rf node_modules &&
npm install &&
npm run lint &&
npm run runtestproject -- ${testUtils.getUserStripeKey()}
npm run runtestproject -- ${FAKE_API_KEY}
`);
};

Expand Down Expand Up @@ -78,7 +83,10 @@ describe('Integration test', function() {
}

const script = `
cd examples/webhook-signing/test &&
(cd examples/webhook-signing/${projectName} &&
rm -rf node_modules &&
npm install) &&
cd examples/webhook-signing/test && rm -rf node_modules &&
npm install &&
./main.ts ../${projectName}
`;
Expand Down
2 changes: 0 additions & 2 deletions test/PlatformFunctions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// @ts-nocheck

require('./testUtils.js');

import * as fs from 'fs';
import * as path from 'path';

Expand Down
52 changes: 25 additions & 27 deletions test/RequestSender.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
// @ts-nocheck

const {RequestSender} = require('../src/RequestSender.js');

const stripe = require('./testUtils.js').getSpyableStripe();
const expect = require('chai').expect;

const {HttpClientResponse} = require('../src/net/HttpClient.js');
const utils = require('./testUtils.js');
const nock = require('nock');

const {
import {expect} from 'chai';
import {
StripeAuthenticationError,
StripeConnectionError,
StripeError,
StripeIdempotencyError,
StripePermissionError,
StripeRateLimitError,
StripeError,
StripeConnectionError,
} = require('../src/Error.js');
} from '../src/Error.js';
import {HttpClientResponse} from '../src/net/HttpClient.js';
import {RequestSender} from '../src/RequestSender.js';
import {
FAKE_API_KEY,
getSpyableStripe,
getTestServerStripe,
} from './testUtils.js';
import nock = require('nock');

const stripe = getSpyableStripe();

describe('RequestSender', () => {
const sender = new RequestSender(stripe, 0);

describe('_makeHeaders', () => {
it('sets the Authorization header with Bearer auth using the global API key', () => {
const headers = sender._makeHeaders(null, 0, null);
expect(headers.Authorization).to.equal('Bearer fakeAuthToken');
expect(headers.Authorization).to.equal(`Bearer ${FAKE_API_KEY}`);
});
it('sets the Authorization header with Bearer auth using the specified API key', () => {
const headers = sender._makeHeaders('anotherFakeAuthToken', 0, null);
Expand Down Expand Up @@ -88,9 +90,7 @@ describe('RequestSender', () => {

describe('Parameter encoding', () => {
// Use a real instance of stripe as we're mocking the http.request responses.
const realStripe = require('../src/stripe.cjs.node.js')(
utils.getUserStripeKey()
);
const realStripe = require('../src/stripe.cjs.node.js')('sk_test_xyz');

after(() => {
nock.cleanAll();
Expand Down Expand Up @@ -337,9 +337,7 @@ describe('RequestSender', () => {

describe('Retry Network Requests', () => {
// Use a real instance of stripe as we're mocking the http.request responses.
const realStripe = require('../src/stripe.cjs.node.js')(
utils.getUserStripeKey()
);
const realStripe = require('../src/stripe.cjs.node.js')('sk_test_xyz');

// Override the sleep timer to speed up tests
realStripe.charges._getSleepTimeInMS = () => 0;
Expand Down Expand Up @@ -379,7 +377,7 @@ describe('RequestSender', () => {
});

it('throws an error on connection timeout', (done) => {
return utils.getTestServerStripe(
return getTestServerStripe(
{timeout: 10},
(req, res) => {
// Do nothing. This will trigger a timeout.
Expand All @@ -401,7 +399,7 @@ describe('RequestSender', () => {
});

it('throws an error on invalid JSON', (done) => {
return utils.getTestServerStripe(
return getTestServerStripe(
{},
(req, res) => {
// Write back JSON to close out the server.
Expand All @@ -423,7 +421,7 @@ describe('RequestSender', () => {
);
});
it('throws an valid headers but connection error', (done) => {
return utils.getTestServerStripe(
return getTestServerStripe(
{},
(req, res) => {
// Send out valid headers and a partial response. We then interrupt
Expand Down Expand Up @@ -515,7 +513,7 @@ describe('RequestSender', () => {

it('retries connection timeout errors', (done) => {
let nRequestsReceived = 0;
return utils.getTestServerStripe(
return getTestServerStripe(
{timeout: 10, maxNetworkRetries: 2},
(req, res) => {
nRequestsReceived += 1;
Expand Down Expand Up @@ -898,7 +896,7 @@ describe('RequestSender', () => {
const returnedCharge = {
id: 'ch_123',
};
return utils.getTestServerStripe(
return getTestServerStripe(
{},
(req, res) => {
res.write(JSON.stringify(returnedCharge));
Expand All @@ -921,7 +919,7 @@ describe('RequestSender', () => {
const returnedCharge = {
id: 'ch_123',
};
return utils.getTestServerStripe(
return getTestServerStripe(
{},
(req, res) => {
res.write(JSON.stringify(returnedCharge));
Expand Down
Loading

0 comments on commit ac9661b

Please sign in to comment.