diff --git a/fosspay/app.py b/fosspay/app.py index 3ea8680..d50fe5a 100644 --- a/fosspay/app.py +++ b/fosspay/app.py @@ -74,5 +74,6 @@ def inject(): 'user': current_user, '_cfg': _cfg, '_cfgi': _cfgi, - 'debug': app.debug + 'debug': app.debug, + 'str': str } diff --git a/fosspay/blueprints/html.py b/fosspay/blueprints/html.py index 48bd5b4..9c59574 100644 --- a/fosspay/blueprints/html.py +++ b/fosspay/blueprints/html.py @@ -53,9 +53,11 @@ def admin(): first = request.args.get("first-run") is not None projects = Project.query.all() unspecified = Donation.query.filter(Donation.project == None).all() + donations = Donation.query.order_by(Donation.created.desc()).limit(50).all() return render_template("admin.html", first=first, projects=projects, + donations=donations, one_times=lambda p: sum([d.amount for d in p.donations if d.type == DonationType.one_time]), recurring=lambda p: sum([d.amount for d in p.donations if d.type == DonationType.monthly]), unspecified_one_times=sum([d.amount for d in unspecified if d.type == DonationType.one_time]), @@ -108,6 +110,8 @@ def donate(): type = request.form.get("type") comment = request.form.get("comment") project_id = request.form.get("project") + + # validate and rejigger the form inputs if not email or not stripe_token or not amount or not type: return { "success": False, "reason": "Invalid request" }, 400 try: @@ -134,8 +138,13 @@ def donate(): customer = stripe.Customer.create(email=user.email, card=stripe_token) user.stripe_customer = customer.id db.add(user) + else: + customer = stripe.Customer.retrieve(user.stripe_customer) + new_source = customer.sources.create(source=stripe_token) + customer.default_source = new_source.id + customer.save() - donation = Donation(user, type, amount, project) + donation = Donation(user, type, amount, project, comment) db.add(donation) try: diff --git a/fosspay/objects.py b/fosspay/objects.py index 45506c2..504727d 100644 --- a/fosspay/objects.py +++ b/fosspay/objects.py @@ -60,14 +60,16 @@ class Donation(Base): amount = Column(Integer, nullable=False) created = Column(DateTime, nullable=False) emailed_about = Column(Boolean, nullable=False) + comment = Column(String(512)) - def __init__(self, user, type, amount, project=None): + def __init__(self, user, type, amount, project=None, comment=None): self.user = user self.type = type self.amount = amount self.created = datetime.now() self.emailed_about = False self.project = project + self.comment = comment def __repr__(self): return "".format( diff --git a/scripts/index.js b/scripts/index.js index dd19977..6b243b2 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -64,6 +64,8 @@ return; } + donation.comment = document.getElementById("comments").value; + var handler = StripeCheckout.configure({ name: your_name, key: window.stripe_key, diff --git a/templates/admin.html b/templates/admin.html index 7a75359..203e955 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -6,9 +6,14 @@

- Log Out + + Get donation button + + Log out

Donation Admin

+

Combine this with your Stripe + dashboard for the full effect.

@@ -52,7 +57,6 @@ Project Name One-time Recurring - README Button @@ -62,7 +66,6 @@ {{ project.name }} ${{ "{:.2f}".format(one_times(project) / 100) }} ${{ "{:.2f}".format(recurring(project) / 100) }} - Get Markdown {% endfor %} @@ -70,7 +73,6 @@ (not specified) ${{ "{:.2f}".format(unspecified_one_times / 100) }} ${{ "{:.2f}".format(unspecified_recurring / 100) }} - @@ -86,7 +88,7 @@
-

Donation History

+

Recent Donations 50 most recent

@@ -94,9 +96,53 @@ - + + + {% for donation in donations %} + + + + + + + + {% endfor %} +
Project Comment AmountRecurringType
{{ donation.user.email }}{{ donation.project.name if donation.project else "" }}{{ donation.comment if donation.comment else "" }}${{ "{:.2f}".format(donation.amount / 100) }}{{ "Once" if str(donation.type) == "DonationType.one_time" else "Monthly" }}
+ + {% endblock %} diff --git a/templates/index.html b/templates/index.html index 9e3b09e..57d0491 100644 --- a/templates/index.html +++ b/templates/index.html @@ -123,7 +123,7 @@ window.default_type = "{{ _cfg("default-type") }}";
- +
diff --git a/templates/layout.html b/templates/layout.html index 3f0ab06..4003cb1 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -2,6 +2,7 @@ + {% block title %} Donate to {{_cfg("your-name")}} diff --git a/templates/panel.html b/templates/panel.html index 8e9d035..af7af5f 100644 --- a/templates/panel.html +++ b/templates/panel.html @@ -3,8 +3,8 @@

- Donate Again - Log Out + Donate again + Log out

Your Donations