diff --git a/src/components/AddBalance.jsx b/src/components/AddBalance.jsx
new file mode 100644
index 0000000..32cdb25
--- /dev/null
+++ b/src/components/AddBalance.jsx
@@ -0,0 +1,360 @@
+import React, {useState, useEffect} from "react";
+import { Button } from "./ui/button";
+import { Input } from "./ui/input";
+import QRCode from "react-qr-code";
+import { Dialog, DialogContent, DialogHeader, DialogTitle} from "./ui/dialog";
+import { Card, CardContent, CardHeader, CardTitle } from "./ui/card";
+import { FileX, Copy, CheckCircle2, AlertCircle, X } from "lucide-react";
+import Loader from "./ui/loader";
+
+const PUBLIC_USER_API_URL = 'https://siliconpin.com/v1/balance/';
+// const PUBLIC_USER_API_URL = import.meta.env.PUBLIC_USER_API_URL;
+
+export default function AddBalance() {
+ const [orderData, setOrderData] = useState(null);
+ const [isLoading, setIsLoading] = useState(true);
+ const [error, setError] = useState(null);
+ const [showQRModal, setShowQRModal] = useState(false);
+ const [showHelpMessage, setShowHelpMessage] = useState(false);
+ const [upiPaymentLink, setUpiPaymentLink] = useState("");
+ const [copied, setCopied] = useState(false);
+ const [orderId, setOrderId] = useState('');
+ const [transactionId, setTransactionId] = useState('');
+ const [paymentResponse, setPaymentResponse] = useState({
+ message: '',
+ visible: false,
+ isSuccess: false
+ });
+
+ useEffect(() => {
+ const urlParams = new URLSearchParams(window.location.search);
+ const orderId = urlParams.get('orderId');
+
+ if (!orderId) {
+ setError('Order ID is missing from URL');
+ setIsLoading(false);
+ return;
+ }
+
+ setOrderId(orderId);
+ fetchOrderData(orderId);
+ }, []);
+
+ const fetchOrderData = async (orderId) => {
+ setIsLoading(true);
+ try {
+ const formData = new FormData();
+ formData.append('order_id', orderId);
+
+ const response = await fetch(`${PUBLIC_USER_API_URL}?query=get-initiated-add-balance`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type' : 'application/json'
+ },
+ body: JSON.stringify({order_id:orderId}),
+ credentials: 'include'
+ });
+
+ if (!response.ok) {
+ throw new Error(`HTTP error! status: ${response.status}`);
+ }
+
+ const data = await response.json();
+
+ if (!data.success) {
+ throw new Error(data.message || 'Failed to fetch payment details');
+ }
+
+ setOrderData(data);
+ setError(null);
+
+ // Generate UPI payment link
+ if (data.payment_data?.amount) {
+ const upiLink = generateUPILink(data.payment_data.amount, data.txn_id);
+ setUpiPaymentLink(upiLink);
+ }
+ } catch (error) {
+ setError(error.message || 'Failed to load payment details. Please try again.');
+ console.error('Error:', error);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ function generateUPILink(amount, transactionId) {
+ const merchantUPI = "7001601485@okbizaxis";
+ const merchantName = "SiliconPin";
+ const currency = "INR";
+ const transactionNote = encodeURIComponent(`Balance top-up #${transactionId}`);
+
+ return `upi://pay?pa=${merchantUPI}&pn=${encodeURIComponent(merchantName)}&am=${amount}&cu=${currency}&tn=${transactionNote}`;
+ }
+
+ const redirectToPayU = () => {
+ if (!orderData?.payment_data || !orderData.payment_url) {
+ console.error('Payment data not loaded yet');
+ alert('Payment information is not ready. Please wait.');
+ return;
+ }
+
+ // Create a form dynamically
+ const form = document.createElement('form');
+ form.method = 'POST';
+ form.action = orderData.payment_url;
+ form.style.display = 'none';
+
+ Object.entries(orderData.payment_data).forEach(([key, value]) => {
+ const input = document.createElement('input');
+ input.type = 'text';
+ input.name = key;
+ input.value = value;
+ form.appendChild(input);
+ });
+
+ document.body.appendChild(form);
+ form.submit();
+ };
+
+ const handlePayPalPayment = () => {
+ const rawInrAmount = orderData.payment_data?.amount || 0;
+ const exchangeRate = 80;
+ const convertedUSD = rawInrAmount / exchangeRate;
+ const usdAmount = Math.max(convertedUSD, 1).toFixed(2);
+ const paypalUrl = `https://www.paypal.com/paypalme/dwdconsultancy/${usdAmount}`;
+ window.open(paypalUrl, '_blank');
+ };
+
+ const handleQRPaymentClick = () => {
+ if(orderData.currency !== 'INR'){
+ return
+ }
+ if (!upiPaymentLink) {
+ alert('Payment information is not ready. Please wait.');
+ return;
+ }
+ setShowQRModal(true);
+ };
+
+ const handleCopy = () => {
+ navigator.clipboard.writeText(orderId)
+ .then(() => {
+ setCopied(true);
+ setTimeout(() => setCopied(false), 1000);
+ })
+ .catch(err => {
+ console.error('Failed to copy text: ', err);
+ });
+ };
+
+ const handleSavePayment = async () => {
+ try {
+ const response = await fetch(`${PUBLIC_USER_API_URL}?query=save-balance-payment`, {
+ method: 'POST',
+ credentials: 'include',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ orderId: orderId,
+ transactionId: transactionId
+ })
+ });
+
+ const data = await response.json();
+
+ if (data.success) {
+ setPaymentResponse({
+ message: `Payment of ₹${orderData?.payment_data?.amount} recorded. Your balance will be updated shortly.`,
+ visible: true,
+ isSuccess: true
+ });
+ } else {
+ throw new Error(data.message || 'Payment verification failed');
+ }
+ } catch (error) {
+ console.error('Error:', error);
+ setPaymentResponse({
+ message: 'Failed to verify payment. Please contact support.',
+ visible: true,
+ isSuccess: false
+ });
+ }
+ };
+
+ useEffect(() => {
+ let timer;
+ if (showQRModal) {
+ setShowHelpMessage(false);
+ timer = setTimeout(() => {
+ setShowHelpMessage(true);
+ }, 2000);
+ }
+ return () => clearTimeout(timer);
+ }, [showQRModal]);
+
+ if (isLoading) {
+ return
No payment request found. Click here to go to your profile.
+UPI QR Code Payment support only for INR currency
+ ) + } + Banking Service by DWD Consultancy Services (0% Processing Fee) + +Pay with PayU support only for INR currency
+ ) + } + + +Author: {topic.user_name}
diff --git a/src/components/Topics.jsx b/src/components/Topics.jsx
index 16d5af2..d578f85 100644
--- a/src/components/Topics.jsx
+++ b/src/components/Topics.jsx
@@ -15,7 +15,7 @@ export default function TopicCreation() {
const [pagination, setPagination] = useState({
current_page: 1,
last_page: 1,
- per_page: 10,
+ per_page: 12,
total: 0
});
diff --git a/src/components/UserProfile.tsx b/src/components/UserProfile.tsx
index b775fbe..5df5bae 100644
--- a/src/components/UserProfile.tsx
+++ b/src/components/UserProfile.tsx
@@ -15,6 +15,7 @@ import { PDFDownloadLink } from '@react-pdf/renderer';
import InvoicePDF from "../lib/InvoicePDF";
import { useIsLoggedIn } from '../lib/isLoggedIn';
import PasswordUpdateCard from './PasswordUpdateCard';
+import Index from "../pages/topic/index.astro";
interface SessionData {
[key: string]: any;
}
@@ -42,7 +43,7 @@ type PaymentData = {
};
export default function ProfilePage() {
- const { isLoggedIn, loading, sessionData } = useIsLoggedIn();
+ const { isLoggedIn, loading, sessionData, balance } = useIsLoggedIn();
const typedSessionData = sessionData as SessionData | null;
const [userData, setUserData] = useState Balance: {formattedBalance}Image Upload Test
-
-