Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for global stripeAccount #1191

Merged
merged 4 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/StripeResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ StripeResource.prototype = {
'X-Stripe-Client-User-Agent': clientUserAgent,
'X-Stripe-Client-Telemetry': this._getTelemetryHeader(),
'Stripe-Version': apiVersion,
'Stripe-Account': this._stripe.getApiField('stripeAccount'),
'Idempotency-Key': this._defaultIdempotencyKey(
method,
userSuppliedSettings
Expand Down
2 changes: 2 additions & 0 deletions lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const ALLOWED_CONFIG_PROPERTIES = [
'protocol',
'telemetry',
'appInfo',
'stripeAccount',
];

const EventEmitter = require('events').EventEmitter;
Expand Down Expand Up @@ -92,6 +93,7 @@ function Stripe(key, config = {}) {
),
agent: props.httpAgent || null,
dev: false,
stripeAccount: props.stripeAccount || null,
};

const typescript = props.typescript || false;
Expand Down
55 changes: 55 additions & 0 deletions test/stripe.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,61 @@ describe('Stripe Module', function() {
});
});

describe('stripeAccount', () => {
describe('when passed in via the config object', () => {
let headers;
let stripeClient;
let closeServer;
before((callback) => {
testUtils.getTestServerStripe(
{
stripeAccount: 'my_stripe_account',
},
(req, res) => {
headers = req.headers;
res.writeHeader(200);
res.write('{}');
res.end();
},
(err, client, close) => {
if (err) {
return callback(err);
}
stripeClient = client;
closeServer = close;
return callback();
}
);
});
after(() => closeServer());
it('is respected', (callback) => {
stripeClient.customers.create((err) => {
closeServer();
if (err) {
return callback(err);
}
expect(headers['stripe-account']).to.equal('my_stripe_account');
return callback();
});
});
it('can still be overridden per-request', (callback) => {
stripeClient.customers.create(
{stripeAccount: 'my_other_stripe_account'},
(err) => {
closeServer();
if (err) {
return callback(err);
}
expect(headers['stripe-account']).to.equal(
'my_other_stripe_account'
);
return callback();
}
);
});
});
});

describe('setMaxNetworkRetries', () => {
describe('when given an empty or non-number variable', () => {
it('should error', () => {
Expand Down
5 changes: 5 additions & 0 deletions types/lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ declare module 'stripe' {
* @docs https://stripe.com/docs/building-plugins?lang=node#setappinfo
*/
appInfo?: AppInfo;

/**
* An account id on whose behalf you wish to make every request.
*/
stripeAccount?: string;
}

export interface RequestOptions {
Expand Down