Add stripe_subscription_id field to MembershipOrder

This commit is contained in:
PCoder 2017-12-24 00:06:21 +01:00
parent 10bc05f700
commit f226c551a8
2 changed files with 23 additions and 0 deletions

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2017-12-23 22:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('digitalglarus', '0024_bookingcancellation'),
]
operations = [
migrations.AddField(
model_name='membershiporder',
name='stripe_subscription_id',
field=models.CharField(max_length=100, null=True),
),
]

View file

@ -129,6 +129,7 @@ class MembershipOrder(Ordereable, models.Model):
membership = models.ForeignKey(Membership)
start_date = models.DateField()
end_date = models.DateField()
stripe_subscription_id = models.CharField(max_length=100, null=True)
@classmethod
def current_membership_dates(cls, user):
@ -172,10 +173,12 @@ class MembershipOrder(Ordereable, models.Model):
@classmethod
def create(cls, data):
stripe_charge = data.pop('stripe_charge', None)
stripe_subscription_id = data.pop('stripe_subscription_id', None)
instance = cls.objects.create(**data)
instance.stripe_charge_id = stripe_charge.id
instance.last4 = stripe_charge.source.last4
instance.cc_brand = stripe_charge.source.brand
instance.stripe_subscription_id = stripe_subscription_id
instance.save()
return instance