Added Hosting Order model, Created Billing Address Model , Method to create a customer using Stripe API , Created Customer Stripe profile to store for further charges , Method in order to charge an amount to a customer
This commit is contained in:
parent
f5978a7da9
commit
bf334a38d4
17 changed files with 281 additions and 42 deletions
25
membership/migrations/0004_stripecustomer.py
Normal file
25
membership/migrations/0004_stripecustomer.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.4 on 2016-04-26 04:44
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('membership', '0003_auto_20160422_1002'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='StripeCustomer',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('stripe_id', models.CharField(max_length=100, unique=True)),
|
||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
@ -8,6 +8,7 @@ from django.core.mail import send_mail
|
|||
from django.core.validators import RegexValidator
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.sites.models import Site
|
||||
from utils.stripe_utils import StripeUtils
|
||||
|
||||
REGISTRATION_MESSAGE = {'subject': "Validation mail",
|
||||
'message': 'Please validate Your account under this link http://localhost:8000/en-us/login/validate/{}',
|
||||
|
|
@ -121,6 +122,32 @@ class CustomUser(AbstractBaseUser):
|
|||
return self.is_admin
|
||||
|
||||
|
||||
class StripeCustomer(models.Model):
|
||||
user = models.OneToOneField(CustomUser)
|
||||
stripe_id = models.CharField(unique=True, max_length=100)
|
||||
|
||||
@classmethod
|
||||
def get_or_create(cls, email=None, token=None):
|
||||
"""
|
||||
Check if there is a registered stripe customer with that email
|
||||
or create a new one
|
||||
"""
|
||||
try:
|
||||
stripe_customer = cls.objects.get(user__email=email)
|
||||
return stripe_customer
|
||||
|
||||
except StripeCustomer.DoesNotExist:
|
||||
user = CustomUser.objects.get(email=email)
|
||||
|
||||
stripe_utils = StripeUtils()
|
||||
stripe_data = stripe_utils.create_customer(token, email)
|
||||
|
||||
stripe_customer = StripeCustomer.objects.\
|
||||
create(user=user, stripe_id=stripe_data.get('id'))
|
||||
|
||||
return stripe_customer
|
||||
|
||||
|
||||
class CreditCards(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
user_id = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue