diff --git a/src/core/models.py b/src/core/models.py index f6816f1..5bad9e0 100644 --- a/src/core/models.py +++ b/src/core/models.py @@ -166,7 +166,7 @@ class ProductVariant(models.Model): ) name = models.CharField(max_length=255) sku = models.CharField(max_length=255, blank=True) - stripe_id = models.CharField(max_length=255, blank=True) + stripe_id = models.CharField(max_length=255, blank=True, db_index=True) price = models.DecimalField( max_digits=settings.DEFAULT_MAX_DIGITS, decimal_places=settings.DEFAULT_DECIMAL_PLACES, @@ -199,6 +199,44 @@ class ProductVariant(models.Model): ordering = ['sorting', 'weight'] +class StripePrice: + # When this model is updated, it will query stripe and update all of the instances of this model + DAY = 'day' + WEEK = 'week' + MONTH = 'month' + YEAR = 'year' + INTERVAL_CHOICES = [ + (DAY, 'Days'), + (WEEK, 'Weeks'), + (MONTH, 'Month'), + (YEAR, 'Year'), + ] + + stripe_id = models.CharField(max_length=255, blank=True, db_index=True) + variant = models.ForeignKey( + ProductVariant, + related_name='stripe_prices', + on_delete=models.CASCADE, + blank=True, + null=True, + ) + unit_amount = models.DecimalField( + max_digits=settings.DEFAULT_MAX_DIGITS, + decimal_places=settings.DEFAULT_DECIMAL_PLACES, + blank=True, + null=True, + ) + interval = models.CharField( + max_length=16, + choices=INTERVAL_CHOICES, + default=MONTH + ) + interval_count = models.PositiveIntegerField(default=1) + + created_at = models.DateTimeField(auto_now_add=True, editable=False) + updated_at = models.DateTimeField(auto_now=True) + + class ProductOption(models.Model): """ Description: Consistent accross all variants diff --git a/src/static/scripts/subscriptions.js b/src/static/scripts/subscriptions.js index 61e94f4..d541d08 100644 --- a/src/static/scripts/subscriptions.js +++ b/src/static/scripts/subscriptions.js @@ -121,6 +121,19 @@ class Subscription { this.items.push(item) return this.items } + + createSubscription() { + fetch('/create-subscription', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + priceId: priceId, + customerId: customerId, + }), + }) + } } diff --git a/src/storefront/templates/storefront/sub_payment.html b/src/storefront/templates/storefront/sub_payment.html new file mode 100644 index 0000000..b489747 --- /dev/null +++ b/src/storefront/templates/storefront/sub_payment.html @@ -0,0 +1,112 @@ +{% extends 'base.html' %} +{% load static %} + +{% block head %} + + + +{% endblock %} + +{% block content %} +
+