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

API Updates #1188

Merged
merged 3 commits into from
Jul 9, 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/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
Prices: require('./resources/Prices'),
Products: require('./resources/Products'),
PromotionCodes: require('./resources/PromotionCodes'),
Quotes: require('./resources/Quotes'),
Refunds: require('./resources/Refunds'),
Reviews: require('./resources/Reviews'),
SetupAttempts: require('./resources/SetupAttempts'),
Expand Down
39 changes: 39 additions & 0 deletions lib/resources/Quotes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// File generated from our OpenAPI spec

'use strict';

const StripeResource = require('../StripeResource');
const stripeMethod = StripeResource.method;

module.exports = StripeResource.extend({
path: 'quotes',

includeBasic: ['create', 'retrieve', 'update', 'list'],

accept: stripeMethod({
method: 'POST',
path: '/{quote}/accept',
}),

cancel: stripeMethod({
method: 'POST',
path: '/{quote}/cancel',
}),

finalizeQuote: stripeMethod({
method: 'POST',
path: '/{quote}/finalize',
}),

listLineItems: stripeMethod({
method: 'GET',
path: '/{quote}/line_items',
}),

pdf: stripeMethod({
host: 'files.stripe.com',
method: 'GET',
path: '/{quote}/pdf',
streaming: true,
}),
});
194 changes: 194 additions & 0 deletions test/resources/Quotes.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
'use strict';

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

const QUOTE_TEST_ID = 'qt_123';

describe('Quotes Resource', () => {
describe('create', () => {
it('Sends the correct request', () => {
const params = {
customer: 'cus_xyz',
line_items: [{price: 'price_abc', quantity: 5}, {price: 'price_xyz'}],
};
stripe.quotes.create(params);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/quotes',
headers: {},
data: params,
settings: {},
});
});
});

describe('list', () => {
it('Sends the correct request', () => {
stripe.quotes.list();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/quotes',
headers: {},
data: {},
settings: {},
});
});
});

describe('retrieve', () => {
it('Sends the correct request', () => {
stripe.quotes.retrieve(QUOTE_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: `/v1/quotes/${QUOTE_TEST_ID}`,
headers: {},
data: {},
settings: {},
});
});
});

describe('update', () => {
it('Sends the correct request', () => {
stripe.quotes.update(QUOTE_TEST_ID, {
metadata: {key: 'value'},
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: `/v1/quotes/${QUOTE_TEST_ID}`,
headers: {},
data: {metadata: {key: 'value'}},
settings: {},
});
});
});

describe('accept', () => {
it('Sends the correct request', () => {
stripe.quotes.accept(QUOTE_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: `/v1/quotes/${QUOTE_TEST_ID}/accept`,
headers: {},
data: {},
settings: {},
});
});
});

describe('cancel', () => {
it('Sends the correct request', () => {
stripe.quotes.cancel(QUOTE_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: `/v1/quotes/${QUOTE_TEST_ID}/cancel`,
headers: {},
data: {},
settings: {},
});
});
});

describe('finalize', () => {
it('Sends the correct request', () => {
stripe.quotes.finalizeQuote(QUOTE_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: `/v1/quotes/${QUOTE_TEST_ID}/finalize`,
headers: {},
data: {},
settings: {},
});
});
});

describe('listLineItems', () => {
it('Sends the correct request', () => {
stripe.quotes.listLineItems(QUOTE_TEST_ID);
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: `/v1/quotes/${QUOTE_TEST_ID}/line_items`,
headers: {},
data: {},
settings: {},
});
});
});

describe('pdf', () => {
it('success', (callback) => {
const handleRequest = (req, res) => {
res.write('Stripe binary response');
res.end();
};

testUtils.getTestServerStripe(
{},
handleRequest,
(err, stripe, closeServer) => {
if (err) {
return callback(err);
}

return stripe.quotes.pdf(
'foo_123',
{host: 'localhost'},
(err, res) => {
closeServer();
if (err) {
return callback(err);
}
const chunks = [];
res.on('data', (chunk) => chunks.push(chunk));
res.on('error', callback);
res.on('end', () => {
expect(Buffer.concat(chunks).toString()).to.equal(
'Stripe binary response'
);
return callback();
});
}
);
}
);
});

it('failure', (callback) => {
const handleRequest = (req, res) => {
setTimeout(() => res.writeHead(500));
setTimeout(
() =>
res.write(
'{"error": "api_error", "error_description": "this is bad"}'
),
10
);
setTimeout(() => res.end(), 20);
};

testUtils.getTestServerStripe(
{},
handleRequest,
(err, stripe, closeServer) => {
if (err) {
return callback(err);
}

return stripe.quotes.pdf(
'foo_123',
{host: 'localhost'},
(err, res) => {
closeServer();
expect(err).to.exist;
expect(err.raw.type).to.equal('api_error');
expect(err.raw.message).to.equal('this is bad');
return callback();
}
);
}
);
});
});
});
4 changes: 2 additions & 2 deletions types/2020-08-27/Charges.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ declare module 'stripe' {
/**
* Indicates the outcome of 3D Secure authentication.
*/
result: ThreeDSecure.Result;
result: ThreeDSecure.Result | null;

/**
* Additional information about why 3D Secure succeeded or failed based
Expand All @@ -805,7 +805,7 @@ declare module 'stripe' {
/**
* The version of 3D Secure that was used.
*/
version: ThreeDSecure.Version;
version: ThreeDSecure.Version | null;
}

namespace ThreeDSecure {
Expand Down
6 changes: 6 additions & 0 deletions types/2020-08-27/Invoices.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ declare module 'stripe' {
*/
pre_payment_credit_notes_amount: number;

/**
* The quote this invoice was generated from.
*/
quote?: string | Stripe.Quote | null;

/**
* This is the transaction number that appears on email receipts sent for this invoice.
*/
Expand Down Expand Up @@ -356,6 +361,7 @@ declare module 'stripe' {
type BillingReason =
| 'automatic_pending_invoice_item_invoice'
| 'manual'
| 'quote_accept'
| 'subscription'
| 'subscription_create'
| 'subscription_cycle'
Expand Down
2 changes: 1 addition & 1 deletion types/2020-08-27/Issuing/Authorizations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ declare module 'stripe' {
verification_data: Authorization.VerificationData;

/**
* What, if any, digital wallet was used for this authorization. One of `apple_pay`, `google_pay`, or `samsung_pay`.
* The digital wallet used for this authorization. One of `apple_pay`, `google_pay`, or `samsung_pay`.
*/
wallet: string | null;
}
Expand Down
Loading