Added missing code from the merge
This commit is contained in:
		
					parent
					
						
							
								29d36faef0
							
						
					
				
			
			
				commit
				
					
						506b5a904a
					
				
			
		
					 2 changed files with 29 additions and 14 deletions
				
			
		|  | @ -89,9 +89,9 @@ def create_vm_task(self, vm_template_id, user, specs, template, stripe_customer_ | ||||||
|             billing_address_user_form.is_valid() |             billing_address_user_form.is_valid() | ||||||
|             billing_address_user_form.save() |             billing_address_user_form.save() | ||||||
| 
 | 
 | ||||||
|         # Associate an order with a stripe payment |         # Associate an order with a stripe subscription | ||||||
|         charge_object = DictDotLookup(charge) |         charge_object = DictDotLookup(charge) | ||||||
|         order.set_stripe_charge(charge_object) |         order.set_subscription_id(charge_object) | ||||||
| 
 | 
 | ||||||
|         # If the Stripe payment succeeds, set order status approved |         # If the Stripe payment succeeds, set order status approved | ||||||
|         order.set_approved() |         order.set_approved() | ||||||
|  |  | ||||||
|  | @ -444,22 +444,37 @@ class OrderConfirmationView(DetailView): | ||||||
|         billing_address_data = request.session.get('billing_address_data') |         billing_address_data = request.session.get('billing_address_data') | ||||||
|         billing_address_id = request.session.get('billing_address') |         billing_address_id = request.session.get('billing_address') | ||||||
|         vm_template_id = template.get('id', 1) |         vm_template_id = template.get('id', 1) | ||||||
|         final_price = specs.get('price') |  | ||||||
| 
 | 
 | ||||||
|         # Make stripe charge to a customer |         # Make stripe charge to a customer | ||||||
|         stripe_utils = StripeUtils() |         stripe_utils = StripeUtils() | ||||||
|         charge_response = stripe_utils.make_charge(amount=final_price, |         cpu = specs.get('cpu') | ||||||
|                                                    customer=customer.stripe_id) |         memory = specs.get('memory') | ||||||
| 
 |         disk_size = specs.get('disk_size') | ||||||
|         # Check if the payment was approved |         amount_to_be_charged = (cpu * 5) + (memory * 2) + (disk_size * 0.6) | ||||||
|         if not charge_response.get('response_object') and not charge_response.get('paid'): |         plan_name = "{cpu} Cores, {memory} GB RAM, {disk_size} GB SSD".format(cpu=cpu, | ||||||
|             msg = charge_response.get('error') |                                                                               memory=memory, | ||||||
|             messages.add_message(self.request, messages.ERROR, msg, extra_tags='make_charge_error') |                                                                               disk_size=disk_size) | ||||||
|             return HttpResponseRedirect(reverse('datacenterlight:payment') + '#payment_error') |         stripe_plan_id = StripeUtils.get_stripe_plan_id(cpu=cpu, | ||||||
| 
 |                                                         ram=memory, | ||||||
|         charge = charge_response.get('response_object') |                                                         ssd=disk_size, | ||||||
|  |                                                         version=1, | ||||||
|  |                                                         app='dcl') | ||||||
|  |         stripe_plan = stripe_utils.get_or_create_stripe_plan(amount=amount_to_be_charged, | ||||||
|  |                                                              name=plan_name, | ||||||
|  |                                                              stripe_plan_id=stripe_plan_id) | ||||||
|  |         subscription_result = stripe_utils.subscribe_customer_to_plan(customer.stripe_id, | ||||||
|  |                                                                       [{"plan": stripe_plan.get( | ||||||
|  |                                                                           'response_object').stripe_plan_id}]) | ||||||
|  |         response_object = subscription_result.get('response_object') | ||||||
|  |         # Check if the subscription was approved and is active | ||||||
|  |         if response_object is None or response_object.status is not 'active': | ||||||
|  |             context = {} | ||||||
|  |             context.update({ | ||||||
|  |                 'paymentError': response_object.get('error') | ||||||
|  |             }) | ||||||
|  |             return render(request, self.payment_template_name, context) | ||||||
|         create_vm_task.delay(vm_template_id, user, specs, template, stripe_customer_id, billing_address_data, |         create_vm_task.delay(vm_template_id, user, specs, template, stripe_customer_id, billing_address_data, | ||||||
|                              billing_address_id, |                              billing_address_id, | ||||||
|                              charge) |                              response_object) | ||||||
|         request.session['order_confirmation'] = True |         request.session['order_confirmation'] = True | ||||||
|         return HttpResponseRedirect(reverse('datacenterlight:order_success')) |         return HttpResponseRedirect(reverse('datacenterlight:order_success')) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue