This is the .NET SDK to call https://app.earnshark.com API. It contains methods to call the EarnShark API making the application integration fast and easy.
- .NET Runtime Environment 4.0 or later.
You can install the package using NuGet package gallery.
Install-Package earnshark-sdk-dot-net
Through this you will be able to access the EarnShark API through your code.
After installation of the EarnShark SDK package call the following command in your main function: RunAsync().Wait();
Then create a method: static async Task RunAsync(){}
Within the method initialize the sdk with earnshark-sdk earnsharksdk = new earnsharksdk();
- getAccountInformation - Retrieve information on a particular account/subscription
- getLicenseInformation - Retrieve information on a particular license
- getAllLicensesOfProduct - Retrieve all the license data for a particular product
- addNewSubscription - Add a new subscription to a product
- getAccountPayments - Returns all the payment transactions associated with the account
- renewSubscription - Renew/Update a Subscription
- getPaymentToken - Returns the token for transactions
- getTransactionURL - Returns the payment portal URL for a subscription(linked to PayPal)
Using RunAsync methods, enter the code to call the above available methods.
Initialize the ID's needed
string key = "<YOUR KEY FROM EarnShark Dashboard>";
string account_id = "<ACCOUNT_ID>";
int product_id = "<PRODUCT_ID>"; // integer
Alternatively, you can use the application's app.config
file to save your IDs.
<add key="key" value=""/>
<add key="account_id" value=""/>
<add key="product_id" value=""/>
And access them in your code as follows,
string key = ConfigurationManager.AppSettings["key"].ToString();
string account_id = Guid.NewGuid().ToString();
int product_id = Int32.Parse(ConfigurationManager.AppSettings["product_id"]);
JArray accountInformation = await earnsharksdk.getAccountInformation(product_id, account_id, key);
int license_id = "<ID>"; // integer
string license_token = "<YOUR LICENSE TOKEN>";
JObject licenseInformation = await earnsharksdk.getLicenseInformation(product_id, license_token,license_id);
JArray allLicenses = await earnsharksdk.getAllLicensesOfProduct(product_id, key);
JObject user = new JObject(
new JProperty("account",
new JObject(
new JProperty("name", "<name>"), //string
new JProperty("email", "<email>"), //string
new JProperty("accountID", "<account_id>"), //string
new JProperty("start_date", "<date>" // Date format MM/dd/yyyy)
)),
new JProperty("license_id", <license_id>), //integer
new JProperty("enableNotifications", "true" //boolean),
new JProperty("sendInvoiceNow", "false" //boolean)
);
JObject newUser = await earnsharksdk.addNewSubscription(product_id, key, user);
JObject body = new JObject(
new JProperty("redirect", "<redirect_url>"), //string
new JProperty("account_id", "<account_id>"), //string
new JProperty("product_id", product_id), //integer
new JProperty("key", key)
);
JObject transactionId = await earnsharksdk.getPaymentToken(body);
string url = earnsharksdk.getTransactionURL(transactionId);
JArray accountPayments = await earnsharksdk.getAccountPayments(product_id, account_id, key);
JObject newSubs = await earnsharksdk.addNewSubscription(product_id, key, jObject);