feat(billing): implement billing module with Stripe and Mercado Pago integration
- Add Stripe and Mercado Pago providers for handling subscriptions. - Create billing repository and access services for managing billing records. - Implement webhook handlers for processing events from Stripe and Mercado Pago. - Add routes for checkout, canceling subscriptions, and retrieving billing status. - Introduce billing status management with appropriate state transitions. - Create tests for billing functionalities including webhook idempotency and provider resolution. - Document the billing module architecture, environment variables, and API endpoints.
This commit is contained in:
52
apps/backend/prisma/billing.prisma
Normal file
52
apps/backend/prisma/billing.prisma
Normal file
@@ -0,0 +1,52 @@
|
||||
enum BillingProvider {
|
||||
STRIPE
|
||||
MERCADOPAGO
|
||||
PAYPAL
|
||||
}
|
||||
|
||||
enum BillingStatus {
|
||||
TRIAL
|
||||
ACTIVE
|
||||
PAST_DUE
|
||||
CANCELED
|
||||
SUSPENDED
|
||||
}
|
||||
|
||||
model ComplexBilling {
|
||||
complexId String @id @map("complex_id") @db.Uuid
|
||||
status BillingStatus @default(TRIAL)
|
||||
planCode String @map("plan_code") @db.VarChar(10)
|
||||
currency String @db.VarChar(3)
|
||||
provider BillingProvider?
|
||||
providerCustomerId String? @map("provider_customer_id")
|
||||
providerSubscriptionId String? @map("provider_subscription_id")
|
||||
providerPreapprovalId String? @map("provider_preapproval_id")
|
||||
currentPeriodStart DateTime? @map("current_period_start")
|
||||
currentPeriodEnd DateTime? @map("current_period_end")
|
||||
trialEndsAt DateTime? @map("trial_ends_at")
|
||||
canceledAt DateTime? @map("canceled_at")
|
||||
suspendedAt DateTime? @map("suspended_at")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
complex Complex @relation(fields: [complexId], references: [id], onDelete: Cascade)
|
||||
events BillingEvent[]
|
||||
|
||||
@@map("complex_billings")
|
||||
}
|
||||
|
||||
model BillingEvent {
|
||||
id String @id @db.Uuid
|
||||
complexId String @map("complex_id") @db.Uuid
|
||||
eventType String @map("event_type") @db.VarChar(100)
|
||||
provider BillingProvider
|
||||
providerEventId String? @unique @map("provider_event_id")
|
||||
providerData Json? @map("provider_data")
|
||||
previousStatus BillingStatus? @map("previous_status")
|
||||
newStatus BillingStatus? @map("new_status")
|
||||
processedAt DateTime @default(now()) @map("processed_at")
|
||||
billing ComplexBilling @relation(fields: [complexId], references: [complexId])
|
||||
|
||||
@@index([provider, providerEventId])
|
||||
@@index([complexId])
|
||||
@@map("billing_events")
|
||||
}
|
||||
Reference in New Issue
Block a user