41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import stripe
|
|
from django.db import models
|
|
from django.urls import reverse
|
|
from django.contrib.auth.models import AbstractUser
|
|
from localflavor.us.us_states import USPS_CHOICES
|
|
|
|
|
|
class User(AbstractUser):
|
|
stripe_id = models.CharField(max_length=255, blank=True)
|
|
|
|
# Shipping address
|
|
shipping_street_address_1 = models.CharField(max_length=256, blank=True)
|
|
shipping_street_address_2 = models.CharField(max_length=256, blank=True)
|
|
shipping_city = models.CharField(max_length=256, blank=True)
|
|
shipping_state = models.CharField(
|
|
max_length=2,
|
|
choices=USPS_CHOICES,
|
|
blank=True
|
|
)
|
|
shipping_postal_code = models.CharField(max_length=20, blank=True)
|
|
|
|
@property
|
|
def has_shipping_address(self):
|
|
if (self.shipping_street_address_1 != ''
|
|
and self.shipping_street_address_2 != ''
|
|
and self.shipping_city != ''
|
|
and self.shipping_state != ''
|
|
and self.shipping_postal_code != ''):
|
|
return True
|
|
return False
|
|
|
|
def get_or_create_stripe_id(self):
|
|
if not self.stripe_id:
|
|
response = stripe.Customer.create(
|
|
name=self.first_name + ' ' + self.last_name,
|
|
email=self.email
|
|
)
|
|
self.stripe_id = response['id']
|
|
self.save()
|
|
return self.stripe_id
|