Skip to content

Commit

Permalink
Merge pull request #22 from TEDx-SJEC/razorpay
Browse files Browse the repository at this point in the history
Razorpay
  • Loading branch information
pranavvraja authored Oct 2, 2024
2 parents c266ebe + c1ae930 commit d66fbdd
Show file tree
Hide file tree
Showing 29 changed files with 1,058 additions and 592 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
echo "TURSO_AUTH_TOKEN is set: ${{ env.TURSO_AUTH_TOKEN != '' }}"
echo "TURSO_DATABASE_URL is set: ${{ env.TURSO_DATABASE_URL != '' }}"
echo "RESEND_API_KEY" is set ${{ env.RESEND_API_KEY != '' }}
echo
env:
NEXT_PUBLIC_SITE_URL: ${{ secrets.NEXT_PUBLIC_SITE_URL }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
Expand All @@ -56,6 +57,9 @@ jobs:
TURSO_AUTH_TOKEN: ${{ secrets.TURSO_AUTH_TOKEN }}
TURSO_DATABASE_URL: ${{ secrets.TURSO_DATABASE_URL }}
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
RAZORPAY_KEY_ID: ${{ secrets.RAZORPAY_KEY_ID }}
RAZORPAY_SECRET: ${{ secrets.RAZORPAY_SECRET }}
NEXT_PUBLIC_RAZORPAY_KEY_ID: ${{ secrets.NEXT_PUBLIC_RAZORPAY_KEY_ID }}

- name: Upload build artifacts (optional)
if: always()
Expand Down
84 changes: 67 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"migrate-latest": "export $(grep -v '^#' .env | xargs) && LATEST_MIGRATION=$(find prisma/migrations/*/ -type d -name '[0-9]*_*' | sort -r | head -n 1) && turso db shell $TURSO_DB_NAME < ${LATEST_MIGRATION}migration.sql"
"migrate-latest": "export $(grep -v '^#' .env | xargs) && LATEST_MIGRATION=$(find prisma/migrations/*/ -type d -name '[0-9]*_*' | sort -r | head -n 1) && turso db shell $TURSO_DB_NAME < ${LATEST_MIGRATION}migration.sql",
"migrate-latest-w": "wsl sh -c \"export $(grep -v '^#' .env.local | xargs) && LATEST_MIGRATION=$(find prisma/migrations/*/ -type d -name '[0-9]*_*' | sort -r | head -n 1) && turso db shell $TURSO_DB_NAME < '${LATEST_MIGRATION}migration.sql'\""

},
"dependencies": {
"@hookform/resolvers": "^3.9.0",
Expand All @@ -31,13 +33,16 @@
"@react-email/components": "^0.0.25",
"@react-three/drei": "^9.114.0",
"@tanstack/react-query": "^5.56.2",
"@types/canvas-confetti": "^1.6.4",
"@types/ioredis": "^4.28.10",
"@types/lodash.debounce": "^4.0.9",
"@uploadthing/react": "^7.0.2",
"axios": "^1.7.7",
"bullmq": "^5.13.0",
"canvas-confetti": "^1.9.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"crypto": "^1.0.1",
"framer-motion": "^11.9.0",
"ioredis": "^5.4.1",
"jest": "^29.7.0",
Expand All @@ -47,11 +52,12 @@
"next-auth": "^4.24.7",
"nodemailer": "^6.9.15",
"otp-generator": "^4.0.1",
"razorpay": "^2.9.4",
"react": "^18.3.1",
"react-dom": "^18",
"react-email": "^3.0.1",
"react-hook-form": "^7.53.0",
"react-icons": "^5.3.0",
"react-hook-form": "^7.53.0",
"resend": "^4.0.0",
"sonner": "^1.5.0",
"tailwind-merge": "^2.5.2",
Expand All @@ -61,6 +67,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@types/canvas-confetti": "^1.6.4",
"@types/node": "^20",
"@types/nodemailer": "^6.4.15",
"@types/otp-generator": "^4.0.2",
Expand Down
Binary file modified prisma/dev.db
Binary file not shown.
Binary file modified prisma/dev.db-journal
Binary file not shown.
16 changes: 16 additions & 0 deletions prisma/migrations/20241001044242_payment/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- DropIndex
DROP INDEX "Form_usn_key";

-- CreateTable
CREATE TABLE "Payment" (
"signature" TEXT,
"form_id" TEXT NOT NULL,
"amount" REAL NOT NULL,
"order_creation_id" TEXT NOT NULL,
"razorpay_payment_id" TEXT NOT NULL PRIMARY KEY,
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" DATETIME NOT NULL,
"formId" TEXT,
CONSTRAINT "Payment_form_id_fkey" FOREIGN KEY ("form_id") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "Payment_formId_fkey" FOREIGN KEY ("formId") REFERENCES "Form" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
16 changes: 16 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ model User {
updated_at DateTime @updatedAt
createdReferrals Referral[] @relation("createdByUser")
usedReferrals Referral[] @relation("usedByUser")
Payment Payment[]
}

model Account {
Expand Down Expand Up @@ -88,4 +89,19 @@ model Form {
user User @relation(fields: [createdById], references: [id], onDelete: Cascade)
referral Referral? @relation(fields: [referralUsed], references: [code])
Payment Payment[]
}

model Payment {
signature String?
userId String @map("form_id")
amount Float
orderCreationId String @map("order_creation_id")
razorpayPaymentId String @id @map("razorpay_payment_id")
created_at DateTime @default(now())
updated_at DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
formId String?
Form Form? @relation(fields: [formId], references: [id])
}
5 changes: 4 additions & 1 deletion src/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ NEXT_PUBLIC_SITE_URL = ""
NEXTAUTH_SECRET = ""
SJEC_DISCOUNT_PRICE = 0
REFERAL_DISCOUNT_PRICE = 0
REGULAR_PRICE = 0
REGULAR_PRICE = 0
RAZORPAY_KEY_ID =
RAZORPAY_KEY_SECRET =
NEXT_PUBLIC_RAZORPAY_KEY_ID =
16 changes: 8 additions & 8 deletions src/app/actions/get-user-by-id.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import prisma from "@/server/db"; // Adjust the import based on your structure

export async function getUserById(userId: string) {
const user = await prisma.user.findUnique({
where: { id: userId },
select: {
id: true,
role: true, // Include any other fields you need
},
});
const user = await prisma.user.findUnique({
where: { id: userId },
select: {
id: true,
role: true, // Include any other fields you need
},
});

return user;
return user;
}
46 changes: 23 additions & 23 deletions src/app/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ import { useSession } from "next-auth/react";
const inter = Inter({ subsets: ["latin"] });

export default function RootLayout({
children,
children,
}: Readonly<{
children: React.ReactNode;
children: React.ReactNode;
}>) {
const { data: session } = useSession({
required: true,
});
if (!session) {
return <div>Unauthorized</div>;
}
const { data: session } = useSession({
required: true,
});
if (!session) {
return <div>Unauthorized</div>;
}

if (session.user.role !== "ADMIN") {
return <div>Forbidden</div>;
}
return (
<html lang="en">
<body className={inter.className}>
<Providers>
<div className="flex">
<AdminNavbar />
{children}
</div>
</Providers>
</body>
</html>
);
if (session.user.role !== "ADMIN") {
return <div>Forbidden</div>;
}
return (
<html lang="en">
<body className={inter.className}>
<Providers>
<div className="flex">
<AdminNavbar />
{children}
</div>
</Providers>
</body>
</html>
);
}
14 changes: 7 additions & 7 deletions src/app/admin/payment/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { SearchableInfiniteScrollTable } from "@/components/searchable-infinite-
import React from "react";

export default async function Payments() {
return (
<>
<div className="pt-20 flex min-h-screen w-full flex-col bg-background">
<SearchableInfiniteScrollTable />
</div>
</>
);
return (
<>
<div className="pt-20 flex min-h-screen w-full flex-col bg-background">
<SearchableInfiniteScrollTable />
</div>
</>
);
}
Loading

0 comments on commit d66fbdd

Please sign in to comment.