Sindbad~EG File Manager
from flask import Flask, request, Blueprint, jsonify, redirect, url_for,flash, render_template,session
from core.model.UserModel import UserModel
from core.model.RazorpayModel import RazorpayModel
from core.model.InstamojoModel import InstamojoModel
from core.model.PayumoneyModel import PayumoneyModel
from core.model.APIModel import APIModel
from random import randint
import datetime
from datetime import timedelta,date,datetime
import requests, json
# from .. import Cryptography
from flask import session, app
import razorpay
from instamojo_wrapper import Instamojo
import flask
import base64
import urllib.parse
app = Flask(__name__,static_folder = "static", static_url_path='')
# razorpay_client = razorpay.Client(auth=("rzp_test_p0fCsPyrmeO28Q", "3dYe8yvI7gEzSeTaqREW4LUj"))
# client = razorpay.Client(auth=("<YOUR_KEY>", "<YOUR_SECRET>"))
app = Blueprint('razorpay', __name__)
@app.route('/razorpayment/<gateway_id>', methods = ["POST"])
def Payment_rayzorpay(gateway_id):
if request.method == 'POST':
base64_bytes = gateway_id.encode("ascii")
sample_bytes = base64.b64decode(base64_bytes)
gateway_id_str = sample_bytes.decode("ascii")
gateway_id_int = int(gateway_id_str)
gateway_data = PayumoneyModel().get_gateway(gateway_id_int)
now = datetime.now()
dt_string = now.strftime("%Y-%m-%d %H:%M:%S")
name = request.values.get("name",None)
email = request.values.get("email",None)
mobile = request.values.get("mobile",None)
amount = request.values.get("amount",None)
res_url = request.values.get("res_url",None)
remarks = request.values.get("remarks",None)
unique_id = request.values.get("unique_id",None) # This is added on feb 23 2020 like order id
key = request.values.get("key",None) # This is added on sep 24 2020 for merchant ref id
key_unique_id = key+"_"+str(unique_id)
is_test = request.values.get("is_test",None)
amount_int = amount
amount_int = amount_int[:-3]
if int(amount_int) <=0 or res_url is None :
return "Please enter response url and valid amount "
else :
gateway_name = "RazorPay"
currency = "INR"
# fetching data from form..
data = {
'name' : name,
'email' : email,
'mobile' : mobile,
'amount' : amount,
'gateway_name' : [gateway_name],
'key_val' : [key],
'is_test' : [is_test],
'remarks' : remarks,
'key_unique_id': [key_unique_id],
'created_at' : [dt_string],
'currency' : [currency],
'unique_id' : unique_id
}
delg_save =UserModel().insert_delegates(data,unique_id)
last_insert_id = delg_save
# encode res_url
url_byte = res_url.encode("ascii")
_bytes = base64.b64encode(url_byte)
r_url = _bytes.decode("ascii")
if int(is_test) == 1 :
# After save data in our database
gateway_name = gateway_data["gateway_name"]
api_key_1 = gateway_data["test_key"]
else :
gateway_name = gateway_data["gateway_name"]
api_key_1 = gateway_data["live_key"]
if gateway_name == "RazorPay":
delegates = UserModel().get_delegate_by_pid(last_insert_id)
amt = delegates["amount"]
amount = int(amt) * 100
return render_template('razorpay/razorpay_payment_screen.html',delegates = delegates,last_insert_id=last_insert_id,amount=amount,gateway_id=gateway_id_int,r_url=r_url,api_key_1=api_key_1,is_test =is_test)
else :
return "Invalid URL "
# if gateway_name == "Instamojo":
# test_auth_token = gateway_data.test_auth_token
# pay_test_link = gateway_data.pay_test_link
# p_id_ =str(last_insert_id)
# instamojo_api = Instamojo(api_key=api_key_1,auth_token=test_auth_token,endpoint='https://test.instamojo.com/api/1.1/')
# response = instamojo_api.payment_request_create(amount=amount, buyer_name= name,phone = mobile,purpose= "Delegate Registration fee " ,send_email=False,email=email,
# redirect_url="http://127.0.0.1:5001/payment_api/payment_instamojo_response/"+p_id_+"/"+r_url
# )
# pay_request_id = response['payment_request']['id']
# status = response['payment_request']['status']
# print (response['payment_request']['shorturl']) # Get the short URL
# print (response['payment_request']['status']) # Get the current status
# print (pay_request_id) # List of payments
# p_id = last_insert_id
# update_pay_req_id = InstamojoModel().update_pay_req_id(p_id,pay_request_id,status)
# return render_template('instamojo/instamojo_payment_screen.html',data= data,payment_request_id=pay_request_id,last_insert_id =p_id,pay_test_link=pay_test_link)
@app.route('/razorpay_response/<int:last_insert_id>/<am_id>/<r_url>', methods=['POST'])
def Razorpay_response(last_insert_id,am_id,r_url):
# r_url = urllib.parse.quote(r_url)
if "%3D" in r_url:
r_url =r_url.replace("%3D","=")
base64_bytes = r_url.encode("ascii")
sample_bytes = base64.b64decode(base64_bytes)
response_url_str = sample_bytes.decode("ascii")
gateway_appmaster = APIModel().getAppMasterGateway(am_id)
delegates = UserModel().get_delegate_by_pid(last_insert_id)
payment_id = request.form['razorpay_payment_id']
amount_f = delegates["amount"]
is_test = delegates["is_test"]
amount = int(amount_f) * 100
if int(is_test) == 1 :
auth_key_1 = gateway_appmaster["test_key"]
auth_secret_1 = gateway_appmaster["test_salt_or_secret"]
else :
auth_key_1 = gateway_appmaster["live_key"]
auth_secret_1 = gateway_appmaster["live_salt_or_secret"]
razorpay_client = razorpay.Client(auth=(auth_key_1, auth_secret_1)) # from database based on gateway id
razorpay_client.payment.capture(payment_id, amount)
razorpay_res = json.dumps(razorpay_client.payment.fetch(payment_id))
response = json.loads(razorpay_res)
email = response["email"]
mobile = response["contact"]
mobile = mobile.replace("+91", "")
status = response["status"]
unique_id = response['notes']['shopping_order_id']
method = response['method'] or 'Card'
if "['" in unique_id : # This is for razorpay payment.So it is need for get unique_id
unique_id = unique_id.replace("['",'')
unique_id = unique_id.replace("']",'')
# **********************************************************************
# *********************************************************************
amount =str(amount_f)
if response["status"] == "captured" or response["status"] == "Credit" :
status = "success"
payment_id_update = UserModel().update_payment_id(last_insert_id,status,payment_id,method)
# flash("Payment status success " )
return flask.redirect(response_url_str+'?payment_id='+payment_id+'&status='+status+'&email='+email+'&mobile='+mobile+'&unique_id='+unique_id+'&amount='+amount+'&method='+method)
else:
# flash("Payment status Failed " )
payment_id_update = UserModel().update_payment_id(last_insert_id,status,payment_id,method)
return flask.redirect(response_url_str+'?payment_id='+payment_id+'&status='+status+'&email='+email+'&mobile='+mobile+'&unique_id='+unique_id+'&amount='+amount+'&method='+method)
@app.route('/emindia23_api', methods = ["GET","POST"])
def EMIndia23():
data_for_result = ""
# abinava rzp_live_08v8FRpvRk1r8a ,IO72cnF7NwfCBNDWSvXkcVD1
client = razorpay.Client(auth=("rzp_live_08v8FRpvRk1r8a", "IO72cnF7NwfCBNDWSvXkcVD1"))
# ts = time.time()
from_date = request.values.get("from_date") or "2023-05-16 00:00:00"
to_date = request.values.get("to_date") or "2023-06-21 00:00:00"
# unique_id = request.values.get("unique_id") or "IPGSDEL23_20230603123220"
unique_id = request.values.get("unique_id") or "EMINDIA23_20230620000916"
#
url_1 = "https://ipgs.org.in/ipgs_payments/timestamp_api.php?from_date="+from_date+"&to_date="+to_date
response = requests.get(url_1)
response = response.text
result = response
res = json.loads(result)
if res :
api_msg = res["msg"]
api_status = res["status"]
if api_status ==1 :
from_date_1 = res["from_date"]
to_date_1 = res["to_date"]
else :
return "Invalid date "
# option = {"from" : 1684195200 , "to" : 1687305600}
option = {"from" : from_date_1 , "to" : to_date_1}
data = client.payment.all(option)
if data :
data= data["items"]
for index ,value in enumerate(data) :
unique_id_pg = value["notes"]["shopping_order_id"]
if unique_id_pg and unique_id_pg == unique_id :
payment_id_pg = value["id"]
stauts_pg = value["status"]
amount_pg = value["amount"]
email_pg = value["email"]
mode_pg = value["method"]
mobile_pg = value["contact"]
created_at_pg = value["created_at"]
if created_at_pg :
url_1 = "https://ipgs.org.in/ipgs_payments/timestamp_api.php?created_at="+str(created_at_pg)
response_1 = requests.get(url_1)
response_1 = response_1.text
result_1 = response_1
res_1 = json.loads(result_1)
created_at_pg = res_1["created_at"]
if stauts_pg and stauts_pg == "captured":
stauts_pg = "success"
msg = "success"
status = 1
data_for_result ={"pg_method":mode_pg,"api_payment_id":payment_id_pg,"mobile": mobile_pg,"email": email_pg,"status": stauts_pg,"created_at":created_at_pg,
"unique_id":unique_id_pg,"amount":amount_pg}
break
else :
status = 3
msg = "Records does not exists."
else :
msg = "Record not found"
status = 2
data = {"data" : data_for_result, "msg" : msg , "status" :status}
json_data = json.dumps(data,default=str)
return json_data
# @app.route('/payment_instamojo_response/<p_id>/<r_url>', methods = ["GET", "POST"])
# def Payment_instamojo_response(p_id,r_url):
# p_id =str(p_id)
# base64_bytes = r_url.encode("ascii")
# sample_bytes = base64.b64decode(base64_bytes)
# response_url_str = sample_bytes.decode("ascii")
# payment_id = request.args.get('payment_id')
# payment_status = request.args.get('payment_status')
# payment_request_id = request.args.get('payment_request_id')
# now = datetime.now()
# dt_string = now.strftime("%Y-%m-%d %H:%M:%S")
# update_pay_status = InstamojoModel().update_pay_status(p_id,payment_id,payment_status,payment_request_id,dt_string)
# if update_pay_status :
# email = update_pay_status.email
# mobile = update_pay_status.mobile
# if payment_status == "Credit":
# flash("Payment status success " )
# return flask.redirect(response_url_str+'?payment_id='+payment_id+'&status='+payment_status+'&email='+email+'&mobile='+mobile+'&payment_request_id='+payment_request_id)
# else:
# flash("Payment status Failed " )
# return flask.redirect(response_url_str+'?payment_id='+payment_id+'&status='+payment_status+'&email='+email+'&mobile='+mobile+'&payment_request_id='+payment_request_id)
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists