Last active
August 29, 2015 14:17
-
-
Save pedroburon/f8de2e1dc9e8b8edb617 to your computer and use it in GitHub Desktop.
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
import urllib2 | |
from flask import Flask, redirect, request | |
from tbk.webpay.commerce import Commerce | |
from tbk.webpay.confirmation import Confirmation | |
from tbk.webpay.payment import Payment | |
app = Flask(__name__) | |
commerce = Commerce(testing=True) | |
server_ip = urllib2.urlopen('http://ip.42.pl/raw').read() | |
server_domain = 'pagos.domain.cl' | |
port = 80 | |
@app.route("/") | |
def index(): | |
payment = Payment( | |
request_ip=request.remote_addr, | |
commerce=commerce, | |
success_url='http://%s:%s/webpay/success' % (server_domain, port), | |
confirmation_url='http://%s:%s/webpay/confirmation' % (server_ip, port), | |
failure_url='http://%s:%s/webpay/failure' % (server_domain, port), | |
session_id='1313', | |
amount=123456, | |
order_id=1, | |
) | |
return redirect(payment.redirect_url, code=302) | |
@app.route("/webpay/success", methods=['POST']) | |
def success(): | |
return "success" | |
@app.route("/webpay/failure", methods=['POST']) | |
def failure(): | |
return "failure" | |
@app.route("/webpay/confirmation", methods=['POST']) | |
def confirmation(): | |
confirmation = Confirmation( | |
commerce=commerce, | |
request_ip=request.remote_addr, | |
data=request.form | |
) | |
# validate_confirmation validate if order_id and amount are valid. | |
if confirmation.is_success(): | |
return commerce.acknowledge | |
return commerce.reject | |
if __name__ == "__main__": | |
app.run(host='0.0.0.0', port=port, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment