quantictech-subscription-components
Version:
Biblioteca de componentes reutilizáveis para sistema de assinatura com Stripe - Arquitetura Service-to-Service
178 lines (177 loc) • 3.97 kB
TypeScript
export interface Subscription {
_id: string;
id?: string;
userId: string;
planId: {
_id: string;
name: string;
description: string;
interval: string;
price: number;
currency: string;
features?: string[];
};
status: 'active' | 'cancelled' | 'expired' | 'pending' | 'authorized';
paymentMethod: string;
startDate: string;
endDate: string;
customerInfo?: {
email: string;
firstName: string;
lastName: string;
document: string;
documentType: string;
};
cardDetails?: {
lastFourDigits: string;
brand: string;
};
paymentUrl?: string;
auto_recurring?: {
frequency: number;
frequency_type: string;
transaction_amount: number;
currency_id: string;
};
stripeSubscriptionId?: string;
cancelAt?: Date;
canceledAt?: Date;
createdAt?: string;
currentPeriodEnd?: string;
}
export interface StripeSubscriptionData {
id: string;
status: string;
start_date?: number;
created?: number;
current_period_end?: number;
cancel_at?: number;
canceled_at?: number;
currency?: string;
plan?: {
id: string;
nickname?: string;
interval?: string;
amount?: number;
};
items?: {
data: Array<{
price: {
id: string;
nickname?: string;
unit_amount?: number;
recurring?: {
interval?: string;
};
};
}>;
};
metadata?: {
userId?: string;
customerEmail?: string;
customerName?: string;
cpf?: string;
};
}
export interface Payment {
_id: string;
id?: string;
userId: string;
planId: string;
subscriptionId: string;
amount: number;
currency: string;
status: 'pending' | 'approved' | 'rejected' | 'authorized';
paymentMethod: string;
createdAt: string;
transactionId?: string;
paymentGateway?: string;
paymentUrl?: string;
}
export interface SubscriptionSummaryProps {
showDetailedHistory?: boolean;
onSubscriptionChange?: () => void;
}
export interface SubscriptionButtonProps {
planId: string;
disabled?: boolean;
loading?: boolean;
onClick?: () => void;
}
export interface PaymentFormProps {
onSuccess?: (subscription: Subscription) => void;
onError?: (error: string) => void;
}
export interface StripeConfig {
publicKey: string;
secretKey?: string;
}
export interface ApiResponse<T> {
success: boolean;
data: T;
message?: string;
error?: string;
}
export interface WebhookEvent {
id: string;
type: string;
data: {
object: unknown;
};
created: number;
}
export interface CreateSubscriptionData {
planId: string;
customerData: {
email: string;
name: string;
cpf?: string;
};
successUrl?: string;
cancelUrl?: string;
}
export interface CreatePaymentIntentData {
planId: string;
customerData: {
email: string;
name: string;
cpf?: string;
};
}
export interface CreateCheckoutData {
planId: string;
successUrl: string;
cancelUrl: string;
customerEmail?: string;
}
export interface SubscriptionResponse {
id: string;
status: string;
url?: string;
clientSecret?: string;
}
export interface PaymentIntentResponse {
id: string;
clientSecret: string;
status: string;
}
export interface CheckoutResponse {
id: string;
url: string;
}
export interface StripeStatusResponse {
success: boolean;
needsSync?: boolean;
wasSynced?: boolean;
subscription?: StripeSubscriptionData;
message?: string;
error?: string;
}
export interface ApiError {
response?: {
data?: {
error?: string;
};
};
message?: string;
}