From 89ad7e85b0854b26fcb70032e19ecd159decd1dc Mon Sep 17 00:00:00 2001 From: anishshobithps Date: Wed, 24 Apr 2024 22:03:50 +0530 Subject: [PATCH] feat: add notes to the Razorpay options --- src/data/categoryList.ts | 46 ++++++++++----------- src/helper/zodSchema.ts | 2 - src/hooks/useViewport.tsx | 49 ---------------------- src/lib/utils.ts | 86 +++++++++++++++++++++++++++++++++++---- 4 files changed, 102 insertions(+), 81 deletions(-) delete mode 100644 src/helper/zodSchema.ts delete mode 100644 src/hooks/useViewport.tsx diff --git a/src/data/categoryList.ts b/src/data/categoryList.ts index 434678d..5a10f63 100644 --- a/src/data/categoryList.ts +++ b/src/data/categoryList.ts @@ -1062,29 +1062,29 @@ const categoriesList = { }, ], }, - // "14": { - // team: false, - // name: "Seasoned-saute (ONLY FOR FACULTIES)", - // description: "", - // rules: ["RR"], - // prerequisites: ["PP"], - // costs: 250, - // thumbnail: "", - // startTime: "2024-05-12 10:00", - // endTime: "2024-05-12 18:00", - // facultyCoordinators: [ - // { - // name: "Michael Johnson", - // phone: "+1122334455", - // }, - // ], - // studentCoordinators: [ - // { - // name: "Emily Brown", - // phone: "+5566778899", - // }, - // ], - // }, + "14": { + team: false, + name: "Seasoned-saute (ONLY FOR FACULTIES)", + description: "", + rules: ["RR"], + prerequisites: ["PP"], + costs: 1, + thumbnail: "", + startTime: "2024-05-12 10:00", + endTime: "2024-05-12 18:00", + facultyCoordinators: [ + { + name: "Michael Johnson", + phone: "+1122334455", + }, + ], + studentCoordinators: [ + { + name: "Emily Brown", + phone: "+5566778899", + }, + ], + }, // "14": { // name: ". Seasoned-saute (ONLY FOR FACULTIES)", // description: "", diff --git a/src/helper/zodSchema.ts b/src/helper/zodSchema.ts deleted file mode 100644 index 139597f..0000000 --- a/src/helper/zodSchema.ts +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/src/hooks/useViewport.tsx b/src/hooks/useViewport.tsx deleted file mode 100644 index f4def9b..0000000 --- a/src/hooks/useViewport.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { useEffect, useRef, useState } from "react"; - -export const isClient = typeof document !== "undefined"; - -const CALL_THRESHOLD_MS = 0; - -export const useViewportSize = ( - { callTreshhold } = { callTreshhold: CALL_THRESHOLD_MS } -) => { - const resizeTimeout = useRef(null); - const [windowSize, setWindowSize] = useState<{ - width: number; - height: number; - aspect: number; - }>({ - width: isClient ? window.innerWidth : 0, - height: isClient ? window.innerHeight : 0, - aspect: isClient ? window.innerWidth / window.innerHeight : 0, - }); - - useEffect(() => { - const handleResize = () => { - if (resizeTimeout.current) { - clearTimeout(resizeTimeout.current); - } - resizeTimeout.current = setTimeout(() => { - setWindowSize({ - width: window.innerWidth, - height: window.innerHeight, - aspect: window.innerWidth / window.innerHeight, - }); - }, callTreshhold); - }; - - window.addEventListener("resize", handleResize, { passive: true }); - - handleResize(); - - return () => { - window.removeEventListener("resize", handleResize); - - if (resizeTimeout.current) { - clearTimeout(resizeTimeout.current); - } - }; - }, [callTreshhold]); - - return windowSize; -}; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 3092652..6755dab 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -36,6 +36,71 @@ export interface makePaymentProps { }; } +interface RazorpaySuccesshandlerArgs { + razorpay_signature: string; + razorpay_order_id: string; + razorpay_payment_id: string; +} + +export interface RazorpayOptions { + key: string; + amount: number; + currency: string; + name: string; + description?: string; + image?: string; + order_id: string; + handler?: (args: RazorpaySuccesshandlerArgs) => void; + prefill?: { + name?: string; + email?: string; + contact?: string; + method?: "card" | "netbanking" | "wallet" | "emi" | "upi"; + }; + notes?: {}; + theme?: { + hide_topbar?: boolean; + color?: string; + backdrop_color?: string; + }; + modal?: { + backdropclose?: boolean; + escape?: boolean; + handleback?: boolean; + confirm_close?: boolean; + ondismiss?: () => void; + animation?: boolean; + }; + subscription_id?: string; + subscription_card_change?: boolean; + recurring?: boolean; + callback_url?: string; + redirect?: boolean; + customer_id?: string; + timeout?: number; + remember_customer?: boolean; + readonly?: { + contact?: boolean; + email?: boolean; + name?: boolean; + }; + hidden?: { + contact?: boolean; + email?: boolean; + }; + send_sms_hash?: boolean; + allow_rotation?: boolean; + retry?: { + enabled?: boolean; + max_count?: boolean; + }; + config?: { + display: { + language: "en" | "ben" | "hi" | "mar" | "guj" | "tam" | "tel"; + }; + }; +} + export const makePayment = async ({ productId = null, productName, @@ -49,11 +114,11 @@ export const makePayment = async ({ headers: { "Content-Type": "application/json", // Assuming the API expects JSON }, - body: JSON.stringify({ amount, prefillData }), + body: JSON.stringify({ amount, prefillData }), }); const { orderId } = await response.json(); - const options = { - key: key, + const options: RazorpayOptions = { + key: key!, name: productName, image: `${tiaraAssetsPrefix}/t24.png`, currency: "INR", @@ -65,7 +130,14 @@ export const makePayment = async ({ email: prefillData.email, contact: prefillData.contact, }, - handler: async function (response: any) { + notes: { + customerName: prefillData.name, + customerEmail: prefillData.email, + customerContact: prefillData.contact, + college: prefillData.college, + events: prefillData.events.join(", "), + }, + handler: async function (response) { const data = { orderCreationId: orderId, razorpayPaymentId: response.razorpay_payment_id, @@ -74,7 +146,7 @@ export const makePayment = async ({ college: prefillData.college, events: prefillData.events, teams: prefillData.teams, - phone:prefillData.contact, + phone: prefillData.contact, }; const result = await fetch("/api/razorpay/verify", { @@ -85,13 +157,13 @@ export const makePayment = async ({ const res = await result.json(); if (res.isOk) { toast({ - title: "Payment successful", + title: "✅ Payment successful", description: "Your payment was successful", }); window.location.href = "/"; } else { toast({ - title: "Payment failed", + title: "❌ Payment failed", description: "Please try again. Contact support for help. " + res.error, variant: "destructive",