Skip to content

Commit 6b513ef

Browse files
authored
Merge branch 'master' into customers-create-plan-quantity
2 parents b9e4b7c + 0a67b62 commit 6b513ef

File tree

8 files changed

+57
-15
lines changed

8 files changed

+57
-15
lines changed

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ env:
1414
- DJANGO=1.9 STRIPE=128
1515
- DJANGO=1.10 STRIPE=127
1616
- DJANGO=1.10 STRIPE=128
17+
- DJANGO=1.11 STRIPE=127
18+
- DJANGO=1.11 STRIPE=128
1719
- DJANGO=master STRIPE=127
1820
- DJANGO=master STRIPE=128
1921
matrix:
@@ -26,6 +28,14 @@ matrix:
2628
env: DJANGO=1.10 STRIPE=127
2729
- python: "3.3"
2830
env: DJANGO=1.10 STRIPE=128
31+
- python: "3.3"
32+
env: DJANGO=1.11 STRIPE=127
33+
- python: "3.3"
34+
env: DJANGO=1.11 STRIPE=128
35+
- python: "2.7"
36+
env: DJANGO=master STRIPE=127
37+
- python: "2.7"
38+
env: DJANGO=master STRIPE=128
2939
- python: "3.3"
3040
env: DJANGO=master STRIPE=127
3141
- python: "3.3"
@@ -34,6 +44,11 @@ matrix:
3444
env: DJANGO=1.7 STRIPE=127
3545
- python: "3.5"
3646
env: DJANGO=1.7 STRIPE=128
47+
allow_failures:
48+
- env: DJANGO=1.11 STRIPE=128
49+
- env: DJANGO=1.11 STRIPE=127
50+
- env: DJANGO=master STRIPE=128
51+
- env: DJANGO=master STRIPE=127
3752
install:
3853
- pip install tox coveralls
3954
script:

pinax/stripe/actions/charges.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def capture(charge, amount=None):
4141
sync_charge_from_stripe_data(stripe_charge)
4242

4343

44-
def create(amount, customer, source=None, currency="usd", description=None, send_receipt=settings.PINAX_STRIPE_SEND_EMAIL_RECEIPTS, capture=True):
44+
def create(amount, customer, source=None, currency="usd", description=None, send_receipt=settings.PINAX_STRIPE_SEND_EMAIL_RECEIPTS, capture=True, email=None):
4545
"""
4646
Creates a charge for the given customer.
4747
@@ -71,7 +71,7 @@ def create(amount, customer, source=None, currency="usd", description=None, send
7171
)
7272
charge = sync_charge_from_stripe_data(stripe_charge)
7373
if send_receipt:
74-
hooks.hookset.send_receipt(charge)
74+
hooks.hookset.send_receipt(charge, email)
7575
return charge
7676

7777

@@ -96,11 +96,8 @@ def sync_charge_from_stripe_data(data):
9696
Returns:
9797
a pinax.stripe.models.Charge object
9898
"""
99-
customer = models.Customer.objects.get(stripe_id=data["customer"])
100-
obj, _ = models.Charge.objects.get_or_create(
101-
customer=customer,
102-
stripe_id=data["id"]
103-
)
99+
obj, _ = models.Charge.objects.get_or_create(stripe_id=data["id"])
100+
obj.customer = models.Customer.objects.filter(stripe_id=data["customer"]).first()
104101
obj.source = data["source"]["id"]
105102
obj.currency = data["currency"]
106103
obj.invoice = next(iter(models.Invoice.objects.filter(stripe_id=data["invoice"])), None)

pinax/stripe/hooks.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def trial_period(self, user, plan):
2525
"""
2626
return None
2727

28-
def send_receipt(self, charge):
28+
def send_receipt(self, charge, email=None):
2929
from django.conf import settings
3030
if not charge.receipt_sent:
3131
# Import here to not add a hard dependency on the Sites framework
@@ -41,10 +41,14 @@ def send_receipt(self, charge):
4141
subject = render_to_string("pinax/stripe/email/subject.txt", ctx)
4242
subject = subject.strip()
4343
message = render_to_string("pinax/stripe/email/body.txt", ctx)
44+
45+
if not email and charge.customer:
46+
email = charge.customer.user.email
47+
4448
num_sent = EmailMessage(
4549
subject,
4650
message,
47-
to=[charge.customer.user.email],
51+
to=[email],
4852
from_email=settings.PINAX_STRIPE_INVOICE_FROM_EMAIL
4953
).send()
5054
charge.receipt_sent = num_sent > 0
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9.8 on 2017-01-08 18:02
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
import django.db.models.deletion
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('pinax_stripe', '0006_coupon'),
13+
]
14+
15+
operations = [
16+
migrations.AlterField(
17+
model_name='charge',
18+
name='customer',
19+
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='charges', to='pinax_stripe.Customer'),
20+
),
21+
]

pinax/stripe/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def plan_display(self):
278278

279279
class Charge(StripeObject):
280280

281-
customer = models.ForeignKey(Customer, related_name="charges", on_delete=models.CASCADE)
281+
customer = models.ForeignKey(Customer, null=True, related_name="charges", on_delete=models.CASCADE)
282282
invoice = models.ForeignKey(Invoice, null=True, related_name="charges", on_delete=models.CASCADE)
283283
source = models.CharField(max_length=100)
284284
currency = models.CharField(max_length=10, default="usd")

pinax/stripe/tests/hooks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def trial_period(self, user, plan):
3030
if plan is not None:
3131
return timezone.now() + timedelta(days=3)
3232

33-
def send_receipt(self, charge):
33+
def send_receipt(self, charge, email=None):
3434
if not charge.receipt_sent:
3535
from django.contrib.sites.models import Site
3636

@@ -44,6 +44,10 @@ def send_receipt(self, charge):
4444
subject = render_to_string("pinax/stripe/email/subject.txt", ctx)
4545
subject = subject.strip()
4646
message = render_to_string("pinax/stripe/email/body.txt", ctx)
47+
48+
if not email and charge.customer:
49+
email = charge.customer.user.email
50+
4751
num_sent = EmailMessage(
4852
subject,
4953
message,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
],
8484
install_requires=[
8585
"django-appconf>=1.0.1",
86-
"jsonfield>=1.0.3",
86+
"jsonfield>=1.0.3,<2.0.0",
8787
"stripe>=1.7.9",
8888
"django>=1.7",
8989
"pytz",

tox.ini

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ exclude = pinax/stripe/migrations/*,docs/*
66

77
[tox]
88
envlist =
9-
py27-{1.7,1.8,1.9,1.10,master}-stripe{127,128},
9+
py27-{1.7,1.8,1.9,1.10,1.11}-stripe{127,128},
1010
py33-{1.7,1.8}-stripe{127,128},
11-
py34-{1.7,1.8,1.9,1.10,master}-stripe{127,128},
12-
py35-{1.8,1.9,1.10,master}-stripe{127,128}
11+
py34-{1.7,1.8,1.9,1.10,1.11,master}-stripe{127,128},
12+
py35-{1.8,1.9,1.10,1.11,master}-stripe{127,128}
1313

1414
[testenv]
1515
deps =
@@ -21,6 +21,7 @@ deps =
2121
1.8: Django>=1.8,<1.9
2222
1.9: Django>=1.9,<1.10
2323
1.10: Django>=1.10,<1.11
24+
1.11: Django>=1.11a1,<2.0
2425
master: https://github.com/django/django/tarball/master
2526
usedevelop = True
2627
setenv =

0 commit comments

Comments
 (0)