Skip to content

Commit

Permalink
Merge branch 'master' into issue-290
Browse files Browse the repository at this point in the history
  • Loading branch information
paltman authored Dec 13, 2016
2 parents d1995af + d12c367 commit 8d426c2
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 4 deletions.
25 changes: 25 additions & 0 deletions docs/reference/templatetags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Template tags

## stripe

#### stripe_public_key

Returns the value of the `PINAX_STRIPE_PUBLIC_KEY` setting as a Javascript
single quoted string. This value can be used to initialize the Stripe
Javascript library. For example:

{% load stripe %}
...
<script>
Stripe.setPublishableKey({% stripe_public_key %});
</script>

will generate:

<script>
Stripe.setPublishableKey('pk_<your public key here>');
</script>

If `PINAX_STRIPE_PUBLIC_KEY` has not been defined, the value
`*** PINAX_STRIPE_PUBLIC_KEY NOT SET ***` is returned **unquoted**. This
will force a JavaScript syntax error to be raised wherever it has been used.
41 changes: 38 additions & 3 deletions pinax/stripe/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
from .models import ( # @@@ make all these read-only
Charge,
Subscription,
Card,
BitcoinReceiver,
Customer,
Event,
EventProcessingException,
Invoice,
InvoiceItem,
Plan,
Transfer
Transfer,
TransferChargeFee
)


Expand Down Expand Up @@ -175,6 +178,20 @@ def queryset(self, request, queryset):

class SubscriptionInline(admin.TabularInline):
model = Subscription
extra = 0
max_num = 0


class CardInline(admin.TabularInline):
model = Card
extra = 0
max_num = 0


class BitcoinReceiverInline(admin.TabularInline):
model = BitcoinReceiver
extra = 0
max_num = 0


def subscription_status(obj):
Expand Down Expand Up @@ -203,12 +220,18 @@ def subscription_status(obj):
search_fields=[
"stripe_id",
] + user_search_fields(),
inlines=[SubscriptionInline]
inlines=[
SubscriptionInline,
CardInline,
BitcoinReceiverInline
]
)


class InvoiceItemInline(admin.TabularInline):
model = InvoiceItem
extra = 0
max_num = 0


def customer_has_card(obj):
Expand Down Expand Up @@ -256,7 +279,9 @@ def customer_user(obj):
"period_end",
"total"
],
inlines=[InvoiceItemInline]
inlines=[
InvoiceItemInline
]
)

admin.site.register(
Expand Down Expand Up @@ -290,6 +315,13 @@ def customer_user(obj):
],
)


class TransferChargeFeeInline(admin.TabularInline):
model = TransferChargeFee
extra = 0
max_num = 0


admin.site.register(
Transfer,
raw_id_fields=["event"],
Expand All @@ -303,5 +335,8 @@ def customer_user(obj):
search_fields=[
"stripe_id",
"event__stripe_id"
],
inlines=[
TransferChargeFeeInline
]
)
Empty file.
14 changes: 14 additions & 0 deletions pinax/stripe/templatetags/stripe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django import template
from django.conf import settings
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe

register = template.Library()


@register.simple_tag
def stripe_public_key():
if settings.PINAX_STRIPE_PUBLIC_KEY:
return mark_safe("'%s'" % conditional_escape(settings.PINAX_STRIPE_PUBLIC_KEY))
else:
return "*** PINAX_STRIPE_PUBLIC_KEY NOT SET ***"
2 changes: 1 addition & 1 deletion pinax/stripe/tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class EmailReceiptTest(TestCase):

def setUp(self):
User = get_user_model()
self.user = User.objects.create_user(username="patrick")
self.user = User.objects.create_user(username="patrick", email='[email protected]')
self.customer = Customer.objects.create(
user=self.user,
stripe_id="cus_xxxxxxxxxxxxxxx"
Expand Down
40 changes: 40 additions & 0 deletions pinax/stripe/tests/test_templatetags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django.test import TestCase, override_settings
from django.template import Template, Context


class TemplateTagTests(TestCase):

@override_settings(PINAX_STRIPE_PUBLIC_KEY='this-is-the-stripe-public-key')
def test_stripe_public_key(self):
self.maxDiff = None
template = Template("""{% load stripe %}
<script>
Stripe.setPublishableKey({% stripe_public_key %});
</script>
""")

self.assertEqual(
template.render(Context()),
"""
<script>
Stripe.setPublishableKey('this-is-the-stripe-public-key');
</script>
"""
)

def test_no_stripe_public_key(self):
self.maxDiff = None
template = Template("""{% load stripe %}
<script>
Stripe.setPublishableKey({% stripe_public_key %});
</script>
""")

self.assertEqual(
template.render(Context()),
"""
<script>
Stripe.setPublishableKey(*** PINAX_STRIPE_PUBLIC_KEY NOT SET ***);
</script>
"""
)

0 comments on commit 8d426c2

Please sign in to comment.