forked from Nickbahson/python-payment-gateway-using-rapyd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
55 lines (44 loc) · 1.9 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from flask import Flask, request, redirect
import utilities
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def app_home():
# payment form submissions (payment-form name) in html below.
if request.method == 'POST' and request.form['amount']:
amount = int(request.form['amount'])
body = {
'amount': amount,
'complete_checkout_url': 'http://example.com/complete',
'country': 'US',
'currency': 'USD',
'cancel_checkout_url': 'http://example.com/cancel',
'language': 'en',
}
try:
# Generate checkout with this payment object
req = utilities.make_request('post', '/v1/checkout', body)
print('++++++ payment created +++++')
print(req['data']['redirect_url'])
print('++++++ payment created +++++')
# Redirect to checkout.
return redirect(req['data']['redirect_url'])
except Exception as ex:
print(ex)
# Checkout html
checkout_markup = "<div> <h1>Welcome to my Website!</h1> <hr>" \
"<h1> Checkout my upcoming event</h1> " \
"<section><h3>Consuming 3rd party apis (online)</h3> " \
"<p>Introduction to Postman Collections and api examples</p>" \
"<bold>$100</bold> <p></p>" \
"<form name=payment-form method=POST> " \
"<input type=hidden name=amount value=100>" \
" <input type=submit value=\"Reserve your slot \" name=submit>" \
"</form>" \
"</section><hr>" \
"</div>"
return checkout_markup
@app.route('/rapyd-webhooks', methods=['POST'])
def rapyd_webhooks():
print("Data received from Rapyd Webhook event is : ", request.json)
return "Data received"
app.run(debug=True)