import { StripePayments, StripePaymentsError } from "./init"; /** * Interface of a Stripe Subscription stored in the app database. */ export interface Subscription { /** * A future date in UTC format at which the subscription will automatically get canceled. */ readonly cancel_at: string | null; /** * If `true`, the subscription has been canceled by the user and will be deleted at the end * of the billing period. */ readonly cancel_at_period_end: boolean; /** * If the subscription has been canceled, the date of that cancellation as a UTC timestamp. * If the subscription was canceled with {@link Subscription.cancel_at_period_end}, this field * will still reflect the date of the initial cancellation request, not the end of the * subscription period when the subscription is automatically moved to a canceled state. */ readonly canceled_at: string | null; /** * The date when the subscription was created as a UTC timestamp. */ readonly created: string; /** * End of the current period that the subscription has been invoiced for as a UTC timestamp. * At the end of the period, a new invoice will be created. */ readonly current_period_end: string; /** * Start of the current period that the subscription has been invoiced for as a UTC timestamp. */ readonly current_period_start: string; /** * If the subscription has ended, the date the subscription ended as a UTC timestamp. */ readonly ended_at: string | null; /** * Unique Stripe subscription ID. */ readonly id: string; /** * Set of extra key-value pairs attached to the subscription object. */ readonly metadata: { [name: string]: string; }; /** * Stripe price ID associated with this subscription. */ readonly price: string; /** * Array of product ID and price ID pairs. If multiple recurring prices were provided to the * checkout session (e.g. via `lineItems`) this array holds all recurring prices for this * subscription. The first element of this array always corresponds to the * {@link Subscription.price} and {@link Subscription.product} fields on the subscription. */ readonly prices: Array<{ product: string; price: string; }>; /** * Stripe product ID associated with this subscription. */ readonly product: string; /** * Quantity of items purchased with this subscription. */ readonly quantity: number | null; /** * The Firebae role that can be assigned to the user with this subscription. */ readonly role: string | null; /** * The status of the subscription object */ readonly status: SubscriptionStatus; /** * A link to the subscription in the Stripe dashboard. */ readonly stripe_link: string; /** * If the subscription has a trial, the end date of that trial as a UTC timestamp. */ readonly trial_end: string | null; /** * If the subscription has a trial, the start date of that trial as a UTC timestamp. */ readonly trial_start: string | null; /** * Firebase Auth UID of the user that created the subscription. */ readonly uid: string; readonly [propName: string]: any; } /** * Possible states a subscription can be in. */ export declare type SubscriptionStatus = "active" | "canceled" | "incomplete" | "incomplete_expired" | "past_due" | "trialing" | "unpaid"; /** * Retrieves an existing Stripe subscription for the currently signed in user from the database. * * @param payments - A valid {@link StripePayments} object. * @param subscriptionId - ID of the subscription to retrieve. * @returns Resolves with a Subscription object if found. Rejects if the specified subscription ID * does not exist, or if the user is not signed in. */ export declare function getCurrentUserSubscription(payments: StripePayments, subscriptionId: string): Promise; /** * Optional parameters for the {@link getCurrentUserSubscriptions} function. */ export interface GetSubscriptionsOptions { /** * Specify one or more subscription status values to retrieve. When set only the subscriptions * with the given status are returned. */ status?: SubscriptionStatus | SubscriptionStatus[]; } /** * Retrieves existing Stripe subscriptions for the currently signed in user from the database. * * @param payments - A valid {@link StripePayments} object. * @param options - A set of options to customize the behavior. * @returns Resolves with an array of Stripe subscriptions. May be empty. */ export declare function getCurrentUserSubscriptions(payments: StripePayments, options?: GetSubscriptionsOptions): Promise; /** * Different types of changes that may occur on a subscription object. */ export declare type SubscriptionChangeType = "added" | "modified" | "removed"; /** * Represents the current state of a set of subscriptions owned by a user. */ export interface SubscriptionSnapshot { /** * A list of all currently available subscriptions ordered by the subscription ID. Empty * if no subscriptions are available. */ subscriptions: Subscription[]; /** * The list of changes in the subscriptions since the last snapshot. */ changes: Array<{ type: SubscriptionChangeType; subscription: Subscription; }>; /** * Number of currently available subscriptions. This is same as the length of the * `subscriptions` array in the snapshot. */ size: number; /** * True if there are no subscriptions available. False whenever at least one subscription is * present. When True, the `subscriptions` array is empty, and the `size` is 0. */ empty: boolean; } /** * Registers a listener to receive subscription update events for the currently signed in * user. If the user is not signed in throws an `unauthenticated` error, and no listener is * registered. * * Upon successful registration, the `onUpdate` callback will fire once with * the current state of all the subscriptions. From then onwards, each update to a subscription * will fire the `onUpdate` callback with the latest state of the subscriptions. * * @param payments - A valid {@link StripePayments} object. * @param onUpdate - A callback that will fire whenever the current user's subscriptions * are updated. * @param onError - A callback that will fire whenever an error occurs while listening to * subscription updates. * @returns A function that can be called to cancel and unregister the listener. */ export declare function onCurrentUserSubscriptionUpdate(payments: StripePayments, onUpdate: (snapshot: SubscriptionSnapshot) => void, onError?: (error: StripePaymentsError) => void): () => void; //# sourceMappingURL=subscription.d.ts.map