This repository has been archived by the owner on Jun 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5812350
commit 68283f4
Showing
44 changed files
with
73,303 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"CurrentProjectSetting": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"ExpandedNodes": [ | ||
"", | ||
"\\bin", | ||
"\\obj" | ||
], | ||
"SelectedNode": "\\WHMCS API.csproj", | ||
"PreviewInSolutionExplorer": false | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace WHMCS_API | ||
{ | ||
public class API | ||
{ | ||
private readonly Call _call; | ||
public API(string Username, string Password, string AccessKey, string Url) | ||
{ | ||
_call = new Call(Username, Password, AccessKey, Url); | ||
} | ||
|
||
/// <summary> | ||
/// Validates a client login | ||
/// </summary> | ||
/// <see cref="https://developers.whmcs.com/api-reference/validatelogin/"/> | ||
/// <param name="Email">Client Email</param> | ||
/// <param name="Password">Client Password (cleartext)</param> | ||
/// <returns>Returns the result of the call | ||
/// The userid string for the session Session["uid"] | ||
/// The passwordhash for the session Session["upw"]</returns> | ||
public ValidateLogin ValidateLogin(string Email, string Password) | ||
{ | ||
NameValueCollection data = new NameValueCollection() | ||
{ | ||
{ "action", APIEnums.Actions.ValidateLogin.ToString() }, | ||
{ EnumUtil.GetString(APIEnums.ValidateLoginParams.Email), Email }, | ||
{ EnumUtil.GetString(APIEnums.ValidateLoginParams.Password), Password } | ||
}; | ||
|
||
return JsonConvert.DeserializeObject<ValidateLogin>(_call.MakeCall(data)); | ||
} | ||
|
||
/// <summary> | ||
/// Checks if a domain is available to regsiter, if not will return the whois | ||
/// </summary> | ||
/// <see cref="https://developers.whmcs.com/api-reference/domainwhois/"/> | ||
/// <param name="Domain">The domain to be checked</param> | ||
/// <returns>Result of the call, if the domain is registered or not, and if registered the WhoIs</returns> | ||
public DomainWhoIs DomainWhoIs(string Domain) | ||
{ | ||
NameValueCollection data = new NameValueCollection() | ||
{ | ||
{ "action", APIEnums.Actions.DomainWhois.ToString() }, | ||
{ EnumUtil.GetString(APIEnums.DomainWhoisParams.Domain), Domain }, | ||
}; | ||
|
||
return JsonConvert.DeserializeObject<DomainWhoIs>(_call.MakeCall(data)); | ||
} | ||
|
||
/// <summary> | ||
/// Registers a new client | ||
/// </summary> | ||
/// <remarks> | ||
/// When registerying an exception may occurr. If you get "An API Error Ocurred" read the inner exception | ||
/// </remarks> | ||
/// <example> | ||
/// try { your code } catch (Exception ex) { Console.WriteLine(ex.InnerException.Message); } | ||
/// </example> | ||
/// <see cref="https://developers.whmcs.com/api-reference/addclient/"/> | ||
/// <param name="ClientInfo">The Model of the AddClient action</param> | ||
/// <returns>If success returns the ID of the newly created user otherwise will throw an exception</returns> | ||
public int AddClient(AddClient ClientInfo) | ||
{ | ||
NameValueCollection data = new NameValueCollection() | ||
{ | ||
{ "action", APIEnums.Actions.AddClient.ToString() } | ||
}; | ||
|
||
//Processes all the data in ClientInfo model into the data NameValueCollection | ||
foreach (string key in ClientInfo.ClientInfo) | ||
{ | ||
data.Add(key, ClientInfo.ClientInfo[key]); | ||
} | ||
|
||
JObject result = JObject.Parse(_call.MakeCall(data)); | ||
|
||
if (result["result"].ToString() == "success") | ||
return Convert.ToInt32(result["clientid"]); | ||
else | ||
throw new Exception("An API Error Ocurred", new Exception(result["message"].ToString())); | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Gets the client details | ||
/// </summary> | ||
/// <param name="ClientID">The client ID to search</param> | ||
/// <param name="ClientEmail">The client Email to search</param> | ||
/// <param name="Stats">Get extended stats for the client</param> | ||
/// <returns>All details of the client</returns> | ||
public GetClientsDetails GetClientsDetails(int ClientID = -1, string ClientEmail = "", bool Stats = false) | ||
{ | ||
if (ClientID == -1 && ClientEmail == "") | ||
throw new Exception("ClientID or ClientEmail needed"); | ||
|
||
NameValueCollection data = new NameValueCollection() | ||
{ | ||
{ "action", APIEnums.Actions.GetClientsDetails.ToString() }, | ||
{ EnumUtil.GetString(APIEnums.GetClientsDetailsParams.Stats), Stats.ToString() }, | ||
}; | ||
if (ClientID != -1) | ||
data.Add(EnumUtil.GetString(APIEnums.GetClientsDetailsParams.ClientID), ClientID.ToString()); | ||
if (ClientEmail != "" && ClientID == -1) | ||
data.Add(EnumUtil.GetString(APIEnums.GetClientsDetailsParams.Email), ClientEmail); | ||
|
||
string req = _call.MakeCall(data); | ||
JObject result = JObject.Parse(req); | ||
if (result["result"].ToString() == "success") | ||
return JsonConvert.DeserializeObject<GetClientsDetails>(req); | ||
else | ||
throw new Exception("An API Error occurred", new Exception(result["message"].ToString())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace WHMCS_API | ||
{ | ||
/// <summary> | ||
/// Params info @ https://developers.whmcs.com/api-reference/addclient/ | ||
/// </summary> | ||
public class AddClient | ||
{ | ||
public readonly NameValueCollection ClientInfo; | ||
public AddClient(string Firstname, string Lastname, string Email, string Address1, | ||
string City, string State, string PostCode, string CountryCode, string PhoneNumber, | ||
string Password, bool NoEmail = false, string CompanyName = "", string Address2 = "", | ||
int SecurityQuestionID = -1, string SecurityQuestionAnswer = "", string CardType = "", | ||
string CardNumber = "", string ExpiricyDate = "", string StartDate = "", | ||
string IssueNumber = "", string CVV = "", int Currency = -1, int GroupID = -1, | ||
string CustomFields = "", string Language = "", string ClientIP = "", string Notes = "") | ||
{ | ||
ClientInfo = new NameValueCollection() | ||
{ | ||
{ EnumUtil.GetString(APIEnums.AddClientParams.Firstname), Firstname }, | ||
{ EnumUtil.GetString(APIEnums.AddClientParams.Lastname), Lastname }, | ||
{ EnumUtil.GetString(APIEnums.AddClientParams.Email), Email }, | ||
{ EnumUtil.GetString(APIEnums.AddClientParams.Address1), Address1 }, | ||
{ EnumUtil.GetString(APIEnums.AddClientParams.City), City }, | ||
{ EnumUtil.GetString(APIEnums.AddClientParams.State), State }, | ||
{ EnumUtil.GetString(APIEnums.AddClientParams.Postcode), PostCode }, | ||
{ EnumUtil.GetString(APIEnums.AddClientParams.CountryCode), CountryCode }, | ||
{ EnumUtil.GetString(APIEnums.AddClientParams.PhoneNumber), PhoneNumber }, | ||
{ EnumUtil.GetString(APIEnums.AddClientParams.Password), Password }, | ||
{ EnumUtil.GetString(APIEnums.AddClientParams.NoEmail), NoEmail.ToString() } | ||
}; | ||
if (CompanyName != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.CompanyName), CompanyName); | ||
if (Address2 != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.Address2), Address2); | ||
if (SecurityQuestionID != -1) | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.SecurityQuestionID), SecurityQuestionID.ToString()); | ||
if (SecurityQuestionAnswer != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.SecurityQuestionAnswer), SecurityQuestionAnswer); | ||
if (CardType != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.CardType), CardType); | ||
if (CardNumber != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.CardNumber), CardNumber); | ||
if (ExpiricyDate != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.ExpiricyDate), ExpiricyDate); | ||
if (StartDate != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.StartDate), StartDate); | ||
if (IssueNumber != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.IssueNumber), IssueNumber); | ||
if (CVV != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.CVV), CVV); | ||
if (Currency != -1) | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.Currency), Currency.ToString()); | ||
if(GroupID != -1) | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.GroupID), GroupID.ToString()); | ||
if (CustomFields != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.CustomFields), CustomFields); | ||
if (Language != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.Language), Language); | ||
if (ClientIP != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.ClientIP), ClientIP); | ||
if (Notes != "") | ||
ClientInfo.Add(EnumUtil.GetString(APIEnums.AddClientParams.Notes), Notes); | ||
} | ||
} | ||
} |
Oops, something went wrong.