2026-03-08 17:37:22 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Customers.mqh |
|
| | | //| Copyright 2025, Niquel Mendoza. |
|
| | | //| https://www.mql5.com/es/users/nique_372 |
|
| | | //+------------------------------------------------------------------+
|
| | | #property copyright "Copyright 2025, Niquel Mendoza."
|
| | | #property link "https://www.mql5.com/es/users/nique_372"
|
| | | #property strict
|
| | |
|
2026-03-10 06:38:32 -05:00 | | | #ifndef TBPWRRAPER_SRC_CUSTOMERS_MQH
|
| | | #define TBPWRRAPER_SRC_CUSTOMERS_MQH
|
2026-03-08 17:37:22 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | #include "Base.mqh"
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | class CTbpCustomers : public CTbpBase
|
| | | {
|
| | | private:
|
2026-03-11 19:21:16 -05:00 | | | bool m_delete_aditional_data;
|
2026-03-08 17:37:22 -05:00 | | | ITbpAdditionalData* m_aditional_data;
|
| | | string m_software_id;
|
| | |
|
| | | public:
|
2026-03-11 19:21:16 -05:00 | | | CTbpCustomers(void) : m_software_id(NULL), m_aditional_data(NULL), m_delete_aditional_data(true) {}
|
| | | ~CTbpCustomers(void) { if(m_delete_aditional_data && CheckPointer(m_aditional_data) == POINTER_DYNAMIC) delete m_aditional_data; }
|
2026-03-08 17:37:22 -05:00 | | |
|
| | | //--- Getters \ Setters
|
| | | // Dato adicional
|
| | | ITbpAdditionalData* AdditionalData() { return m_aditional_data; }
|
2026-03-11 19:21:16 -05:00 | | | void AdditionalData(ITbpAdditionalData* ptr, bool delete_on_destructor);
|
2026-03-08 17:37:22 -05:00 | | |
|
| | | // Software id
|
| | | string SoftwareId() const { return m_software_id; }
|
| | | void SoftwareId(const string& software_id) { m_software_id = software_id; }
|
| | |
|
| | | //---
|
| | | // Nota importante
|
| | | // Las funciones reontanr un bool de exito o falso en la llamda \ parse json como tal no el valor
|
| | | // Para eso consulten el json o hay funciones que ya trean un &out
|
| | |
|
| | | // Get customers of a software
|
| | | // Lista clientes de un software concreto.
|
| | | bool GetCustomersSotfware(); // Para el resultado consultar el json
|
| | |
|
| | | //---
|
| | | // User has software
|
| | | // Verifica licencia incluyendo datos adicionales.
|
| | | bool UserHasSoftware(const string& userd_id, bool &out); // Resultado en out
|
| | |
|
| | | //---
|
| | | // User has software (no additional data)
|
| | | // Comprueba si un usuario posee una licencia sin la necesidad de enviar un dato adicional.
|
| | | // ATENCIÓN: este endpoint no valida datos adicionales asociados a la licencia, por lo que puede si un
|
| | | // tercero posee el userId podrá usar tu bot. Este endpoint está pensado para la reventa de bots.
|
| | | bool UserHastSoftwareNoaAdditionalData(const string& userd_id, bool &out); // Resultado en out
|
| | |
|
| | |
|
| | | //---
|
| | | // User has software (Telegram)
|
| | | // Comprueba licencia usando identificador de Telegram.
|
2026-03-11 19:21:16 -05:00 | | | bool UserHastSoftwareTelegram(const string& telegram_user, bool& out); // Resultado en out
|
2026-03-08 17:37:22 -05:00 | | |
|
| | | //---
|
| | | // First demo download
|
| | | // Comprueba si es la primera descarga de demo de un software.
|
| | | bool FirstDemoDowlandSoftware(const string& user_id, datetime& out); // Resultado en out
|
| | |
|
| | |
|
| | | //---
|
| | | // Check job delivery access
|
| | | // Verifica si un usuario puede acceder a la entrega de un trabajo.
|
| | | // bool CheckJobDeliveryAccess();
|
| | |
|
| | | };
|
| | |
|
2026-03-11 19:21:16 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | void CTbpCustomers::AdditionalData(ITbpAdditionalData *ptr, bool delete_on_destructor)
|
| | | {
|
| | | m_aditional_data = ptr;
|
| | | m_delete_aditional_data = delete_on_destructor;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
2026-03-08 17:37:22 -05:00 | | | //+------------------------------------------------------------------+
|
| | | bool CTbpCustomers::GetCustomersSotfware(void)
|
| | | {
|
| | | //---
|
| | | string res_headers;
|
| | | char data[], result[];
|
| | | string req_headers = "api-key: " + m_api_key + "\r\n";
|
| | | const string url = THE_BOT_PLACE_BASE_URL + "customers/" + m_software_id;
|
| | |
|
| | | //---
|
| | | const int request = WebRequest(
|
| | | "GET",
|
| | | url,
|
| | | req_headers,
|
| | | m_timeout,
|
| | | data,
|
| | | result,
|
| | | res_headers
|
| | | );
|
| | |
|
| | | //---
|
| | | const string msg = CharArrayToString(result);
|
| | |
|
| | | //---
|
| | | if(request != 200)
|
| | | {
|
| | | LogError(StringFormat("Fallo al mandar request, codigo de requeset = %d, result:\n%s", request, msg), FUNCION_ACTUAL);
|
| | | return false;
|
| | | }
|
| | |
|
| | | //---
|
| | | return m_json.Parse(msg);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTbpCustomers::UserHasSoftware(const string& userd_id, bool &out)
|
| | | {
|
| | | //---
|
| | | string res_headers;
|
| | | char data[], result[];
|
| | | string req_headers = "api-key: " + m_api_key + "\r\n";
|
| | | // URL: https://europe-west2-thebotplace.cloudfunctions.net/api/v1/api/customers/user-has-product?userId=<userId>&softwareId=<softwareId>&additional=<additional>
|
| | | const string url = StringFormat("%scustomers/user-has-product?userId=%s&softwareId=%s&additional=%s",
|
| | | THE_BOT_PLACE_BASE_URL, userd_id, m_software_id, m_aditional_data.Get());
|
| | |
|
| | | //---
|
| | | const int request = WebRequest(
|
| | | "GET",
|
| | | url,
|
| | | req_headers,
|
| | | m_timeout,
|
| | | data,
|
| | | result,
|
| | | res_headers
|
| | | );
|
| | |
|
| | | //---
|
| | | const string msg = CharArrayToString(result);
|
| | |
|
| | | //---
|
| | | if(request != 200)
|
| | | {
|
| | | LogError(StringFormat("Fallo al mandar request, codigo de requeset = %d, result:\n%s", request, msg), FUNCION_ACTUAL);
|
| | | return false;
|
| | | }
|
| | |
|
| | | //---
|
| | | out = (msg == "true");
|
| | | return true;
|
| | | }
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTbpCustomers::UserHastSoftwareNoaAdditionalData(const string &userd_id, bool &out)
|
| | | {
|
| | | //---
|
| | | string res_headers;
|
| | | char data[], result[];
|
| | | string req_headers = "api-key: " + m_api_key + "\r\n";
|
| | | // URL: https://europe-west2-thebotplace.cloudfunctions.net/api/v1/api/customers/user-has-product-no-additional?userId=<userId>&softwareId=<softwareId>
|
| | | const string url = StringFormat("%scustomers/user-has-product-no-additional?userId=%s&softwareId=%s",
|
| | | THE_BOT_PLACE_BASE_URL, userd_id, m_software_id);
|
| | |
|
| | | //---
|
| | | const int request = WebRequest(
|
| | | "GET",
|
| | | url,
|
| | | req_headers,
|
| | | m_timeout,
|
| | | data,
|
| | | result,
|
| | | res_headers
|
| | | );
|
| | |
|
| | | //---
|
| | | const string msg = CharArrayToString(result);
|
| | |
|
| | | //---
|
| | | if(request != 200)
|
| | | {
|
| | | LogError(StringFormat("Fallo al mandar request, codigo de requeset = %d, result:\n%s", request, msg), FUNCION_ACTUAL);
|
| | | return false;
|
| | | }
|
| | |
|
| | | //---
|
| | | out = (msg == "true");
|
| | | return true;
|
| | | }
|
| | | //+------------------------------------------------------------------+
|
2026-03-11 19:21:16 -05:00 | | | bool CTbpCustomers::UserHastSoftwareTelegram(const string &telegram_user, bool &out)
|
2026-03-08 17:37:22 -05:00 | | | {
|
| | | //---
|
| | | string res_headers;
|
| | | char data[], result[];
|
| | | string req_headers = "api-key: " + m_api_key + "\r\n";
|
| | | // URL: https://europe-west2-thebotplace.cloudfunctions.net/api/v1/api/customers/user-has-product-by-telegram?telegram=<telegram>&softwareId=<softwareId>&additional=<additional>
|
2026-03-11 19:21:16 -05:00 | | | string url = StringFormat("%scustomers/user-has-product-by-telegram?telegram=%s&softwareId=%s&additional=%s",
|
| | | THE_BOT_PLACE_BASE_URL, telegram_user, m_software_id, m_aditional_data.Get());
|
| | | // quite lo de adicional al parecer es obligatorio: https://documenter.getpostman.com/view/19130707/2s9XxztsWt
|
2026-03-08 17:37:22 -05:00 | | |
|
| | | //---
|
| | | const int request = WebRequest(
|
| | | "GET",
|
| | | url,
|
| | | req_headers,
|
| | | m_timeout,
|
| | | data,
|
| | | result,
|
| | | res_headers
|
| | | );
|
| | |
|
| | | //---
|
| | | const string msg = CharArrayToString(result);
|
| | |
|
| | | //---
|
| | | if(request != 200)
|
| | | {
|
| | | LogError(StringFormat("Fallo al mandar request, codigo de requeset = %d, result:\n%s", request, msg), FUNCION_ACTUAL);
|
| | | return false;
|
| | | }
|
| | |
|
| | | //---
|
| | | out = (msg == "true");
|
| | | return true;
|
| | | }
|
| | | //+------------------------------------------------------------------+
|
| | | bool CTbpCustomers::FirstDemoDowlandSoftware(const string &user_id, datetime &out)
|
| | | {
|
| | | //---
|
| | | string res_headers;
|
| | | char data[], result[];
|
| | | string req_headers = "api-key: " + m_api_key + "\r\n";
|
| | | // URL: https://europe-west2-thebotplace.cloudfunctions.net/api/v1/api/software/first-demo-download?userId=<userId>&softwareId=<softwareId>
|
| | | const string url = StringFormat("%ssoftware/first-demo-download?userId=%s&softwareId=%s",
|
| | | THE_BOT_PLACE_BASE_URL, user_id, m_software_id);
|
| | |
|
| | | //---
|
| | | const int request = WebRequest(
|
| | | "GET",
|
| | | url,
|
| | | req_headers,
|
| | | m_timeout,
|
| | | data,
|
| | | result,
|
| | | res_headers
|
| | | );
|
| | |
|
| | | //---
|
| | | const string msg = CharArrayToString(result);
|
| | |
|
| | | //---
|
| | | if(request != 200)
|
| | | {
|
| | | LogError(StringFormat("Fallo al mandar request, codigo de requeset = %d, result:\n%s", request, msg), FUNCION_ACTUAL);
|
| | | return false;
|
| | | }
|
| | |
|
| | | //---
|
| | | out = datetime(long(msg)); // Viene en unix
|
| | | return true;
|
| | | }
|
| | | //+------------------------------------------------------------------+
|
2026-03-11 19:21:16 -05:00 | | | #endif // TBPWRRAPER_SRC_CUSTOMERS_MQH
|