feat: added tpv form view

This commit is contained in:
2024-09-11 15:52:33 +02:00
parent 475deeb371
commit 14d11cf0b9
3 changed files with 44 additions and 1 deletions
+20
View File
@@ -0,0 +1,20 @@
<div>
{% if order.status == 'PEN' %}
<form name="from" action="{{ redsys_target_url }}" method="POST">
{% csrf_token %}
<input type="hidden" name="Ds_SignatureVersion" value="{{ signature_version }}"/>
<input type="hidden" name="Ds_MerchantParameters" value="{{ merchant_parameters }}"/>
<input type="hidden" name="Ds_Signature" value="{{ signature }}"/>
{% if order.contact_email != '' %}
<input
class="mt-6 w-full rounded-md bg-primary-500 py-1.5 font-medium text-primary-50 hover:bg-primary-600 cursor-pointer"
type="submit" value="Ir a pagar">
{% else %}
<input
class="mt-6 w-full rounded-md bg-primary-500 py-1.5 font-medium text-primary-50 hover:bg-primary-600 cursor-pointer"
type="submit" value="Ir a pagar" disabled>
{% endif %}
</form>
{% endif %}
</div>
+2 -1
View File
@@ -1,5 +1,5 @@
from django.urls import path from django.urls import path
from tpv.views import transaction_created, webhook, payment_accepted, payment_rejected from tpv.views import transaction_created, webhook, payment_accepted, payment_rejected, payment_form
app_name = "tpv" app_name = "tpv"
@@ -9,4 +9,5 @@ urlpatterns = [
path("transaction/<str:transaction>/webhook/", webhook, name="webhook"), path("transaction/<str:transaction>/webhook/", webhook, name="webhook"),
path("transaction/<str:transaction>/ok/", payment_accepted, name="ok"), path("transaction/<str:transaction>/ok/", payment_accepted, name="ok"),
path("transaction/<str:transaction>/ko/", payment_rejected, name="ko"), path("transaction/<str:transaction>/ko/", payment_rejected, name="ko"),
path("transaction/<str:transaction>/form/", payment_form, name="payment_form"),
] ]
+22
View File
@@ -2,6 +2,7 @@ from django.urls import reverse
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render, get_object_or_404, redirect from django.shortcuts import render, get_object_or_404, redirect
from django.http.response import HttpResponse from django.http.response import HttpResponse
from django.views.generic import TemplateView
from tpv.forms import UpdateEmailForm from tpv.forms import UpdateEmailForm
from tpv.models import PaymentTransaction from tpv.models import PaymentTransaction
@@ -75,3 +76,24 @@ def transaction_created(request, transaction):
"redsys_target_url": client.get_target_url(), "redsys_target_url": client.get_target_url(),
}, },
) )
class PaymentFormView(TemplateView):
template_name = "tpv/form.html"
def get_context_data(self, transaction):
transaction = get_object_or_404(PaymentTransaction, hash=transaction)
client = RedsysClient()
parameters = client.get_body_for_transaction(transaction)
target_url = client.get_target_url()
return {
"order": transaction,
"signature_version": parameters.get("Ds_SignatureVersion"),
"merchant_parameters": parameters.get("Ds_MerchantParameters"),
"signature": parameters.get("Ds_Signature"),
"redsys_target_url": target_url,
}
payment_form = PaymentFormView.as_view()