diff --git a/types/stripe/index.d.ts b/types/stripe/index.d.ts index 33bc44b0ee..cc4a5e4d7d 100644 --- a/types/stripe/index.d.ts +++ b/types/stripe/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for stripe 5.0.19 +// Type definitions for stripe 6.0.0 // Project: https://github.com/stripe/stripe-node/ // Definitions by: William Johnston // Peter Harris @@ -12,6 +12,7 @@ // Hunter Tunnicliff // Tyler Jones // Troy Zarger +// Ifiok Jr. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -72,6 +73,10 @@ declare class Stripe { skus: Stripe.resources.SKUs; webhooks: Stripe.resources.WebHooks; ephemeralKeys: Stripe.resources.EphemeralKeys; + usageRecords: Stripe.resources.UsageRecords; + usageRecordSummarys: Stripe.resources.UsageRecordSummarys; + + setHost(host: string): void; setHost(host: string, port: string|number): void; @@ -716,12 +721,12 @@ declare namespace Stripe { * or "transfer_failure" */ type?: string; - + /** - * For automatic Stripe payouts only, only returns transactions that were payed out on the specified payout ID. + * For automatic Stripe payouts only, only returns transactions that were payed out on the specified payout ID. */ payout?: string; - + /** * A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10. */ @@ -3118,6 +3123,51 @@ declare namespace Stripe { * A brief description of the plan, hidden from customers. */ nickname?: string; + + /** + * Specifies a usage aggregation strategy for plans of `usage_type=metered`. Allowed values are `sum` for summing up all usage during a period, `last_during_period` for picking the last usage record reported within a period, `last_ever` for picking the last usage record ever (across period bounds) or `max` which picks the usage record with the maximum reported usage during a period. Defaults to `sum`. + */ + aggregate_usage?: "sum" | "last_during_period" | "last_ever" | "max" | null; + + /** + * Describes how to compute the price per period. Either `per_unit` or `tiered`. `per_unit` indicates that the fixed amount (specified in `amount`) will be charged per unit in `quantity` (for plans with `usage_type=licensed`), or per unit of total usage (for plans with `usage_type=metered`). `tiered` indicates that the unit pricing will be computed using a tiering strategy as defined using the `tiers` and `tiers_mode` attributes. + */ + billing_scheme?: "per_unit" | "tiered"; + + /** + * Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. + */ + livemode?: boolean; + + /** + * Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. + */ + metadata?: IMetadata; + + /** + * Each element represents a pricing tier. This parameter requires `billing_scheme` to be set to `tiered`. See also the documentation for `billing_scheme`. + */ + tiers?: plans.ITier[] | null; + + /** + * Defines if the tiering price should be `graduated` or `volume` based. In `volume`-based tiering, the maximum quantity within a period determines the per unit price, in `graduated` tiering pricing can successively change as the quantity grows. + */ + tiers_mode?: "graduated" | "volume" | null; + + /** + * Apply a transformation to the reported usage or set quantity before computing the billed price. Cannot be combined with `tiers`. + */ + transform_usage?: plans.ITransformUsage | null; + + /** + * Default number of trial days when subscribing a customer to this plan using `trial_from_plan=true`. + */ + trial_period_days?: number; + + /** + * Configures how the quantity per period should be determined, can be either `metered` or `licensed`. `licensed` will automatically bill the `quantity` set for a plan when adding it to a subscription, `metered` will aggregate the total usage based on usage records. Defaults to `licensed`. + */ + usage_type?: "metered" | "licensed"; } interface IPlanUpdateOptions extends IDataOptionsWithMetadata { @@ -5239,11 +5289,94 @@ declare namespace Stripe { } } + namespace usageRecords { + type IUsageRecordAction = 'increment' | 'set'; + + interface IUsageRecordCreationOptions { + /** + * The usage quantity for the specified timestamp + */ + quantity: number; + /** + * The timestamp for the usage event. This timestamp must be within the current billing period of the subscription of the provided subscription_item + */ + timestamp: number; + /** + * Valid values are increment (default) or set. When using increment the specified quantity will be added to the usage at the specified + * timestamp. The set action will overwrite the usage quantity at that timestamp. + */ + action?: IUsageRecordAction; + } + + interface IUsageRecord extends IObject { + object: 'usage_record'; + id: string; + livemode: boolean; + quantity: number; + subscription_item: string; + timestamp: number; + } + } + + namespace usageRecordSummarys { + /** + * A object with a data property that contains an array of up to limit summaries, + * starting after summary starting_after. Each entry in the array is a separate summary object. + * If no more summaries are available, the resulting array is empty. + */ + interface IUsageRecordSummarys extends IList{ + object: 'list' + } + + interface IUsageRecordSummarysItem { + id: string; + object: string; + invoice: string; + livemode: boolean; + period: invoices.IPeriod; + subscription_item: string; + total_usage: number; + } + + interface IUsageRecordSummarysListOptions extends + IListOptions{ + /** + * Only summary items for the given subscription item. + */ + subscription_item: string; + /** + * A limit on the number of objects to be returned. The limit can range between 1 and 100. + * @default 10 + */ + limit?: number; + } + } + class StripeResource { constructor(stripe: Stripe, urlData: any); } namespace resources { + class UsageRecords extends StripeResource { + /** + * Creates a usage record for a specified subscription item and date, and fills it with a quantity. + * @param subscription + * @param options + */ + create(subscription: string, data: usageRecords.IUsageRecordCreationOptions, options: HeaderOptions, response?: IResponseFn): Promise; + create(subscription: string, data: usageRecords.IUsageRecordCreationOptions, response?: IResponseFn): Promise; + } + + class UsageRecordSummarys extends StripeResource { + /** + * Creates a usage record for a specified subscription item and date, and fills it with a quantity. + * @param subscription + * @param options + */ + list(data: usageRecordSummarys.IUsageRecordSummarysListOptions, options: HeaderOptions, response?: IResponseFn): Promise; + list(data: usageRecordSummarys.IUsageRecordSummarysListOptions, response?: IResponseFn): Promise; + } + class Accounts extends StripeResource { /** * With Connect, you can create Stripe accounts for your users. To do this, you'll first need to register your platform. diff --git a/types/stripe/stripe-tests.ts b/types/stripe/stripe-tests.ts index 4e538abddb..46362b9f8c 100644 --- a/types/stripe/stripe-tests.ts +++ b/types/stripe/stripe-tests.ts @@ -1164,7 +1164,9 @@ stripe.plans.create({ }, nickname: "Something to remember me by", currency: "usd", - id: "gold-plan" + id: "gold-plan", + usage_type: 'metered', + billing_scheme: 'per_unit' }, function (err, plan) { // asynchronously called }); @@ -1344,3 +1346,10 @@ stripe.subscriptionItems.list({ subscription: "si_C9gimdd2l9qvCU" }).then(functi stripe.ephemeralKeys.create({ customer: "cus_5rfJKDJkuxzh5Q" }, { stripe_version: "2017-08-15" }).then(function(ephemeralKeys) { // asynchronously called }); + + +stripe.usageRecords.create('sub_8QwCiwZ9tmMSpt', { action: 'set', quantity: 10000, timestamp: 1537006853 }).then((usageRecord: Stripe.usageRecords.IUsageRecord) => {}); +stripe.usageRecords.create('sub_8QwCiwZ9tmMSpt', { action: 'set', quantity: 10000, timestamp: 1537006853 }, (err, usageRecord: Stripe.usageRecords.IUsageRecord) => {}) + +stripe.usageRecordSummarys.list({ subscription_item: 'si_C9gimdd2l9qvCU', limit: 10 }).then((usageRecordSummarys: Stripe.usageRecordSummarys.IUsageRecordSummarys) => {}); +stripe.usageRecordSummarys.list({ subscription_item: 'si_C9gimdd2l9qvCU', limit: 10 }, (err, usageRecordSummarys: Stripe.usageRecordSummarys.IUsageRecordSummarys) => {}) diff --git a/types/stripe/tsconfig.json b/types/stripe/tsconfig.json index f2ac469aad..46d4cf5ff6 100644 --- a/types/stripe/tsconfig.json +++ b/types/stripe/tsconfig.json @@ -20,4 +20,4 @@ "index.d.ts", "stripe-tests.ts" ] -} \ No newline at end of file +}