Skip to content

Commit

Permalink
Merge pull request #513 from blueyed/plan-per-account-upstream
Browse files Browse the repository at this point in the history
Add UniquePerAccountStripeObject for Plans
  • Loading branch information
paltman authored Dec 1, 2017
2 parents 51bbea3 + 2ba464f commit 55704ae
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
24 changes: 24 additions & 0 deletions pinax/stripe/migrations/0011_auto_20171121_1648.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-11-21 16:48
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pinax_stripe', '0010_connect'),
]

operations = [
migrations.AlterField(
model_name='plan',
name='stripe_id',
field=models.CharField(max_length=191),
),
migrations.AlterUniqueTogether(
name='plan',
unique_together=set([('stripe_id', 'stripe_account')]),
),
]
2 changes: 1 addition & 1 deletion pinax/stripe/migrations/0011_auto_20171123_2016.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Migration(migrations.Migration):

dependencies = [
('pinax_stripe', '0010_connect'),
('pinax_stripe', '0011_auto_20171121_1648'),
]

operations = [
Expand Down
20 changes: 18 additions & 2 deletions pinax/stripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Meta:
abstract = True


class AccountRelatedStripeObject(StripeObject):
class AccountRelatedStripeObjectMixin(models.Model):

stripe_account = models.ForeignKey(
"pinax_stripe.Account",
Expand All @@ -44,6 +44,22 @@ class Meta:
abstract = True


class AccountRelatedStripeObject(AccountRelatedStripeObjectMixin, StripeObject):
"""Uses a mixin to support Django 1.8 (name clash for stripe_id)"""

class Meta:
abstract = True


class UniquePerAccountStripeObject(AccountRelatedStripeObjectMixin):
stripe_id = models.CharField(max_length=191)
created_at = models.DateTimeField(default=timezone.now)

class Meta:
abstract = True
unique_together = ("stripe_id", "stripe_account")


class StripeAccountFromCustomerMixin(object):
@property
def stripe_account(self):
Expand All @@ -56,7 +72,7 @@ def stripe_account_stripe_id(self):


@python_2_unicode_compatible
class Plan(AccountRelatedStripeObject):
class Plan(UniquePerAccountStripeObject):
amount = models.DecimalField(decimal_places=2, max_digits=9)
currency = models.CharField(max_length=15, blank=False)
interval = models.CharField(max_length=15)
Expand Down
6 changes: 6 additions & 0 deletions pinax/stripe/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def test_plan_stripe_plan_with_account(self, RetrieveMock):
self.assertTrue(RetrieveMock.call_args_list, [
call("plan", stripe_account="acct_A")])

def test_plan_per_account(self):
Plan.objects.create(stripe_id="plan", amount=decimal.Decimal("100"), interval="monthly", interval_count=1)
account = Account.objects.create(stripe_id="acct_A")
Plan.objects.create(stripe_id="plan", stripe_account=account, amount=decimal.Decimal("100"), interval="monthly", interval_count=1)
self.assertEquals(Plan.objects.count(), 2)

def test_event_processing_exception_str(self):
e = EventProcessingException(data="hello", message="hi there", traceback="fake")
self.assertTrue("Event=" in str(e))
Expand Down

0 comments on commit 55704ae

Please sign in to comment.