Commit 4cd66e0f authored by Mindiell's avatar Mindiell
Browse files

Added a page in order to choose payment way, plus signature is now ok

parent 26421c86
ve/
__pycache__
config.py
db.sqlite3
......
#encoding: utf-8
from flask import render_template, request, redirect
from flask import render_template, request, redirect, session
import requests
from random import randint
import hashlib
import config
from app.controller.controller import Controller
class Core(Controller):
......@@ -13,52 +14,57 @@ class Core(Controller):
def payment(self):
"""
Processing fake payment request
Example of datas POSTed
('signature', '8736af0cd9d457f5e15ec7bf10005a12a9d2ff48'),
('vads_url_check', 'https://localhost/payment/pledge/check/'),
('vads_shop_url', 'https://localhost'),
('submit', 'Valider ce don'),
('vads_page_action', 'PAYMENT'),
('vads_redirect_error_timeout', '5'),
('vads_trans_date', '20180310080607'),
('vads_trans_id', '000004'),
('csrfmiddlewaretoken', 'xe6CYxhA4Esa4zBmPAT7Ee29hAlZtYKld0o4waId5hxi5IvRbvZU787mzbbySLnU'),
('vads_ctx_mode', 'TEST'),
('vads_redirect_success_timeout', '5'),
('vads_validation_mode', '0'),
('vads_return_mode', 'GET'),
('vads_language', 'fr'),
('vads_action_mode', 'INTERACTIVE'),
('vads_currency', '978'),
('vads_site_id', '1'),
('vads_capture_delay', '0'),
('vads_url_return', 'https://localhost/payment/pledge/4/return/'),
('vads_amount', '3000'),
('vads_version', 'V2'),
('vads_shop_name', 'localhost:8000'),
('vads_payment_config', 'SINGLE')
"""
# First of all, let's keep posted datas
session['url_check'] = request.form.get('vads_url_check').replace('https', 'http')
session['url_return'] = request.form.get('vads_url_return').replace('https', 'http')
session['vads_trans_date'] = request.form.get('vads_trans_date')
session['vads_trans_id'] = request.form.get('vads_trans_id')
session['vads_order_id'] = request.form.get('vads_order_id')
session['vads_action_mode'] = request.form.get('vads_action_mode')
session['vads_ctx_mode'] = request.form.get('vads_ctx_mode')
session['vads_language'] = request.form.get('vads_language')
session['vads_page_action'] = request.form.get('vads_page_action')
session['vads_site_id'] = request.form.get('vads_site_id')
session['vads_presentation_date'] = request.form.get('vads_trans_date')
session['vads_currency'] = request.form.get('vads_currency')
session['vads_amount'] = request.form.get('vads_amount')
session['vads_effective_amount'] = request.form.get('vads_amount')
session['vads_effective_creation_date'] = request.form.get('vads_trans_date')
session['vads_effective_currency'] = request.form.get('vads_currency')
session['vads_payment_config'] = request.form.get('vads_payment_config')
session['vads_cust_email'] = request.form.get('vads_cust_email')
session['vads_identifier'] = request.form.get('vads_identifier')
session['vads_sub_amount'] = request.form.get('vads_sub_amount')
session['vads_sub_currency'] = request.form.get('vads_sub_currency')
session['vads_sub_desc'] = request.form.get('vads_sub_desc')
session['vads_sub_effect_date'] = request.form.get('vads_sub_effect_date')
session['vads_effective_amount'] = request.form.get('vads_sub_amount')
session['vads_effective_currency'] = request.form.get('vads_sub_currency')
session['vads_amount'] = request.form.get('vads_sub_amount')
session['vads_currency'] = request.form.get('vads_sub_currency')
url_check = request.form['vads_url_check'].replace('https', 'http')
url_return = request.form['vads_url_return'].replace('https', 'http')
# Then let the user choose if payment is ok or not
return render_template('core/payment.html')
def valid(self):
"""
Processing valid payment
"""
# Preparing answer data
params = {}
try:
params = {
'vads_trans_status' : 'AUTHORISED',
'vads_trans_date' : request.form['vads_trans_date'],
'vads_trans_id' : int(request.form['vads_trans_id']),
'vads_action_mode': request.form['vads_action_mode'],
'vads_ctx_mode': request.form['vads_ctx_mode'],
'vads_language': request.form['vads_language'],
'vads_page_action': request.form['vads_page_action'],
'vads_shop_url': request.form['vads_shop_url'],
'vads_site_id': request.form['vads_site_id'],
'vads_presentation_date': request.form['vads_trans_date'],
'signature' : '78cb45e9a68f0f7d27211bb194d0019c2d69ed03',
'vads_trans_date' : session['vads_trans_date'],
'vads_trans_id' : int(session['vads_trans_id']),
'vads_action_mode': session['vads_action_mode'],
'vads_ctx_mode': session['vads_ctx_mode'],
'vads_language': session['vads_language'],
'vads_page_action': session['vads_page_action'],
'vads_site_id': session['vads_site_id'],
'vads_presentation_date': session['vads_trans_date'],
'vads_order_id': session['vads_order_id'],
'vads_expiry_month': '12',
'vads_expiry_year': '2024',
......@@ -92,6 +98,7 @@ class Core(Controller):
'vads_threeds_xid': 'VkZHZVViWXpscWRDQkRjdWNuakE=',
'vads_trans_uuid': '6c673fec09d047bea48b8ac137c7d7e4',
'vads_url_check_src': 'PAY',
'vads_shop_url': '',
'vads_validation_mode': '0',
'vads_version': 'V2',
'vads_warranty_result': 'YES',
......@@ -99,47 +106,63 @@ class Core(Controller):
except:
print("error data basic")
try:
if request.form['vads_page_action']=='PAYMENT':
params['vads_currency'] = request.form['vads_currency']
params['vads_amount'] = request.form['vads_amount']
params['vads_effective_amount'] = request.form['vads_amount']
params['vads_effective_creation_date'] = request.form['vads_trans_date']
params['vads_effective_currency'] = request.form['vads_currency']
params['vads_payment_config'] = request.form['vads_payment_config']
if session['vads_page_action']=='PAYMENT':
params['vads_currency'] = session['vads_currency']
params['vads_amount'] = session['vads_amount']
params['vads_effective_amount'] = session['vads_amount']
params['vads_effective_creation_date'] = session['vads_trans_date']
params['vads_effective_currency'] = session['vads_currency']
params['vads_payment_config'] = session['vads_payment_config']
except:
print("error data payment")
try:
if request.form['vads_page_action']=='REGISTER_SUBSCRIBE':
params['vads_cust_email'] = request.form['vads_cust_email'] or 'test@test.fr'
params['vads_identifier'] = request.form['vads_identifier']
params['vads_sub_amount'] = request.form['vads_sub_amount']
params['vads_sub_currency'] = request.form['vads_sub_currency']
params['vads_sub_desc'] = request.form['vads_sub_desc']
params['vads_sub_effect_date'] = request.form['vads_sub_effect_date']
params['vads_effective_amount'] = request.form['vads_sub_amount']
params['vads_effective_currency'] = request.form['vads_sub_currency']
params['vads_amount'] = request.form['vads_sub_amount']
params['vads_currency'] = request.form['vads_sub_currency']
if session['vads_page_action']=='REGISTER_SUBSCRIBE':
params['vads_cust_email'] = session['vads_cust_email']
params['vads_identifier'] = session['vads_identifier']
params['vads_sub_amount'] = session['vads_sub_amount']
params['vads_sub_currency'] = session['vads_sub_currency']
params['vads_sub_desc'] = session['vads_sub_desc']
params['vads_sub_effect_date'] = session['vads_sub_effect_date']
params['vads_effective_amount'] = session['vads_sub_amount']
params['vads_effective_currency'] = session['vads_sub_currency']
params['vads_amount'] = session['vads_sub_amount']
params['vads_currency'] = session['vads_sub_currency']
params['vads_identifier_status'] = 'CREATED'
params['vads_recurrence_status'] = 'CREATED'
params['vads_subscription'] = 'SUBSCRIBED'
except:
print("error data subscribe")
print("="*42)
print(request.form)
params['signature'] = compute_signature(params)
print("="*42)
print(params)
print("="*42)
print(request.form['vads_url_check'], url_check)
print(request.form['vads_url_return'], url_return)
print(session['url_check'])
print(session['url_return'])
# Calling the check page
result = requests.post(url_check, data=params)
print(result)
with open('result.html', 'w') as f:
f.write(result.text)
url_check = config.CHECK_URL
if session['url_check']!='':
url_check = session['url_check']
if url_check!='':
result = requests.post(url_check, data=params)
print(result)
with open('result.html', 'w') as f:
f.write(result.text)
# Then, we need to redirect to the return page
return redirect(url_return)
if session['url_return']!='':
return redirect(session['url_return'])
# Else, let's display a single page
return render_template('core/end.html')
def compute_signature(form):
to_hash = '+'.join([str(form[f]) for f in sorted(form.keys()) if f.startswith('vads_')])
to_hash += '+{}'.format(config.VADS_PAYMENT_CERTIFICATE)
signature = hashlib.sha1()
signature.update(to_hash.encode())
return signature.hexdigest()
......@@ -5,6 +5,8 @@ from app.controller.core import Core
routes = [
('/', Core.as_view('home')),
('/payment', Core.as_view('payment'), ['GET', 'POST']),
('/valid', Core.as_view('valid')),
# ('/invalid', Core.as_view('invalid')),
]
apis = [
......
{% extends 'base.html' %}
{% block content %}
<!-- Content -->
<h1>FakeBank</h1>
<h2>Choose which way payment is going on :</h2>
<a href="{{ url_for('core.valid') }}">Authorized</a>
<br />
<a href="#">Refused</a>
{% endblock %}
......@@ -2,7 +2,7 @@
import os
APPLICATION = 'Flask MVC'
APPLICATION = 'Fake Bank'
DEBUG = False
HOST = '0.0.0.0'
......@@ -29,3 +29,7 @@ AVAILABLE_LANGUAGES = {
'en': 'English',
'fr': 'French',
}
VADS_PAYMENT_CERTIFICATE = '1234567890123456'
CHECK_URL = 'http://back_check_url'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment