dcl views.py: passing cc details to create_vm_task + reformatted code
This commit is contained in:
parent
3111255673
commit
16f000c723
1 changed files with 33 additions and 15 deletions
|
@ -476,32 +476,50 @@ class OrderConfirmationView(DetailView):
|
||||||
|
|
||||||
# Make stripe charge to a customer
|
# Make stripe charge to a customer
|
||||||
stripe_utils = StripeUtils()
|
stripe_utils = StripeUtils()
|
||||||
|
card_details = stripe_utils.get_card_details(customer.stripe_id,
|
||||||
|
request.session.get(
|
||||||
|
'token'))
|
||||||
|
if not card_details.get('response_object'):
|
||||||
|
msg = card_details.get('error')
|
||||||
|
messages.add_message(self.request, messages.ERROR, msg,
|
||||||
|
extra_tags='failed_payment')
|
||||||
|
return HttpResponseRedirect(
|
||||||
|
reverse('datacenterlight:payment') + '#payment_error')
|
||||||
|
card_details_dict = card_details.get('response_object')
|
||||||
cpu = specs.get('cpu')
|
cpu = specs.get('cpu')
|
||||||
memory = specs.get('memory')
|
memory = specs.get('memory')
|
||||||
disk_size = specs.get('disk_size')
|
disk_size = specs.get('disk_size')
|
||||||
amount_to_be_charged = (cpu * 5) + (memory * 2) + (disk_size * 0.6)
|
amount_to_be_charged = (cpu * 5) + (memory * 2) + (disk_size * 0.6)
|
||||||
plan_name = "{cpu} Cores, {memory} GB RAM, {disk_size} GB SSD".format(cpu=cpu,
|
plan_name = "{cpu} Cores, {memory} GB RAM, {disk_size} GB SSD".format(
|
||||||
memory=memory,
|
cpu=cpu,
|
||||||
disk_size=disk_size)
|
memory=memory,
|
||||||
|
disk_size=disk_size)
|
||||||
|
|
||||||
stripe_plan_id = StripeUtils.get_stripe_plan_id(cpu=cpu,
|
stripe_plan_id = StripeUtils.get_stripe_plan_id(cpu=cpu,
|
||||||
ram=memory,
|
ram=memory,
|
||||||
ssd=disk_size,
|
ssd=disk_size,
|
||||||
version=1,
|
version=1,
|
||||||
app='dcl')
|
app='dcl')
|
||||||
stripe_plan = stripe_utils.get_or_create_stripe_plan(amount=amount_to_be_charged,
|
stripe_plan = stripe_utils.get_or_create_stripe_plan(
|
||||||
name=plan_name,
|
amount=amount_to_be_charged,
|
||||||
stripe_plan_id=stripe_plan_id)
|
name=plan_name,
|
||||||
subscription_result = stripe_utils.subscribe_customer_to_plan(customer.stripe_id,
|
stripe_plan_id=stripe_plan_id)
|
||||||
[{"plan": stripe_plan.get(
|
subscription_result = stripe_utils.subscribe_customer_to_plan(
|
||||||
'response_object').stripe_plan_id}])
|
customer.stripe_id,
|
||||||
response_object = subscription_result.get('response_object')
|
[{"plan": stripe_plan.get(
|
||||||
|
'response_object').stripe_plan_id}])
|
||||||
|
stripe_subscription_obj = subscription_result.get('response_object')
|
||||||
# Check if the subscription was approved and is active
|
# Check if the subscription was approved and is active
|
||||||
if response_object is None or response_object.status != 'active':
|
if stripe_subscription_obj is None or \
|
||||||
|
stripe_subscription_obj.status != 'active':
|
||||||
msg = subscription_result.get('error')
|
msg = subscription_result.get('error')
|
||||||
messages.add_message(self.request, messages.ERROR, msg, extra_tags='failed_payment')
|
messages.add_message(self.request, messages.ERROR, msg,
|
||||||
return HttpResponseRedirect(reverse('datacenterlight:payment') + '#payment_error')
|
extra_tags='failed_payment')
|
||||||
create_vm_task.delay(vm_template_id, user, specs, template, stripe_customer_id, billing_address_data,
|
return HttpResponseRedirect(
|
||||||
|
reverse('datacenterlight:payment') + '#payment_error')
|
||||||
|
create_vm_task.delay(vm_template_id, user, specs, template,
|
||||||
|
stripe_customer_id, billing_address_data,
|
||||||
billing_address_id,
|
billing_address_id,
|
||||||
response_object)
|
stripe_subscription_obj, card_details_dict)
|
||||||
request.session['order_confirmation'] = True
|
request.session['order_confirmation'] = True
|
||||||
return HttpResponseRedirect(reverse('datacenterlight:order_success'))
|
return HttpResponseRedirect(reverse('datacenterlight:order_success'))
|
||||||
|
|
Loading…
Reference in a new issue