Esempio n. 1
0
 static void Main(string[] args)
 {
     var service = new ZohoBooks();
     service.initialize("{authtoken}", "{organizationId}");
     var bankAccountsApi = service.GetBankAccountsApi();
     try
     {
         var parameters = new Dictionary<object, object>();
         var bankaccountsList = bankAccountsApi.GetBankAccounts(parameters);
         var bankaccounts = bankaccountsList;
         if (bankaccounts != null)
             foreach (var bankAccount in bankaccounts)
                 Console.WriteLine("{0},{1},{2}", bankAccount.account_id, bankAccount.account_name, bankAccount.balance);
         string accountId = bankaccounts[0].account_id;
        var bankaccount = bankAccountsApi.Get(accountId);
         if(bankaccount!=null)
             Console.WriteLine("{0},{1},{2}", bankaccount.account_number, bankaccount.account_name, bankaccount.balance);
         var newAccountInfo = new BankAccount()
         {
             account_name = "name of account",
             account_type = "bank",
             is_primary_account = true
         };
         var newAccount = bankAccountsApi.Create(newAccountInfo);
         if (newAccount != null)
             Console.WriteLine("{0},{1},{2}", newAccount.is_primary_account, newAccount.account_name, newAccount.balance);
         var updateInfo = new BankAccount()
         {
             account_name = "name of account",
             routing_number = "158987"
         };
         var updatedAccount = bankAccountsApi.Update(accountId, updateInfo);
         if(updatedAccount!=null)
             Console.WriteLine("{0},{1},{2}", updatedAccount.routing_number, updatedAccount.account_name, updatedAccount.balance);
        var delAccount = bankAccountsApi.Delete(bankaccounts[1].account_id);
        Console.WriteLine(delAccount);
        var deactAccount = bankAccountsApi.DeactivateAccount(accountId);
        Console.WriteLine(deactAccount);
        var actAccount = bankAccountsApi.ActivateAccount(accountId);
        Console.WriteLine(actAccount);
        var statement = bankAccountsApi.GetLastImportedStatement(accountId);
       if (statement != null)
       {
           Console.WriteLine("{0},{1},{2}", statement.statement_id, statement.to_date, statement.transactions.Count);
           var transactions = statement.transactions;
           foreach(var transaction in transactions)
           {
               Console.WriteLine("{0},{1},{2}", transaction.debit_or_credit, transaction.amount, transaction.transaction_type);
           }
       }
        var delstatement = bankAccountsApi.DeleteLastImportedStatement(accountId, statement.statement_id);
        Console.WriteLine(delstatement);
     }
     catch(Exception e)
     {
         Console.WriteLine(e.Message);
     }
     Console.ReadKey();
 }
 /// <summary>
 /// Creates the Bank account or credit card acount with the specified information.
 /// The specified information must contains the accountName, accountType parameters as a mandatory.
 /// </summary>
 /// <param name="new_account_info">The new_account_info is the object with account_name,account_type as mandatory parameters.</param>
 /// <returns>Bankaccount object.</returns>
 public BankAccount Create(BankAccount new_account_info)
 {
     string url = baseAddress;
     var json = JsonConvert.SerializeObject(new_account_info);
     var requestBody = new Dictionary<object, object>();
     requestBody.Add("JSONString", json);
     var responce = ZohoHttpClient.post(url, getQueryParameters(requestBody));
     return BankAccountParser.getBankAccount(responce);
 }
 internal static BankAccount getBankAccount(HttpResponseMessage responce)
 {
     var jsonObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(responce.Content.ReadAsStringAsync().Result);
     var bankAccount = new BankAccount();
     if (jsonObj.ContainsKey("bankaccount"))
     {
         bankAccount = JsonConvert.DeserializeObject<BankAccount>(jsonObj["bankaccount"].ToString());
     }
     return bankAccount;
 }
 internal static BankAccountList getBankAccountList(HttpResponseMessage responce)
 {
     var bankAccountList = new BankAccountList();
     var jsonObject = JsonConvert.DeserializeObject<Dictionary<string, object>>(responce.Content.ReadAsStringAsync().Result);
     if (jsonObject.ContainsKey("bankaccounts"))
     {
         var bankAccountsArray = JsonConvert.DeserializeObject<List<object>>(jsonObject["bankaccounts"].ToString());
         foreach (var bankAccountObj in bankAccountsArray)
         {
             var bankAccount = new BankAccount();
             bankAccount = JsonConvert.DeserializeObject<BankAccount>(bankAccountObj.ToString());
             bankAccountList.Add(bankAccount);
         }
     }
     if (jsonObject.ContainsKey("page_context"))
     {
         var pageContext = new PageContext();
         pageContext = JsonConvert.DeserializeObject<PageContext>(jsonObject["page_context"].ToString());
         bankAccountList.page_context = pageContext;
     }
     return bankAccountList;
 }
 /// <summary>
 /// Updates the details of the specified account.
 /// </summary>
 /// <param name="account_id">The account_id is the identifier of the acoount on which the modifications has to be applied .</param>
 /// <param name="update_info">The update_info is the Bankaccount object which is having the modification details.</param>
 /// <returns>Bankaccount object.</returns>
 public BankAccount Update(string account_id, BankAccount update_info)
 {
     string url = baseAddress + "/" + account_id;
     var json = JsonConvert.SerializeObject(update_info);
     var jsonString = new Dictionary<object, object>();
     jsonString.Add("JSONString", json);
     var responce = ZohoHttpClient.put(url, getQueryParameters(jsonString));
     return BankAccountParser.getBankAccount(responce);
 }