chore: rename model
This commit is contained in:
+23
-23
@@ -4,68 +4,68 @@ from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.http.response import HttpResponse
|
||||
|
||||
from tpv.forms import UpdateEmailForm
|
||||
from tpv.models import PaymentTPV
|
||||
from tpv.models import PaymentTransaction
|
||||
from tpv.redsys import RedsysClient
|
||||
from tpv.utils import pay_order, validate_payment_for_order
|
||||
from tpv.utils import pay_transaction, validate_payment_for_transaction
|
||||
from tpv.signals import redsys_payment_accepted, redsys_payment_rejected
|
||||
|
||||
|
||||
def payment_accepted(request, order):
|
||||
order = get_object_or_404(PaymentTPV, hash=order)
|
||||
def payment_accepted(request, transaction):
|
||||
transaction = get_object_or_404(PaymentTransaction, hash=transaction)
|
||||
|
||||
return render(
|
||||
request,
|
||||
template_name="tpv/order_created.html",
|
||||
context={
|
||||
"order": order,
|
||||
"order": transaction,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def payment_rejected(request, order):
|
||||
order = get_object_or_404(PaymentTPV, hash=order)
|
||||
def payment_rejected(request, transaction):
|
||||
transaction = get_object_or_404(PaymentTransaction, hash=transaction)
|
||||
|
||||
return render(
|
||||
request,
|
||||
template_name="tpv/order_created.html",
|
||||
context={
|
||||
"order": order,
|
||||
"order": transaction,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def webhook(request, order):
|
||||
order = get_object_or_404(PaymentTPV, hash=order)
|
||||
def webhook(request, transaction):
|
||||
transaction = get_object_or_404(PaymentTransaction, hash=transaction)
|
||||
|
||||
try:
|
||||
amount_paid = validate_payment_for_order(request, order)
|
||||
pay_order(order, amount_paid)
|
||||
redsys_payment_accepted.send_robust(PaymentTPV.__class__, hash=order.hash)
|
||||
amount_paid = validate_payment_for_transaction(request, transaction)
|
||||
pay_transaction(transaction, amount_paid)
|
||||
redsys_payment_accepted.send_robust(PaymentTransaction.__class__, hash=transaction.hash)
|
||||
|
||||
return HttpResponse(status=200)
|
||||
except Exception as e:
|
||||
order.status = PaymentTPV.StatusChoices.ERROR
|
||||
order.observations = str(e)
|
||||
order.save()
|
||||
redsys_payment_rejected.send_robust(PaymentTPV.__class__, hash=order.hash)
|
||||
transaction.status = PaymentTransaction.StatusChoices.ERROR
|
||||
transaction.observations = str(e)
|
||||
transaction.save()
|
||||
redsys_payment_rejected.send_robust(PaymentTransaction.__class__, hash=transaction.hash)
|
||||
|
||||
return HttpResponse(status=409)
|
||||
|
||||
|
||||
def order_created(request, order):
|
||||
order = get_object_or_404(PaymentTPV, hash=order)
|
||||
def transaction_created(request, transaction):
|
||||
transaction = get_object_or_404(PaymentTransaction, hash=transaction)
|
||||
|
||||
client = RedsysClient()
|
||||
parameters = client.get_body_for_order(order)
|
||||
parameters = client.get_body_for_transaction(transaction)
|
||||
|
||||
return render(
|
||||
request,
|
||||
template_name="tpv/order_created.html",
|
||||
context={
|
||||
"form": UpdateEmailForm({"contact_email": order.contact_email}),
|
||||
"action": reverse("tpv:order_created", kwargs={"order": order.hash}),
|
||||
"order": order,
|
||||
"form": UpdateEmailForm({"contact_email": transaction.contact_email}),
|
||||
"action": reverse("tpv:order_created", kwargs={"transaction": transaction.hash}),
|
||||
"order": transaction,
|
||||
"signature_version": parameters.get("Ds_SignatureVersion"),
|
||||
"merchant_parameters": parameters.get("Ds_MerchantParameters"),
|
||||
"signature": parameters.get("Ds_Signature"),
|
||||
|
||||
Reference in New Issue
Block a user