payment bug fixed

This commit is contained in:
nabijonovdavronbek619@gmail.com
2026-04-03 20:37:09 +05:00
parent 9ca13fceda
commit b32057a6af
11 changed files with 188 additions and 94 deletions

View File

@@ -62,6 +62,7 @@
"amount": "Amount", "amount": "Amount",
"result": "Result", "result": "Result",
"actions": "", "actions": "",
"state": "Payment status",
"emptyMessage": "No plagiarism checks found.", "emptyMessage": "No plagiarism checks found.",
"tryAgain": "Try again", "tryAgain": "Try again",
"view": "View", "view": "View",
@@ -121,7 +122,9 @@
"certificateId": "Certificate ID", "certificateId": "Certificate ID",
"downloadCertificate": "Download Certificate", "downloadCertificate": "Download Certificate",
"unknownError": "Unknown error", "unknownError": "Unknown error",
"words": "words" "words": "words",
"aiProbabilityText": "Probability that the text was generated with AI has been detected",
"documentNumber": "Document subject"
}, },
"Hero": { "Hero": {
"badge": "Academic Integrity Platform", "badge": "Academic Integrity Platform",
@@ -228,6 +231,7 @@
"serviceFee": "Service fee", "serviceFee": "Service fee",
"certificateLabel": "Certificate", "certificateLabel": "Certificate",
"total": "Total", "total": "Total",
"paymentRequired": "Payment not completed",
"connecting": "Connecting to Payme…", "connecting": "Connecting to Payme…",
"payButton": "Pay with Payme" "payButton": "Pay with Payme"
}, },

View File

@@ -62,6 +62,7 @@
"amount": "Сумма", "amount": "Сумма",
"result": "Результат", "result": "Результат",
"actions": "", "actions": "",
"state": "Статус оплаты",
"emptyMessage": "Проверки на плагиат не найдены.", "emptyMessage": "Проверки на плагиат не найдены.",
"tryAgain": "Попробовать снова", "tryAgain": "Попробовать снова",
"view": "Просмотр", "view": "Просмотр",
@@ -121,7 +122,9 @@
"certificateId": "ID сертификата", "certificateId": "ID сертификата",
"downloadCertificate": "Скачать сертификат", "downloadCertificate": "Скачать сертификат",
"unknownError": "Неизвестная ошибка", "unknownError": "Неизвестная ошибка",
"words": "слов" "words": "слов",
"aiProbabilityText": "Обнаружена вероятность того, что текст создан с помощью ИИ",
"documentNumber": "Тема документа"
}, },
"Hero": { "Hero": {
"badge": "Платформа академической честности", "badge": "Платформа академической честности",
@@ -228,6 +231,7 @@
"serviceFee": "Стоимость услуги", "serviceFee": "Стоимость услуги",
"certificateLabel": "Сертификат", "certificateLabel": "Сертификат",
"total": "Итого", "total": "Итого",
"paymentRequired": "Оплата не произведена",
"connecting": "Подключение к Payme…", "connecting": "Подключение к Payme…",
"payButton": "Оплатить через Payme" "payButton": "Оплатить через Payme"
}, },

View File

@@ -65,6 +65,7 @@ declare const messages: {
amount: 'Summa'; amount: 'Summa';
result: 'Natija'; result: 'Natija';
actions: ''; actions: '';
state: "To'lov holati";
emptyMessage: 'Plagiat tekshiruvlari topilmadi.'; emptyMessage: 'Plagiat tekshiruvlari topilmadi.';
tryAgain: "Qayta urinib ko'ring"; tryAgain: "Qayta urinib ko'ring";
view: "Ko'rish"; view: "Ko'rish";
@@ -125,6 +126,8 @@ declare const messages: {
downloadCertificate: 'Sertifikatni yuklab olish'; downloadCertificate: 'Sertifikatni yuklab olish';
unknownError: "Noma'lum xato"; unknownError: "Noma'lum xato";
words: "so'z"; words: "so'z";
aiProbabilityText: 'Ai yordamida yaratilganlik ehtimoli aniqlandi';
documentNumber: 'Dokument mavzusi';
}; };
Hero: { Hero: {
badge: 'Akademik halollik platformasi'; badge: 'Akademik halollik platformasi';
@@ -231,6 +234,7 @@ declare const messages: {
serviceFee: "Xizmat to'lovi"; serviceFee: "Xizmat to'lovi";
certificateLabel: 'Sertifikat'; certificateLabel: 'Sertifikat';
total: 'Jami'; total: 'Jami';
paymentRequired: "To'lov qilinmagan";
connecting: 'Paymega ulanmoqda…'; connecting: 'Paymega ulanmoqda…';
payButton: "Payme orqali to'lash"; payButton: "Payme orqali to'lash";
}; };

View File

@@ -62,6 +62,7 @@
"amount": "Summa", "amount": "Summa",
"result": "Natija", "result": "Natija",
"actions": "", "actions": "",
"state": "To'lov holati",
"emptyMessage": "Plagiat tekshiruvlari topilmadi.", "emptyMessage": "Plagiat tekshiruvlari topilmadi.",
"tryAgain": "Qayta urinib ko'ring", "tryAgain": "Qayta urinib ko'ring",
"view": "Ko'rish", "view": "Ko'rish",
@@ -121,7 +122,9 @@
"certificateId": "Sertifikat ID", "certificateId": "Sertifikat ID",
"downloadCertificate": "Sertifikatni yuklab olish", "downloadCertificate": "Sertifikatni yuklab olish",
"unknownError": "Noma'lum xato", "unknownError": "Noma'lum xato",
"words": "so'z" "words": "so'z",
"aiProbabilityText":"Ai yordamida yaratilganlik ehtimoli aniqlandi",
"documentNumber":"Dokument mavzusi"
}, },
"Hero": { "Hero": {
"badge": "Akademik halollik platformasi", "badge": "Akademik halollik platformasi",
@@ -228,6 +231,7 @@
"serviceFee": "Xizmat to'lovi", "serviceFee": "Xizmat to'lovi",
"certificateLabel": "Sertifikat", "certificateLabel": "Sertifikat",
"total": "Jami", "total": "Jami",
"paymentRequired":"To'lov qilinmagan",
"connecting": "Paymega ulanmoqda…", "connecting": "Paymega ulanmoqda…",
"payButton": "Payme orqali to'lash" "payButton": "Payme orqali to'lash"
}, },

View File

@@ -7,6 +7,7 @@ import { useParams } from 'next/navigation';
import { links } from '@/shared/request/links'; import { links } from '@/shared/request/links';
import { apiRequest } from '@/shared/request/apiRequest'; import { apiRequest } from '@/shared/request/apiRequest';
import Sertifikat from './sertifikat'; import Sertifikat from './sertifikat';
import PaymentStatus from './paidStatus';
// ── Types ──────────────────────────────────────────────────────────────────── // ── Types ────────────────────────────────────────────────────────────────────
@@ -46,6 +47,7 @@ interface Document {
text: string; text: string;
created_at: string; created_at: string;
updated_at: string; updated_at: string;
state: 'paid' | 'unpaid';
results: Result[]; results: Result[];
} }
@@ -394,6 +396,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
</div> </div>
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<PaymentStatus status={doc.state} />
{doc.certificate && <Sertifikat document_id={Number(id)} />} {doc.certificate && <Sertifikat document_id={Number(id)} />}
{doc.file && ( {doc.file && (
<a <a

View File

@@ -157,7 +157,9 @@ export function usePlagiarismForm() {
form, form,
errors, errors,
submission, submission,
senderFullName: user ? `${user?.name} ${user?.surname}` : null, senderFullName: localUser
? `${localUser?.name} ${localUser?.surname}`
: null,
isLoading, isLoading,
setTopic, setTopic,
setFile, setFile,

View File

@@ -6,7 +6,7 @@ export const TABLE_COLUMNS = [
{ key: 'senderFullName', labelKey: 'sender' }, { key: 'senderFullName', labelKey: 'sender' },
{ key: 'fileName', labelKey: 'file' }, { key: 'fileName', labelKey: 'file' },
{ key: 'date', labelKey: 'date' }, { key: 'date', labelKey: 'date' },
{ key: 'result', labelKey: 'result' }, { key: 'state', labelKey: 'state' },
{ key: 'actions', labelKey: 'actions' }, { key: 'actions', labelKey: 'actions' },
] as const; ] as const;

View File

@@ -11,6 +11,8 @@ export interface DocumentData {
created_at: string; created_at: string;
updated_at: string; updated_at: string;
results: []; results: [];
state: 'paid' | 'unpaid';
order_id: number;
} }
export interface PlagiarismCheckDetail extends DocumentData { export interface PlagiarismCheckDetail extends DocumentData {

View File

@@ -1,23 +1,68 @@
'use client'; 'use client';
import React from 'react'; import React, { useEffect, useState } from 'react';
import { useTranslations } from 'next-intl'; import { useTranslations } from 'next-intl';
import { HistoryTableRowProps } from '../lib/types'; import { HistoryTableRowProps } from '../lib/types';
import { formatDate } from '../lib/utils'; import { formatDate } from '../lib/utils';
import { ResultBadge } from './resultBadge';
import { useRouter } from '@/shared/config/i18n/navigation'; import { useRouter } from '@/shared/config/i18n/navigation';
import { useUserPlagiatStore } from '@/shared/zustand/user'; import { useUserPlagiatStore } from '@/shared/zustand/user';
import PaymentStatus from '@/widgets/detail/paidStatus';
import { PaymentModal } from '@/widgets/paymentModal/ui/Paymentmodal';
import { useMutation } from '@tanstack/react-query';
import { apiRequest } from '@/shared/request/apiRequest';
import { links } from '@/shared/request/links';
import { toast } from 'react-toastify';
export const HistoryTableRow: React.FC<HistoryTableRowProps> = ({ item }) => { export const HistoryTableRow: React.FC<HistoryTableRowProps> = ({ item }) => {
const router = useRouter(); const router = useRouter();
const t = useTranslations('HistoryPage'); const t = useTranslations('HistoryPage');
const tPay = useTranslations('Payment');
const tUnknown = useTranslations(); const tUnknown = useTranslations();
const user = useUserPlagiatStore((state) => state.user); const user = useUserPlagiatStore((state) => state.user);
const [isPaymentOpen, setIsPaymentOpen] = useState(false);
const [localUser, setLocalUser] = useState<{
id: number;
name: string;
surname: string;
} | null>(null);
const userName = user useEffect(() => {
? `${user.name} ${user.surname}` const data = localStorage.getItem('user');
if (data) {
setLocalUser(JSON.parse(data));
} else {
setLocalUser(null);
}
}, [user]);
const userName = localUser
? `${localUser.name} ${localUser.surname}`
: tUnknown('unknownUser'); : tUnknown('unknownUser');
const payment = useMutation({
mutationKey: ['payload'],
mutationFn: ({ order_id }: { order_id: number }) =>
apiRequest<{ payment_link: string }>('POST', links.payment(order_id)),
onSuccess: (res) => {
console.log('payment res: ', res);
window.open(res.data.payment_link, '_self');
//route.push(`/${document_id}`);
setIsPaymentOpen(false);
},
onError: (err) => {
const message =
err instanceof Error ? err.message : 'An unexpected error occurred.';
toast.error(message);
setIsPaymentOpen(false);
},
});
const handleSubmit = ({ document_id }: { document_id: number }) => {
payment.mutate({ order_id: document_id });
};
return ( return (
<>
<tr className="border-b border-slate-100 hover:bg-slate-50/70 transition-colors duration-100 group"> <tr className="border-b border-slate-100 hover:bg-slate-50/70 transition-colors duration-100 group">
{/* Sender */} {/* Sender */}
<td className="px-4 py-3.5"> <td className="px-4 py-3.5">
@@ -44,7 +89,10 @@ export const HistoryTableRow: React.FC<HistoryTableRowProps> = ({ item }) => {
> >
<path d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" /> <path d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg> </svg>
<span className="text-sm text-slate-600 font-mono" title={item.file}> <span
className="text-sm text-slate-600 font-mono"
title={item.file}
>
{tUnknown('file')} {tUnknown('file')}
</span> </span>
</a> </a>
@@ -57,22 +105,30 @@ export const HistoryTableRow: React.FC<HistoryTableRowProps> = ({ item }) => {
</span> </span>
</td> </td>
{/* Amount */} {/* State */}
{/* <td className="px-4 py-3.5">
<span className="text-sm font-medium text-slate-700 whitespace-nowrap tabular-nums">
{item.} UZS
</span>
</td> */}
{/* Result */}
<td className="px-4 py-3.5"> <td className="px-4 py-3.5">
<ResultBadge result={'clean'} /> <span
onClick={() => {
if (item.state === 'unpaid') {
setIsPaymentOpen(true);
}
}}
className="text-sm font-medium text-slate-700 whitespace-nowrap tabular-nums"
>
<PaymentStatus status={item.state} />
</span>
</td> </td>
{/* View Button */} {/* View Button */}
<td className="px-4 py-3.5 text-right"> <td className="px-4 py-3.5 text-right">
<button <button
onClick={() => router.push(`/${item.id}`)} onClick={() => {
if (item.state === 'paid') {
router.push(`/${item.id}`);
} else {
toast.error(tPay('paymentRequired'));
}
}}
aria-label={t('viewDetails', { sender: item.title })} aria-label={t('viewDetails', { sender: item.title })}
className=" className="
inline-flex items-center gap-1.5 px-3 py-1.5 inline-flex items-center gap-1.5 px-3 py-1.5
@@ -100,5 +156,16 @@ export const HistoryTableRow: React.FC<HistoryTableRowProps> = ({ item }) => {
</button> </button>
</td> </td>
</tr> </tr>
<PaymentModal
isOpen={isPaymentOpen}
onClose={() => setIsPaymentOpen(false)}
hasCertificate={false}
onConfirmPayment={() => {
handleSubmit({ document_id: Number(item.order_id) });
}}
isLoading={payment.isPending}
/>
</>
); );
}; };

View File

@@ -1,10 +1,17 @@
import { MenuItem } from '../lib/model'; import { MenuItem } from '../lib/model';
const SubMenuLink = ({ item }: { item: MenuItem }) => { const SubMenuLink = ({
item,
logOut,
}: {
item: MenuItem;
logOut: () => void;
}) => {
return ( return (
<a <a
className="flex flex-row gap-4 rounded-md p-3 leading-none no-underline transition-colors outline-none select-none hover:bg-muted hover:text-accent-foreground" className="flex flex-row gap-4 rounded-md p-3 leading-none no-underline transition-colors outline-none select-none hover:bg-muted hover:text-accent-foreground"
href={item.url} href={item.url}
onClick={logOut}
> >
<div className="text-foreground"> <div className="text-foreground">
{item.icon && <item.icon className="size-5 shrink-0" />} {item.icon && <item.icon className="size-5 shrink-0" />}

View File

@@ -41,6 +41,7 @@ function AuthButtons() {
localStorage.removeItem('access'); localStorage.removeItem('access');
localStorage.removeItem('refresh'); localStorage.removeItem('refresh');
localStorage.removeItem('user'); localStorage.removeItem('user');
clearUser();
}; };
console.log('Current user:', user); console.log('Current user:', user);
@@ -71,12 +72,8 @@ function AuthButtons() {
asChild asChild
key={subItem.title} key={subItem.title}
className="w-80" className="w-80"
onClick={() => {
clearTokens();
clearUser();
}}
> >
<SubMenuLink item={subItem} /> <SubMenuLink logOut={clearTokens} item={subItem} />
</NavigationMenuLink> </NavigationMenuLink>
))} ))}
</NavigationMenuContent> </NavigationMenuContent>