diff --git a/fosspay/blueprints/html.py b/fosspay/blueprints/html.py index f8ba861..db3581c 100644 --- a/fosspay/blueprints/html.py +++ b/fosspay/blueprints/html.py @@ -295,3 +295,10 @@ def cancel(id): db.commit() send_cancellation_notice(user, donation) return redirect("/panel") + +@html.route("/invoice/") +def invoice(id): + invoice = Invoice.query.filter(Invoice.external_id == id).first() + if not invoice: + abort(404) + return render_template("invoice.html", invoice=invoice) diff --git a/fosspay/objects.py b/fosspay/objects.py index 562ff4d..3607796 100644 --- a/fosspay/objects.py +++ b/fosspay/objects.py @@ -8,6 +8,7 @@ from .database import Base from datetime import datetime from enum import Enum import bcrypt +import binascii import os import hashlib @@ -99,3 +100,15 @@ class Project(Base): def __repr__(self): return "".format(self.id, self.name) + +class Invoice(Base): + __tablename__ = 'invoices' + id = Column(Integer, primary_key=True) + created = Column(DateTime, nullable=False) + external_id = Column(String(16), index=True) + amount = Column(Integer, nullable=False) + comment = Column(String(512), nullable=False) + + def __init__(self): + self.external_id = binascii.hexlify(os.urandom(8)).decode() + self.created = datetime.now() diff --git a/invoice b/invoice new file mode 100755 index 0000000..e2d32da --- /dev/null +++ b/invoice @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +from fosspay.database import db +from fosspay.objects import Invoice +from fosspay.config import _cfg +import sys + +if len(sys.argv) != 3: + print(f"Usage: {sys.argv[0]} ") + sys.exit(1) + +amount = int(sys.argv[1]) +comment = sys.argv[2] + +invoice = Invoice() +invoice.amount = amount +invoice.comment = comment +db.add(invoice) +db.commit() + +print(f"{_cfg('protocol')}://{_cfg('domain')}/invoice/{invoice.external_id}") diff --git a/templates/invoice.html b/templates/invoice.html new file mode 100644 index 0000000..be5de7e --- /dev/null +++ b/templates/invoice.html @@ -0,0 +1,60 @@ +{% extends "layout.html" %} +{% block scripts %} + + + +{% endblock %} +{% block body %} + + + + + Invoice to {{ _cfg("your-name") }} + + + + + + + + This page requires Javascript. It's necessary to send your credit card number to + Stripe directly. + + + + + Thank you for your payment - it has been processed successfully. + + + Invoice for ${{"{:.2f}".format(invoice.amount / 100)}} + + + + {{invoice.comment}} + + + + + + + + Submit Payment + + + + + + + + Powered by fosspay. + + + +{% endblock %}
This page requires Javascript. It's necessary to send your credit card number to + Stripe directly.
Thank you for your payment - it has been processed successfully.
+ {{invoice.comment}} +
+ + Powered by fosspay. + +