diff --git a/src/components/mika/PaymentIssueBanner.tsx b/src/components/mika/PaymentIssueBanner.tsx new file mode 100644 index 0000000..bd055cc --- /dev/null +++ b/src/components/mika/PaymentIssueBanner.tsx @@ -0,0 +1,94 @@ +"use client"; + +import { useState } from "react"; +import { AlertTriangle, ExternalLink, Loader2 } from "lucide-react"; +import { toast } from "sonner"; +import { supabase } from "@/integrations/supabase/client"; +import { useSubscription } from "@/hooks/use-profile"; +import { Button } from "@/components/ui/button"; + +/** + * Persistent banner shown at the top of the dashboard when the user's + * subscription status indicates a payment problem (past_due / unpaid). + * + * Provides a one-click action to open the Paddle customer portal so the + * user can update their payment method. + */ +export function PaymentIssueBanner() { + const { data: subscription } = useSubscription(); + const [loading, setLoading] = useState(false); + + const status = subscription?.status; + const showBanner = status === "past_due" || status === "unpaid"; + + if (!showBanner) return null; + + const isUnpaid = status === "unpaid"; + + const openPortal = async () => { + setLoading(true); + try { + const { data, error } = await supabase.functions.invoke("create-portal-session"); + if (error || !data?.url) { + toast.error("Não foi possível abrir o portal. Tente novamente."); + return; + } + window.open(data.url, "_blank", "noopener,noreferrer"); + } finally { + setLoading(false); + } + }; + + return ( +
+
+
+ +
+

+ {isUnpaid + ? "Sua assinatura está sem pagamento" + : "Pagamento pendente na sua assinatura"} +

+

+ {isUnpaid + ? "Regularize o pagamento para reativar o acesso completo aos recursos." + : "Atualize seu método de pagamento para evitar a suspensão do serviço."} +

+
+
+ +
+
+ ); +}