/// <summary>
        /// Constructs the Freshbooks API authentication and wrapper class
        /// </summary>
        /// <param name="accountName">The account name for which you are trying to access</param>
        /// <param name="consumerKey">The developer's freshbooks account name</param>
        /// <param name="oauthSecret">The developer's oauth-secret provided by freshbooks</param>
        public FreshbooksApi(string accountName, string consumerKey, string oauthSecret)
        {
            _accountName = accountName;
            _consumerKey = consumerKey;
            _oauthSecret = oauthSecret ?? String.Empty;

            _baseUri = new UriBuilder { Scheme = "https", Host = accountName + ".freshbooks.com" }.Uri;
            _serviceUri = new Uri(_baseUri, "/api/2.1/xml-in");
            Clear();

            UserAgent = String.Format("{0}/{1} ({2})", 
                GetType().Name,
                GetType().Assembly.GetName().Version.ToString(2), 
                GetType().Assembly.FullName);

            Callback = new CallbackService(new ServiceProxy(this, "callback"));
            Category = new CategoryService(new ServiceProxy(this, "category"));
            Client = new ClientService(new ServiceProxy(this, "client"));
            Estimate = new EstimateService(new ServiceProxy(this, "estimate"));
            Expense = new ExpenseService(new ServiceProxy(this, "expense"));
            Gateway = new GatewayService(new ServiceProxy(this, "gateway"));
            Invoice = new InvoiceService(new ServiceProxy(this, "invoice"));
            Item = new ItemService(new ServiceProxy(this, "item"));
            Language = new LanguageService(new ServiceProxy(this, "language"));
            Payment = new PaymentService(new ServiceProxy(this, "payment"));
            Project = new ProjectService(new ServiceProxy(this, "project"));
            Recurring = new RecurringService(new ServiceProxy(this, "recurring"));
            System = new SystemService(new ServiceProxy(this, "system"));
            Staff = new StaffService(new ServiceProxy(this, "staff"));
            Task = new TaskService(new ServiceProxy(this, "task"));
            Tax = new TaxService(new ServiceProxy(this, "tax"));
            TimeEntry = new TimeEntryService(new ServiceProxy(this, "time_entry"));
        }
示例#2
0
        public void Test_006c_GetSchedule()
        {
            var schedule = Schedule.Find(PaymentId("Credit"));

            Assert.IsNotNull(schedule);

            schedule = RecurringService.Get <Schedule>(schedule.Key);
            Assert.IsNotNull(schedule);
        }
示例#3
0
        public void Test_006b_GetPaymentMethod()
        {
            var paymentMethod = RecurringPaymentMethod.Find(PaymentId("Credit"));

            Assert.IsNotNull(paymentMethod);

            paymentMethod = RecurringService.Get <RecurringPaymentMethod>(paymentMethod.Key);
            Assert.IsNotNull(paymentMethod);
        }
示例#4
0
        public void Test_006a_GetCustomer()
        {
            var customer = Customer.Find(CustomerId);

            Assert.IsNotNull(customer);

            customer = RecurringService.Get <Customer>(customer.Key);
            Assert.IsNotNull(customer);
        }
示例#5
0
 /// <summary>
 /// Delete a record from the gateway.
 /// </summary>
 /// <param name="force">Indicates if the deletion should be forced</summary>
 /// <exception cref="ApiException">Thrown when the record cannot be deleted.</exception>
 public void Delete(bool force = false)
 {
     try {
         RecurringService.Delete(this as TResult, force);
     }
     catch (ApiException exc) {
         throw new ApiException("Failed to delete record, see inner exception for more details", exc);
     }
 }
示例#6
0
 /// <summary>
 /// The current record should be updated.
 /// </summary>
 /// <remarks>
 /// Any modified properties will be persisted with the gateway.
 /// </remarks>
 /// <exception cref="ApiException">Thrown when the record cannot be updated.</exception>
 public void SaveChanges()
 {
     try {
         RecurringService.Edit(this as TResult);
     }
     catch (ApiException exc) {
         throw new ApiException("Update failed, see inner exception for more details", exc);
     }
 }
示例#7
0
        /// <summary>
        /// Lists all records of type `TResult`.
        /// </summary>
        /// <exception cref="UnsupportedTransactionException">
        /// Thrown when gateway does not support retrieving recurring records.
        /// </exception>
        public static List <TResult> FindAll(string configName = "default")
        {
            var client = ServicesContainer.Instance.GetRecurringClient(configName);

            if (client.SupportsRetrieval)
            {
                return(RecurringService.Search <List <TResult> >().Execute());
            }
            throw new UnsupportedTransactionException();
        }
示例#8
0
        /// <summary>
        /// Searches for a specific record by `id`.
        /// </summary>
        /// <param name="id">The ID of the record to find</summary>
        /// <returns>`TResult` or `null` if the record cannot be found.</returns>
        /// <exception cref="UnsupportedTransactionException">
        /// Thrown when gateway does not support retrieving recurring records.
        /// </exception>
        public static TResult Find(string id, string configName = "default")
        {
            var client = ServicesContainer.Instance.GetRecurringClient(configName);

            if (client.SupportsRetrieval)
            {
                var identifier = GetIdentifierName();
                var response   = RecurringService.Search <List <TResult> >()
                                 .AddSearchCriteria(identifier, id)
                                 .Execute();
                var entity = response.FirstOrDefault();
                if (entity != null)
                {
                    return(RecurringService.Get <TResult>(entity.Key));
                }
                return(null);
            }
            throw new UnsupportedTransactionException();
        }
        private void InitializeRecurringServices()
        {
            var firstServiceTemplate = _client.ServiceTemplates.ElementAt(0);
            var secondServiceTemplate = _client.ServiceTemplates.ElementAt(1);
            var thirdServiceTemplate = _client.ServiceTemplates.ElementAt(2);

            var recurringServiceOne = new RecurringService { ServiceTemplate = firstServiceTemplate.MakeChild(ServiceTemplateLevel.RecurringServiceDefined) };

            var repeat = (new RepeatDesignData()).DesignWeeklyRepeat;
            repeat.Id = recurringServiceOne.Id; //Fix Referential Contraint
            recurringServiceOne.Repeat = repeat;
            recurringServiceOne.CreatedDate = DateTime.UtcNow;
            recurringServiceOne.LastModified = DateTime.UtcNow;

            var recurringServiceTwo = new RecurringService { ServiceTemplate = secondServiceTemplate.MakeChild(ServiceTemplateLevel.RecurringServiceDefined) };

            repeat = (new RepeatDesignData()).DesignMonthlyRepeat;
            repeat.Id = recurringServiceTwo.Id; //Fix Referential Contraint
            recurringServiceTwo.Repeat = repeat;
            recurringServiceTwo.CreatedDate = DateTime.UtcNow;
            recurringServiceTwo.LastModified = DateTime.UtcNow;

            var recurringServiceThree = new RecurringService { ServiceTemplate = thirdServiceTemplate.MakeChild(ServiceTemplateLevel.RecurringServiceDefined) };

            repeat = (new RepeatDesignData()).DesignNeverEndingWeeklyRepeat;
            repeat.Id = recurringServiceThree.Id; //Fix Referential Contraint
            recurringServiceThree.Repeat = repeat;
            recurringServiceThree.CreatedDate = DateTime.UtcNow;
            recurringServiceThree.LastModified = DateTime.UtcNow;

            DesignRecurringServices = new ObservableCollection<RecurringService>
            {
               recurringServiceOne,
               recurringServiceTwo,
               recurringServiceThree
            };
        }
示例#10
0
 /// <summary>
 /// Creates a resource
 /// </summary>
 /// <returns>TResult</returns>
 public TResult Create(string configName = "default")
 {
     return(RecurringService.Create(this as TResult));
 }