62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
import os
|
|
|
|
from flask import Flask, redirect, request, jsonify
|
|
|
|
from yoomoney import Quickpay
|
|
from check_ip import check_user_ip
|
|
from reg import paid
|
|
|
|
app = Flask(__name__)
|
|
|
|
remote_docker_address = os.environ.get('REMOTE_ADDRESS', 'Empty')
|
|
|
|
@app.route('/pay', methods=['POST'])
|
|
def process_data():
|
|
#client_ip = request.remote_addr
|
|
#print(client_ip)
|
|
# if not check_user_ip(client_ip) and client_ip != "127.0.0.1" and client_ip != remote_docker_address:
|
|
# return jsonify({"mes" : "Nice try"}), 403
|
|
|
|
data = request.get_json()
|
|
print(data)
|
|
if not data or 'sum' not in data or 'id' not in data:
|
|
return jsonify({"error": "Invalid data: 'sum' and 'id' are required"}), 400
|
|
|
|
sum_value = data['sum']
|
|
id_value = data['id']
|
|
|
|
quickpay = Quickpay(
|
|
receiver="410012845407838", # change
|
|
quickpay_form="shop",
|
|
targets="Pay or get out",
|
|
paymentType="SB",
|
|
sum=sum_value,
|
|
label=id_value
|
|
)
|
|
redirect_url = quickpay.redirected_url
|
|
|
|
response = {
|
|
"message": "SUCCESS",
|
|
"redir_url" : redirect_url
|
|
}
|
|
|
|
return jsonify(response), 200
|
|
|
|
@app.route('/check_pay', methods=['GET', 'POST'])
|
|
def check_pay():
|
|
#client_ip = request.remote_addr
|
|
# if not check_user_ip(client_ip) and client_ip != "127.0.0.1" and client_ip != remote_docker_address:
|
|
# return jsonify({"mes" : "Nice try"}), 403
|
|
|
|
data = request.get_json()
|
|
if not data or 'uuid' not in data:
|
|
return jsonify({"mes": "Invalid data: 'id' is required"}), 400
|
|
|
|
id_value = data['uuid']
|
|
resp = paid(id_value)
|
|
if resp:
|
|
return jsonify({"mes" : "OK"}), 200
|
|
return jsonify({"mes" : "ERR"}), 400
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True, host='0.0.0.0') |