forked from GithubBackups/healthchecks
Users can edit their company details for invoices.
This commit is contained in:
parent
dfed908873
commit
d6917065d4
5
hc/payments/forms.py
Normal file
5
hc/payments/forms.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from django import forms
|
||||||
|
|
||||||
|
|
||||||
|
class BillToForm(forms.Form):
|
||||||
|
bill_to = forms.CharField(max_length=500, required=False)
|
@ -24,3 +24,11 @@ class BillingTestCase(BaseTestCase):
|
|||||||
r = self.client.get("/billing/")
|
r = self.client.get("/billing/")
|
||||||
self.assertContains(r, "123")
|
self.assertContains(r, "123")
|
||||||
self.assertContains(r, "def456")
|
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")
|
||||||
|
@ -6,7 +6,8 @@ from django.http import (HttpResponseBadRequest, HttpResponseForbidden,
|
|||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
from django.views.decorators.http import require_POST
|
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:
|
if settings.USE_PAYMENTS:
|
||||||
import braintree
|
import braintree
|
||||||
@ -177,6 +178,13 @@ def cancel_plan(request):
|
|||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def billing(request):
|
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)
|
sub = Subscription.objects.get(user=request.user)
|
||||||
|
|
||||||
transactions = braintree.Transaction.search(
|
transactions = braintree.Transaction.search(
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.channels-table .channel-row > td {
|
.channels-table .channel-row > td {
|
||||||
padding: 10px 0;
|
padding-top: 10px;
|
||||||
|
padding-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.channels-table .value-cell {
|
.channels-table .value-cell {
|
||||||
|
@ -4,50 +4,95 @@
|
|||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h1>Billing History</h1>
|
<h1>Billing History</h1>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-9">
|
||||||
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
<th>Payment Method</th>
|
<th>Payment Method</th>
|
||||||
<th>Amount</th>
|
<th>Amount</th>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for tx in transactions %}
|
{% for tx in transactions %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ tx.created_at }}</td>
|
<td>{{ tx.created_at }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% if tx.payment_instrument_type == "paypal_account" %}
|
{% if tx.payment_instrument_type == "paypal_account" %}
|
||||||
Paypal from {{ tx.paypal.payer_email }}
|
Paypal from {{ tx.paypal.payer_email }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if tx.payment_instrument_type == "credit_card" %}
|
||||||
|
{{ tx.credit_card.card_type }} ending in {{ tx.credit_card.last_4 }}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if tx.currency_iso_code == "USD" %}
|
||||||
|
${{ tx.amount }}
|
||||||
|
{% elif tx.currency_iso_code == "EUR" %}
|
||||||
|
€{{ tx.amount }}
|
||||||
|
{% else %}
|
||||||
|
{{ tx.currency_iso_code }} {{ tx.amount }}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td><code>{{ tx.status }}</code></td>
|
||||||
|
<td>
|
||||||
|
<a href="{% url 'hc-invoice' tx.id %}">View Invoice</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% empty %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="5">
|
||||||
|
No past transactions to display here
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor%}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<p><strong>Bill to:</strong></p>
|
||||||
|
<p>
|
||||||
|
{% if request.user.profile.bill_to %}
|
||||||
|
{{ request.user.profile.bill_to|linebreaksbr }}
|
||||||
|
{% else %}
|
||||||
|
{{ request.user.email }}
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
data-toggle="modal"
|
||||||
|
data-target="#bill-to-modal"
|
||||||
|
class="btn btn-default">
|
||||||
|
Edit Company Details…
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="bill-to-modal" class="modal">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<form id="bill-to-form" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||||
|
<h4>Company Details for Invoice</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<textarea
|
||||||
|
name="bill_to"
|
||||||
|
class="form-control"
|
||||||
|
rows="5">{{ request.user.profile.bill_to|default:request.user.email }}</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% if tx.payment_instrument_type == "credit_card" %}
|
|
||||||
{{ tx.credit_card.card_type }} ending in {{ tx.credit_card.last_4 }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{% if tx.currency_iso_code == "USD" %}
|
|
||||||
${{ tx.amount }}
|
|
||||||
{% elif tx.currency_iso_code == "EUR" %}
|
|
||||||
€{{ tx.amount }}
|
|
||||||
{% else %}
|
|
||||||
{{ tx.currency_iso_code }} {{ tx.amount }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
<td><code>{{ tx.status }}</code></td>
|
|
||||||
<td>
|
|
||||||
<a href="{% url 'hc-invoice' tx.id %}">View Invoice</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% empty %}
|
|
||||||
<tr>
|
|
||||||
<td colspan="5">
|
|
||||||
No past transactions to display here
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor%}
|
|
||||||
</table>
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user