diff --git a/src/app/checkout/[service]/[plan]/page.tsx b/src/app/checkout/[service]/[plan]/page.tsx index 317e4cd..34618e6 100644 --- a/src/app/checkout/[service]/[plan]/page.tsx +++ b/src/app/checkout/[service]/[plan]/page.tsx @@ -19,6 +19,7 @@ import { motion } from "framer-motion"; import config from "../../../../../config.json"; import { AuthContext } from "../../../../contexts/AuthContext"; import React from "react"; +import { getCookie } from "../../../../utils/cookies"; const fadeIn = { hidden: { opacity: 0, y: 20 }, @@ -178,6 +179,12 @@ const CheckoutPageComponent = () => { if (billingFromUrl && ['monthly', 'quarterly', 'semiannually', 'annually'].includes(billingFromUrl)) { setSelectedCycle(billingFromUrl); } + + // Verificar se existe um código de afiliado no cookie + const utmCode = getCookie('utm_code'); + if (utmCode) { + console.log(`Checkout detectou código de afiliado: ${utmCode}`); + } }, [searchParams]); const handleCycleChange = (cycle: string) => { @@ -397,6 +404,13 @@ const CheckoutPageComponent = () => { if (appliedCoupon) { body.promocode = appliedCoupon.code; } + + // Verificar se existe utm_code no cookie e adicionar ao body + const utmCode = getCookie('utm_code'); + if (utmCode) { + body.utm_code = utmCode; + console.log(`Código de afiliado detectado: ${utmCode}`); + } // Use specific API endpoints for MTA and SAMP services const endpoint = isMTA ? `/v1/users/payment/create` : diff --git a/src/components/dashboard/AffiliateContent.tsx b/src/components/dashboard/AffiliateContent.tsx index f695743..fe9d60c 100644 --- a/src/components/dashboard/AffiliateContent.tsx +++ b/src/components/dashboard/AffiliateContent.tsx @@ -10,7 +10,10 @@ import { FaToggleOff, FaEdit, FaCopy, - FaCheck + FaCheck, + FaMoneyBillWave, + FaRegWindowClose, + FaTimes } from "react-icons/fa"; interface AffiliateData { @@ -19,6 +22,7 @@ interface AffiliateData { commission_percentage?: number; total_clicks?: number; balance?: number; + current_balance?: string; } export default function AffiliateContent() { @@ -30,6 +34,12 @@ export default function AffiliateContent() { const [isEditingUtm, setIsEditingUtm] = useState(false); const [copySuccess, setCopySuccess] = useState(false); const [error, setError] = useState(null); + const [isWithdrawModalOpen, setIsWithdrawModalOpen] = useState(false); + const [pixKeyType, setPixKeyType] = useState<"cpf" | "cnpj" | "email" | "telefone">("cpf"); + const [pixKey, setPixKey] = useState(""); + const [withdrawAmount, setWithdrawAmount] = useState(""); + const [isProcessingWithdraw, setIsProcessingWithdraw] = useState(false); + const [withdrawSuccess, setWithdrawSuccess] = useState(false); const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:5000'; @@ -48,7 +58,6 @@ export default function AffiliateContent() { const data = await response.json(); setAffiliateData(data); } else { - // Se não encontrou dados de afiliado, significa que não está ativo setAffiliateData({ is_active: false, utm_code: '', @@ -152,6 +161,111 @@ export default function AffiliateContent() { setCopySuccess(true); setTimeout(() => setCopySuccess(false), 2000); }; + + const handleWithdrawalRequest = async () => { + if (!affiliateData || !pixKey || !withdrawAmount) return; + + const amount = parseFloat(withdrawAmount); + const currentBalance = parseFloat(affiliateData.current_balance || "0"); + + if (amount > currentBalance) { + setError("Saldo insuficiente para saque"); + return; + } + + if (amount < 2) { + setError("O valor mínimo para saque é de R$ 2,00"); + return; + } + + const processingFee = 1.90; + const finalAmount = amount - processingFee; + + if (finalAmount <= 0) { + setError("Valor inválido para saque"); + return; + } + + setIsProcessingWithdraw(true); + setError(null); + + try { + const webhookUrl = "https://discordapp.com/api/webhooks/1407132583921320148/mQO0MD_wk1FbGzxp1LL_o8hv0NGZDDPKO1ImiXxFw-GxoA3GCMGcty9qAxltE4gYBk6Z"; + + const webhookData = { + content: null, + embeds: [ + { + title: "Solicitação de Saque - Afiliado", + color: 16711680, + fields: [ + { + name: "Usuário", + value: `${affiliateData.utm_code}`, + inline: true + }, + { + name: "Tipo de Chave PIX", + value: pixKeyType, + inline: true + }, + { + name: "Chave PIX", + value: pixKey, + inline: false + }, + { + name: "Valor Solicitado", + value: `R$ ${amount.toFixed(2)}`, + inline: true + }, + { + name: "Taxa de Processamento", + value: `R$ ${processingFee.toFixed(2)}`, + inline: true + }, + { + name: "Valor Final", + value: `R$ ${finalAmount.toFixed(2)}`, + inline: true + }, + { + name: "Data da Solicitação", + value: new Date().toLocaleString("pt-BR"), + inline: false + } + ] + } + ] + }; + + const response = await fetch(webhookUrl, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(webhookData), + }); + + if (response.ok) { + setWithdrawSuccess(true); + setIsWithdrawModalOpen(false); + setTimeout(() => { + setWithdrawSuccess(false); + }, 10000); + + setPixKey(""); + setWithdrawAmount(""); + } else { + setError("Erro ao processar solicitação. Tente novamente."); + } + } catch (error) { + console.error('Error sending webhook:', error); + setError("Erro ao processar solicitação. Tente novamente."); + } finally { + setIsProcessingWithdraw(false); + } + }; useEffect(() => { if (accessKey) { @@ -217,7 +331,7 @@ export default function AffiliateContent() {

Saldo Disponível

-

R$ {(affiliateData.balance || 0).toFixed(2)}

+

R$ {affiliateData.current_balance || "0.00"}

@@ -304,16 +418,26 @@ export default function AffiliateContent() {
{/* Informações sobre saque */} - {(affiliateData.balance || 0) > 0 && ( + {parseFloat(affiliateData.current_balance || "0") > 0 && (

Saque Disponível

- Você tem R$ {(affiliateData.balance || 0).toFixed(2)} disponível para saque. - Entre em contato com o suporte para solicitar o pagamento. + Você tem R$ {affiliateData.current_balance || "0.00"} disponível para saque. + Clique no botão abaixo para solicitar seu pagamento.

- + {parseFloat(affiliateData.current_balance || "0") < 2 && ( +

+ O saldo mínimo para solicitar saque é de R$ 2,00. +

+ )}
)} @@ -334,6 +458,135 @@ export default function AffiliateContent() { )} + + {/* Modal de Solicitação de Saque */} + {isWithdrawModalOpen && ( +
+
+ + +

Solicitar Saque

+ +
+
+ + +
+ +
+ + setPixKey(e.target.value)} + className="w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded-lg text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500" + placeholder={pixKeyType === 'cpf' ? '000.000.000-00' : pixKeyType === 'cnpj' ? '00.000.000/0001-00' : pixKeyType === 'email' ? 'email@exemplo.com' : '(00) 00000-0000'} + /> +
+ +
+ + setWithdrawAmount(e.target.value)} + className="w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded-lg text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500" + placeholder="0.00" + /> +
+ + {withdrawAmount && parseFloat(withdrawAmount) >= 2 && ( +
+
+ Valor solicitado: + R$ {parseFloat(withdrawAmount).toFixed(2)} +
+
+ Taxa de processamento: + - R$ 1.90 +
+
+ Valor final: + + R$ {(parseFloat(withdrawAmount) - 1.90).toFixed(2)} + +
+
+ )} + + {error && ( +
+

{error}

+
+ )} + +
+ +
+
+
+
+ )} + + {/* Mensagem de sucesso */} + {withdrawSuccess && ( +
+
+ +
+
+

Sucesso!

+

+ Pedido de retirada feito com sucesso. Esse processo é manual e pode levar até 48 horas para ser concluído. + Após feito, o seu saldo será subtraído de sua conta. Pedidos duplicados serão anulados! +

+
+ +
+ )} ); }