예제 #1
0
        public async Task <IIntacctSession> InitiateApiSession(IntacctUserCredential cred, CancellationToken token)
        {
            var operation = new GetApiSessionOperation(cred);

            // construct and execute request
            var operations = new[] { operation };
            var response   = await ExecuteOperations(operations, token);

            // expecting a single operation result (more or less is a problem)
            var result = response.OperationResults.OfType <IntacctOperationResult <IntacctSession> >().SingleOrDefault();

            if (result != null)
            {
                return(result.Value);
            }

            // let's see what the result is
            var badResult = response.OperationResults.FirstOrDefault();

            if (badResult == null)
            {
                throw new Exception("Unable to initiate API session, and no results were captured.");
            }

            var authError = badResult as IntacctOperationAuthFailedResult;

            if (authError != null)
            {
                throw new Exception($"Unable to initiate API session, authentication failed. Service error: {authError.Errors.Select(e => e.ToString()).Aggregate((curr, next) => curr + " " + next)}");
            }

            throw new Exception($"Unable to initiate API session, unexpected result type {badResult.GetType().Name}.");
        }
예제 #2
0
		public async Task<IIntacctSession> InitiateApiSession(IntacctUserCredential cred, CancellationToken token)
		{
			var operation = new GetApiSessionOperation(cred);

			// construct and execute request
			var operations = new[] { operation };
			var response = await ExecuteOperations(operations, token);

			// expecting a single operation result (more or less is a problem)
			var result = response.OperationResults.OfType<IntacctOperationResult<IntacctSession>>().SingleOrDefault();
			if (result != null) return result.Value;

			// let's see what the result is
			var badResult = response.OperationResults.FirstOrDefault();
			if (badResult == null) throw new Exception("Unable to initiate API session, and no results were captured.");

			var authError = badResult as IntacctOperationAuthFailedResult;
			if (authError != null) throw new Exception($"Unable to initiate API session, authentication failed. Service error: {authError.Errors.Select(e => e.ToString()).Aggregate((curr, next) => curr + " " + next)}");

			throw new Exception($"Unable to initiate API session, unexpected result type {badResult.GetType().Name}.");
		}
예제 #3
0
		private static void Main()
		{
			var settings = LoadSettings();

			var serverUri = new Uri(settings.ServerUri);
			var serverCredential = new NetworkCredential(settings.AccountUsername, settings.AccountPassword);
			var userCredential = new IntacctUserCredential(settings.CompanyName, settings.Username, settings.Password);

			var client = new IntacctClient(serverUri, serverCredential);

			var session = client.InitiateApiSession(userCredential).Result;

			Console.WriteLine($"Session created, ID: {session.SessionId}, Endpoint: {session.EndpointUri}");

			// create customer
			var customer = new IntacctCustomer("C0021", "MT Test " + Guid.NewGuid())
				               {
					               ExternalId = "1337",
					               PrimaryContact = new IntacctContact(Guid.NewGuid().ToString(), "Random")
				               };
			var response = client.ExecuteOperations(new[] { new CreateCustomerOperation(session, customer) }, CancellationToken.None).Result;

			Console.WriteLine($"Customer created: {response.Success}");
			if (!response.Success) return;

			// retrieve customer
			response = client.ExecuteOperations(new[] { new GetEntityOperation<IntacctCustomer>(session, customer.Id) }, CancellationToken.None).Result;
			Console.WriteLine($"Customer retrieved: {response.Success}");
			if (!response.Success) return;

			// create invoice
			var invoice = new IntacctInvoice(customer.Id, new IntacctDate(1, 1, 2015), new IntacctDate(1, 1, 2015));
			var lineItem = IntacctLineItem.CreateWithAccountNumber("2000", 15);
			lineItem.Memo = "Services rendered";
			invoice.Items.Add(lineItem);
			response = client.ExecuteOperations(new[] { new CreateInvoiceOperation(session, invoice) }, CancellationToken.None).Result;

			Console.WriteLine($"Invoice created: {response.Success}");
		}
예제 #4
0
		public async Task<IIntacctSession> InitiateApiSession(IntacctUserCredential cred)
		{
			return await InitiateApiSession(cred, CancellationToken.None);
		}
예제 #5
0
 public async Task <IIntacctSession> InitiateApiSession(IntacctUserCredential cred)
 {
     return(await InitiateApiSession(cred, CancellationToken.None));
 }