Implementacion Inicial SumUP
This commit is contained in:
+45
-1
@@ -5,10 +5,11 @@ from django.http import HttpResponse, JsonResponse
|
||||
from django.db import connections
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import logout
|
||||
from .pagos_sumup import crear_checkout
|
||||
from django import forms
|
||||
import stripe
|
||||
from .pagos_stripe import create_checkout_session
|
||||
from .models import Noticia, ClienteCategoria, ServerSelection, RecruitAFriend, DownloadClientPage, ContentCreator, RecruitReward, ClaimedReward, AccountActivation, SecurityToken, GuildRenameSettings, VoteSite, VoteLog, HomeApiPoints, UnstuckHistory, ReviveHistory, RenamePrice, CustomizePrice, ChangeRacePrice, ChangeFactionPrice, LevelUpPrice, GoldPrice, TransferPrice, Category, Item, StripeLog, LoginAttempt
|
||||
from .models import Noticia, ClienteCategoria, ServerSelection, RecruitAFriend, DownloadClientPage, ContentCreator, RecruitReward, ClaimedReward, AccountActivation, SecurityToken, GuildRenameSettings, VoteSite, VoteLog, HomeApiPoints, UnstuckHistory, ReviveHistory, RenamePrice, CustomizePrice, ChangeRacePrice, ChangeFactionPrice, LevelUpPrice, GoldPrice, TransferPrice, Category, Item, StripeLog, LoginAttempt, Pedido
|
||||
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from datetime import datetime, timedelta
|
||||
@@ -2895,3 +2896,46 @@ def novawow_players_view(request):
|
||||
'classes_data': classes_data,
|
||||
'first_realm_data': first_realm_data
|
||||
})
|
||||
|
||||
|
||||
def pagar_sumup(request):
|
||||
"""Genera un pago de prueba y lo muestra en el widget"""
|
||||
try:
|
||||
checkout_id = crear_checkout(10.00) # Pago de 10 EUR
|
||||
pedido = Pedido.objects.create(email_cliente="cliente@example.com", monto=10.00)
|
||||
return render(request, "account/pago_sumup.html", {"checkout_id": checkout_id, "pedido": pedido})
|
||||
except Exception as e:
|
||||
return render(request, "account/pago_sumup.html", {"error": str(e)})
|
||||
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def sumup_webhook(request):
|
||||
"""Recibe el webhook de SumUp y actualiza la base de datos"""
|
||||
if request.method == "POST":
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
|
||||
# Verificar si el evento es un pago exitoso
|
||||
if data.get("event_type") == "transaction.successful":
|
||||
transaction_id = data.get("data", {}).get("transaction_id")
|
||||
amount = data.get("data", {}).get("amount")
|
||||
email_cliente = data.get("data", {}).get("customer_email")
|
||||
|
||||
# Buscar el pedido y actualizarlo como pagado
|
||||
pedido = Pedido.objects.filter(email_cliente=email_cliente, monto=amount).first()
|
||||
if pedido:
|
||||
pedido.transaction_id = transaction_id
|
||||
pedido.estado = "Pagado"
|
||||
pedido.save()
|
||||
return JsonResponse({"message": "Pago actualizado"}, status=200)
|
||||
else:
|
||||
return JsonResponse({"error": "Pedido no encontrado"}, status=404)
|
||||
|
||||
return JsonResponse({"error": "Evento no reconocido"}, status=400)
|
||||
|
||||
except json.JSONDecodeError:
|
||||
return JsonResponse({"error": "JSON inválido"}, status=400)
|
||||
|
||||
return JsonResponse({"error": "Método no permitido"}, status=405)
|
||||
|
||||
Reference in New Issue
Block a user