Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

WIP: Payments app #158

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
731976b
Django 2 compat
kirknorthrop Feb 16, 2018
dc75667
Django 2.0 compatability
kirknorthrop Feb 20, 2018
98472e6
Initial version of payments models
kirknorthrop Feb 21, 2018
83d0acb
Change variable names following feedback
kirknorthrop Mar 4, 2018
a8f8e69
Change scrambler offsets and choices representations
kirknorthrop Mar 4, 2018
826b362
Add payments application and migration
kirknorthrop Mar 18, 2018
60376ca
Split out VAT rates
kirknorthrop Mar 18, 2018
bcfdb6d
Add create invoice and credit note
kirknorthrop Mar 18, 2018
5bb97c4
Add invoice row
kirknorthrop Mar 18, 2018
8974f6b
Alteration to creating invoices
kirknorthrop Mar 18, 2018
7c09289
Add invoice row tests and VAT improvements
kirknorthrop Mar 18, 2018
2c8f873
Invoice total updates
kirknorthrop Mar 18, 2018
0073968
Add items only once per invoice
kirknorthrop Mar 18, 2018
a3caff6
Further add row tests
kirknorthrop Mar 18, 2018
787bab7
Credit note totals and tests
kirknorthrop Mar 18, 2018
20d1ede
Don’t add rows to invoices with payments
kirknorthrop Mar 18, 2018
0af6252
Kill bob
kirknorthrop Mar 18, 2018
0f883c3
Make ticket_2 a different price to ensure tests are correct
kirknorthrop Mar 18, 2018
e03d50e
Deleting of invoice rows
kirknorthrop Mar 18, 2018
f2e0c6c
Rename functions
kirknorthrop Mar 18, 2018
a2764a9
Move stripe integration to payments
Mar 20, 2018
3decea5
Remove scrambler from invoice
Mar 21, 2018
3b98db7
Move rate onto ticket
Mar 21, 2018
9c6c2b7
URLs, new views for invoice info, create invoice when creating ticket
Mar 24, 2018
10231e8
Working but untested full flow
Mar 25, 2018
a86d45f
Further changes to invoice
Mar 26, 2018
b3ec252
Change instances of 2017 to 2018
Mar 26, 2018
c7483cf
Another 2018 change
Mar 26, 2018
407d2dc
Orders is not used in the account profile
Mar 27, 2018
96373c3
Improve formatting and readability
Mar 27, 2018
d5b5641
Add the profile link to the profile incomplete message
Mar 27, 2018
87ce281
Remove Order
Mar 31, 2018
88b94a8
Remove existing migrations for payments
kirknorthrop Mar 31, 2018
3bf5827
Rename migration to remove order
kirknorthrop Mar 31, 2018
5c2f5b2
Change conference days
kirknorthrop Mar 31, 2018
31be595
Improving integrity of data
kirknorthrop Mar 31, 2018
8fc0fc6
More data integrity
kirknorthrop Mar 31, 2018
270c0aa
Update Broken and changed URLs and attributes
kirknorthrop Mar 31, 2018
d298056
Change stripe charge creation patch
kirknorthrop Mar 31, 2018
10e05f7
More data integrity changes
kirknorthrop Mar 31, 2018
4ec3d03
Moving lots of things round to replace old flows
kirknorthrop Mar 31, 2018
164266c
Payment models (new version)
kirknorthrop Mar 31, 2018
e2141a2
Changes to failed stripe payments, and how they are shown on receipts…
kirknorthrop Mar 31, 2018
dc10e07
Very brief summary
kirknorthrop Mar 31, 2018
5a76a27
Fix tests for altered models and AAA
kirknorthrop Apr 1, 2018
c82c51a
Fix tests for altered models and AAA
kirknorthrop Apr 1, 2018
bd1d182
Merge branch 'payments_app' of github.com:kirknorthrop/ironcage into …
kirknorthrop Apr 1, 2018
d54bcda
Beautify tests
kirknorthrop Apr 1, 2018
37a03e8
Fix test utils and factories
kirknorthrop Apr 1, 2018
1bc4756
Clean up payment flow and naming
kirknorthrop Apr 1, 2018
e40b49d
Had a clear up
kirknorthrop Apr 1, 2018
78d306c
More changes to payments to make them more resilient
kirknorthrop Apr 1, 2018
f623456
Goodbye old Stripe code
kirknorthrop Apr 1, 2018
9cc7866
Fix things that moving stripe broke
kirknorthrop Apr 1, 2018
7fe34e8
Pending order is now unpaid order
kirknorthrop Apr 1, 2018
a50bde8
And now replace the idea of an unpaid order past a few factories
kirknorthrop Apr 1, 2018
615a716
Now confirmed orders become paid orders
kirknorthrop Apr 1, 2018
650e93c
Fix create_invoice_with_tickets params
kirknorthrop Apr 1, 2018
f8a6596
Some beautiful tests for pay invoice via stripe
kirknorthrop Apr 1, 2018
27aacd1
Forgot to delete old code
kirknorthrop Apr 1, 2018
7ed1f0e
Tests for creating payments
kirknorthrop Apr 1, 2018
725b4ff
Change mark payment names to create payment
kirknorthrop Apr 1, 2018
d5e9770
Fix view tests and confirm order
kirknorthrop Apr 1, 2018
d2662fc
Change ticket for self location and logic
kirknorthrop Apr 1, 2018
666efec
Add “basket” stage to order process
kirknorthrop Apr 1, 2018
9e0e3a6
Action tests and other fixes
kirknorthrop Apr 1, 2018
327c929
Make it work when you’re not buying other people tickets
kirknorthrop Apr 1, 2018
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
4 changes: 2 additions & 2 deletions accommodation/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

We look forward to seeing you in Cardiff!

~ The PyCon UK 2017 team
~ The PyCon UK 2018 team
'''.strip()


def send_booking_confirmation_mail(booking):
body = INVITATION_TEMPLATE.format(room_description=booking.room_description())

send_mail(
f'PyCon UK 2017 accommodation confirmation',
f'PyCon UK 2018 accommodation confirmation',
body,
booking.guest.email_addr,
)
2 changes: 1 addition & 1 deletion accommodation/templates/accommodation/booking_payment.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h1>Accommodation booking payment</h1>
data-currency="gbp"
data-name="PyCon UK Society Ltd"
data-image="{% static 'ironcage/img/yellow.png' %}"
data-description="PyCon UK 2017 accommodation"
data-description="PyCon UK 2018 accommodation"
data-locale="auto"
data-email="{{ user.email_addr }}"
>
Expand Down
2 changes: 1 addition & 1 deletion accommodation/templates/accommodation/booking_receipt.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'ironcage/base.html' %}

{% block content %}
<h1>Receipt for PyCon UK 2017 accommodation</h1>
<h1>Receipt for PyCon UK 2018 accommodation</h1>

<p>Issued by the PyCon UK Society Ltd, c/o Acconomy, Arena Business Centre, Holyrood Close, Poole, BH17 7FJ, United Kingdom (VAT Number 249244982)</p>

Expand Down
4 changes: 2 additions & 2 deletions accommodation/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def test_post_stripe_success(self):
self.assertEqual(len(mail.outbox), 1)
email = mail.outbox[0]
self.assertEqual(email.to, [self.alice.email_addr])
self.assertEqual(email.from_email, 'PyCon UK 2017 <[email protected]>')
self.assertEqual(email.subject, 'PyCon UK 2017 accommodation confirmation')
self.assertEqual(email.from_email, 'PyCon UK 2018 <[email protected]>')
self.assertEqual(email.subject, 'PyCon UK 2018 accommodation confirmation')
self.assertIn(ROOMS[1].description, email.body)

backend = get_slack_backend()
Expand Down
4 changes: 2 additions & 2 deletions accommodation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.contrib import messages
from django.shortcuts import redirect, render

from ironcage.stripe_integration import create_charge
from payments.stripe_integration import create_charge

from .mailer import send_booking_confirmation_mail
from .models import Booking, available_rooms, get_room_by_key, has_availability
Expand Down Expand Up @@ -49,7 +49,7 @@ def booking_payment(request):
token = request.POST['stripeToken']
charge = create_charge(
room.cost_incl_vat * 100,
'PyCon UK 2017 accommodation',
'PyCon UK 2018 accommodation',
'PyCon UK accommodation',
token
)
Expand Down
4 changes: 3 additions & 1 deletion accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def get_short_name(self):

def get_ticket(self):
try:
return self.ticket
if self.ticket and (self.ticket.rate == Ticket.FREE or self.ticket.invoice.successful_payment):
return self.ticket
return None
except Ticket.DoesNotExist:
return None

Expand Down
2 changes: 1 addition & 1 deletion accounts/templates/registration/password_reset_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

Your username, in case you've forgotten: {{ user.get_username }}

~ The PyCon UK 2017 team
~ The PyCon UK 2018 team
1 change: 0 additions & 1 deletion accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def profile(request):

context = {
'name': user.name,
'orders': user.orders.all(),
'ticket': user.get_ticket(),
}
return render(request, 'accounts/profile.html', context)
Expand Down
4 changes: 2 additions & 2 deletions cfp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def is_interested_for_form(self, user):


class Vote(models.Model):
proposal = models.ForeignKey('Proposal')
user = models.ForeignKey(settings.AUTH_USER_MODEL)
proposal = models.ForeignKey('Proposal', on_delete=models.CASCADE)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
is_interested = models.BooleanField(default=True)

created_at = models.DateTimeField(auto_now_add=True)
Expand Down
4 changes: 2 additions & 2 deletions children/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.db import transaction

from ironcage.stripe_integration import create_charge_for_order
from payments.stripe_integration import create_charge_for_invoice

from .mailer import send_order_confirmation_mail
from .models import Order
Expand Down Expand Up @@ -36,7 +36,7 @@ def process_stripe_charge(order, token):
logger.info('children:process_stripe_charge', order=order.order_id, token=token)
assert order.payment_required()
try:
charge = create_charge_for_order(order, token)
charge = create_charge_for_invoice(order, token)
confirm_order(order, charge.id, charge.created)
except stripe.error.CardError as e:
mark_order_as_failed(order, e._message)
Expand Down
2 changes: 1 addition & 1 deletion children/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def send_order_confirmation_mail(order):
body = re.sub('\n\n\n+', '\n\n', body_raw)

send_mail(
f"PyCon UK 2017 children's day order confirmation ({order.order_id})",
f"PyCon UK 2018 children's day order confirmation ({order.order_id})",
body,
order.purchaser.email_addr,
)
4 changes: 2 additions & 2 deletions children/templates/children/emails/order-confirmation.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Hi {{ purchaser_name }},

You have purchased {{ num_tickets }} ticket{{ num_tickets|pluralize }} for the children's day at PyCon UK 2017.
You have purchased {{ num_tickets }} ticket{{ num_tickets|pluralize }} for the children's day at PyCon UK 2018.

You can view your order at:

{{ order_url }}

Best wishes,

~ The PyCon UK 2017 team
~ The PyCon UK 2018 team
2 changes: 1 addition & 1 deletion children/templates/children/order.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1>Details of your children's day order ({{ order.order_id }})</h1>
data-currency="gbp"
data-name="PyCon UK Society Ltd"
data-image="{% static 'ironcage/img/yellow.png' %}"
data-description="PyCon UK 2017 order {{ order.order_id }}"
data-description="PyCon UK 2018 order {{ order.order_id }}"
data-locale="auto"
data-email="{{ order.purchaser.email_addr }}"
>
Expand Down
6 changes: 3 additions & 3 deletions children/tests/test_mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_send_order_confirmation_mail(self):
self.assertEqual(len(mail.outbox), 1)
email = mail.outbox[0]
self.assertEqual(email.to, ['[email protected]'])
self.assertEqual(email.from_email, 'PyCon UK 2017 <[email protected]>')
self.assertEqual(email.subject, f"PyCon UK 2017 children's day order confirmation ({order.order_id})")
self.assertTrue(re.search(r"You have purchased 1 ticket for the children's day at PyCon UK 2017", email.body))
self.assertEqual(email.from_email, 'PyCon UK 2018 <[email protected]>')
self.assertEqual(email.subject, f"PyCon UK 2018 children's day order confirmation ({order.order_id})")
self.assertTrue(re.search(r"You have purchased 1 ticket for the children's day at PyCon UK 2018", email.body))
self.assertTrue(re.search(fr'http://testserver/children/orders/{order.order_id}/', email.body))
2 changes: 1 addition & 1 deletion dinners/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def send_booking_confirmation_mail(booking):
user = booking.guest
subject = f'PyCon UK 2017 dinner confirmation | {user.user_id}'
subject = f'PyCon UK 2018 dinner confirmation | {user.user_id}'

template = get_template('dinners/emails/order-confirmation.txt')
context = {
Expand Down
2 changes: 1 addition & 1 deletion dinners/templates/dinners/conference_dinner_payment.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h1>Conference dinner payment</h1>
data-currency="gbp"
data-name="PyCon UK Society Ltd"
data-image="{% static 'ironcage/img/yellow.png' %}"
data-description="PyCon UK 2017 conference dinner"
data-description="PyCon UK 2018 conference dinner"
data-locale="auto"
data-email="{{ user.email_addr }}"
>
Expand Down
6 changes: 3 additions & 3 deletions dinners/templates/dinners/conference_dinner_receipt.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{% extends 'ironcage/base.html' %}

{% block content %}
<h1>Receipt for PyCon UK 2017 conference dinner</h1>
<h1>Receipt for PyCon UK 2018 conference dinner</h1>

<p>Issued by the PyCon UK Society Ltd, c/o Acconomy, Arena Business Centre, Holyrood Close, Poole, BH17 7FJ, United Kingdom (VAT Number 249244982)</p>

<p>Issued to {{ booking.guest.name }}</p>

<p>Ticket for PyCon UK 2017 conference dinner</p>
<p>Ticket for PyCon UK 2018 conference dinner</p>

<div class="row">
<div class="col-md-4">
Expand Down Expand Up @@ -49,7 +49,7 @@ <h1>Receipt for PyCon UK 2017 conference dinner</h1>

<tbody>
<tr>
<td>Ticket for PyCon UK 2017 conference dinner</td>
<td>Ticket for PyCon UK 2018 conference dinner</td>
<td>1</td>
<td>£25</td>
<td>£30</td>
Expand Down
2 changes: 1 addition & 1 deletion dinners/templates/dinners/emails/order-confirmation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ You can download a receipt at :

Best wishes,

~ The PyCon UK 2017 team
~ The PyCon UK 2018 team
{% endautoescape %}
2 changes: 1 addition & 1 deletion dinners/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,4 @@ def test_get_when_booked_as_contributor(self):
def test_get_when_booked(self):
factories.create_paid_booking(self.alice)
rsp = self.client.get(self.url, follow=True)
self.assertContains(rsp, 'Receipt for PyCon UK 2017 conference dinner')
self.assertContains(rsp, 'Receipt for PyCon UK 2018 conference dinner')
4 changes: 2 additions & 2 deletions dinners/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.contrib import messages
from django.shortcuts import redirect, render

from ironcage.stripe_integration import create_charge
from payments.stripe_integration import create_charge

from .forms import ConferenceDinnerForm, ContributorsDinnerForm, WhichDinnerForm
from .mailer import send_booking_confirmation_mail
Expand Down Expand Up @@ -131,7 +131,7 @@ def conference_dinner_payment(request):
token = request.POST['stripeToken']
charge = create_charge(
CONFERENCE_DINNER_PRICE_PENCE,
'PyCon UK 2017 dinner',
'PyCon UK 2018 dinner',
'PyCon UK dinner',
token
)
Expand Down
2 changes: 1 addition & 1 deletion emails/templates/emails/cfp-proposals-notification.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Hi {{ recipient.name }},
assistance.

{% elif application.requested_ticket_only %}
You have applied for a complementary ticket for PyCon UK 2017, and we're
You have applied for a complementary ticket for PyCon UK 2018, and we're
also pleased to tell you that we can offer you a ticket for the conference.

We will send instructions for claiming your ticket in the next few days.
Expand Down
2 changes: 1 addition & 1 deletion emails/templates/emails/schedule-days.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Hi {{ recipient.name }},

We mentioned in an email last week that we have published a provisional
day-by-day schedule for PyCon UK 2017, which you can find our website at
day-by-day schedule for PyCon UK 2018, which you can find our website at
http://2017.pyconuk.org/schedule/.

We'd like to minimise further changes to the schedule; so if you can't speak on
Expand Down
2 changes: 1 addition & 1 deletion emails/templates/emails/ukpa-ticket-holders.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Python Association, a newly-formed charity whose purpose is support the Python
community in the UK. You can read more about the UKPA on the conference
website[1].

The UKPA is a membership organisation, and anybody who attends PyCon UK 2017 is
The UKPA is a membership organisation, and anybody who attends PyCon UK 2018 is
entitled to membership. For now, membership entitles you to vote to elect the
organisation's trustees. You can indicate that you would like to join the UKPA
when you fill out your profile[2].
Expand Down
2 changes: 1 addition & 1 deletion emails/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ def test_wet_run(self):
self.assertEqual(len(mail.outbox), 2)
email = mail.outbox[0]
self.assertEqual(email.to, ['[email protected]'])
self.assertEqual(email.from_email, 'PyCon UK 2017 <[email protected]>')
self.assertEqual(email.from_email, 'PyCon UK 2018 <[email protected]>')
self.assertEqual(email.subject, f'This is a test | {self.alice.user_id}')
self.assertIn('Hi Alice', email.body)
4 changes: 2 additions & 2 deletions grants/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@


DAY_CHOICES = [
('thu', 'Thursday'),
('fri', 'Friday'),
('sat', 'Saturday'),
('sun', 'Sunday'),
('mon', 'Monday'),
('tue', 'Tuesday'),
('wed', 'Wednesday'),
]


Expand Down
23 changes: 23 additions & 0 deletions grants/migrations/0003_change_days.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.0.2 on 2018-03-31 12:16

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('grants', '0002_auto_20170827_1856'),
]

operations = [
migrations.RenameField(
model_name='application',
old_name='fri',
new_name='tue',
),
migrations.RenameField(
model_name='application',
old_name='thu',
new_name='wed',
),
]
4 changes: 2 additions & 2 deletions grants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class Application(models.Model):
applicant = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='grant_application', on_delete=models.CASCADE)
amount_requested = models.IntegerField()
would_like_ticket_set_aside = models.BooleanField()
thu = models.BooleanField()
fri = models.BooleanField()
sat = models.BooleanField()
sun = models.BooleanField()
mon = models.BooleanField()
tue = models.BooleanField()
wed = models.BooleanField()
about_you = models.TextField()
amount_offered = models.IntegerField(default=0)
requested_ticket_only = models.BooleanField(default=False)
Expand Down
4 changes: 2 additions & 2 deletions grants/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def create_application(user=None):
applicant=user,
amount_requested=1000,
would_like_ticket_set_aside=False,
thu=False,
fri=False,
sat=True,
sun=True,
mon=True,
tue=False,
wed=False,
about_you='I have two thumbs',
)
8 changes: 4 additions & 4 deletions grants/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_post(self):
self.client.force_login(self.alice)
form_data = {
'amount_requested': '2000',
'days': ['fri', 'sat', 'sun', 'mon'],
'days': ['sat', 'sun', 'mon', 'tue'],
'about_you': 'I have two thumbs',
}
rsp = self.client.post(f'/grants/applications/{self.application.application_id}/edit/', form_data, follow=True)
Expand All @@ -96,7 +96,7 @@ def test_post(self):
application = self.alice.get_grant_application()
application.refresh_from_db()
self.assertEqual(application.amount_requested, 2000)
self.assertEqual(application.days(), ['Friday', 'Saturday', 'Sunday', 'Monday'])
self.assertEqual(application.days(), ['Saturday', 'Sunday', 'Monday', 'Tuesday'])

def test_get_when_not_authenticated(self):
rsp = self.client.get(f'/grants/applications/{self.application.application_id}/edit/')
Expand Down Expand Up @@ -242,7 +242,7 @@ def test_get_application_edit_with_token(self):
def test_post_application_edit(self):
form_data = {
'amount_requested': '2000',
'days': ['fri', 'sat', 'sun', 'mon'],
'days': ['sat', 'sun', 'mon', 'tue'],
'about_you': 'I have two thumbs',
}
rsp = self.client.post(f'/grants/applications/{self.application.application_id}/edit/', form_data, follow=True)
Expand All @@ -252,7 +252,7 @@ def test_post_application_edit(self):
def test_post_application_edit_with_token(self):
form_data = {
'amount_requested': '2000',
'days': ['fri', 'sat', 'sun', 'mon'],
'days': ['sat', 'sun', 'mon', 'tue'],
'about_you': 'I have two thumbs',
}
rsp = self.client.post(f'/grants/applications/{self.application.application_id}/edit/?deadline-bypass-token=abc123', form_data, follow=True)
Expand Down
2 changes: 1 addition & 1 deletion ironcage/management/commands/sendtestemail.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def add_arguments(self, parser):

def handle(self, *args, to_addr, **kwargs):
send_mail(
'PyCon UK 2017 test email',
'PyCon UK 2018 test email',
f'This is a test, generated at {datetime.now()}',
to_addr,
)
Loading