forked from uncloud/uncloud
implement credit card listing
This commit is contained in:
parent
e2c4a19049
commit
e225bf1cc0
12 changed files with 183 additions and 63 deletions
|
|
@ -17,7 +17,6 @@ from django.utils import timezone
|
|||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||
from django.conf import settings
|
||||
|
||||
import uncloud_pay.stripe
|
||||
from uncloud import AMOUNT_DECIMALS, AMOUNT_MAX_DIGITS
|
||||
from uncloud.models import UncloudAddress
|
||||
|
||||
|
|
@ -92,6 +91,21 @@ class StripeCustomer(models.Model):
|
|||
def __str__(self):
|
||||
return self.owner.username
|
||||
|
||||
|
||||
class StripeCreditCard(models.Model):
|
||||
owner = models.OneToOneField( get_user_model(),
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
card_name = models.CharField(null=False, max_length=128, default="My credit card")
|
||||
card_id = models.CharField(null=False, max_length=32)
|
||||
last4 = models.CharField(null=False, max_length=4)
|
||||
brand = models.CharField(null=False, max_length=64)
|
||||
expiry_date = models.DateField(null=False)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.card_name}: {self.brand} {self.last4} ({self.expiry_date})"
|
||||
|
||||
|
||||
###
|
||||
# Payments and Payment Methods.
|
||||
|
||||
|
|
@ -148,14 +162,14 @@ class PaymentMethod(models.Model):
|
|||
stripe_payment_method_id = models.CharField(max_length=32, blank=True, null=True)
|
||||
stripe_setup_intent_id = models.CharField(max_length=32, blank=True, null=True)
|
||||
|
||||
@property
|
||||
def stripe_card_last4(self):
|
||||
if self.source == 'stripe' and self.active:
|
||||
payment_method = uncloud_pay.stripe.get_payment_method(
|
||||
self.stripe_payment_method_id)
|
||||
return payment_method.card.last4
|
||||
else:
|
||||
return None
|
||||
# @property
|
||||
# def stripe_card_last4(self):
|
||||
# if self.source == 'stripe' and self.active:
|
||||
# payment_method = uncloud_pay.stripe.get_payment_method(
|
||||
# self.stripe_payment_method_id)
|
||||
# return payment_method.card.last4
|
||||
# else:
|
||||
# return None
|
||||
|
||||
@property
|
||||
def active(self):
|
||||
|
|
@ -1261,3 +1275,24 @@ class ProductToRecurringPeriod(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return f"{self.product} - {self.recurring_period} (default: {self.is_default})"
|
||||
|
||||
|
||||
class Membership(models.Model):
|
||||
owner = models.ForeignKey(get_user_model(),
|
||||
on_delete=models.CASCADE)
|
||||
|
||||
starting_date = models.DateField(blank=True, null=True)
|
||||
ending_date = models.DateField(blank=True, null=True)
|
||||
|
||||
|
||||
@classmethod
|
||||
def user_has_membership(user, when):
|
||||
"""
|
||||
Return true if user has membership at a point of time,
|
||||
return false if that is not the case
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
# cls.objects.filter(owner=user,
|
||||
# starting_date)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue