Skip to content

Instantly share code, notes, and snippets.

@justintoth
Created February 27, 2013 03:12
Show Gist options
  • Save justintoth/5044672 to your computer and use it in GitHub Desktop.
Save justintoth/5044672 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using Newtonsoft.Json;
using Housters.Schemas.Models.Account;
using Housters.Business.Utility.Helpers;
using Housters.Schemas.Models.Accounting;
using Housters.Schemas.Models.Tenancy;
using Housters.Business.Services.Tenancy;
using Housters.Business.Services.Common;
using MongoDB.Bson;
using Housters.Schemas;
using System.Net;
using System.IO;
namespace Housters.Business.Services.Account.Billing {
public class BalancedService {
protected string APIDomain = ConfigurationManager.AppSettings["BalancedAPIDomain"].ToString();
private string Marketplace = ConfigurationManager.AppSettings["BalancedAPIMarketplace"].ToString();
protected string APIBaseUrl {
get { return APIDomain + "/v1"; }
}
protected string APIUrl {
get { return APIBaseUrl + "/marketplaces/" + Marketplace; }
}
protected CreateAccountResponse CreateAccount() {
var url = APIUrl + "/accounts";
var responseJson = WebRequestHelper.PostWithAuth(url);
return JsonConvert.DeserializeObject<CreateAccountResponse>(responseJson);
}
protected CreateBankAccountResponse CreateBankAccount(string accountName,
string accountNumber, string routingNumber, string accountType, string url = null) {
if(String.IsNullOrEmpty(url))
url = APIUrl + "/bank_accounts";
var request = new CreateBankAccountRequest {
account_number = accountNumber,
name = accountName,
routing_number = routingNumber,
type = accountType
};
var requestJson = JsonConvert.SerializeObject(request);
var responseJson = WebRequestHelper.PostWithAuth(url, requestJson);
return JsonConvert.DeserializeObject<CreateBankAccountResponse>(responseJson);
}
protected BankAccountVerificationResponse CreateBankAccountVerification(string bankAccountId, string url = null) {
if (String.IsNullOrEmpty(url))
url = String.Format("{0}/bank_accounts/{1}/verifications", APIBaseUrl, bankAccountId);
var request = new CreateBankAccountVerificationRequest {
none = ""
};
var requestJson = JsonConvert.SerializeObject(request);
var responseJson = WebRequestHelper.PostWithAuth(url, requestJson);
return JsonConvert.DeserializeObject<BankAccountVerificationResponse>(responseJson);
}
protected BankAccountVerificationResponse ConfirmBankAccountVerification(string bankAccountId,
string verificationId, int amount1, int amount2, string url = null) {
if (String.IsNullOrEmpty(url))
url = String.Format("{0}/bank_accounts/{1}/verifications/{2}", APIBaseUrl, bankAccountId, verificationId);
var request = new ConfirmBankAccountVerificationRequest {
amount_1 = amount1,
amount_2 = amount2
};
var requestJson = JsonConvert.SerializeObject(request);
var responseJson = WebRequestHelper.PostWithAuth(url, requestJson, "PUT");
return JsonConvert.DeserializeObject<BankAccountVerificationResponse>(responseJson);
}
protected CreateNewDebitResponse CreateNewDebit(string accountId, double amount,
string appearsOnStatement, string description, string url = null) {
if (String.IsNullOrEmpty(url))
url = APIUrl + "/accounts/" + accountId + "/debits";
var request = new CreateNewDebitRequest {
appears_on_statement_as = appearsOnStatement,
amount = Convert.ToInt32(amount * 100),
description = description
};
var requestJson = JsonConvert.SerializeObject(request);
var responseJson = WebRequestHelper.PostWithAuth(url, requestJson);
return JsonConvert.DeserializeObject<CreateNewDebitResponse>(responseJson);
}
protected CreateNewCreditResponse CreateNewCredit(string bankAccountId, double amount,
string url = null) {
if (String.IsNullOrEmpty(url))
url = APIBaseUrl + "/bank_accounts/" + bankAccountId + "/credits";
var request = new CreateNewCreditRequest {
amount = Convert.ToInt32(amount * 100)
};
var requestJson = JsonConvert.SerializeObject(request);
var responseJson = WebRequestHelper.PostWithAuth(url, requestJson);
return JsonConvert.DeserializeObject<CreateNewCreditResponse>(responseJson);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment