- 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.
57 lines
1.8 KiB
SQL
57 lines
1.8 KiB
SQL
-- Mercado Pago OAuth (Authorization Code + PKCE). Replaces the simulated
|
|
-- payment setup, where a fake access token was stored in plaintext.
|
|
|
|
-- CreateEnum
|
|
CREATE TYPE "MpAccountStatus" AS ENUM ('ACTIVE', 'REQUIRES_REAUTH', 'REVOKED');
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "mp_accounts" (
|
|
"id" TEXT NOT NULL,
|
|
"owner_id" TEXT NOT NULL,
|
|
"mp_user_id" TEXT NOT NULL,
|
|
"access_token_enc" TEXT NOT NULL,
|
|
"refresh_token_enc" TEXT NOT NULL,
|
|
"expires_at" TIMESTAMP(3) NOT NULL,
|
|
"scope" TEXT,
|
|
"live_mode" BOOLEAN NOT NULL DEFAULT false,
|
|
"status" "MpAccountStatus" NOT NULL DEFAULT 'ACTIVE',
|
|
"connected_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
|
|
CONSTRAINT "mp_accounts_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "mp_oauth_states" (
|
|
"state" TEXT NOT NULL,
|
|
"owner_id" TEXT NOT NULL,
|
|
"code_verifier" TEXT NOT NULL,
|
|
"return_to" TEXT NOT NULL,
|
|
"expires_at" TIMESTAMP(3) NOT NULL,
|
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
CONSTRAINT "mp_oauth_states_pkey" PRIMARY KEY ("state")
|
|
);
|
|
|
|
-- CreateIndex
|
|
CREATE INDEX "mp_accounts_status_expiresAt_idx" ON "mp_accounts"("status", "expires_at");
|
|
|
|
-- CreateIndex
|
|
CREATE UNIQUE INDEX "mp_accounts_ownerId_key" ON "mp_accounts"("owner_id");
|
|
|
|
-- CreateIndex
|
|
CREATE UNIQUE INDEX "mp_accounts_mpUserId_key" ON "mp_accounts"("mp_user_id");
|
|
|
|
-- CreateIndex
|
|
CREATE INDEX "mp_oauth_states_expiresAt_idx" ON "mp_oauth_states"("expires_at");
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "mp_accounts" ADD CONSTRAINT "mp_accounts_ownerId_fkey" FOREIGN KEY ("owner_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- DropTable
|
|
DROP TABLE "merchant_accounts";
|
|
|
|
-- DropEnum
|
|
DROP TYPE "PaymentProvider";
|