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

Add support for the LineItem resource and APIs #890

Merged
merged 1 commit into from
May 12, 2020
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
7 changes: 7 additions & 0 deletions lib/resources/Checkout/Sessions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
'use strict';

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

module.exports = StripeResource.extend({
path: 'checkout/sessions',

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

listLineItems: stripeMethod({
method: 'GET',
path: '/{session}/line_items',
methodType: 'list',
}),
});
13 changes: 13 additions & 0 deletions test/resources/Checkout/Sessions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,18 @@ describe('Checkout', () => {
});
});
});

describe('listLineItems', () => {
it('Sends the correct request', () => {
stripe.checkout.sessions.listLineItems('cs_123');
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/checkout/sessions/cs_123/line_items',
headers: {},
data: {},
settings: {},
});
});
});
});
});
3 changes: 0 additions & 3 deletions types/2020-03-02/Accounts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2024,9 +2024,6 @@ declare module 'stripe' {
/**
* With [Connect](https://stripe.com/docs/connect), you can create Stripe accounts for your users.
* To do this, you'll first need to [register your platform](https://dashboard.stripe.com/account/applications/settings).
*
* For Standard accounts, parameters other than country, email, and type
* are used to prefill the account application that we ask the account holder to complete.
*/
create(
params?: AccountCreateParams,
Expand Down
77 changes: 77 additions & 0 deletions types/2020-03-02/Checkout/Sessions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ declare module 'stripe' {
*/
display_items?: Array<Session.DisplayItem>;

/**
* The line items purchased by the customer. [Expand](https://stripe.com/docs/api/expanding_objects) this field to include it in the response.
*/
line_items?: ApiList<Stripe.LineItem> | null;

/**
* Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
*/
Expand Down Expand Up @@ -547,6 +552,8 @@ declare module 'stripe' {
* A list of items the customer is purchasing. Use this parameter for
* one-time payments or adding invoice line items to a subscription (used
* in conjunction with `subscription_data`).
* There is a maximum of 100 line items, however it is recommended to
* consolidate line items if there are more than a few dozen.
*/
line_items?: Array<SessionCreateParams.LineItem>;

Expand Down Expand Up @@ -623,6 +630,16 @@ declare module 'stripe' {
*/
name?: string;

/**
* The ID of the price object.
*/
price?: string;

/**
* Data used to generate a new price object inline.
*/
price_data?: LineItem.PriceData;

/**
* The quantity of the line item being purchased.
*/
Expand All @@ -634,6 +651,53 @@ declare module 'stripe' {
tax_rates?: Array<string>;
}

namespace LineItem {
interface PriceData {
/**
* Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
*/
currency: string;

/**
* The ID of the product that this price will belong to.
*/
product: string;

/**
* The recurring components of a price such as `interval` and `usage_type`.
*/
recurring?: PriceData.Recurring;

/**
* A positive integer in %s (or 0 for a free price) representing how much to charge.
*/
unit_amount?: number;

/**
* Same as `unit_amount`, but accepts a decimal value with at most 12 decimal places. Only one of `unit_amount` and `unit_amount_decimal` can be set.
*/
unit_amount_decimal?: string;
}

namespace PriceData {
interface Recurring {
/**
* Specifies billing frequency. Either `day`, `week`, `month` or `year`.
*/
interval: Recurring.Interval;

/**
* The number of intervals between subscription billings. For example, `interval=month` and `interval_count=3` bills every 3 months. Maximum of one year interval allowed (1 year, 12 months, or 52 weeks).
*/
interval_count?: number;
}

namespace Recurring {
type Interval = 'day' | 'month' | 'week' | 'year';
}
}
}

type Locale =
| 'auto'
| 'da'
Expand Down Expand Up @@ -1167,6 +1231,19 @@ declare module 'stripe' {
options?: RequestOptions
): ApiListPromise<Stripe.Checkout.Session>;
list(options?: RequestOptions): ApiListPromise<Stripe.Checkout.Session>;

/**
* When retrieving a Checkout Session, there is an includable line_items property containing the first handful of those items. There is also a URL where you can retrieve the full (paginated) list of line items.
*/
listLineItems(
id: string,
params?: LineItemListParams,
options?: RequestOptions
): ApiListPromise<Stripe.LineItem>;
listLineItems(
id: string,
options?: RequestOptions
): ApiListPromise<Stripe.LineItem>;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion types/2020-03-02/Coupons.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ declare module 'stripe' {
expand?: Array<string>;

/**
* Unique string of your choice that will be used to identify this coupon when applying it to a customer. This is often a specific code you'll give to your customer to use when signing up (e.g., `FALL25OFF`). If you don't want to specify a particular code, you can leave the ID blank and we'll generate a random code for you.
* Unique string of your choice that will be used to identify this coupon when applying it to a customer. If you don't want to specify a particular code, you can leave the ID blank and we'll generate a random code for you.
*/
id?: string;

Expand Down
2 changes: 1 addition & 1 deletion types/2020-03-02/Invoices.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ declare module 'stripe' {
total_tax_amounts: Array<Invoice.TotalTaxAmount> | null;

/**
* If specified, the funds from the invoice will be transferred to the destination and the ID of the resulting transfer will be found on the invoice's charge.
* The account (if any) the payment will be attributed to for tax reporting, and where funds from the payment will be transferred to for the invoice.
*/
transfer_data?: Invoice.TransferData | null;

Expand Down
81 changes: 81 additions & 0 deletions types/2020-03-02/LineItems.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
declare module 'stripe' {
namespace Stripe {
/**
* The LineItem object.
*/
interface LineItem {
/**
* Unique identifier for the object.
*/
id: string;

/**
* String representing the object's type. Objects of the same type share the same value.
*/
object: 'item';

/**
* Total before any discounts or taxes is applied.
*/
amount_subtotal: number | null;

/**
* Total after discounts and taxes.
*/
amount_total: number | null;

/**
* Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
*/
currency: string;

/**
* An arbitrary string attached to the object. Often useful for displaying to users. Defaults to product name.
*/
description: string;

/**
* Prices define the unit cost, currency, and (optional) billing cycle for both recurring and one-time purchases of products.
* Products help you track inventory or provisioning, and prices help you track payment terms. Different physical goods or levels of service should be represented by products, and pricing options should be represented by prices. This approach lets you change prices without having to change your provisioning scheme.
*
* For example, you might have a single "gold" product that has prices for $10/month, $100/year, and €9 once.
*
* Related guides: [Set up a subscription](https://stripe.com/docs/billing/subscriptions/set-up-subscription), [create an invoice](https://stripe.com/docs/billing/invoices/create), and more about [products and prices](https://stripe.com/docs/billing/prices-guide).
*/
price: Stripe.Price;

/**
* The quantity of products being purchased.
*/
quantity: number | null;

/**
* The taxes applied to the line item.
*/
taxes: Array<LineItem.Tax> | null;
}

namespace LineItem {
interface Tax {
/**
* Amount of tax for this line item.
*/
amount: number;

/**
* Tax rates can be applied to invoices and subscriptions to collect tax.
*
* Related guide: [Tax Rates](https://stripe.com/docs/billing/taxes/tax-rates).
*/
rate: Stripe.TaxRate;
}
}

interface LineItemListParams extends PaginationParams {
/**
* Specifies which fields in the response should be expanded.
*/
expand?: Array<string>;
}
}
}
4 changes: 2 additions & 2 deletions types/2020-03-02/Plans.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ declare module 'stripe' {
aggregate_usage: Plan.AggregateUsage | null;

/**
* The amount in %s to be charged on the interval specified.
* The unit amount in %s to be charged, represented as a whole integer if possible.
*/
amount: number | null;

/**
* Same as `amount`, but contains a decimal value with at most 12 decimal places.
* The unit amount in %s to be charged, represented as a decimal string with at most 12 decimal places.
*/
amount_decimal: string | null;

Expand Down
4 changes: 2 additions & 2 deletions types/2020-03-02/Prices.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ declare module 'stripe' {
type: Price.Type;

/**
* The unit amount in %s to be charged.
* The unit amount in %s to be charged, represented as a whole integer if possible.
*/
unit_amount: number | null;

/**
* Same as `amount`, but contains a decimal value with at most 12 decimal places.
* The unit amount in %s to be charged, represented as a decimal string with at most 12 decimal places.
*/
unit_amount_decimal: string | null;
}
Expand Down
2 changes: 1 addition & 1 deletion types/2020-03-02/Subscriptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ declare module 'stripe' {
tax_percent: number | null;

/**
* If specified, the funds from the subscription's invoices will be transferred to the destination and the ID of the resulting transfers will be found on the resulting charges.
* The account (if any) the subscription's payments will be attributed to for tax reporting, and where funds from each payment will be transferred to for each of the subscription's invoices.
*/
transfer_data?: Subscription.TransferData | null;

Expand Down
1 change: 1 addition & 0 deletions types/2020-03-02/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
///<reference path='./Issuing/Cards.d.ts' />
///<reference path='./Issuing/Disputes.d.ts' />
///<reference path='./Issuing/Transactions.d.ts' />
///<reference path='./LineItems.d.ts' />
///<reference path='./LoginLinks.d.ts' />
///<reference path='./Mandates.d.ts' />
///<reference path='./OrderItems.d.ts' />
Expand Down