diff --git a/.vs/WHMCS API/v15/.suo b/.vs/WHMCS API/v15/.suo index bc5bad25b9255e452481561df7e0c2b95761d062..20b3c0f2abc723710f23aee7deb0630e7182e2bd 100644 Binary files a/.vs/WHMCS API/v15/.suo and b/.vs/WHMCS API/v15/.suo differ diff --git a/API.cs b/API.cs index 77b681fb04e70c61998be39397b158b865cecd7c..7b19094e9c49f879a16e97821b603fdbfe88f281 100644 --- a/API.cs +++ b/API.cs @@ -11,21 +11,21 @@ namespace WHMCS_API { public class API { + + JsonSerializerSettings settings; + private readonly Call _call; public API(string Username, string Password, string AccessKey, string Url) { _call = new Call(Username, Password, AccessKey, Url); + settings = new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore, + MissingMemberHandling = MissingMemberHandling.Ignore + }; } - /// - /// Validates a client login - /// - /// - /// Client Email - /// Client Password (cleartext) - /// Returns the result of the call - /// The userid string for the session Session["uid"] - /// The passwordhash for the session Session["upw"] + public ValidateLogin.ValidateLogin ValidateLogin(string Email, string Password) { NameValueCollection data = new NameValueCollection() @@ -35,15 +35,17 @@ namespace WHMCS_API { EnumUtil.GetString(APIEnums.ValidateLoginParams.Password), Password } }; + string req = _call.MakeCall(data); + JObject result = JObject.Parse(req); + + if (result["result"].ToString() == "success") + return JsonConvert.DeserializeObject(req, settings); + else + throw new Exception("An API Error Ocurred", new Exception(result["message"].ToString())); + return JsonConvert.DeserializeObject(_call.MakeCall(data)); } - - /// - /// Checks if a domain is available to regsiter, if not will return the whois - /// - /// - /// The domain to be checked - /// Result of the call, if the domain is registered or not, and if registered the WhoIs + public DomainWhoIs DomainWhoIs(string Domain) { NameValueCollection data = new NameValueCollection() @@ -56,24 +58,12 @@ namespace WHMCS_API JObject result = JObject.Parse(req); if (result["result"].ToString() == "success") - return JsonConvert.DeserializeObject(req); + return JsonConvert.DeserializeObject(req, settings); else throw new Exception("An API Error Ocurred", new Exception(result["message"].ToString())); } - - /// - /// Registers a new client - /// - /// - /// When registerying an exception may occurr. If you get "An API Error Ocurred" read the inner exception - /// - /// - /// try { your code } catch (Exception ex) { Console.WriteLine(ex.InnerException.Message); } - /// - /// - /// The Model of the AddClient action - /// If success returns the ID of the newly created user otherwise will throw an exception + public int AddClient(AddClient ClientInfo) { NameValueCollection data = new NameValueCollection() @@ -95,14 +85,7 @@ namespace WHMCS_API throw new Exception("An API Error Ocurred", new Exception(result["message"].ToString())); } - - /// - /// Gets the client details - /// - /// The client ID to search - /// The client Email to search - /// Get extended stats for the client - /// All details of the client + public GetClientsDetails.GetClientsDetails GetClientsDetails(int ClientID = -1, string ClientEmail = "", bool Stats = false) { if (ClientID == -1 && ClientEmail == "") @@ -121,20 +104,11 @@ namespace WHMCS_API string req = _call.MakeCall(data); JObject result = JObject.Parse(req); if (result["result"].ToString() == "success") - return JsonConvert.DeserializeObject(req); + return JsonConvert.DeserializeObject(req, settings); else throw new Exception("An API Error occurred", new Exception(result["message"].ToString())); } - - /// - /// Get the orders (for all clients/specific client/specific order/specific status) - /// - /// The offset for the returned order data (default: 0) - /// The number of records to return (default: 25) - /// Find orders for a specific id - /// Find orders for a specific client id - /// Find orders for a specific status - /// In a modelm, total results, start number, the number of results returned + public GetOrders.GetOrders GetOrders(int LimitStart = 0, int LimitNumber = 25, int OrderID = -1, int UserID = -1, string Status = "") { NameValueCollection data = new NameValueCollection() @@ -150,7 +124,7 @@ namespace WHMCS_API if (Status != "") data.Add(EnumUtil.GetString(APIEnums.GetOrdersParams.Status), Status); - return JsonConvert.DeserializeObject(_call.MakeCall(data)); + return JsonConvert.DeserializeObject(_call.MakeCall(data), settings); } public GetTransactions.GetTransactions GetTransactions(int InvoiceID = -1, int ClientID = -1, string TransactionID = "") @@ -166,7 +140,7 @@ namespace WHMCS_API if (TransactionID != "") data.Add(EnumUtil.GetString(APIEnums.GetTransactionsParams.TransactionID), TransactionID); - return JsonConvert.DeserializeObject(_call.MakeCall(data)); + return JsonConvert.DeserializeObject(_call.MakeCall(data), settings); } public GetClientsProducts.GetClientsProducts GetClientsProducts(int LimitStart = 0, int LimitNum = 25, int ClientID = -1, int ServiceID = -1, int ProductID = -1, string Domain = "", string Username = "") @@ -189,7 +163,42 @@ namespace WHMCS_API if (Username != "") data.Add(EnumUtil.GetString(APIEnums.GetClientsProductsParams.Username), Username); - return JsonConvert.DeserializeObject(_call.MakeCall(data)); + return JsonConvert.DeserializeObject(_call.MakeCall(data), settings); + } + + public GetInvoices.GetInvoices GetInvoices(int LimitStart = 0, int LimitNumber = 25, int UserID = -1, string Status = "") + { + NameValueCollection data = new NameValueCollection() + { + { "action", APIEnums.Actions.GetInvoices.ToString() }, + { EnumUtil.GetString(APIEnums.GetInvoicesParams.LimitStart), LimitStart.ToString() }, + { EnumUtil.GetString(APIEnums.GetInvoicesParams.LimitNumber), LimitNumber.ToString() } + }; + if (UserID != -1) + data.Add(EnumUtil.GetString(APIEnums.GetInvoicesParams.UserID), UserID.ToString()); + if (Status != "") + data.Add(EnumUtil.GetString(APIEnums.GetInvoicesParams.Status), Status); + + return JsonConvert.DeserializeObject(_call.MakeCall(data), settings); + } + + public GetInvoice.GetInvoice GetInvoice(int InvoiceID) + { + NameValueCollection data = new NameValueCollection() + { + { "action", EnumUtil.GetString(APIEnums.Actions.GetInvoice) }, + { EnumUtil.GetString(APIEnums.GetInvoiceParams.InvoiceID), InvoiceID.ToString() } + }; + + string req = _call.MakeCall(data); + + JObject result = JObject.Parse(req); + + if (result["result"].ToString() == "success") + return JsonConvert.DeserializeObject(req, settings); + else + throw new Exception("An API Error Ocurred", new Exception(result["message"].ToString())); + } } } diff --git a/Call.cs b/Call.cs index 19b58248699e1310106d475d3cfe4b64712c3a5c..4820b6564d84e9bc6a479a45140dc709f4750338 100644 --- a/Call.cs +++ b/Call.cs @@ -16,13 +16,7 @@ namespace WHMCS_API private readonly string AccessKey; private readonly string Url; - /// - /// Prepare the call of the API - /// - /// API Username - /// API Password - /// API AccessKey (must be set in config.php) - /// WHMCS User Front End URL (ex: https://example.com/client) + public Call(string Username, string Password, string AccessKey, string Url) { this.Username = Username; @@ -69,12 +63,10 @@ namespace WHMCS_API private string CalculateMD5Hash(string input) { - // step 1, calculate MD5 hash from input MD5 md5 = MD5.Create(); byte[] inputBytes = Encoding.ASCII.GetBytes(input); byte[] hash = md5.ComputeHash(inputBytes); - // step 2, convert byte array to hex string StringBuilder sb = new StringBuilder(); foreach (byte t in hash) { diff --git a/Enums.cs b/Enums.cs index b2da36f3dfd38cf015307759b99e8ef63912690c..5256fd3ec1c416ced347bf5d590b36b15d57a717 100644 --- a/Enums.cs +++ b/Enums.cs @@ -86,6 +86,19 @@ namespace WHMCS_API [StringValue("username2")] Username } + public enum GetInvoicesParams + { + [StringValue("limitstart")] LimitStart, + [StringValue("limitnum")] LimitNumber, + [StringValue("userid")] UserID, + [StringValue("status")] Status + } + + public enum GetInvoiceParams + { + [StringValue("invoiceid")] InvoiceID + } + /// /// Actions Supported by the WHMCS API that are implemented in this Wrapper /// @@ -97,12 +110,14 @@ namespace WHMCS_API [StringValue("GetClientsDetails")] GetClientsDetails, [StringValue("GetOrders")] GetOrders, [StringValue("GetTransactions")] GetTransactions, - [StringValue("GetClientsProducts")] GetClientsProducts + [StringValue("GetClientsProducts")] GetClientsProducts, + [StringValue("GetInvoices")] GetInvoices, + [StringValue("GetInvoice")] GetInvoice } } /// - /// Creastes an attribute called StringValue + /// Creates an attribute called StringValue /// public class StringValue : Attribute { @@ -125,11 +140,6 @@ namespace WHMCS_API /// public static class EnumUtil { - /// - /// Gets the string out of the enum - /// - /// The enum from witch will be extracted the string - /// The string associated with the value enum public static string GetString(Enum value) { string output = null; diff --git a/GetInvoice.cs b/GetInvoice.cs new file mode 100644 index 0000000000000000000000000000000000000000..0081de44ca3b316975b5b23e9bd27be11ac9dc0c --- /dev/null +++ b/GetInvoice.cs @@ -0,0 +1,155 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WHMCS_API.GetInvoice +{ + public class Item + { + + [JsonProperty("id")] + public string ID { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("relid")] + public string relid { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("amount")] + public string Amount { get; set; } + + [JsonProperty("taxed")] + public string Taxed { get; set; } + } + + public class Items + { + + [JsonProperty("item")] + public IList Item { get; set; } + } + + public class Transaction + { + + [JsonProperty("id")] + public string ID { get; set; } + + [JsonProperty("userid")] + public string UserID { get; set; } + + [JsonProperty("currency")] + public string Currency { get; set; } + + [JsonProperty("gateway")] + public string Gateway { get; set; } + + [JsonProperty("date")] + public string Date { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("amountin")] + public string AmountIn { get; set; } + + [JsonProperty("fees")] + public string Fees { get; set; } + + [JsonProperty("amountout")] + public string AmountOut { get; set; } + + [JsonProperty("rate")] + public string Rate { get; set; } + + [JsonProperty("transid")] + public string TransactionID { get; set; } + + [JsonProperty("invoiceid")] + public string InvoiceID { get; set; } + + [JsonProperty("refundid")] + public string RefundID { get; set; } + } + + public class Transactions + { + + [JsonProperty("transaction")] + public IList Transaction { get; set; } + } + + public class GetInvoice + { + + [JsonProperty("result")] + public string Result { get; set; } + + [JsonProperty("invoiceid")] + public string InvoiceID { get; set; } + + [JsonProperty("invoicenum")] + public string InvoiceNumber { get; set; } + + [JsonProperty("userid")] + public string UserID { get; set; } + + [JsonProperty("date")] + public string Date { get; set; } + + [JsonProperty("duedate")] + public string DueDate { get; set; } + + [JsonProperty("datepaid")] + public string DatePaid { get; set; } + + [JsonProperty("subtotal")] + public string SubTotal { get; set; } + + [JsonProperty("credit")] + public string Credit { get; set; } + + [JsonProperty("tax")] + public string Tax { get; set; } + + [JsonProperty("tax2")] + public string Tax2 { get; set; } + + [JsonProperty("total")] + public string Total { get; set; } + + [JsonProperty("balance")] + public string Balance { get; set; } + + [JsonProperty("taxrate")] + public string TaxRate { get; set; } + + [JsonProperty("taxrate2")] + public string TaxRate2 { get; set; } + + [JsonProperty("status")] + public string Status { get; set; } + + [JsonProperty("paymentmethod")] + public string PaymentMethod { get; set; } + + [JsonProperty("notes")] + public string Notes { get; set; } + + [JsonProperty("ccgateway")] + public bool CCGateway { get; set; } + + [JsonProperty("items")] + public Items Items { get; set; } + + [JsonProperty("transactions")] + public Transactions Transactions { get; set; } + } +} diff --git a/GetInvoices.cs b/GetInvoices.cs new file mode 100644 index 0000000000000000000000000000000000000000..9a59a375cee285e5b0c9abeb3eaf2325daa66605 --- /dev/null +++ b/GetInvoices.cs @@ -0,0 +1,105 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WHMCS_API.GetInvoices +{ + public class Invoice + { + + [JsonProperty("id")] + public string ID { get; set; } + + [JsonProperty("userid")] + public string UserID { get; set; } + + [JsonProperty("firstname")] + public string Firstname { get; set; } + + [JsonProperty("lastname")] + public string Lastname { get; set; } + + [JsonProperty("companyname")] + public string CompanyName { get; set; } + + [JsonProperty("invoicenum")] + public string InvoiceNumber { get; set; } + + [JsonProperty("date")] + public string Date { get; set; } + + [JsonProperty("duedate")] + public string DueDate { get; set; } + + [JsonProperty("datepaid")] + public string DatePaid { get; set; } + + [JsonProperty("subtotal")] + public string SubTotal { get; set; } + + [JsonProperty("credit")] + public string Credit { get; set; } + + [JsonProperty("tax")] + public string Tax { get; set; } + + [JsonProperty("tax2")] + public string Tax2 { get; set; } + + [JsonProperty("total")] + public string Total { get; set; } + + [JsonProperty("taxrate")] + public string TaxRate { get; set; } + + [JsonProperty("taxrate2")] + public string TaxRate2 { get; set; } + + [JsonProperty("status")] + public string Status { get; set; } + + [JsonProperty("paymentmethod")] + public string PaymentMethod { get; set; } + + [JsonProperty("notes")] + public string Notes { get; set; } + + [JsonProperty("currencycode")] + public string CurrencyCode { get; set; } + + [JsonProperty("currencyprefix")] + public string CurrencyPrefix { get; set; } + + [JsonProperty("currencysuffix")] + public string CurrencySuffix { get; set; } + } + + public class Invoices + { + + [JsonProperty("invoice")] + public IList Invoice { get; set; } + } + + public class GetInvoices + { + + [JsonProperty("result")] + public string Result { get; set; } + + [JsonProperty("totalresults")] + public string TotalResults { get; set; } + + [JsonProperty("startnumber")] + public int StartNumber { get; set; } + + [JsonProperty("numreturned")] + public int NumberReturned { get; set; } + + [JsonProperty("invoices")] + public Invoices Invoices { get; set; } + } +} diff --git a/NuGet.exe b/NuGet.exe deleted file mode 100644 index 9f8781de0db12095b1bf32b209c112a2d85704d2..0000000000000000000000000000000000000000 Binary files a/NuGet.exe and /dev/null differ diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 3605e13e64b631c439868303a5aff514ccbb11c5..27d0a97eaa04d9837113fe79ab02d2e76be0767a 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // É possível especificar todos os valores ou usar como padrão os Números de Build e da Revisão // usando o '*' como mostrado abaixo: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.5.7.1")] -[assembly: AssemblyFileVersion("0.5.7.1")] +[assembly: AssemblyVersion("0.6.9")] +[assembly: AssemblyFileVersion("0.6.9")] diff --git a/ValidateLogin.cs b/ValidateLogin.cs index a175f310daf5e0aab100b1f3c161822c89f87d31..008ddd1af5386e846d9ade4b2c7445771f373b56 100644 --- a/ValidateLogin.cs +++ b/ValidateLogin.cs @@ -16,6 +16,9 @@ namespace WHMCS_API.ValidateLogin [JsonProperty("userid")] public int UserID { get; set; } + [JsonProperty("contactid")] + public int ContactID { get; set; } + [JsonProperty("passwordhash")] public string PasswordHash { get; set; } } diff --git a/WHMCS API.csproj b/WHMCS API.csproj index 44573cf7762f29f93cbf2623470cb64acc237587..19504fde239b9ddde5bc20c48402915d124cd8c7 100644 --- a/WHMCS API.csproj +++ b/WHMCS API.csproj @@ -50,6 +50,8 @@ + + diff --git a/WHMCS_API.0.5.7.nupkg b/WHMCS_API.0.5.7.nupkg new file mode 100644 index 0000000000000000000000000000000000000000..ef53ab90d2629093653b4d52661fd14dd6e397be Binary files /dev/null and b/WHMCS_API.0.5.7.nupkg differ diff --git a/bin/Debug/WHMCS API.dll b/bin/Debug/WHMCS API.dll new file mode 100644 index 0000000000000000000000000000000000000000..33c2fbb0ca22d9368255e4897c0bf4223ee1300c Binary files /dev/null and b/bin/Debug/WHMCS API.dll differ diff --git a/bin/Debug/WHMCS API.pdb b/bin/Debug/WHMCS API.pdb new file mode 100644 index 0000000000000000000000000000000000000000..d46d211c799286a1c32b862dd436629387de75f9 Binary files /dev/null and b/bin/Debug/WHMCS API.pdb differ diff --git a/bin/Release/WHMCS API.dll b/bin/Release/WHMCS API.dll index 96df9b5f3e74294e6b285c48f2c7aa47b782b19f..33c2fbb0ca22d9368255e4897c0bf4223ee1300c 100644 Binary files a/bin/Release/WHMCS API.dll and b/bin/Release/WHMCS API.dll differ diff --git a/bin/Release/WHMCS API.pdb b/bin/Release/WHMCS API.pdb index d46d211c799286a1c32b862dd436629387de75f9..d4a58632546ee8a333b4d34e5b83800a164b68e4 100644 Binary files a/bin/Release/WHMCS API.pdb and b/bin/Release/WHMCS API.pdb differ diff --git a/obj/Release/CoreCompileInputs.cache b/obj/Release/CoreCompileInputs.cache index 65ec8686a2acc6a0f512cc74edebaf5a79a6f181..a95119b6725f79bd05bd19428e27a3b3e98b4c6c 100644 --- a/obj/Release/CoreCompileInputs.cache +++ b/obj/Release/CoreCompileInputs.cache @@ -1 +1 @@ -9bdd758f24ddef82f3a54b8ed3aca9e67b7ee3cb +5f59b426423b1b66e7999b655253504f3f57ee0f diff --git a/obj/Release/WHMCS API.csprojResolveAssemblyReference.cache b/obj/Release/WHMCS API.csprojResolveAssemblyReference.cache index 4499eacebc64b2c2b3b4be566416f7ffb8aef69c..77d308a29a105acdb848817cc92f377f20132e0c 100644 Binary files a/obj/Release/WHMCS API.csprojResolveAssemblyReference.cache and b/obj/Release/WHMCS API.csprojResolveAssemblyReference.cache differ diff --git a/obj/Release/WHMCS API.dll b/obj/Release/WHMCS API.dll index 96df9b5f3e74294e6b285c48f2c7aa47b782b19f..33c2fbb0ca22d9368255e4897c0bf4223ee1300c 100644 Binary files a/obj/Release/WHMCS API.dll and b/obj/Release/WHMCS API.dll differ diff --git a/obj/Release/WHMCS API.pdb b/obj/Release/WHMCS API.pdb index d46d211c799286a1c32b862dd436629387de75f9..d4a58632546ee8a333b4d34e5b83800a164b68e4 100644 Binary files a/obj/Release/WHMCS API.pdb and b/obj/Release/WHMCS API.pdb differ