Rename do_create_vm to do_provisioning; and pass real_request
This commit is contained in:
parent
41e993a3d9
commit
a99924b94c
2 changed files with 21 additions and 14 deletions
|
@ -1016,11 +1016,12 @@ class OrderConfirmationView(DetailView, FormView):
|
||||||
"requires_source_action")
|
"requires_source_action")
|
||||||
msg = subscription_result.get('error')
|
msg = subscription_result.get('error')
|
||||||
return show_error(msg, self.request)
|
return show_error(msg, self.request)
|
||||||
do_create_vm(
|
do_provisioning(
|
||||||
req, user, stripe_api_cus_id,
|
req, user, stripe_api_cus_id,
|
||||||
card_details_response, stripe_subscription_obj,
|
card_details_response, stripe_subscription_obj,
|
||||||
stripe_onetime_charge, gp_details, specs, vm_template_id,
|
stripe_onetime_charge, gp_details, specs, vm_template_id,
|
||||||
template, request.session.get('billing_address_data')
|
template, request.session.get('billing_address_data'),
|
||||||
|
self.request
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
custom_user = CustomUser.objects.get(email=user.get('email'))
|
custom_user = CustomUser.objects.get(email=user.get('email'))
|
||||||
|
@ -1047,9 +1048,10 @@ class OrderConfirmationView(DetailView, FormView):
|
||||||
return JsonResponse(response)
|
return JsonResponse(response)
|
||||||
|
|
||||||
|
|
||||||
def do_create_vm(request, user, stripe_api_cus_id, card_details_response,
|
def do_provisioning(request, user, stripe_api_cus_id, card_details_response,
|
||||||
stripe_subscription_obj, stripe_onetime_charge, gp_details,
|
stripe_subscription_obj, stripe_onetime_charge, gp_details,
|
||||||
specs, vm_template_id, template, billing_address_data):
|
specs, vm_template_id, template, billing_address_data,
|
||||||
|
real_request):
|
||||||
"""
|
"""
|
||||||
:param request: a dict
|
:param request: a dict
|
||||||
{
|
{
|
||||||
|
@ -1077,6 +1079,7 @@ def do_create_vm(request, user, stripe_api_cus_id, card_details_response,
|
||||||
:param specs:
|
:param specs:
|
||||||
:param vm_template_id:
|
:param vm_template_id:
|
||||||
:param template:
|
:param template:
|
||||||
|
:param real_request:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
# Create user if the user is not logged in and if he is not already
|
# Create user if the user is not logged in and if he is not already
|
||||||
|
@ -1255,14 +1258,14 @@ def do_create_vm(request, user, stripe_api_cus_id, card_details_response,
|
||||||
'reply_to': ['info@ungleich.ch'],
|
'reply_to': ['info@ungleich.ch'],
|
||||||
}
|
}
|
||||||
send_plain_email_task.delay(email_data)
|
send_plain_email_task.delay(email_data)
|
||||||
|
redirect_url = reverse('datacenterlight:index')
|
||||||
|
if real_request:
|
||||||
|
clear_all_session_vars(real_request)
|
||||||
|
if real_request.user.is_authenticated():
|
||||||
|
redirect_url = reverse('hosting:invoices')
|
||||||
response = {
|
response = {
|
||||||
'status': True,
|
'status': True,
|
||||||
'redirect': (
|
'redirect': redirect_url,
|
||||||
reverse('hosting:invoices')
|
|
||||||
if request.user.is_authenticated()
|
|
||||||
else reverse('datacenterlight:index')
|
|
||||||
),
|
|
||||||
'msg_title': str(_('Thank you for the payment.')),
|
'msg_title': str(_('Thank you for the payment.')),
|
||||||
'msg_body': str(
|
'msg_body': str(
|
||||||
_('You will soon receive a confirmation email of the '
|
_('You will soon receive a confirmation email of the '
|
||||||
|
@ -1290,6 +1293,9 @@ def do_create_vm(request, user, stripe_api_cus_id, card_details_response,
|
||||||
vm_template_id, template, user
|
vm_template_id, template, user
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if real_request:
|
||||||
|
clear_all_session_vars(real_request)
|
||||||
|
|
||||||
|
|
||||||
def show_error(msg, request):
|
def show_error(msg, request):
|
||||||
messages.add_message(request, messages.ERROR, msg,
|
messages.add_message(request, messages.ERROR, msg,
|
||||||
|
|
|
@ -9,7 +9,7 @@ from django.http import HttpResponse
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
|
|
||||||
from datacenterlight.views import do_create_vm
|
from datacenterlight.views import do_provisioning
|
||||||
from membership.models import StripeCustomer
|
from membership.models import StripeCustomer
|
||||||
from hosting.models import IncompleteSubscriptions
|
from hosting.models import IncompleteSubscriptions
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ def handle_webhook(request):
|
||||||
logger.debug("5*******")
|
logger.debug("5*******")
|
||||||
logger.debug(template)
|
logger.debug(template)
|
||||||
logger.debug("6*******")
|
logger.debug("6*******")
|
||||||
do_create_vm(
|
do_provisioning(
|
||||||
request=request,
|
request=request,
|
||||||
user={'name': incomplete_sub.name,
|
user={'name': incomplete_sub.name,
|
||||||
'email': incomplete_sub.email},
|
'email': incomplete_sub.email},
|
||||||
|
@ -192,7 +192,8 @@ def handle_webhook(request):
|
||||||
specs=specs,
|
specs=specs,
|
||||||
vm_template_id=incomplete_sub.vm_template_id,
|
vm_template_id=incomplete_sub.vm_template_id,
|
||||||
template=template,
|
template=template,
|
||||||
billing_address_data=billing_address_data
|
billing_address_data=billing_address_data,
|
||||||
|
real_request=None
|
||||||
)
|
)
|
||||||
except (IncompleteSubscriptions.DoesNotExist,
|
except (IncompleteSubscriptions.DoesNotExist,
|
||||||
IncompleteSubscriptions.MultipleObjectsReturned) as ex:
|
IncompleteSubscriptions.MultipleObjectsReturned) as ex:
|
||||||
|
|
Loading…
Reference in a new issue