cronos_cpa
Tue Sep 03 2024 09:28:23 GMT+0000 (Coordinated Universal Time)
Saved by @menaheero
import frappe import base64 import requests import json from heero.utils.common import * @frappe.whitelist() def cronos_cpa(docname): url = "https://tb.panteonaffs.com/api/signup/procform" headers = { "x-api-key": "2643889w34df345676ssdas323tgc738", "Content-Type": "application/json", "x-trackbox-username": "Heero", "x-trackbox-password": "EYN2R%h?@lDM", } try: doc = frappe.get_doc("Flagedu-Lead", docname) except frappe.DoesNotExistError: return {"message": f"Document with name {docname} does not exist"} email = doc.email firstName = doc.name1 phone = doc.phone country = get_country_code(doc.country) lastName = doc.last_name or doc.name1 afp = doc.afp or "Heero" afp2 = doc.afp2 or "" ip = doc.ip if doc.ip else "137.184.226.177", data = { "ai": "2958297", "ci": "1", "gi": "297", "country": country, "userip": ip, "firstname": firstName, "lastname": lastName, "email": email, "password": "Aa12345!", "phone": phone, "so": "AFF_2958974", "sub": "AFF_2958974", "MPC_1": afp, "MPC_2": afp2, "MPC_3": "FreeParam", "MPC_4": "Emaar", } try: response = requests.post(url, headers=headers, json=data) response.raise_for_status() except requests.exceptions.RequestException as e: doc.all = json.dumps({"message": "Request failed", "error": str(e)}) doc.save() return {"message": "Request failed", "error": str(e)} try: response_data = response.json() except ValueError: doc.all = json.dumps({"message": "Failed to parse response as JSON", "response": response.text}) doc.save() return {"message": "Failed to parse response as JSON", "response": response.text} if response_data.get("status") == True: addon_data = response_data.get("addonData", {}).get("data", {}) doc.axia_response = json.dumps(addon_data) # Store the raw response as a JSON string if needed for reference doc.axia_login_url = addon_data.get("loginURL") doc.axia_client_id = addon_data.get("customerId") doc.append("brokers", { "broker": "Fxglobe", "signup_date":today(), "client_id":addon_data.get("customerId"), "loginurl":addon_data.get("loginURL"), "success":True, 'type':"CPA" }) doc.add_tag('Fxglobe') doc.save() return {"message": "Signup successful", "data": response_data} else: doc.all = json.dumps({"message": "Signup failed", "response": response_data}) doc.append("brokers", { "broker": "Fxglobe", "signup_date":today(), "error":True, "type":"CPA", "response":json.dumps({"message": "Signup failed", "response": response_data}) }) doc.save() return {"message": "Signup failed", "response": response_data }
Comments