From 5ec87c83ec41f12fc115e8ba0b6664701514c656 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Wed, 29 Jun 2022 00:22:49 +0530 Subject: [PATCH] feat: redirect user after successful payments for VM creation --- billing/tests.py | 5 ++++- billing/views.py | 5 ++--- infrastructure/views.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/billing/tests.py b/billing/tests.py index d5a2b74..16a6c37 100644 --- a/billing/tests.py +++ b/billing/tests.py @@ -117,7 +117,10 @@ class BillingTest(TestCase): ## payment success page; no real functionality but user is redirected here # by stripe if payment is successful resp = c.get(reverse("billing.invoice.success", args=(payment.public_ref,))) - self.assertEqual(b"success" in resp.content, True) + self.assertEqual( + resp.headers["Location"], + reverse("infra.create", args=(payment.instance_name,)), + ) ## payment failure page; no real functionality but user is redirected here # by stripe if payment is successful diff --git a/billing/views.py b/billing/views.py index 1c2de6f..d3cf5ed 100644 --- a/billing/views.py +++ b/billing/views.py @@ -23,6 +23,7 @@ from django.urls import reverse from payments import get_payment_model, RedirectNeeded, PaymentStatus from dash.models import Instance from django.db.models import Q +from infrastructure.utils import create_vm_if_not_exists def default_ctx(title: str, username: str): @@ -115,9 +116,7 @@ def payment_success(request, payment_public_id): payment = get_object_or_404( get_payment_model(), public_ref=payment_public_id, paid_by=request.user ) - return HttpResponse( - f"{payment.description} worth {payment.total}{payment.currency} paid via {payment.variant} is success" - ) + return redirect(reverse("infra.create", args=(payment.instance_name,))) @login_required diff --git a/infrastructure/views.py b/infrastructure/views.py index a55c548..a7823de 100644 --- a/infrastructure/views.py +++ b/infrastructure/views.py @@ -48,7 +48,7 @@ def create_instance(request, instance_name: str): if not payment_fullfilled(instance=instance): return redirect(reverse("billing.invoice.generate", args=(instance_name,))) - create_vm_if_not_exists() + create_vm_if_not_exists(instance=instance) return HttpResponse()