Midnightar commited on
Commit
d260f0e
·
verified ·
1 Parent(s): d2f0363

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -8
app.py CHANGED
@@ -1,8 +1,14 @@
1
  from flask import Flask, request, jsonify
 
2
 
3
  app = Flask(__name__)
4
 
5
- # Route 1: PayerMax Callback (used in PayerMax Dashboard)
 
 
 
 
 
6
  @app.route("/payermax", methods=["POST", "GET"])
7
  def payermax_notify():
8
  try:
@@ -15,14 +21,12 @@ def payermax_notify():
15
  return "success", 200
16
 
17
 
18
- # ✅ Route 2: Test Endpoint (you’ll call this from FlutterFlow)
19
  @app.route("/test", methods=["POST"])
20
  def test_endpoint():
21
  try:
22
  data = request.get_json(force=True, silent=True)
23
  print("🧪 FlutterFlow test data:", data)
24
-
25
- # Send back a response to show it works
26
  return jsonify({
27
  "status": "ok",
28
  "message": "Received test data successfully!",
@@ -30,10 +34,34 @@ def test_endpoint():
30
  }), 200
31
  except Exception as e:
32
  print("🔥 Error in test endpoint:", str(e))
33
- return jsonify({
34
- "status": "error",
35
- "message": str(e)
36
- }), 500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
 
39
  if __name__ == "__main__":
 
1
  from flask import Flask, request, jsonify
2
+ import base64, hashlib, hmac, rsa
3
 
4
  app = Flask(__name__)
5
 
6
+ # ⚙️ Replace this with your real PayerMax private key (PEM string)
7
+ PRIVATE_KEY = """-----BEGIN RSA PRIVATE KEY-----
8
+ YOUR_RSA_PRIVATE_KEY_CONTENT_HERE
9
+ -----END RSA PRIVATE KEY-----"""
10
+
11
+ # ✅ 1. PayerMax callback endpoint
12
  @app.route("/payermax", methods=["POST", "GET"])
13
  def payermax_notify():
14
  try:
 
21
  return "success", 200
22
 
23
 
24
+ # ✅ 2. FlutterFlow test endpoint
25
  @app.route("/test", methods=["POST"])
26
  def test_endpoint():
27
  try:
28
  data = request.get_json(force=True, silent=True)
29
  print("🧪 FlutterFlow test data:", data)
 
 
30
  return jsonify({
31
  "status": "ok",
32
  "message": "Received test data successfully!",
 
34
  }), 200
35
  except Exception as e:
36
  print("🔥 Error in test endpoint:", str(e))
37
+ return jsonify({"status": "error", "message": str(e)}), 500
38
+
39
+
40
+ # ✅ 3. Signature generator endpoint
41
+ @app.route("/sign", methods=["POST"])
42
+ def sign_payload():
43
+ """
44
+ Expects JSON body with a single field `payload` (the string you need to sign).
45
+ Returns base64-encoded RSA-SHA256 signature.
46
+ """
47
+ try:
48
+ data = request.get_json(force=True)
49
+ payload = data.get("payload", "")
50
+ if not payload:
51
+ return jsonify({"error": "Missing 'payload' field"}), 400
52
+
53
+ # Load private key
54
+ priv_key = rsa.PrivateKey.load_pkcs1(PRIVATE_KEY.encode())
55
+
56
+ # Create signature
57
+ signature = rsa.sign(payload.encode(), priv_key, 'SHA-256')
58
+ signature_b64 = base64.b64encode(signature).decode()
59
+
60
+ print("✅ Generated signature for payload:", payload)
61
+ return jsonify({"signature": signature_b64}), 200
62
+ except Exception as e:
63
+ print("🔥 Error generating signature:", str(e))
64
+ return jsonify({"error": str(e)}), 500
65
 
66
 
67
  if __name__ == "__main__":