Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ STELLAR_HORIZON_URL=https://horizon-testnet.stellar.org
TREASURY_WALLET_ADDRESS=GDTREASURYADDRESSXXXXXX
SUPPORTED_ASSETS=USDC,ARS

# Database (for when implemented)
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/stellar_pay

# Redis (for when implemented)
Expand Down
6 changes: 5 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:e2e": "jest --config ./test/jest-e2e.json",
"prisma:generate": "prisma generate",
"prisma:migrate": "prisma migrate deploy"
},
"dependencies": {
"@nestjs/common": "^11.0.1",
Expand All @@ -26,6 +28,7 @@
"@nestjs/platform-express": "^11.0.1",
"@nestjs/terminus": "^11.1.1",
"@nestjs/throttler": "^6.5.0",
"@prisma/client": "^6.7.0",
"@stellar/stellar-sdk": "^14.6.1",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
Expand All @@ -49,6 +52,7 @@
"globals": "^16.0.0",
"jest": "^30.0.0",
"prettier": "^3.4.2",
"prisma": "^6.7.0",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
"ts-jest": "^29.2.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
-- CreateEnum
CREATE TYPE "KycStatus" AS ENUM ('pending', 'approved', 'rejected');

-- CreateEnum
CREATE TYPE "PaymentIntentStatus" AS ENUM ('pending', 'detected', 'confirmed', 'failed');

-- CreateTable
CREATE TABLE "merchants" (
"id" UUID NOT NULL,
"email" TEXT NOT NULL,
"password_hash" TEXT NOT NULL,
"kyc_status" "KycStatus" NOT NULL DEFAULT 'pending',
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,

CONSTRAINT "merchants_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "payment_intents" (
"id" UUID NOT NULL,
"merchant_id" UUID NOT NULL,
"amount" DECIMAL(20,2) NOT NULL,
"currency" VARCHAR(3) NOT NULL,
"status" "PaymentIntentStatus" NOT NULL DEFAULT 'pending',
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,

CONSTRAINT "payment_intents_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "treasury_assets" (
"symbol" VARCHAR(16) NOT NULL,
"total_minted" DECIMAL(30,7) NOT NULL DEFAULT 0,
"total_reserved" DECIMAL(30,7) NOT NULL DEFAULT 0,

CONSTRAINT "treasury_assets_pkey" PRIMARY KEY ("symbol")
);

-- CreateTable
CREATE TABLE "webhook_endpoints" (
"id" UUID NOT NULL,
"merchant_id" UUID NOT NULL,
"url" TEXT NOT NULL,
"secret" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,

CONSTRAINT "webhook_endpoints_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "merchants_email_key" ON "merchants"("email");

-- CreateIndex
CREATE INDEX "payment_intents_merchant_id_idx" ON "payment_intents"("merchant_id");

-- CreateIndex
CREATE INDEX "webhook_endpoints_merchant_id_idx" ON "webhook_endpoints"("merchant_id");

-- AddForeignKey
ALTER TABLE "payment_intents" ADD CONSTRAINT "payment_intents_merchant_id_fkey" FOREIGN KEY ("merchant_id") REFERENCES "merchants"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "webhook_endpoints" ADD CONSTRAINT "webhook_endpoints_merchant_id_fkey" FOREIGN KEY ("merchant_id") REFERENCES "merchants"("id") ON DELETE CASCADE ON UPDATE CASCADE;
2 changes: 2 additions & 0 deletions apps/api/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Please do not edit this file manually
provider = "postgresql"
69 changes: 69 additions & 0 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

enum KycStatus {
PENDING @map("pending")
APPROVED @map("approved")
REJECTED @map("rejected")
}

enum PaymentIntentStatus {
PENDING @map("pending")
DETECTED @map("detected")
CONFIRMED @map("confirmed")
FAILED @map("failed")
}

model Merchant {
id String @id @default(uuid()) @db.Uuid
email String @unique
passwordHash String @map("password_hash")
kycStatus KycStatus @default(PENDING) @map("kyc_status")
paymentIntents PaymentIntent[]
webhookEndpoints WebhookEndpoint[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@map("merchants")
}

model PaymentIntent {
id String @id @default(uuid()) @db.Uuid
merchantId String @map("merchant_id") @db.Uuid
merchant Merchant @relation(fields: [merchantId], references: [id], onDelete: Cascade)
amount Decimal @db.Decimal(20, 2)
currency String @db.VarChar(3)
status PaymentIntentStatus @default(PENDING)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@index([merchantId])
@@map("payment_intents")
}

model TreasuryAsset {
symbol String @id @db.VarChar(16)
totalMinted Decimal @default(0) @map("total_minted") @db.Decimal(30, 7)
totalReserved Decimal @default(0) @map("total_reserved") @db.Decimal(30, 7)

@@map("treasury_assets")
}

model WebhookEndpoint {
id String @id @default(uuid()) @db.Uuid
merchantId String @map("merchant_id") @db.Uuid
merchant Merchant @relation(fields: [merchantId], references: [id], onDelete: Cascade)
url String
secret String
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@index([merchantId])
@@map("webhook_endpoints")
}
2 changes: 2 additions & 0 deletions apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { APP_GUARD } from '@nestjs/core';
import { ThrottlerModule } from '@nestjs/throttler';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PrismaModule } from './prisma/prisma.module';
import { HealthModule } from './health/health.module';
import { TreasuryModule } from './treasury/treasury.module';
import { AuthModule } from './auth/auth.module';
Expand All @@ -11,6 +12,7 @@ import { ThrottlerRedisGuard } from './rate-limiter/guards/throttler-redis.guard

@Module({
imports: [
PrismaModule,
HealthModule,
TreasuryModule,
AuthModule,
Expand Down
9 changes: 9 additions & 0 deletions apps/api/src/prisma/prisma.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Global, Module } from '@nestjs/common';
import { PrismaService } from './prisma.service';

@Global()
@Module({
providers: [PrismaService],
exports: [PrismaService],
})
export class PrismaModule {}
13 changes: 13 additions & 0 deletions apps/api/src/prisma/prisma.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
async onModuleInit() {
await this.$connect();
}

async onModuleDestroy() {
await this.$disconnect();
}
}
Loading
Loading