diff --git a/.env.example b/.env.example index 0d9c0486..aaf811a3 100644 --- a/.env.example +++ b/.env.example @@ -18,3 +18,4 @@ REDIS_URL=redis://localhost:7379 # NEXT_PUBLIC_GTM_ID="" # NEXT_PUBLIC_CRYPTO_TO_FIAT_TRUSTED_ORIGINS="" INVOICE_PROCESSING_TTL="60" +NEXT_PUBLIC_DEFAULT_ECOMMERCE_DOMAIN=http://localhost:3001 diff --git a/drizzle/0009_slippery_penance.sql b/drizzle/0009_slippery_penance.sql new file mode 100644 index 00000000..5970f74c --- /dev/null +++ b/drizzle/0009_slippery_penance.sql @@ -0,0 +1,19 @@ +CREATE TABLE IF NOT EXISTS "easyinvoice_ecommerce_client" ( + "id" text PRIMARY KEY NOT NULL, + "externalId" text NOT NULL, + "rnClientId" text NOT NULL, + "userId" text NOT NULL, + "label" text NOT NULL, + "domain" text NOT NULL, + "feeAddress" text, + "feePercentage" text, + "created_at" timestamp DEFAULT now() +); +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "easyinvoice_ecommerce_client" ADD CONSTRAINT "easyinvoice_ecommerce_client_userId_easyinvoice_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."easyinvoice_user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +CREATE UNIQUE INDEX IF NOT EXISTS "ecommerce_client_user_id_domain_unique" ON "easyinvoice_ecommerce_client" USING btree ("userId","domain"); \ No newline at end of file diff --git a/drizzle/0010_peaceful_lionheart.sql b/drizzle/0010_peaceful_lionheart.sql new file mode 100644 index 00000000..1fbda354 --- /dev/null +++ b/drizzle/0010_peaceful_lionheart.sql @@ -0,0 +1,30 @@ +CREATE TABLE IF NOT EXISTS "easyinvoice_client_payment" ( + "id" text PRIMARY KEY NOT NULL, + "userId" text NOT NULL, + "requestId" text NOT NULL, + "ecommerceClientId" text NOT NULL, + "invoiceCurrency" text NOT NULL, + "paymentCurrency" text NOT NULL, + "txHash" text NOT NULL, + "network" text NOT NULL, + "amount" text NOT NULL, + "customerInfo" json, + "reference" text, + "origin" text, + "created_at" timestamp DEFAULT now() +); +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "easyinvoice_client_payment" ADD CONSTRAINT "easyinvoice_client_payment_userId_easyinvoice_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."easyinvoice_user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "easyinvoice_client_payment" ADD CONSTRAINT "easyinvoice_client_payment_ecommerceClientId_easyinvoice_ecommerce_client_id_fk" FOREIGN KEY ("ecommerceClientId") REFERENCES "public"."easyinvoice_ecommerce_client"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +CREATE UNIQUE INDEX IF NOT EXISTS "client_payment_request_id_tx_hash_unique" ON "easyinvoice_client_payment" USING btree ("requestId","txHash");--> statement-breakpoint +CREATE UNIQUE INDEX IF NOT EXISTS "ecommerce_client_user_id_client_id_unique" ON "easyinvoice_ecommerce_client" USING btree ("rnClientId"); \ No newline at end of file diff --git a/drizzle/meta/0009_snapshot.json b/drizzle/meta/0009_snapshot.json new file mode 100644 index 00000000..b566fd27 --- /dev/null +++ b/drizzle/meta/0009_snapshot.json @@ -0,0 +1,1068 @@ +{ + "id": "6e0a4809-52c5-406f-91d0-c7469ebdf1b2", + "prevId": "296b4b36-5687-473f-9650-cf716a005485", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.easyinvoice_ecommerce_client": { + "name": "easyinvoice_ecommerce_client", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "externalId": { + "name": "externalId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rnClientId": { + "name": "rnClientId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "feeAddress": { + "name": "feeAddress", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "feePercentage": { + "name": "feePercentage", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "ecommerce_client_user_id_domain_unique": { + "name": "ecommerce_client_user_id_domain_unique", + "columns": [ + { + "expression": "userId", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "domain", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "easyinvoice_ecommerce_client_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_ecommerce_client_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_ecommerce_client", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_invoice_me": { + "name": "easyinvoice_invoice_me", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_invoice_me_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_invoice_me_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_invoice_me", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_payment_details_payers": { + "name": "easyinvoice_payment_details_payers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "paymentDetailsId": { + "name": "paymentDetailsId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payerId": { + "name": "payerId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payment_details_status": { + "name": "payment_details_status", + "type": "payment_details_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "externalPaymentDetailId": { + "name": "externalPaymentDetailId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_payment_details_payers_paymentDetailsId_easyinvoice_payment_details_id_fk": { + "name": "easyinvoice_payment_details_payers_paymentDetailsId_easyinvoice_payment_details_id_fk", + "tableFrom": "easyinvoice_payment_details_payers", + "tableTo": "easyinvoice_payment_details", + "columnsFrom": ["paymentDetailsId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "easyinvoice_payment_details_payers_payerId_easyinvoice_user_id_fk": { + "name": "easyinvoice_payment_details_payers_payerId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_payment_details_payers", + "tableTo": "easyinvoice_user", + "columnsFrom": ["payerId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_payment_details": { + "name": "easyinvoice_payment_details", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bankName": { + "name": "bankName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "accountName": { + "name": "accountName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "accountNumber": { + "name": "accountNumber", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "routingNumber": { + "name": "routingNumber", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "account_type": { + "name": "account_type", + "type": "account_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'checking'" + }, + "sortCode": { + "name": "sortCode", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "iban": { + "name": "iban", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "swiftBic": { + "name": "swiftBic", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "documentNumber": { + "name": "documentNumber", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "documentType": { + "name": "documentType", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ribNumber": { + "name": "ribNumber", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bsbNumber": { + "name": "bsbNumber", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ncc": { + "name": "ncc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "branchCode": { + "name": "branchCode", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bankCode": { + "name": "bankCode", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ifsc": { + "name": "ifsc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "beneficiary_type": { + "name": "beneficiary_type", + "type": "beneficiary_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "dateOfBirth": { + "name": "dateOfBirth", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "addressLine1": { + "name": "addressLine1", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "addressLine2": { + "name": "addressLine2", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "city": { + "name": "city", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "postalCode": { + "name": "postalCode", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "country": { + "name": "country", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rails_type": { + "name": "rails_type", + "type": "rails_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'local'" + }, + "currency": { + "name": "currency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "businessActivity": { + "name": "businessActivity", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "nationality": { + "name": "nationality", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "gender": { + "name": "gender", + "type": "gender", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_payment_details_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_payment_details_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_payment_details", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_recurring_payment": { + "name": "easyinvoice_recurring_payment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "externalPaymentId": { + "name": "externalPaymentId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "recurring_payment_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "totalAmount": { + "name": "totalAmount", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "paymentCurrency": { + "name": "paymentCurrency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chain": { + "name": "chain", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "totalNumberOfPayments": { + "name": "totalNumberOfPayments", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "currentNumberOfPayments": { + "name": "currentNumberOfPayments", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subscriptionId": { + "name": "subscriptionId", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "payer": { + "name": "payer", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "recurrence": { + "name": "recurrence", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "recipient": { + "name": "recipient", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "payments": { + "name": "payments", + "type": "json", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_recurring_payment_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_recurring_payment_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_recurring_payment", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "easyinvoice_recurring_payment_subscriptionId_easyinvoice_subscription_plans_id_fk": { + "name": "easyinvoice_recurring_payment_subscriptionId_easyinvoice_subscription_plans_id_fk", + "tableFrom": "easyinvoice_recurring_payment", + "tableTo": "easyinvoice_subscription_plans", + "columnsFrom": ["subscriptionId"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_request": { + "name": "easyinvoice_request", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "dueDate": { + "name": "dueDate", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "issuedDate": { + "name": "issuedDate", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "clientName": { + "name": "clientName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "clientEmail": { + "name": "clientEmail", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "creatorName": { + "name": "creatorName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "creatorEmail": { + "name": "creatorEmail", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "invoiceNumber": { + "name": "invoiceNumber", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "items": { + "name": "items", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "amount": { + "name": "amount", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "invoiceCurrency": { + "name": "invoiceCurrency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "paymentCurrency": { + "name": "paymentCurrency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "request_status": { + "name": "request_status", + "type": "request_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "payee": { + "name": "payee", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "requestId": { + "name": "requestId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "paymentReference": { + "name": "paymentReference", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "originalRequestPaymentReference": { + "name": "originalRequestPaymentReference", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "originalRequestId": { + "name": "originalRequestId", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "invoicedTo": { + "name": "invoicedTo", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recurrence": { + "name": "recurrence", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "isRecurrenceStopped": { + "name": "isRecurrenceStopped", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "isCryptoToFiatAvailable": { + "name": "isCryptoToFiatAvailable", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "paymentDetailsId": { + "name": "paymentDetailsId", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_request_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_request_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_request", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "easyinvoice_request_paymentDetailsId_easyinvoice_payment_details_id_fk": { + "name": "easyinvoice_request_paymentDetailsId_easyinvoice_payment_details_id_fk", + "tableFrom": "easyinvoice_request", + "tableTo": "easyinvoice_payment_details", + "columnsFrom": ["paymentDetailsId"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_session": { + "name": "easyinvoice_session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_session_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_session_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_session", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_subscription_plans": { + "name": "easyinvoice_subscription_plans", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "trialDays": { + "name": "trialDays", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "paymentCurrency": { + "name": "paymentCurrency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chain": { + "name": "chain", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "totalNumberOfPayments": { + "name": "totalNumberOfPayments", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "frequency": { + "name": "frequency", + "type": "frequency_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "recipient": { + "name": "recipient", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_subscription_plans_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_subscription_plans_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_subscription_plans", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_user": { + "name": "easyinvoice_user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "googleId": { + "name": "googleId", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "agreement_status": { + "name": "agreement_status", + "type": "agreement_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "kyc_status": { + "name": "kyc_status", + "type": "kyc_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "isCompliant": { + "name": "isCompliant", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "easyinvoice_user_googleId_unique": { + "name": "easyinvoice_user_googleId_unique", + "nullsNotDistinct": false, + "columns": ["googleId"] + }, + "easyinvoice_user_email_unique": { + "name": "easyinvoice_user_email_unique", + "nullsNotDistinct": false, + "columns": ["email"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.account_type": { + "name": "account_type", + "schema": "public", + "values": ["checking", "savings"] + }, + "public.agreement_status": { + "name": "agreement_status", + "schema": "public", + "values": ["not_started", "pending", "completed"] + }, + "public.beneficiary_type": { + "name": "beneficiary_type", + "schema": "public", + "values": ["individual", "business"] + }, + "public.frequency_enum": { + "name": "frequency_enum", + "schema": "public", + "values": ["DAILY", "WEEKLY", "MONTHLY", "YEARLY"] + }, + "public.gender": { + "name": "gender", + "schema": "public", + "values": ["male", "female", "other", "prefer_not_to_say"] + }, + "public.kyc_status": { + "name": "kyc_status", + "schema": "public", + "values": ["not_started", "initiated", "pending", "approved"] + }, + "public.payment_details_status": { + "name": "payment_details_status", + "schema": "public", + "values": ["pending", "approved", "rejected"] + }, + "public.rails_type": { + "name": "rails_type", + "schema": "public", + "values": ["local", "swift", "wire"] + }, + "public.recurring_payment_status": { + "name": "recurring_payment_status", + "schema": "public", + "values": ["pending", "active", "paused", "completed", "cancelled"] + }, + "public.request_status": { + "name": "request_status", + "schema": "public", + "values": [ + "pending", + "paid", + "crypto_paid", + "offramp_initiated", + "offramp_failed", + "offramp_pending", + "processing", + "overdue" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/drizzle/meta/0010_snapshot.json b/drizzle/meta/0010_snapshot.json new file mode 100644 index 00000000..9c02eda3 --- /dev/null +++ b/drizzle/meta/0010_snapshot.json @@ -0,0 +1,1216 @@ +{ + "id": "9c05fd19-afb4-41b6-820f-f4bbaef48195", + "prevId": "6e0a4809-52c5-406f-91d0-c7469ebdf1b2", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.easyinvoice_client_payment": { + "name": "easyinvoice_client_payment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "requestId": { + "name": "requestId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ecommerceClientId": { + "name": "ecommerceClientId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "invoiceCurrency": { + "name": "invoiceCurrency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "paymentCurrency": { + "name": "paymentCurrency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "txHash": { + "name": "txHash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "network": { + "name": "network", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "customerInfo": { + "name": "customerInfo", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "reference": { + "name": "reference", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "origin": { + "name": "origin", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "client_payment_request_id_tx_hash_unique": { + "name": "client_payment_request_id_tx_hash_unique", + "columns": [ + { + "expression": "requestId", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "txHash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "easyinvoice_client_payment_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_client_payment_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_client_payment", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "easyinvoice_client_payment_ecommerceClientId_easyinvoice_ecommerce_client_id_fk": { + "name": "easyinvoice_client_payment_ecommerceClientId_easyinvoice_ecommerce_client_id_fk", + "tableFrom": "easyinvoice_client_payment", + "tableTo": "easyinvoice_ecommerce_client", + "columnsFrom": ["ecommerceClientId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_ecommerce_client": { + "name": "easyinvoice_ecommerce_client", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "externalId": { + "name": "externalId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rnClientId": { + "name": "rnClientId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "feeAddress": { + "name": "feeAddress", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "feePercentage": { + "name": "feePercentage", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "ecommerce_client_user_id_domain_unique": { + "name": "ecommerce_client_user_id_domain_unique", + "columns": [ + { + "expression": "userId", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "domain", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "ecommerce_client_user_id_client_id_unique": { + "name": "ecommerce_client_user_id_client_id_unique", + "columns": [ + { + "expression": "rnClientId", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "easyinvoice_ecommerce_client_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_ecommerce_client_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_ecommerce_client", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_invoice_me": { + "name": "easyinvoice_invoice_me", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_invoice_me_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_invoice_me_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_invoice_me", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_payment_details_payers": { + "name": "easyinvoice_payment_details_payers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "paymentDetailsId": { + "name": "paymentDetailsId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payerId": { + "name": "payerId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payment_details_status": { + "name": "payment_details_status", + "type": "payment_details_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "externalPaymentDetailId": { + "name": "externalPaymentDetailId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_payment_details_payers_paymentDetailsId_easyinvoice_payment_details_id_fk": { + "name": "easyinvoice_payment_details_payers_paymentDetailsId_easyinvoice_payment_details_id_fk", + "tableFrom": "easyinvoice_payment_details_payers", + "tableTo": "easyinvoice_payment_details", + "columnsFrom": ["paymentDetailsId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "easyinvoice_payment_details_payers_payerId_easyinvoice_user_id_fk": { + "name": "easyinvoice_payment_details_payers_payerId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_payment_details_payers", + "tableTo": "easyinvoice_user", + "columnsFrom": ["payerId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_payment_details": { + "name": "easyinvoice_payment_details", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bankName": { + "name": "bankName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "accountName": { + "name": "accountName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "accountNumber": { + "name": "accountNumber", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "routingNumber": { + "name": "routingNumber", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "account_type": { + "name": "account_type", + "type": "account_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'checking'" + }, + "sortCode": { + "name": "sortCode", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "iban": { + "name": "iban", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "swiftBic": { + "name": "swiftBic", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "documentNumber": { + "name": "documentNumber", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "documentType": { + "name": "documentType", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ribNumber": { + "name": "ribNumber", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bsbNumber": { + "name": "bsbNumber", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ncc": { + "name": "ncc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "branchCode": { + "name": "branchCode", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bankCode": { + "name": "bankCode", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ifsc": { + "name": "ifsc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "beneficiary_type": { + "name": "beneficiary_type", + "type": "beneficiary_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "dateOfBirth": { + "name": "dateOfBirth", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "addressLine1": { + "name": "addressLine1", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "addressLine2": { + "name": "addressLine2", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "city": { + "name": "city", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "postalCode": { + "name": "postalCode", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "country": { + "name": "country", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rails_type": { + "name": "rails_type", + "type": "rails_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'local'" + }, + "currency": { + "name": "currency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "businessActivity": { + "name": "businessActivity", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "nationality": { + "name": "nationality", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "gender": { + "name": "gender", + "type": "gender", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_payment_details_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_payment_details_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_payment_details", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_recurring_payment": { + "name": "easyinvoice_recurring_payment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "externalPaymentId": { + "name": "externalPaymentId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "recurring_payment_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "totalAmount": { + "name": "totalAmount", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "paymentCurrency": { + "name": "paymentCurrency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chain": { + "name": "chain", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "totalNumberOfPayments": { + "name": "totalNumberOfPayments", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "currentNumberOfPayments": { + "name": "currentNumberOfPayments", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subscriptionId": { + "name": "subscriptionId", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "payer": { + "name": "payer", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "recurrence": { + "name": "recurrence", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "recipient": { + "name": "recipient", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "payments": { + "name": "payments", + "type": "json", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_recurring_payment_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_recurring_payment_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_recurring_payment", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "easyinvoice_recurring_payment_subscriptionId_easyinvoice_subscription_plans_id_fk": { + "name": "easyinvoice_recurring_payment_subscriptionId_easyinvoice_subscription_plans_id_fk", + "tableFrom": "easyinvoice_recurring_payment", + "tableTo": "easyinvoice_subscription_plans", + "columnsFrom": ["subscriptionId"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_request": { + "name": "easyinvoice_request", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "dueDate": { + "name": "dueDate", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "issuedDate": { + "name": "issuedDate", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "clientName": { + "name": "clientName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "clientEmail": { + "name": "clientEmail", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "creatorName": { + "name": "creatorName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "creatorEmail": { + "name": "creatorEmail", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "invoiceNumber": { + "name": "invoiceNumber", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "items": { + "name": "items", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "amount": { + "name": "amount", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "invoiceCurrency": { + "name": "invoiceCurrency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "paymentCurrency": { + "name": "paymentCurrency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "request_status": { + "name": "request_status", + "type": "request_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "payee": { + "name": "payee", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "requestId": { + "name": "requestId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "paymentReference": { + "name": "paymentReference", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "originalRequestPaymentReference": { + "name": "originalRequestPaymentReference", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "originalRequestId": { + "name": "originalRequestId", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "invoicedTo": { + "name": "invoicedTo", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recurrence": { + "name": "recurrence", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "isRecurrenceStopped": { + "name": "isRecurrenceStopped", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "isCryptoToFiatAvailable": { + "name": "isCryptoToFiatAvailable", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "paymentDetailsId": { + "name": "paymentDetailsId", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_request_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_request_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_request", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "easyinvoice_request_paymentDetailsId_easyinvoice_payment_details_id_fk": { + "name": "easyinvoice_request_paymentDetailsId_easyinvoice_payment_details_id_fk", + "tableFrom": "easyinvoice_request", + "tableTo": "easyinvoice_payment_details", + "columnsFrom": ["paymentDetailsId"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_session": { + "name": "easyinvoice_session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_session_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_session_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_session", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_subscription_plans": { + "name": "easyinvoice_subscription_plans", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "trialDays": { + "name": "trialDays", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "paymentCurrency": { + "name": "paymentCurrency", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chain": { + "name": "chain", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "totalNumberOfPayments": { + "name": "totalNumberOfPayments", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "frequency": { + "name": "frequency", + "type": "frequency_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "recipient": { + "name": "recipient", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "easyinvoice_subscription_plans_userId_easyinvoice_user_id_fk": { + "name": "easyinvoice_subscription_plans_userId_easyinvoice_user_id_fk", + "tableFrom": "easyinvoice_subscription_plans", + "tableTo": "easyinvoice_user", + "columnsFrom": ["userId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.easyinvoice_user": { + "name": "easyinvoice_user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "googleId": { + "name": "googleId", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "agreement_status": { + "name": "agreement_status", + "type": "agreement_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "kyc_status": { + "name": "kyc_status", + "type": "kyc_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'pending'" + }, + "isCompliant": { + "name": "isCompliant", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "easyinvoice_user_googleId_unique": { + "name": "easyinvoice_user_googleId_unique", + "nullsNotDistinct": false, + "columns": ["googleId"] + }, + "easyinvoice_user_email_unique": { + "name": "easyinvoice_user_email_unique", + "nullsNotDistinct": false, + "columns": ["email"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.account_type": { + "name": "account_type", + "schema": "public", + "values": ["checking", "savings"] + }, + "public.agreement_status": { + "name": "agreement_status", + "schema": "public", + "values": ["not_started", "pending", "completed"] + }, + "public.beneficiary_type": { + "name": "beneficiary_type", + "schema": "public", + "values": ["individual", "business"] + }, + "public.frequency_enum": { + "name": "frequency_enum", + "schema": "public", + "values": ["DAILY", "WEEKLY", "MONTHLY", "YEARLY"] + }, + "public.gender": { + "name": "gender", + "schema": "public", + "values": ["male", "female", "other", "prefer_not_to_say"] + }, + "public.kyc_status": { + "name": "kyc_status", + "schema": "public", + "values": ["not_started", "initiated", "pending", "approved"] + }, + "public.payment_details_status": { + "name": "payment_details_status", + "schema": "public", + "values": ["pending", "approved", "rejected"] + }, + "public.rails_type": { + "name": "rails_type", + "schema": "public", + "values": ["local", "swift", "wire"] + }, + "public.recurring_payment_status": { + "name": "recurring_payment_status", + "schema": "public", + "values": ["pending", "active", "paused", "completed", "cancelled"] + }, + "public.request_status": { + "name": "request_status", + "schema": "public", + "values": [ + "pending", + "paid", + "crypto_paid", + "offramp_initiated", + "offramp_failed", + "offramp_pending", + "processing", + "overdue" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index f9e15e1a..06fe14ef 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -64,6 +64,20 @@ "when": 1753346217295, "tag": "0008_mysterious_celestials", "breakpoints": true + }, + { + "idx": 9, + "version": "7", + "when": 1759323380579, + "tag": "0009_slippery_penance", + "breakpoints": true + }, + { + "idx": 10, + "version": "7", + "when": 1759497538341, + "tag": "0010_peaceful_lionheart", + "breakpoints": true } ] } diff --git a/src/app/api/webhook/route.ts b/src/app/api/webhook/route.ts index d85a3406..217713ea 100644 --- a/src/app/api/webhook/route.ts +++ b/src/app/api/webhook/route.ts @@ -4,6 +4,8 @@ import { generateInvoiceNumber } from "@/lib/helpers/client"; import { getInvoiceCount } from "@/lib/helpers/invoice"; import { db } from "@/server/db"; import { + clientPaymentTable, + ecommerceClientTable, paymentDetailsPayersTable, recurringPaymentTable, type requestStatusEnum, @@ -14,6 +16,67 @@ import { and, eq, not } from "drizzle-orm"; import { NextResponse } from "next/server"; import { ulid } from "ulid"; +async function addClientPayment(webhookBody: any) { + await db.transaction(async (tx) => { + const ecommerceClient = await tx + .select() + .from(ecommerceClientTable) + .where(eq(ecommerceClientTable.rnClientId, webhookBody.clientId)) + .limit(1); + + if (!ecommerceClient.length) { + throw new ResourceNotFoundError( + `No ecommerce client found with client ID: ${webhookBody.clientId}`, + ); + } + const requiredFields = [ + "requestId", + "currency", + "paymentCurrency", + "txHash", + "network", + "amount", + ]; + + const missingFields = requiredFields.filter((field) => !webhookBody[field]); + if (missingFields.length > 0) { + throw new Error( + `Missing required webhook fields: ${missingFields.join(", ")}`, + ); + } + + const client = ecommerceClient[0]; + + const inserted = await tx + .insert(clientPaymentTable) + .values({ + id: ulid(), + userId: client.userId, + ecommerceClientId: client.id, + requestId: webhookBody.requestId, + invoiceCurrency: webhookBody.currency, + paymentCurrency: webhookBody.paymentCurrency, + txHash: webhookBody.txHash, + network: webhookBody.network, + amount: webhookBody.amount, + customerInfo: webhookBody.customerInfo || null, + reference: webhookBody.reference || null, + origin: webhookBody.origin, + }) + .onConflictDoNothing({ + target: [clientPaymentTable.requestId, clientPaymentTable.txHash], + }) + .returning({ id: clientPaymentTable.id }); + + if (!inserted.length) { + console.warn( + `Duplicate client payment detected for requestId: ${webhookBody.requestId} and txHash: ${webhookBody.txHash}`, + ); + return; + } + }); +} + /** * Updates the request status in the database */ @@ -132,6 +195,8 @@ export async function POST(req: Request) { txHash: body.txHash, requestScanUrl: body.explorer, }); + } else if (body.clientId) { + await addClientPayment(body); } else { await updateRequestStatus( requestId, diff --git a/src/app/dashboard/receipts/page.tsx b/src/app/dashboard/receipts/page.tsx new file mode 100644 index 00000000..9643ec59 --- /dev/null +++ b/src/app/dashboard/receipts/page.tsx @@ -0,0 +1,16 @@ +import { DashboardReceipts } from "@/components/dashboard/receipts"; +import { getCurrentSession } from "@/server/auth"; +import { api } from "@/trpc/server"; +import { redirect } from "next/navigation"; + +export default async function ReceiptsPage() { + const { user } = await getCurrentSession(); + + if (!user) { + redirect("/"); + } + + const clientPayments = await api.ecommerce.getAllUserReceipts.query(); + + return ; +} diff --git a/src/app/ecommerce/layout.tsx b/src/app/ecommerce/layout.tsx new file mode 100644 index 00000000..34bf16c4 --- /dev/null +++ b/src/app/ecommerce/layout.tsx @@ -0,0 +1,33 @@ +import { BackgroundWrapper } from "@/components/background-wrapper"; +import { EcommerceNavigation } from "@/components/ecommerce/ecommerce-navigation"; +import { Footer } from "@/components/footer"; +import { Header } from "@/components/header"; +import { getCurrentSession } from "@/server/auth"; +import { redirect } from "next/navigation"; + +export default async function EcommerceLayout({ + children, +}: { + children: React.ReactNode; +}) { + const { user } = await getCurrentSession(); + if (!user) redirect("/"); + + return ( + +
+
+

Ecommerce

+

+ Create and manage your ecommerce clients and view sales +

+ + {children} +
+