cosmic-payments
Version:
A payments library for cosmic.new. Designed to be used and deployed on cosmic.new
86 lines (85 loc) • 2.36 kB
TypeScript
export interface CosmicPrice {
price_id: string;
unitAmount: number;
currency: string;
recurring?: {
interval: 'day' | 'week' | 'month' | 'year';
intervalCount: number;
} | null;
active: boolean;
createdAt: string;
}
export interface CosmicProduct {
product_id: string;
name: string;
description?: string;
createdAt: string;
product_image_urls: string[];
product_type: 'service' | 'software' | 'physical_good';
active: boolean;
prices: CosmicPrice[];
is_subscription: boolean;
}
export interface PurchaseHistoryItem {
product_id: string;
quantity: number;
price: number;
currency: string;
timestamp: string;
}
export interface ActiveSubscription {
subscription_id: string;
subscription_status: string;
subscription_product_id: string;
subscription_quantity: number;
subscription_price: number;
subscription_currency: string;
timestamp: string;
}
export interface CreateCheckoutParams {
priceId: string;
productId: string;
quantity?: number;
allowGuestCheckout?: boolean;
successPath?: string;
cancelPath?: string;
}
export interface UseCosmicPaymentsResult {
getProducts: (filter?: 'subscription' | 'one-time' | 'all') => Promise<CosmicProduct[] | null>;
checkout: (params: CreateCheckoutParams) => Promise<void>;
openBillingPortal: () => Promise<void>;
hasAccess: (productId: string) => Promise<boolean>;
getPurchaseHistory: () => Promise<PurchaseHistoryItem[] | null>;
getActiveSubscriptions: () => Promise<ActiveSubscription[] | null>;
loading: boolean;
error: string | null;
}
export interface BillingPortalPayload {
customer_id: string;
return_url: URL;
user_id: string;
project_id: string;
is_live: boolean;
stripe_connect_id?: string;
}
export interface CheckoutLinkPayload {
project_id: string;
price_id: string;
product_id: string;
quantity: number;
success_url: string;
cancel_url: string;
parent_client_id: string;
is_live: boolean;
stripe_connect_id?: string;
user_id?: string;
}
export interface CreateCheckoutLinkBody {
actionType: string;
priceId: string;
productId: string;
quantity?: number;
allowGuestCheckout?: boolean;
successPath?: string;
cancelPath?: string;
}