diff --git a/hc/payments/forms.py b/hc/payments/forms.py new file mode 100644 index 00000000..7dd571e7 --- /dev/null +++ b/hc/payments/forms.py @@ -0,0 +1,5 @@ +from django import forms + + +class BillToForm(forms.Form): + bill_to = forms.CharField(max_length=500, required=False) diff --git a/hc/payments/tests/test_billing.py b/hc/payments/tests/test_billing.py index 64770d4b..906ffb82 100644 --- a/hc/payments/tests/test_billing.py +++ b/hc/payments/tests/test_billing.py @@ -24,3 +24,11 @@ class BillingTestCase(BaseTestCase): r = self.client.get("/billing/") self.assertContains(r, "123") self.assertContains(r, "def456") + + def test_it_saves_company_details(self): + self.client.login(username="alice@example.org", password="password") + r = self.client.post("/billing/", {"bill_to": "foo\nbar"}) + + self.assertEqual(r.status_code, 302) + self.profile.refresh_from_db() + self.assertEqual(self.profile.bill_to, "foo\nbar") diff --git a/hc/payments/views.py b/hc/payments/views.py index e9f03663..e9455921 100644 --- a/hc/payments/views.py +++ b/hc/payments/views.py @@ -6,7 +6,8 @@ from django.http import (HttpResponseBadRequest, HttpResponseForbidden, from django.shortcuts import redirect, render from django.views.decorators.http import require_POST -from .models import Subscription +from hc.payments.forms import BillToForm +from hc.payments.models import Subscription if settings.USE_PAYMENTS: import braintree @@ -177,6 +178,13 @@ def cancel_plan(request): @login_required def billing(request): + if request.method == "POST": + form = BillToForm(request.POST) + if form.is_valid(): + request.user.profile.bill_to = form.cleaned_data["bill_to"] + request.user.profile.save() + return redirect("hc-billing") + sub = Subscription.objects.get(user=request.user) transactions = braintree.Transaction.search( diff --git a/static/css/channels.css b/static/css/channels.css index 05e094b5..b8286255 100644 --- a/static/css/channels.css +++ b/static/css/channels.css @@ -3,7 +3,8 @@ } .channels-table .channel-row > td { - padding: 10px 0; + padding-top: 10px; + padding-bottom: 10px; } .channels-table .value-cell { diff --git a/templates/payments/billing.html b/templates/payments/billing.html index dc67c386..279ff89b 100644 --- a/templates/payments/billing.html +++ b/templates/payments/billing.html @@ -4,50 +4,95 @@ {% block content %} -

Billing History

+
+
+ + + + + + + + + + {% for tx in transactions %} + + + + + + + + {% empty %} + + + + {% endfor%} +
DatePayment MethodAmountStatus
{{ tx.created_at }} + {% if tx.payment_instrument_type == "paypal_account" %} + Paypal from {{ tx.paypal.payer_email }} + {% endif %} + + {% if tx.payment_instrument_type == "credit_card" %} + {{ tx.credit_card.card_type }} ending in {{ tx.credit_card.last_4 }} + {% endif %} + + {% if tx.currency_iso_code == "USD" %} + ${{ tx.amount }} + {% elif tx.currency_iso_code == "EUR" %} + €{{ tx.amount }} + {% else %} + {{ tx.currency_iso_code }} {{ tx.amount }} + {% endif %} + {{ tx.status }} + View Invoice +
+ No past transactions to display here +
+
+
+

Bill to:

+

+ {% if request.user.profile.bill_to %} + {{ request.user.profile.bill_to|linebreaksbr }} + {% else %} + {{ request.user.email }} + {% endif %} +

+ + +
+
+ + - - - - - - - - - {% for tx in transactions %} - - - - - - - - {% empty %} - - - - {% endfor%} -
DatePayment MethodAmountStatus
{{ tx.created_at }} - {% if tx.payment_instrument_type == "paypal_account" %} - Paypal from {{ tx.paypal.payer_email }} - {% endif %} - - {% if tx.payment_instrument_type == "credit_card" %} - {{ tx.credit_card.card_type }} ending in {{ tx.credit_card.last_4 }} - {% endif %} - - {% if tx.currency_iso_code == "USD" %} - ${{ tx.amount }} - {% elif tx.currency_iso_code == "EUR" %} - €{{ tx.amount }} - {% else %} - {{ tx.currency_iso_code }} {{ tx.amount }} - {% endif %} - {{ tx.status }} - View Invoice -
- No past transactions to display here -
{% endblock %}