Skip to content

Commit

Permalink
Add Coupon.stripe_coupon
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Nov 20, 2017
1 parent 9f727b9 commit a0d4373
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pinax/stripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def __repr__(self):
class Coupon(models.Model):
stripe_id = models.CharField(max_length=191)
created_at = models.DateTimeField(default=timezone.now)

stripe_account = models.ForeignKey(
"pinax_stripe.Account",
on_delete=models.CASCADE,
Expand Down Expand Up @@ -138,6 +137,13 @@ def __repr__(self):
str(self.stripe_id),
))

@property
def stripe_coupon(self):
return stripe.Coupon.retrieve(
self.stripe_id,
stripe_account=self.stripe_account.stripe_id,
)


@python_2_unicode_compatible
class EventProcessingException(models.Model):
Expand Down
9 changes: 8 additions & 1 deletion pinax/stripe/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.test import TestCase
from django.utils import timezone

from mock import patch
from mock import call, patch

from ..models import (
Account,
Expand Down Expand Up @@ -104,6 +104,13 @@ def test_coupon_absolute(self):
c = Coupon(amount_off=decimal.Decimal(50.00), duration="once", currency="usd")
self.assertEquals(str(c), "Coupon for $50, once")

@patch("stripe.Coupon.retrieve")
def test_coupon_stripe_coupon(self, RetrieveMock):
c = Coupon(stripe_id="coupon", stripe_account=Account(stripe_id="acct_A"))
self.assertEqual(c.stripe_coupon, RetrieveMock.return_value)
self.assertTrue(RetrieveMock.call_args_list, [
call("coupon", stripe_account="acct_A")])

def test_model_table_name(self):
self.assertEquals(Customer()._meta.db_table, "pinax_stripe_customer")

Expand Down

0 comments on commit a0d4373

Please sign in to comment.