Introduction
In this article, I explain how to integrate Zoho subscriptions using the Zoho APIs in Asp.Net MVC, In this article, I create the Customer and plans for the subscriptions.
Step1: Create a simple web application in Asp.Net MVC
now create a new controller for this and give the name of this controller like ZohoController.
Step 2: now add the new NuGet package for the Zoho API.
open your package manager console and install the latest version of Zoho API.
Install-Package Zoho.Api
Step 3: Now you need to get ZohoOrganizationID and ZohoAuthToken.
Login to the Zoho Invoice admin console. Click the drop-down with the organization’s name as the label and click Manage Organizations.
Now you’ll be able to find Organization IDs for each of your organizations.
Step 5: Now you need to add ZohoOrganizationID and ZohoAuthToken on the web.config file for global use.
add below key on the web.config file.
<add key="ZohoOrganizationID" value="686788585" /> <add key="ZohoAuthToken" value="9d31f2e7a29b52b5ca5331f22c11e732" />
Step 6: Create the class (get set) for the Customer
Request
public class ZohoCustomersRequest { public string display_name { get; set; } public string first_name { get; set; } public string last_name { get; set; } public string email { get; set; } public string company_name { get; set; } public string phone { get; set; } public string website { get; set; } public Address billing_address { get; set; } public Address shipping_address { get; set; } public bool is_portal_enabled { get; set; } } public class Address { public string street { get; set; } public string city { get; set; } public string state { get; set; } public string zip { get; set; } public string country { get; set; } public string address_id { get; set; } public string street2 { get; set; } public string fax { get; set; } public string state_code { get; set; } public string phone { get; set; } public string attention { get; set; } }
Response
public class ZohoCustomersResponse { public int code { get; set; } public string message { get; set; } public Customer customer { get; set; } public PageContext page_context { get; set; } }
Step 7: now create the method of creating a customer in this controller.
public string InsertCustomer() { try { ZohoCustomersRequest ObjCustomer = new ZohoCustomersRequest(); ObjCustomer.first_name = "Bhavdip"; ObjCustomer.last_name = "Talaviya"; ObjCustomer.email = "bhavdip.vision@gmail.com"; ObjCustomer.phone = "9825891108"; ObjCustomer.company_name = "vision infotech"; ObjCustomer.display_name = "Bhavdip Talaviya"; Address objBillingAddress = new Address(); objBillingAddress.country = "India"; objBillingAddress.state = "gujarat"; objBillingAddress.city = "Surat"; objBillingAddress.zip = "394101"; objBillingAddress.street = "7th street motavarachha"; ObjCustomer.billing_address = objBillingAddress; ObjCustomer.shipping_address = objBillingAddress; string body = new JavaScriptSerializer().Serialize(ObjCustomer); var result = CommonMethods.CallZohoAPI("customers", "POST", body); var CustomerAdded = JsonConvert.DeserializeObject<ZohoCustomersResponse>(result); return JsonConvert.SerializeObject(new { IsSuccess = true, data = CustomerAdded, Operation = "InsertCustomer", Message = "Customer Insert into zoho successfully." }); } catch (Exception ex) { return JsonConvert.SerializeObject(new { IsSuccess = false, Operation = "InsertCustomer", Message = "Something went wrong" }); } }
Step 8: Create the class (get set) for the Plan
public class Plan { [DisplayFormat(ConvertEmptyStringToNull = false)] public string plan_code { get; set; } [DisplayFormat(ConvertEmptyStringToNull = false)] public string plan_description { get; set; } [DisplayFormat(ConvertEmptyStringToNull = false)] public string name { get; set; } = ""; public int interval { get; set; } public string interval_unit { get; set; } public decimal recurring_price { get; set; } public decimal price { get; set; } public decimal setup_fee { get; set; } [DisplayFormat(ConvertEmptyStringToNull = false)] public string setup_fee_tax_id { get; set; } public int quantity { get; set; } public string tax_name { get; set; } public string setup_fee_tax_percentage { get; set; } //[DisplayFormat(ConvertEmptyStringToNull = false)] //public string tax_id { get; set; } //[DisplayFormat(ConvertEmptyStringToNull = false)] //public string tax_exemption_id { get; set; } //[DisplayFormat(ConvertEmptyStringToNull = false)] //public string tax_exemption_code { get; set; } //[DisplayFormat(ConvertEmptyStringToNull = false)] //public string setup_fee_tax_exemption_id { get; set; } //[DisplayFormat(ConvertEmptyStringToNull = false)] //public string setup_fee_tax_exemption_code { get; set; } public bool exclude_trial { get; set; } public bool exclude_setup_fee { get; set; } public decimal billing_cycles { get; set; } public int trial_days { get; set; } public string status { get; set; } public string description { get; set; } public decimal discount { get; set; } public string tax_id { get; set; } public decimal total { get; set; } public string setup_fee_tax_name { get; set; } public string tax_type { get; set; } public decimal tax_percentage { get; set; } public string setup_fee_tax_type { get; set; } public string plan_id { get; set; } }
Step 9: Create a method for creating a plan in the Zoho account.
public string InsertPlans() { try { Plan ObjPlan = new Plan(); ObjPlan.plan_code = "Gold"; ObjPlan.price = 150; ObjPlan.quantity = 1; ObjPlan.plan_description = "test gold plan"; ObjPlan.name = "Gold Plan"; string body = new JavaScriptSerializer().Serialize(ObjPlan); var result = CommonMethods.CallZohoAPI("Plan", "POST", body); var PlanAdded = JsonConvert.DeserializeObject<ZohoCustomersResponse>(result); return JsonConvert.SerializeObject(new { IsSuccess = true, data = PlanAdded, Operation = "InsertPlans", Message = "Customer Insert into zoho successfully." }); } catch (Exception ex) { return JsonConvert.SerializeObject(new { IsSuccess = false, Operation = "InsertPlans", Message = "Something went wrong" }); } }
Now you can call this method and then show this customer and plan inserted or not in your Zoho Account.
here are some incomplete explanations…can you please tell me where from this ZohoAuthToken came?
how I use CommonMethods.CallZohoAPI() where it should I create?