public void ConstructWithLoginTest()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>sessionProvider</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>testuser</userid>
                  <companyid>testcompany</companyid>
                  <sessiontimestamp>2015-12-06T15:57:08-08:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>success</status>
                  <function>getAPISession</function>
                  <controlid>getSession</controlid>
                  <data>
                        <api>
                              <sessionid>helloworld..</sessionid>
                              <endpoint>https://p1.intacct.com/ia/xml/xmlgw.phtml</endpoint>
                        </api>
                  </data>
            </result>
      </operation>
</response>";

            HttpResponseMessage mockResponse1 = new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(xml)
            };

            List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage>
            {
                mockResponse1,
            };

            MockHandler mockHandler = new MockHandler(mockResponses);

            SdkConfig config = new SdkConfig
            {
                SenderId       = "testsenderid",
                SenderPassword = "******",
                SessionId      = "originalSeSsIonID..",
                MockHandler    = mockHandler,
            };

            IntacctClient test = new IntacctClient(config);

            Assert.AreEqual("helloworld..", test.SessionCreds.SessionId);
            StringAssert.Equals("https://p1.intacct.com/ia/xml/xmlgw.phtml", test.SessionCreds.Endpoint);
        }
        public void Initialize()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>sessionProvider</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>testuser</userid>
                  <companyid>testcompany</companyid>
                  <sessiontimestamp>2015-12-06T15:57:08-08:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>success</status>
                  <function>getAPISession</function>
                  <controlid>getSession</controlid>
                  <data>
                        <api>
                              <sessionid>testSeSsionID..</sessionid>
                              <endpoint>https://p1.intacct.com/ia/xml/xmlgw.phtml</endpoint>
                        </api>
                  </data>
            </result>
      </operation>
</response>";

            HttpResponseMessage mockResponse1 = new HttpResponseMessage()
            {
                StatusCode = System.Net.HttpStatusCode.OK,
                Content    = new StringContent(xml)
            };

            List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage>
            {
                mockResponse1,
            };

            MockHandler mockHandler = new MockHandler(mockResponses);

            SdkConfig config = new SdkConfig
            {
                SenderId       = "testsenderid",
                SenderPassword = "******",
                CompanyId      = "testcompany",
                UserId         = "testuser",
                UserPassword   = "******",
                MockHandler    = mockHandler,
            };

            client = new IntacctClient(config);
        }
Example #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}");
        }