diff options
Diffstat (limited to 'pyblackbird_cc/payments/models.py')
-rw-r--r-- | pyblackbird_cc/payments/models.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/pyblackbird_cc/payments/models.py b/pyblackbird_cc/payments/models.py new file mode 100644 index 0000000..2b66c14 --- /dev/null +++ b/pyblackbird_cc/payments/models.py @@ -0,0 +1,61 @@ +from django.conf import settings +from django.db import models + +from pyblackbird_cc.resources.models import Resource + + +class Product(models.Model): + name = models.CharField(max_length=255) + stripe_product_id = models.CharField(max_length=100) + + +class Price(models.Model): + product = models.ForeignKey(Product, on_delete=models.CASCADE) + price = models.IntegerField(default=0) + stripe_price_id = models.CharField(max_length=100) + + def get_display_price(self): + return "{0:.2f}".format(self.price / 100) + + +class ShoppingCart(models.Model): + user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + def __str__(self): + return f"Shopping Cart for {self.user.username}" + + +class CartItem(models.Model): + cart = models.ForeignKey(ShoppingCart, on_delete=models.CASCADE, related_name="items") + resource = models.ForeignKey(Resource, on_delete=models.CASCADE) + quantity = models.PositiveIntegerField(default=1) + added_at = models.DateTimeField(auto_now_add=True) + + class Meta: + unique_together = ("cart", "resource") + + def __str__(self): + return f"{self.quantity} of {self.resource.name} in {self.cart.user.username}'s cart" + + def get_total_price(self): + return self.quantity * self.resource.price + + +class SubscriptionPlan(models.Model): + name = models.CharField(max_length=255) + price = models.DecimalField(max_digits=6, decimal_places=2) + description = models.TextField() + allowed_downloads = models.PositiveIntegerField() + stripe_plan_id = models.CharField(max_length=255) + + +class Subscription(models.Model): + user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) + is_active = models.BooleanField(default=False) + start_date = models.DateTimeField(null=True, blank=True) + end_date = models.DateTimeField(null=True, blank=True) + + def __str__(self): + return f"Subscription for {self.user.username}" |