Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UniquePerAccountStripeObject for Plans #513

Merged
merged 1 commit into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -62,6 +62,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