-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
64 lines (52 loc) · 1.63 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
56
57
58
59
60
61
62
63
64
import requests
from flask import Flask, render_template, request, jsonify, redirect, url_for,send_from_directory
import uuid
import squareAuth
app = Flask(__name__)
idempotency_key = str(uuid.uuid4())
@app.route('/')
def index():
return render_template('index.html')
@app.route('/charge', methods=['POST','GET'])
def charge():
amount = int(request.form['amount'])
email = request.form['email']
fullName = request.form['fullName']
phone_number = request.form['phoneNumber']
txRef = request.form['txRef']
result = squareAuth.client.checkout.create_payment_link(
body = {
"idempotency_key": idempotency_key,
"quick_pay": {
"name": 'fullName',
"price_money": {
"amount": 150,
"currency": "USD"
},
"location_id": "LJGHD7PBGN574"
},
"pre_populated_data": {}
}
)
if result.is_success():
response_data = result.body
# print(result.body)
elif result.is_error():
print(result.errors)
# Assuming 'response' contains the JSON response you provided
payment_link = response_data.get('payment_link', {})
# Extract the payment URL
payment_url = payment_link.get('url')
if payment_url:
print(f'Payment URL for redirection: {payment_url}')
return redirect(payment_url)
else:
print('Payment URL not found in the response.')
@app.route('/images/<filename>')
def get_image(filename):
return send_from_directory('images', filename)
@app.route('/success')
def success():
return render_template('success.html')
# if __name__ == '__main__':
# app.run()