Skip to content

Commit

Permalink
Update Subscription model with all the new fields (as of 2018-05-21)
Browse files Browse the repository at this point in the history
  • Loading branch information
jleclanche committed May 27, 2018
1 parent 814192e commit 8aa62d2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
30 changes: 30 additions & 0 deletions djstripe/migrations/0025_auto_20180528_0237.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 2.0.5 on 2018-05-27 23:37

from django.db import migrations
import djstripe.fields


class Migration(migrations.Migration):

dependencies = [
('djstripe', '0024_auto_20180527_0956'),
]

operations = [
migrations.AddField(
model_name='subscription',
name='billing',
field=djstripe.fields.StripeCharField(choices=[('charge_automatically', 'Charge automatically'), ('send_invoice', 'Send invoice')], default='', help_text='Either `charge_automatically`, or `send_invoice`. When charging automatically, Stripe will attempt to pay this subscription at the end of the cycle using the default source attached to the customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions.', max_length=20),
preserve_default=False,
),
migrations.AddField(
model_name='subscription',
name='billing_cycle_anchor',
field=djstripe.fields.StripeDateTimeField(help_text='Determines the date of the first full invoice, and, for plans with `month` or `year` intervals, the day of the month for subsequent invoices.', null=True),
),
migrations.AddField(
model_name='subscription',
name='days_until_due',
field=djstripe.fields.StripeIntegerField(help_text='Number of days a customer has to pay invoices generated by this subscription. This value will be `null` for subscriptions where `billing=charge_automatically`.', null=True),
),
]
19 changes: 19 additions & 0 deletions djstripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2800,6 +2800,20 @@ class Subscription(StripeObject):
help_text="A positive decimal that represents the fee percentage of the subscription invoice amount that "
"will be transferred to the application owner's Stripe account each billing period."
)
billing = StripeCharField(
max_length=20,
choices=enums.InvoiceBilling.choices,
help_text=(
"Either `charge_automatically`, or `send_invoice`. When charging automatically, "
"Stripe will attempt to pay this subscription at the end of the cycle using the "
"default source attached to the customer. When sending an invoice, Stripe will "
"email your customer an invoice with payment instructions."
)
)
billing_cycle_anchor = StripeDateTimeField(stripe_required=False, help_text=(
"Determines the date of the first full invoice, and, for plans with `month` or "
"`year` intervals, the day of the month for subsequent invoices."
))
cancel_at_period_end = StripeBooleanField(
default=False,
help_text="If the subscription has been canceled with the ``at_period_end`` flag set to true, "
Expand All @@ -2825,12 +2839,17 @@ class Subscription(StripeObject):
related_name="subscriptions",
help_text="The customer associated with this subscription."
)
days_until_due = StripeIntegerField(stripe_required=False, help_text=(
"Number of days a customer has to pay invoices generated by this subscription. "
"This value will be `null` for subscriptions where `billing=charge_automatically`."
))
# TODO: discount
ended_at = StripeDateTimeField(
null=True, blank=True,
help_text="If the subscription has ended (either because it was canceled or because the customer was switched "
"to a subscription to a new plan), the date the subscription ended."
)
# TODO: items (SubscriptionItem)
plan = ForeignKey(
"Plan", on_delete=models.CASCADE,
related_name="subscriptions",
Expand Down
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ def save(self, idempotency_key=None):
"id": "sub_6lsC8pt7IcFpjA",
"object": "subscription",
"application_fee_percent": None,
"billing": "charge_automatically",
"cancel_at_period_end": False,
"canceled_at": None,
"current_period_end": 1441907581,
Expand Down Expand Up @@ -603,6 +604,7 @@ def save(self, idempotency_key=None):
"id": "sub_6mkwMbhaZF9jih",
"object": "subscription",
"application_fee_percent": None,
"billing": "charge_automatically",
"cancel_at_period_end": False,
"canceled_at": None,
"current_period_end": 1442111228,
Expand All @@ -624,6 +626,7 @@ def save(self, idempotency_key=None):
"id": "sub_8NDptncNY485qZ",
"object": "subscription",
"application_fee_percent": None,
"billing": "charge_automatically",
"cancel_at_period_end": False,
"canceled_at": None,
"current_period_end": 1464821382,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_contrib/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_valid_serializer(self):
data={
'stripe_id': "sub_6lsC8pt7IcFpjA",
'customer': self.customer.id,
"billing": "charge_automatically",
'plan': self.plan.id,
'quantity': 2,
'start': now,
Expand All @@ -48,6 +49,7 @@ def test_valid_serializer(self):
self.assertEqual(serializer.validated_data, {
'stripe_id': "sub_6lsC8pt7IcFpjA",
'customer': self.customer,
"billing": "charge_automatically",
'plan': self.plan,
'quantity': 2,
'start': now,
Expand All @@ -63,6 +65,7 @@ def test_invalid_serializer(self):
data={
'stripe_id': "sub_6lsC8pt7IcFpjA",
'customer': self.customer.id,
"billing": "charge_automatically",
'plan': self.plan.id,
'start': now,
'status': SubscriptionStatus.active,
Expand Down

0 comments on commit 8aa62d2

Please sign in to comment.