Created custom “add order view” to admin panel, Added vm name and user email to orders list admin view , Started function to charge an user for his VM subscription from the admin panel, Created template for email after charge an user for his virtual machine plan, Handle errors creating an order in the admin panel, Now an email is sent to the user after charge him for his virtual machine plan
This commit is contained in:
parent
a846f42bf6
commit
d472d37fab
10 changed files with 649 additions and 21 deletions
|
|
@ -2,6 +2,34 @@ from django import forms
|
|||
from membership.models import CustomUser
|
||||
from django.contrib.auth import authenticate
|
||||
|
||||
from utils.stripe_utils import StripeUtils
|
||||
|
||||
from .models import HostingOrder
|
||||
|
||||
|
||||
class HostingOrderAdminForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = HostingOrder
|
||||
fields = ['vm_plan', 'customer']
|
||||
|
||||
def clean(self):
|
||||
customer = self.cleaned_data.get('customer')
|
||||
vm_plan = self.cleaned_data.get('vm_plan')
|
||||
|
||||
# Make a charge to the customer
|
||||
stripe_utils = StripeUtils()
|
||||
charge_response = stripe_utils.make_charge(customer=customer.stripe_id,
|
||||
amount=vm_plan.price)
|
||||
charge = charge_response.get('response_object')
|
||||
if not charge:
|
||||
raise forms.ValidationError(charge_response.get('error'))
|
||||
|
||||
self.cleaned_data.update({
|
||||
'charge': charge
|
||||
})
|
||||
return self.cleaned_data
|
||||
|
||||
|
||||
class HostingUserLoginForm(forms.Form):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue