forked from PolyLAN/polybanking
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lot of things, main base for transaction, trasactions working, sample
client.
- Loading branch information
Showing
31 changed files
with
1,045 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
config.py |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h3>PolyBanking Test/Demo client</h3> | ||
|
||
We're back. {% if result %}Status seem ok{% else %}Status seem err{%endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<h3>PolyBanking Test/Demo client</h3> | ||
|
||
<a href="/start?amount=10000">New payement, 100.-</a><br /> | ||
<a href="/start?amount=1000000">New payement, 10'000.-</a><br /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<h3>PolyBanking Test/Demo client</h3> | ||
|
||
Result is {{result}}. | ||
|
||
User should go to <a href="{{url}}">{{url}}</a><br /><br /> | ||
|
||
<a href="/">Home</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import requests | ||
import hashlib | ||
from django.conf import settings | ||
|
||
|
||
class PostFinance(): | ||
"""Api for postfinance""" | ||
|
||
def __init__(self, SHA_IN, SHA_OUT, PSPID, testMode=False): | ||
self.SHA_IN = SHA_IN | ||
self.SHA_OUT = SHA_OUT | ||
self.PSPID = PSPID | ||
self.testMode = testMode | ||
|
||
def computeSign(self, secret, data): | ||
"""Compute a SHA signature following PostFinance's protocol""" | ||
|
||
h = hashlib.sha512() | ||
|
||
for key, value in sorted(data.iteritems(), key=lambda (k, v): k): | ||
h.update(key) | ||
h.update('=') | ||
h.update(value) | ||
h.update(secret) | ||
|
||
return h.hexdigest() | ||
|
||
def computeOutSign(self, data): | ||
"""Compute a SHA signature following PostFinance's protocol using OUT key""" | ||
return self.computeSign(self.SHA_OUT, data) | ||
|
||
def computeInSign(self, data): | ||
"""Compute a SHA signature following PostFinance's protocol using IN key""" | ||
return self.computeSign(self.SHA_IN, data) | ||
|
||
def getPspIp(self): | ||
"""Return the pspId""" | ||
return self.PSPID | ||
|
||
|
||
def buildPostFinance(testMode=False): | ||
"""Return a postfinance object with correct parameters""" | ||
|
||
if testMode: | ||
return PostFinance(settings.SHA_IN_TEST, settings.SHA_OUT_TEST, settings.PSPID_TEST, True) | ||
else: | ||
return PostFinance(settings.SHA_IN_PROD, settings.SHA_OUT_PROD, settings.PSPID_PROD, False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import hashlib | ||
|
||
|
||
def compute_sign(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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
from django.db import models | ||
|
||
# Create your models here. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
import datetime | ||
from south.db import db | ||
from south.v2 import SchemaMigration | ||
from django.db import models | ||
|
||
|
||
class Migration(SchemaMigration): | ||
|
||
def forwards(self, orm): | ||
pass | ||
|
||
def backwards(self, orm): | ||
pass | ||
|
||
models = { | ||
|
||
} | ||
|
||
complete_apps = ['paiements'] |
Oops, something went wrong.