import type Stripe from 'stripe'; import type { DateTime } from 'luxon'; import type { HasMany } from '@adonisjs/lucid/types/relations'; import type { LucidModel } from '@adonisjs/lucid/types/model'; import type { Invoice } from './invoice.js'; import type { Payment } from './payment.js'; import type { PaymentMethod } from './payment_method.js'; import type { CheckoutBuilder } from './builders/checkout_builder.js'; import type { Discount } from './discount.js'; import type { PromotionCode } from './promotion_code.js'; import type { CustomerBalanceTransaction } from './customer_balance_transaction.js'; import type { SubscriptionBuilder } from './builders/subscription_builder.js'; import type { InvoiceBuilder } from './builders/invoice_builder.js'; import type Subscription from './models/subscription.js'; export interface ManagesStripeContract { stripeId: Optional extends false ? string : string | null; hasStripeId(): boolean; stripeIdOrFail(): string; } export interface HandlesTaxesContract { customerIpAddress: string | null; estimationBillingAddress: Partial; collectTaxIds: boolean; withTaxIpAddress(ipAddress: string): void; withTaxAddress(country: string, postalCode?: string, state?: string): void; automaticTaxPayload(): { enabled: boolean; }; isAutomaticTaxEnabled(): boolean; withTaxIdsCollect(): void; } export interface ManagesCustomerContract extends ManagesStripeContract { createAsStripeCustomer(params?: Stripe.CustomerCreateParams): Promise; updateStripeCustomer(params?: Stripe.CustomerUpdateParams): Promise; createOrGetStripeCustomer(params?: Stripe.CustomerCreateParams): Promise; updateOrCreateStripeCustomer(params?: Stripe.CustomerCreateParams): Promise; syncOrCreateStripeCustomer(params?: Stripe.CustomerCreateParams): Promise; asStripeCustomer(expand?: string[]): Promise; stripeName(): string | undefined; stripeEmail(): string | undefined; stripePhone(): string | undefined; stripeAddress(): Stripe.Emptyable | undefined; stripePreferredLocales(): string[]; stripeMetadata(): Record; syncStripeCustomerDetails(): Promise; discount(): Promise; findPromotionCode(code: string, params?: Stripe.PromotionCodeListParams): Promise; findActivePromotionCode(code: string, params?: Stripe.PromotionCodeListParams): Promise; balance(): Promise; rawBalance(): Promise; balanceTransaction(limit?: number, params?: Stripe.CustomerListBalanceTransactionsParams): Promise; creditBalance(amount: number, description?: string, params?: Partial): Promise; debitBalance(amount: number, description?: string, params?: Partial): Promise; applyBalance(amount: number, description?: string, params?: Partial): Promise; preferredCurrency(): string; formatAmount(amount: number): string; billingPortalUrl(returnUrl?: string, params?: Stripe.BillingPortal.SessionCreateParams): Promise; taxIds(params?: Stripe.CustomerListTaxIdsParams): Promise; findTaxId(id: string): Promise; createTaxId(type: Stripe.CustomerCreateTaxIdParams.Type, value: string): Promise; deleteTaxId(id: string): Promise; isNotTaxExempt(): Promise; isTaxExempt(): Promise; reverseChargeApplies(): Promise; } export interface ManagesPaymentMethodsContract extends ManagesCustomerContract { pmType: string | null; pmLastFour: string | null; createSetupIntent(params?: Stripe.SetupIntentCreateParams): Promise; findSetupIntent(id: string, params?: Stripe.SetupIntentRetrieveParams, options?: Stripe.RequestOptions): Promise; hasDefaultPaymentMethod(): boolean; hasPaymentMethod(type?: string): Promise; paymentMethods(type?: Stripe.PaymentMethodListParams.Type, params?: Stripe.PaymentMethodListParams): Promise; addPaymentMethod(paymentMethod: string | Stripe.PaymentMethod): Promise; deletePaymentMethod(paymentMethod: string | Stripe.PaymentMethod): Promise; defaultPaymentMethod(): Promise; updateDefaultPaymentMethod(paymentMethod: string | Stripe.PaymentMethod): Promise; updateDefaultPaymentMethodFromStripe(): Promise; deletePaymentMethods(type?: Stripe.PaymentMethodListParams.Type): Promise; findPaymentMethod(paymentMethod: string): Promise; } export interface ManagesInvoicesContract extends ManagesCustomerContract, HandlesTaxesContract { invoice(): InvoiceBuilder; upcomingInvoice(params?: Stripe.InvoiceCreatePreviewParams): Promise; findInvoice(id: string): Promise; findInvoiceOrFail(id: string): Promise; invoices(includePending?: boolean, params?: Stripe.InvoiceListParams): Promise; invoicesIncludingPending(params?: Stripe.InvoiceListParams): Promise; } export interface ManagesSubscriptionsContract { trialEndsAt: DateTime | null; subscriptions: HasMany; /** * Begin creating a new subscription. */ newSubscription(type: string, prices?: string | string[]): SubscriptionBuilder; /** * Determine if the Stripe model is on trial. */ onTrial(type?: string, price?: string): Promise; /** * Determine if the Stripe model's trial has ended. */ hasExpiredTrial(type?: string, price?: string): Promise; /** * Determine if the Stripe model is on a "generic" trial at the model level. */ onGenericTrial(): boolean; /** * Determine if the Stripe model's "generic" trial at the model level has expired. */ hasExpiredGenericTrial(): boolean; /** * Get the ending date of the trial. */ getTrialEndsAt(type?: string): Promise; /** * Determine if the Stripe model has a given subscription. */ subscribed(type?: string, price?: string): Promise; /** * Get a subscription instance by $type. */ subscription(type?: string): Promise; /** * Determine if the Stripe model is actively subscribed to one of the given products. */ subscribedToProduct(products: string[], type: string): Promise; /** * Determine if the Stripe model is actively subscribed to one of the given prices. */ subscribedToPrice(prices: string[], type: string): Promise; /** * Get the tax rates to apply to the subscription. */ taxRates(): string[]; /** * Get the tax rates to apply to individual subscription items. */ priceTaxRates(): Record; /** * Apply a coupon to the customer's subscriptions. */ applyCoupon(coupon: string, subscriptionTypes?: string | string[]): Promise; /** * Apply a promotion code to the customer's subscriptions. */ applyPromotionCode(promotionCodeId: string, subscriptionTypes?: string | string[]): Promise; } export interface PerformsChargesContract extends ManagesCustomerContract { charge(amount: number, paymentMethod: string, params: Partial): Promise; pay(amount: number, params?: Partial>): Promise; payWith(amount: number, paymentMethods: string[], params?: Partial>): Promise; createPayment(amount: number, params?: Partial): Promise; findPayment(id: string): Promise; refund(paymentIntent: string, params?: Omit): Promise; checkout(): CheckoutBuilder; checkoutCharge(amount: number, name: string, quantity?: number, productData?: Omit): CheckoutBuilder; } export interface AllowsCouponContract { couponId?: string; promotionCodeId?: string; allowPromotionCodes: boolean; withCoupon(couponId: string): this; withPromotionCode(promotionCodeId: string): this; withAllowPromotionsCodes(): this; checkoutDiscounts(): Stripe.Checkout.SessionCreateParams.Discount[] | undefined; } /** * Combined interface for a Billable model instance. * Used by wrapper classes (Invoice, Payment, Checkout, etc.) to reference * the owner without creating circular type dependencies. */ export interface BillableContract extends ManagesStripeContract, HandlesTaxesContract, ManagesCustomerContract, ManagesPaymentMethodsContract, ManagesInvoicesContract, ManagesSubscriptionsContract, PerformsChargesContract { } export type BillableModel = LucidModel & { new (...args: any[]): BillableContract; };