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 Price resource and APIs #881

Merged
merged 2 commits into from
Apr 29, 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
1 change: 1 addition & 0 deletions lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
PaymentMethods: require('./resources/PaymentMethods'),
Payouts: require('./resources/Payouts'),
Plans: require('./resources/Plans'),
Prices: require('./resources/Prices'),
Products: require('./resources/Products'),
Refunds: require('./resources/Refunds'),
Reviews: require('./resources/Reviews'),
Expand Down
9 changes: 9 additions & 0 deletions lib/resources/Prices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

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

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

includeBasic: ['create', 'list', 'retrieve', 'update'],
});
79 changes: 79 additions & 0 deletions test/resources/Prices.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
'use strict';

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

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

describe('create', () => {
it('Sends the correct request', () => {
stripe.prices.create({
unit_amount: 200,
currency: 'usd',
recurring: {
interval: 'month',
},
product_data: {
name: 'Product name',
},
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/prices',
headers: {},
data: {
unit_amount: 200,
currency: 'usd',
recurring: {
interval: 'month',
},
product_data: {
name: 'Product name',
},
},
settings: {},
});
});
});

describe('update', () => {
it('Sends the correct request', () => {
stripe.prices.update('priceId3', {
amount: 1900,
currency: 'usd',
});
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/v1/prices/priceId3',
headers: {},
data: {amount: 1900, currency: 'usd'},
settings: {},
});
});
});

describe('list', () => {
it('Sends the correct request', () => {
stripe.prices.list();
expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'GET',
url: '/v1/prices',
headers: {},
data: {},
settings: {},
});
});
});
});
69 changes: 69 additions & 0 deletions types/2020-03-02/InvoiceItems.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ declare module 'stripe' {
*/
plan: Stripe.Plan | null;

/**
* The price of the invoice item.
*/
price?: Stripe.Price | null;

/**
* Whether the invoice item was created automatically as a proration adjustment when the customer switched plans.
*/
Expand Down Expand Up @@ -189,6 +194,16 @@ declare module 'stripe' {
*/
period?: InvoiceItemCreateParams.Period;

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

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

/**
* Non-negative integer. The quantity of units for the invoice item.
*/
Expand Down Expand Up @@ -227,6 +242,28 @@ declare module 'stripe' {
*/
start: number;
}

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;

/**
* 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;
}
}

interface InvoiceItemRetrieveParams {
Expand Down Expand Up @@ -267,6 +304,16 @@ declare module 'stripe' {
*/
period?: InvoiceItemUpdateParams.Period;

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

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

/**
* Non-negative integer. The quantity of units for the invoice item.
*/
Expand Down Expand Up @@ -300,6 +347,28 @@ declare module 'stripe' {
*/
start: number;
}

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;

/**
* 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;
}
}

interface InvoiceItemListParams extends PaginationParams {
Expand Down
115 changes: 115 additions & 0 deletions types/2020-03-02/InvoiceLineItems.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ declare module 'stripe' {
*/
plan: Stripe.Plan | null;

/**
* The price of the line item.
*/
price?: Stripe.Price | null;

/**
* Whether this is a proration.
*/
Expand Down Expand Up @@ -279,6 +284,16 @@ declare module 'stripe' {
*/
period?: InvoiceItem.Period;

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

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

/**
* Non-negative integer. The quantity of units for the invoice item.
*/
Expand Down Expand Up @@ -309,6 +324,28 @@ declare module 'stripe' {
*/
start: number;
}

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;

/**
* 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;
}
}

type SubscriptionBillingCycleAnchor = 'now' | 'unchanged';
Expand Down Expand Up @@ -344,6 +381,16 @@ declare module 'stripe' {
*/
plan?: string;

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

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

/**
* Quantity for this item.
*/
Expand All @@ -362,6 +409,74 @@ declare module 'stripe' {
*/
usage_gte: number;
}

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 a usage aggregation strategy for prices of `usage_type=metered`. Allowed values are `sum` for summing up all usage during a period, `last_during_period` for using the last usage record reported within a period, `last_ever` for using the last usage record ever (across period bounds) or `max` which uses the usage record with the maximum reported usage during a period. Defaults to `sum`.
*/
aggregate_usage?: Recurring.AggregateUsage;

/**
* 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;

/**
* Default number of trial days when subscribing a customer to this price using [`trial_from_plan=true`](https://stripe.com/docs/api#create_subscription-trial_from_plan).
*/
trial_period_days?: number;

/**
* Configures how the quantity per period should be determined. Can be either `metered` or `licensed`. `licensed` automatically bills the `quantity` set when adding it to a subscription. `metered` aggregates the total usage based on usage records. Defaults to `licensed`.
*/
usage_type?: Recurring.UsageType;
}

namespace Recurring {
type AggregateUsage =
| 'last_during_period'
| 'last_ever'
| 'max'
| 'sum';

type Interval = 'day' | 'month' | 'week' | 'year';

type UsageType = 'licensed' | 'metered';
}
}
}

type SubscriptionProrationBehavior =
Expand Down
Loading