diff --git a/client/.gitignore b/client/.gitignore new file mode 100644 index 0000000..f85c6b1 --- /dev/null +++ b/client/.gitignore @@ -0,0 +1 @@ +config.py \ No newline at end of file diff --git a/client/config.py.dist b/client/config.py.dist new file mode 100644 index 0000000..e69de29 diff --git a/client/httpd.py b/client/httpd.py new file mode 100644 index 0000000..bf1f26d --- /dev/null +++ b/client/httpd.py @@ -0,0 +1,35 @@ +from flask import Flask +from flask import render_template +from flask import request + +import config +from libs.polybanking import PolyBanking + +import uuid + +api = PolyBanking(config.POLYBANKING_SERVER, config.CONFIG_ID, config.KEY_REQUESTS, config.KEY_IPN, config.KEY_API) + +app = Flask(__name__) + + +@app.route("/") +def home(): + """Display the home page""" + return render_template('home.html') + + +@app.route('/start') +def start(): + """Start a new paiement""" + + (result, url) = api.new_transation(request.args.get('amount', ''), str(uuid.uuid4())) + + return render_template('start.html', result=result, url=url) + +@app.route('/back') +def back(): + + return render_template('back.html', result='ok' in request.args) + +if __name__ == "__main__": + app.run(debug=True) diff --git a/client/libs/__init__.py b/client/libs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/client/libs/polybanking.py b/client/libs/polybanking.py new file mode 100644 index 0000000..0a95d66 --- /dev/null +++ b/client/libs/polybanking.py @@ -0,0 +1,47 @@ +import requests +import hashlib + + +class PolyBanking(): + """Api for polybanking accesses""" + + def __init__(self, server, config_id, keyRequests, keyIPN, keyAPI): + self.server = server + self.config_id = config_id + self.keyRequests = keyRequests + self.keyIPN = keyIPN + self.keyAPI = keyAPI + + def compute_sign(self, secret, data): + """Compute the signature for a dict""" + + def escape_chars(s): + """Remove = and ; from a string""" + return s.replace(';', '!!').replace('=', '??') + + h = hashlib.sha512() + + for key, value in sorted(data.iteritems(), key=lambda (k, v): k): + h.update(escape_chars(key)) + h.update('=') + h.update(escape_chars(value)) + h.update(';') + h.update(secret) + h.update(';') + + return h.hexdigest() + + def new_transation(self, amount, reference, extra_data=''): + """Start a new transation, with the specified amount and reference. The reference must be unique. + Return (Status, the URL where the user should be redirected or None) + Status can be 'OK', 'KEY_ERROR', 'CONFIG_ERROR', 'AMOUNT_ERROR', 'REFERENCE_ERROR', 'ERROR'""" + + data = {'amount': amount, 'reference': reference, 'extra_data': extra_data, 'config_id': self.config_id} + + data['sign'] = self.compute_sign(self.keyRequests, data) + + try: + result = requests.post(self.server + '/paiements/start/', data=data).json() + return (result['status'], result['url']) + except: + return ('ERROR', '') diff --git a/client/templates/back.html b/client/templates/back.html new file mode 100644 index 0000000..6e8ebf8 --- /dev/null +++ b/client/templates/back.html @@ -0,0 +1,3 @@ +
{{object.admin_enable|yesno}}
+{{object.pk}}
+
diff --git a/server/configs/urls.py b/server/configs/urls.py
index 85d0b78..c827e54 100644
--- a/server/configs/urls.py
+++ b/server/configs/urls.py
@@ -6,14 +6,14 @@
'configs.views',
url(r'^$', 'list'),
- url(r'^(?PPolyBanking
+
+ {% trans "You are being redirect to the PostFinance's website. Please wait :)" %}
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/server/paiements/templates/paiements/transactions/list.html b/server/paiements/templates/paiements/transactions/list.html
new file mode 100644
index 0000000..e76f59a
--- /dev/null
+++ b/server/paiements/templates/paiements/transactions/list.html
@@ -0,0 +1,85 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block title %}{{block.super}} :: {% trans "Transactions" %} :: {% trans "List" %}{% endblock %}
+
+{% block content %}
+
+
+
+{% trans "Configs" %}
+
+
+
+
+ {% if configPk == 'all' %}
+ {% trans "List of all transactions" %}
+ {% else %}
+ {% trans "List of transactions" %} ({{config|safe}})
+ {% endif %}
+
+
+
+
+
+ {% if user.is_superuser or user.is_staff %}
+
+ {% endif %}
+
+
+
+
+
+ {% for elem in list %}
+ {% trans "Reference" %}
+ {% trans "Amount" %}
+ {% trans "Postfinance status" %}
+ {% trans "Internal status" %}
+ {% trans "Date" %}
+
+
+
+ {% endfor %}
+
+
+ {{elem.reference}}
+ {{elem.amount_chf|floatformat:"2"}} CHF
+ {{elem.get_postfinance_status_display}}
+ {{elem.get_internal_status_display}}
+ {{elem.creation_date|date}} {{elem.creation_date|time}} ({{elem.creation_date|timesince}})
+
+ {% trans "Logs" %}
+
+