diff --git a/src/features/modals/paymentModal/lib/constant.ts b/src/features/modals/paymentModal/lib/constant.ts deleted file mode 100644 index b7a68f4..0000000 --- a/src/features/modals/paymentModal/lib/constant.ts +++ /dev/null @@ -1,22 +0,0 @@ -// ─── Pricing Constants ───────────────────────────────────────────────────────── - -export const PRICING = { - SERVICE_FEE: 45_000, - CERTIFICATE_FEE: 15_000, - CURRENCY: 'UZS', - // Payme works in tiyin (1 UZS = 100 tiyin) - TIYIN_MULTIPLIER: 100, -} as const; - -// ─── Payme Config ────────────────────────────────────────────────────────────── - -export const PAYME_CONFIG = { - MERCHANT_ID: process.env.NEXT_PUBLIC_PAYME_MERCHANT_ID ?? 'your_merchant_id', - BASE_URL: 'https://checkout.paycom.uz', - // In development, point to your own backend - API_ENDPOINT: '/api/payments/payme/create', - RETURN_URL: - typeof window !== 'undefined' - ? `${window.location.origin}/payment/success` - : 'https://yourapp.uz/payment/success', -} as const; diff --git a/src/features/modals/paymentModal/lib/types.ts b/src/features/modals/paymentModal/lib/types.ts index 135ed38..9567007 100644 --- a/src/features/modals/paymentModal/lib/types.ts +++ b/src/features/modals/paymentModal/lib/types.ts @@ -7,11 +7,6 @@ export interface PaymePaymentRequest { returnUrl: string; } -export interface PaymePaymentResponse { - redirectUrl: string; - transactionId: string; -} - export type PaymentStatus = 'idle' | 'loading' | 'success' | 'error'; // ─── Component Props ─────────────────────────────────────────────────────────── @@ -29,10 +24,3 @@ export interface PaymentModalProps { onConfirmPayment: () => void; isLoading: boolean; } - -export interface PaymeButtonProps { - amount: number; - orderId: string; - onSuccess?: (response: PaymePaymentResponse) => void; - onError?: (error: Error) => void; -} diff --git a/src/features/modals/paymentModal/lib/usePayment.ts b/src/features/modals/paymentModal/lib/usePayment.ts deleted file mode 100644 index 195e3aa..0000000 --- a/src/features/modals/paymentModal/lib/usePayment.ts +++ /dev/null @@ -1,71 +0,0 @@ -'use client'; -import { useState, useCallback } from 'react'; -import { PaymentStatus, PaymePaymentResponse } from './types'; -import { - calculateTotal, - createPaymePayment, - generateOrderId, - redirectToPayme, - toTiyin, -} from './utils'; -import { PAYME_CONFIG } from './constant'; - -interface UsePaymentOptions { - hasCertificate: boolean; - onSuccess?: (response: PaymePaymentResponse) => void; - onError?: (error: Error) => void; -} - -interface UsePaymentReturn { - status: PaymentStatus; - error: string | null; - totalAmount: number; - handlePaymePayment: () => Promise; - resetError: () => void; -} - -export const usePayment = ({ - hasCertificate, - onSuccess, - onError, -}: UsePaymentOptions): UsePaymentReturn => { - const [status, setStatus] = useState('idle'); - const [error, setError] = useState(null); - - const totalAmount = calculateTotal(hasCertificate); - - const handlePaymePayment = useCallback(async () => { - setStatus('loading'); - setError(null); - - const orderId = generateOrderId(); - - try { - const response = await createPaymePayment({ - amount: toTiyin(totalAmount), - orderId, - description: `Service fee${hasCertificate ? ' + Certificate' : ''}`, - returnUrl: PAYME_CONFIG.RETURN_URL, - }); - - setStatus('success'); - onSuccess?.(response); - redirectToPayme(response.redirectUrl); - } catch (err) { - const paymentError = - err instanceof Error - ? err - : new Error('Payment failed. Please try again.'); - setStatus('error'); - setError(paymentError.message); - onError?.(paymentError); - } - }, [totalAmount, hasCertificate, onSuccess, onError]); - - const resetError = useCallback(() => { - setError(null); - setStatus('idle'); - }, []); - - return { status, error, totalAmount, handlePaymePayment, resetError }; -}; diff --git a/src/features/modals/paymentModal/lib/utils.ts b/src/features/modals/paymentModal/lib/utils.ts index 244e300..1eb56d7 100644 --- a/src/features/modals/paymentModal/lib/utils.ts +++ b/src/features/modals/paymentModal/lib/utils.ts @@ -2,14 +2,6 @@ export const formatPrice = (amount: number, currency: string): string => `${amount.toLocaleString('uz-UZ')} ${currency}`; -// ─── Order ID Generator ──────────────────────────────────────────────────────── - -export const generateOrderId = (): string => { - const timestamp = Date.now(); - const random = Math.random().toString(36).slice(2, 8).toUpperCase(); - return `ORDER-${timestamp}-${random}`; -}; - // ─── Payme API ───────────────────────────────────────────────────────────────── /** diff --git a/src/features/modals/paymentModal/ui/Paymentmodal.tsx b/src/features/modals/paymentModal/ui/Paymentmodal.tsx index 0df24e8..970e8df 100644 --- a/src/features/modals/paymentModal/ui/Paymentmodal.tsx +++ b/src/features/modals/paymentModal/ui/Paymentmodal.tsx @@ -34,38 +34,6 @@ const CloseButton: React.FC<{ onClick: () => void }> = ({ onClick }) => ( ); -// ─── Error Banner ────────────────────────────────────────────────────────────── - -// const ErrorBanner: React.FC<{ message: string; onDismiss: () => void }> = ({ -// message, -// onDismiss, -// }) => ( -//
-// -// -// -//

{message}

-// -//
-// ); - // ─── Security Badge ──────────────────────────────────────────────────────────── const SecurityBadge: React.FC<{ securityText: string }> = ({