mirror of
https://github.com/yusufipk/RepoHub.git
synced 2026-09-11 10:36:07 +00:00
feat: add Cryptomus payment service toggle
- Added CRYPTOMUS_ENABLED environment variable to control payment service availability - Created status endpoint to check service availability from frontend - Updated Header to conditionally show support button based on service status
This commit is contained in:
@@ -3,6 +3,7 @@ import { NextRequest, NextResponse } from 'next/server'
|
|||||||
const CRYPTOMUS_API_URL = 'https://api.cryptomus.com/v1/payment'
|
const CRYPTOMUS_API_URL = 'https://api.cryptomus.com/v1/payment'
|
||||||
const MERCHANT_ID = process.env.CRYPTOMUS_MERCHANT_ID || ''
|
const MERCHANT_ID = process.env.CRYPTOMUS_MERCHANT_ID || ''
|
||||||
const PAYMENT_API_KEY = process.env.CRYPTOMUS_PAYMENT_API_KEY || ''
|
const PAYMENT_API_KEY = process.env.CRYPTOMUS_PAYMENT_API_KEY || ''
|
||||||
|
const CRYPTOMUS_ENABLED = process.env.CRYPTOMUS_ENABLED !== 'false'
|
||||||
|
|
||||||
interface PaymentRequest {
|
interface PaymentRequest {
|
||||||
amount: number
|
amount: number
|
||||||
@@ -35,6 +36,13 @@ function generateSign(data: any, apiKey: string): string {
|
|||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
try {
|
try {
|
||||||
|
if (!CRYPTOMUS_ENABLED) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: 'Payment service is temporarily disabled' },
|
||||||
|
{ status: 503 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (!MERCHANT_ID || !PAYMENT_API_KEY) {
|
if (!MERCHANT_ID || !PAYMENT_API_KEY) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: 'Payment service not configured' },
|
{ error: 'Payment service not configured' },
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { NextResponse } from 'next/server'
|
||||||
|
|
||||||
|
const CRYPTOMUS_ENABLED = process.env.CRYPTOMUS_ENABLED !== 'false'
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
return NextResponse.json({
|
||||||
|
cryptomus_enabled: CRYPTOMUS_ENABLED
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { useTheme } from '@/hooks/useTheme'
|
import { useTheme } from '@/hooks/useTheme'
|
||||||
import { useLocale } from '@/contexts/LocaleContext'
|
import { useLocale } from '@/contexts/LocaleContext'
|
||||||
@@ -11,6 +11,22 @@ export function Header() {
|
|||||||
const { theme, isDark, toggleTheme } = useTheme()
|
const { theme, isDark, toggleTheme } = useTheme()
|
||||||
const { locale, toggleLocale, t } = useLocale()
|
const { locale, toggleLocale, t } = useLocale()
|
||||||
const [isSupportModalOpen, setIsSupportModalOpen] = useState(false)
|
const [isSupportModalOpen, setIsSupportModalOpen] = useState(false)
|
||||||
|
const [cryptomusEnabled, setCryptomusEnabled] = useState(true)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const checkCryptomusStatus = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/support/status')
|
||||||
|
const data = await response.json()
|
||||||
|
setCryptomusEnabled(data.cryptomus_enabled)
|
||||||
|
} catch (error) {
|
||||||
|
// Default to enabled if check fails
|
||||||
|
setCryptomusEnabled(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkCryptomusStatus()
|
||||||
|
}, [])
|
||||||
|
|
||||||
const getThemeIcon = () => {
|
const getThemeIcon = () => {
|
||||||
switch (theme) {
|
switch (theme) {
|
||||||
@@ -48,7 +64,8 @@ export function Header() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
{/* Support Button */}
|
{/* Support Button - Only show when Cryptomus is enabled */}
|
||||||
|
{cryptomusEnabled && (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
@@ -60,6 +77,7 @@ export function Header() {
|
|||||||
{t('support.title')}
|
{t('support.title')}
|
||||||
</span>
|
</span>
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Theme Toggle */}
|
{/* Theme Toggle */}
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Reference in New Issue
Block a user