feat(mp): add Mercado Pago reauthorization notice and status card components

- Implemented MpReauthNotice component to notify users when reauthorization is needed.
- Created MpStatusCard component to display the current status of the Mercado Pago account.
- Added utility functions and constants for handling Mercado Pago status and messages.
- Introduced hooks for managing the connection and disconnection of Mercado Pago accounts.
- Developed a disconnect confirmation modal for user actions.
- Added tests for the new functionality and utility functions.
- Defined schemas for Mercado Pago account status and callback reasons in shared package.
This commit is contained in:
Jose Selesan
2026-10-07 12:00:38 -03:00
parent e03f510874
commit 21a4c69f38
64 changed files with 3154 additions and 425 deletions

View File

@@ -18,7 +18,7 @@ model User {
orgMemberships Member[]
orgInvitations Invitation[] @relation("InvitedBy")
waitlist WaitlistEntry[]
merchantAccount MerchantAccount?
mpAccount MpAccount?
@@map("users")
}

View File

@@ -182,22 +182,49 @@ model GroupPreRegistration {
@@map("group_pre_registrations")
}
enum PaymentProvider {
MERCADO_PAGO
STRIPE
enum MpAccountStatus {
ACTIVE
REQUIRES_REAUTH
REVOKED
}
model MerchantAccount {
id String @id @default(cuid())
userId String @unique(map: "merchant_accounts_userId_key") @map("user_id")
provider PaymentProvider
accessToken String? @map("access_token")
sandbox Boolean @default(true)
connectedAt DateTime @default(now()) @map("connected_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
// Mercado Pago account linked by a teacher through OAuth (Authorization Code + PKCE).
// Tokens are stored encrypted (AES-256-GCM); there is a single active account per
// teacher and a Mercado Pago user cannot be linked to two teachers.
model MpAccount {
id String @id @default(cuid())
ownerId String @unique(map: "mp_accounts_ownerId_key") @map("owner_id")
mpUserId String @unique(map: "mp_accounts_mpUserId_key") @map("mp_user_id")
accessTokenEnc String @map("access_token_enc")
refreshTokenEnc String @map("refresh_token_enc")
expiresAt DateTime @map("expires_at")
scope String?
liveMode Boolean @default(false) @map("live_mode")
status MpAccountStatus @default(ACTIVE)
connectedAt DateTime @default(now()) @map("connected_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade, map: "merchant_accounts_userId_fkey")
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade, map: "mp_accounts_ownerId_fkey")
@@map("merchant_accounts")
// The daily refresh job looks for ACTIVE accounts expiring within 30 days.
@@index([status, expiresAt], map: "mp_accounts_status_expiresAt_idx")
@@map("mp_accounts")
}
// Pending OAuth authorization: the `state` sent to Mercado Pago plus the PKCE
// `code_verifier`. The `state` is the primary key because consuming it (deleting
// the row) is what makes it single use.
model MpOAuthState {
state String @id
ownerId String @map("owner_id")
codeVerifier String @map("code_verifier")
// Constrained to 'onboarding' | 'settings'; decides where the callback lands.
returnTo String @map("return_to")
expiresAt DateTime @map("expires_at")
createdAt DateTime @default(now()) @map("created_at")
// Expired rows are swept on every new authorization request.
@@index([expiresAt], map: "mp_oauth_states_expiresAt_idx")
@@map("mp_oauth_states")
}