Python Integration Guide
index.py – Start Payment
index.js
1from flask import Flask, request, session
2from functions import verify_payment
3
4app = Flask(__name__)
5app.secret_key = "your_secret_key_here"
6
7@app.route('/verify')
8def verify_transaction():
9 status = request.args.get('status')
10 if status != "success":
11 return "<h1>Transaction was unsuccessful</h1>"
12
13 api_key = 'sandbox'
14 token = session.get('token')
15 amount = 10000
16
17 result = verify_payment(api_key, token, amount)
18
19 if result.get('success'):
20 return "<h1>Transaction was successful</h1>"
21 else:
22 return f"<h1>Transaction failed</h1><p>{result.get('errors')}</p>"
23
24if __name__ == '__main__':
25 app.run(debug=True)
verify.py – Verify Transaction
index.js
1from flask import Flask, request, session
2from functions import verify_payment
3
4app = Flask(__name__)
5app.secret_key = "your_secret_key_here"
6
7@app.route('/verify')
8def verify_transaction():
9 status = request.args.get('status')
10 if status != "success":
11 return "<h1>Transaction was unsuccessful</h1>"
12
13 api_key = 'sandbox'
14 token = session.get('token')
15 amount = 10000
16
17 result = verify_payment(api_key, token, amount)
18
19 if result.get('success'):
20 return "<h1>Transaction was successful</h1>"
21 else:
22 return f"<h1>Transaction failed</h1><p>{result.get('errors')}</p>"
23
24if __name__ == '__main__':
25 app.run(debug=True)
functions.py – Helper Functions
index.js
1from flask import Flask, request, session
2from functions import verify_payment
3
4app = Flask(__name__)
5app.secret_key = "your_secret_key_here"
6
7@app.route('/verify')
8def verify_transaction():
9 status = request.args.get('status')
10 if status != "success":
11 return "<h1>Transaction was unsuccessful</h1>"
12
13 api_key = 'sandbox'
14 token = session.get('token')
15 amount = 10000
16
17 result = verify_payment(api_key, token, amount)
18
19 if result.get('success'):
20 return "<h1>Transaction was successful</h1>"
21 else:
22 return f"<h1>Transaction failed</h1><p>{result.get('errors')}</p>"
23
24if __name__ == '__main__':
25 app.run(debug=True)
Sandbox mode API endpoint:
1https://sandbox.coinpay.ir/api/v1
Sandbox mode API endpoint:
1https://coinpay.ir/api/v1
Important Notes
Install Dependencies: Flask and requests are required.
1pip install flask requests
- Replace `secret_key` with a secure random value.
- Switch from sandbox to https://coinpay.ir/api/v1/... in production.