Esempio n. 1
0
        public void InsertAndGetInvoicePaymentForMultiCcyInvoice()
        {
            var invoice = GetInvoiceTransaction01();

            invoice.Currency           = "USD";
            invoice.AutoPopulateFxRate = true;
            var invoiceProxy        = new InvoiceProxy();
            var insertInvoiceResult = invoiceProxy.InsertInvoice(invoice);

            Assert.IsTrue(insertInvoiceResult.DataObject.InsertedEntityId > 0,
                          "There was an error creating the invoice for payment test.");

            var insertedInvoiceFromDb = invoiceProxy.GetInvoice(insertInvoiceResult.DataObject.InsertedEntityId);
            var insertedInvoiceAutoPopulatedFxRate = insertedInvoiceFromDb.DataObject.FxRate;

            var invoicePayment = new PaymentTransaction
            {
                TransactionDate    = DateTime.Now,
                TransactionType    = "SP",
                Currency           = "USD",
                AutoPopulateFxRate = true,
                Summary            =
                    string.Format("Test Payment insert for Inv# {0}",
                                  insertInvoiceResult.DataObject.GeneratedInvoiceNumber),
                PaymentAccountId = _bankAccount01Id,
                PaymentItems     = new List <PaymentItem>
                {
                    new PaymentItem
                    {
                        InvoiceTransactionId =
                            insertInvoiceResult.DataObject.InsertedEntityId,
                        AmountPaid = 110.00M
                    }
                }
            };

            var invoicePaymentProxy          = new PaymentProxy();
            var insertInvoicePaymentResponse = invoicePaymentProxy.InsertInvoicePayment(invoicePayment);

            Assert.IsNotNull(insertInvoicePaymentResponse);
            Assert.IsTrue(insertInvoicePaymentResponse.IsSuccessfull);
            Assert.IsNotNull(insertInvoicePaymentResponse.RawResponse);

            var insertInvoicePaymentResult = insertInvoicePaymentResponse.DataObject;


            Assert.IsTrue(insertInvoicePaymentResult.InsertedEntityId > 0,
                          string.Format("There was an error creating the invoice payment for Invoice Id {0}",
                                        insertInvoiceResult.DataObject.InsertedEntityId));

            var getInvoicePaymentResponse = invoicePaymentProxy.GetPayment(insertInvoicePaymentResult.InsertedEntityId);
            var getInvoicePaymentResult   = getInvoicePaymentResponse.DataObject;

            Assert.IsNotNull(getInvoicePaymentResult);
            Assert.IsTrue(getInvoicePaymentResult.TransactionId == insertInvoicePaymentResult.InsertedEntityId, "Incorrect payment transaction ID");
            Assert.AreEqual(110M, getInvoicePaymentResult.TotalAmount, "Incorrect payment amount.");
            Assert.IsTrue(getInvoicePaymentResult.AutoPopulateFxRate, "Incorrect auto populate Fx Rate status.");
            Assert.AreEqual(insertedInvoiceAutoPopulatedFxRate, getInvoicePaymentResult.FxRate, "Incorrect Auto Populated FX Rate");
            Assert.IsTrue(getInvoicePaymentResult.PaymentItems.Count == 1, "Incorrect number of payment items.");
        }
Esempio n. 2
0
        public void ShouldRetreivePaymentSummaryForInvoiceId()
        {
            var invoice             = GetInvoiceTransaction01();
            var invoiceProxy        = new InvoiceProxy();
            var insertInvoiceResult = invoiceProxy.InsertInvoice(invoice);

            Assert.IsTrue(insertInvoiceResult.DataObject.InsertedEntityId > 0,
                          "There was an error creating the first invoice for payment test - ShouldRetreivePaymentSummaryForInvoiceId.");

            var invoice01TransctionId = insertInvoiceResult.DataObject.InsertedEntityId;

            invoice             = GetInvoiceTransaction02();
            invoiceProxy        = new InvoiceProxy();
            insertInvoiceResult = invoiceProxy.InsertInvoice(invoice);

            Assert.IsTrue(insertInvoiceResult.DataObject.InsertedEntityId > 0,
                          "There was an error creating the second invoice for payment test - ShouldRetreivePaymentSummaryForInvoiceId.");

            var invoice02TransactionId = insertInvoiceResult.DataObject.InsertedEntityId;

            var invoicePayment = new PaymentTransaction
            {
                TransactionDate = DateTime.Now,
                TransactionType = "SP",
                Currency        = "AUD",
                Summary         =
                    string.Format("Test Payment insert for multiple invoices"),
                PaymentAccountId = _bankAccount01Id,
                PaymentItems     = new List <PaymentItem>
                {
                    new PaymentItem
                    {
                        InvoiceTransactionId = invoice01TransctionId,
                        AmountPaid           = 110.00M
                    },

                    new PaymentItem
                    {
                        InvoiceTransactionId = invoice02TransactionId,
                        AmountPaid           = 150.00M
                    }
                }
            };

            var invoicePaymentProxy          = new PaymentProxy();
            var insertInvoicePaymentResponse = invoicePaymentProxy.InsertInvoicePayment(invoicePayment);

            Assert.IsNotNull(insertInvoicePaymentResponse);
            Assert.IsTrue(insertInvoicePaymentResponse.IsSuccessfull);
            Assert.IsNotNull(insertInvoicePaymentResponse.RawResponse);

            var paymentsResponse = new PaymentsProxy().GetPayments(null, null, invoice02TransactionId, null, null, null,
                                                                   null, null, null, null, null, null);

            Assert.IsNotNull(paymentsResponse, "Payments response is NULL.");
            Assert.IsTrue(paymentsResponse.IsSuccessfull, "Payments response was not successful.");
            Assert.IsNotNull(paymentsResponse.DataObject.PaymentTransactions, "Payments response does not contain a payments summary.");
            Assert.IsTrue(paymentsResponse.DataObject.PaymentTransactions.Count > 0, "No payment summaries found for transaction type.");
            Assert.AreEqual(150M, paymentsResponse.DataObject.PaymentTransactions[0].TotalAmount, "Incorrect payment amount");
        }
Esempio n. 3
0
        public void CannotApplyPaymentToIncorrectInvoiceTransactionType()
        {
            var invoice             = GetInvoiceTransaction01();
            var invoiceProxy        = new InvoiceProxy();
            var insertInvoiceResult = invoiceProxy.InsertInvoice(invoice);

            Assert.IsTrue(insertInvoiceResult.DataObject.InsertedEntityId > 0,
                          "There was an error creating the invoice for payment test.");

            var invoicePayment = new PaymentTransaction
            {
                TransactionDate = DateTime.Now,
                TransactionType = "PP",
                Currency        = "AUD",
                Summary         =
                    string.Format("Test Incorrect Payment Type for Inv# {0}",
                                  insertInvoiceResult.DataObject.GeneratedInvoiceNumber),
                PaymentAccountId = _bankAccount01Id,
                PaymentItems     = new List <PaymentItem>
                {
                    new PaymentItem
                    {
                        InvoiceTransactionId =
                            insertInvoiceResult.DataObject.InsertedEntityId,
                        AmountPaid = 110.00M
                    }
                }
            };

            var invoicePaymentProxy          = new PaymentProxy();
            var insertInvoicePaymentResponse = invoicePaymentProxy.InsertInvoicePayment(invoicePayment);

            Assert.IsNotNull(insertInvoicePaymentResponse);
            Assert.IsFalse(insertInvoicePaymentResponse.IsSuccessfull);
        }
Esempio n. 4
0
        public void InsertAndGetPaymentForSingleInvoice()
        {
            var invoice             = GetInvoiceTransaction01();
            var invoiceProxy        = new InvoiceProxy();
            var insertInvoiceResult = invoiceProxy.InsertInvoice(invoice);

            Assert.IsTrue(insertInvoiceResult.DataObject.InsertedEntityId > 0,
                          "There was an error creating the invoice for payment test.");

            var invoicePayment = new PaymentTransaction
            {
                TransactionDate = DateTime.Now,
                TransactionType = "SP",
                Currency        = "AUD",
                Summary         =
                    string.Format("Test Payment insert for Inv# {0}",
                                  insertInvoiceResult.DataObject.GeneratedInvoiceNumber),
                PaymentAccountId = _bankAccount01Id,
                PaymentItems     = new List <PaymentItem>
                {
                    new PaymentItem()
                    {
                        InvoiceTransactionId =
                            insertInvoiceResult.DataObject.InsertedEntityId,
                        AmountPaid = 110.00M
                    }
                }
            };

            var invoicePaymentProxy          = new PaymentProxy();
            var insertInvoicePaymentResponse = invoicePaymentProxy.InsertInvoicePayment(invoicePayment);

            Assert.IsNotNull(insertInvoicePaymentResponse);
            Assert.IsTrue(insertInvoicePaymentResponse.IsSuccessfull);
            Assert.IsNotNull(insertInvoicePaymentResponse.RawResponse);

            var insertInvoicePaymentResult = insertInvoicePaymentResponse.DataObject;


            Assert.IsTrue(insertInvoicePaymentResult.InsertedEntityId > 0,
                          string.Format("There was an error creating the invoice payment for Invoice Id {0}",
                                        insertInvoiceResult.DataObject.InsertedEntityId));

            var getInvoicePaymentResponse = invoicePaymentProxy.GetPayment(insertInvoicePaymentResult.InsertedEntityId);
            var getInvoicePaymentResult   = getInvoicePaymentResponse.DataObject;

            Assert.IsNotNull(getInvoicePaymentResult);
            Assert.IsTrue(getInvoicePaymentResult.TransactionId == insertInvoicePaymentResult.InsertedEntityId, "Incorrect payment transaction ID");
            Assert.AreEqual(110M, getInvoicePaymentResult.TotalAmount, "Incorrect payment amount.");
            Assert.IsTrue(getInvoicePaymentResult.PaymentItems.Count == 1, "Incorrect number of payment items.");
            Assert.IsNull(getInvoicePaymentResult.ClearedDate, "Incorrect cleared date.");

            foreach (var paymentItem in getInvoicePaymentResult.PaymentItems)
            {
                Assert.AreEqual(paymentItem.InvoiceTransactionId, insertInvoiceResult.DataObject.InsertedEntityId, "Incorrect invoice payment item invoice transaction Id.");
                Assert.AreEqual(paymentItem.AmountPaid, 110M, "Incorrect invoice payment item paid amount.");
            }
        }
Esempio n. 5
0
        private InvoiceTransactionDetail GetTestInsertInvoice(string invoiceLayout, List <InvoiceTransactionLineItem> lineItems = null, string notesInternal = null,
                                                              string notesExternal = null, InvoiceTradingTerms terms = null, List <FileAttachmentInfo> attachments = null, int?templateId       = null,
                                                              bool emailContact    = false, Saasu.API.Core.Models.Email emailMessage = null, string currency       = null, string invoiceNumber = null, string purchaseOrderNumber = null,
                                                              string invoiceType   = null, string transactionType = null, string summary     = null, decimal?totalAmountInclTax = null, bool requiresFollowUp = false, DateTime?transactionDate = null,
                                                              int?billingContactId = null, int?shippingContactId  = null, List <string> tags = null, decimal?fxRate             = null, string invoiceStatus  = null,
                                                              bool actuallyInsertAndVerifyResponse = false, bool autoPopulateFxRate = false)
        {
            var tranType = transactionType ?? "S";

            var invDetail = new InvoiceTransactionDetail
            {
                LineItems           = lineItems ?? GetInsertItems(invoiceLayout, tranType),
                NotesInternal       = notesInternal ?? "Test internal note",
                NotesExternal       = notesExternal ?? "Test external note",
                Terms               = terms ?? GetTradingTerms(),
                Attachments         = attachments ?? GetAttachments(),
                TemplateId          = templateId ?? GetTemplateUid(),
                SendEmailToContact  = emailContact,
                EmailMessage        = emailMessage ?? GetEmailMessage(),
                Currency            = currency ?? "AUD",
                InvoiceNumber       = invoiceNumber ?? AutoNumber,
                PurchaseOrderNumber = purchaseOrderNumber ?? AutoNumber,
                InvoiceType         = invoiceType ?? "Tax Invoice",
                TransactionType     = tranType,
                Layout              = invoiceLayout,
                Summary             = summary ?? "Summary " + Guid.NewGuid(),
                TotalAmount         = totalAmountInclTax ?? new decimal(20.00),
                IsTaxInc            = true,
                RequiresFollowUp    = requiresFollowUp,
                TransactionDate     = transactionDate ?? DateTime.Now.AddDays(-10),
                BillingContactId    = billingContactId ?? _BillingContactId,
                ShippingContactId   = shippingContactId ?? _ShippingContactId,
                FxRate              = fxRate,
                AutoPopulateFxRate  = autoPopulateFxRate,
                InvoiceStatus       = invoiceStatus,
                Tags = tags ?? new List <string> {
                    "invoice header tag 1", "invoice header tag 2"
                }
            };

            if (actuallyInsertAndVerifyResponse)
            {
                var response = new InvoiceProxy().InsertInvoice(invDetail);

                Assert.IsNotNull(response, "Inserting an invoice did not return a response");
                Assert.IsTrue(response.IsSuccessfull, "Inserting an invoice was not successfull. Status code: " + ((int)response.StatusCode).ToString());
                Assert.IsNotNull(response.RawResponse, "No raw response returned as part of inserting an invoice");

                var serialized = response.DataObject;

                Assert.IsTrue(serialized.InsertedEntityId > 0, "Invoice insert did not return an InsertedEntityId > 0");

                invDetail.TransactionId = serialized.InsertedEntityId;
            }

            return(invDetail);
        }
Esempio n. 6
0
        public void DeleteInvoicePayment()
        {
            var invoice             = GetInvoiceTransaction01();
            var invoiceProxy        = new InvoiceProxy();
            var insertInvoiceResult = invoiceProxy.InsertInvoice(invoice);

            Assert.IsTrue(insertInvoiceResult.DataObject.InsertedEntityId > 0,
                          "There was an error creating the invoice for payment test.");

            var invoicePayment = new PaymentTransaction
            {
                TransactionDate = DateTime.Now,
                TransactionType = "SP",
                Currency        = "AUD",
                Summary         =
                    string.Format("Test Update Payment for Inv# {0}",
                                  insertInvoiceResult.DataObject.GeneratedInvoiceNumber),
                PaymentAccountId = _bankAccount01Id,
                PaymentItems     = new List <PaymentItem>
                {
                    new PaymentItem
                    {
                        InvoiceTransactionId =
                            insertInvoiceResult.DataObject.InsertedEntityId,
                        AmountPaid = 30.00M
                    }
                }
            };

            var invoicePaymentProxy          = new PaymentProxy();
            var insertInvoicePaymentResponse = invoicePaymentProxy.InsertInvoicePayment(invoicePayment);

            Assert.IsNotNull(insertInvoicePaymentResponse);
            Assert.IsTrue(insertInvoicePaymentResponse.IsSuccessfull);
            Assert.IsNotNull(insertInvoicePaymentResponse.RawResponse);

            var deleteInvoicePaymentResponse =
                invoicePaymentProxy.DeleteInvoicePayment(insertInvoicePaymentResponse.DataObject.InsertedEntityId);

            Assert.IsNotNull(deleteInvoicePaymentResponse);
            Assert.IsTrue(deleteInvoicePaymentResponse.IsSuccessfull, "Invoice payment was not deleted successfully.");
        }
Esempio n. 7
0
        public void ShouldNotBeAbleToAddAttachmentWithInvalidInvoiceId()
        {
            var attachment = CreateTestAttachment();
            attachment.ItemIdAttachedTo = 0; // invalid invoice id

            var addResponse = new InvoiceProxy().AddAttachment(attachment);

            Assert.IsNotNull(addResponse, "No response when adding an attachment");
            Assert.IsFalse(addResponse.IsSuccessfull, "Adding an attachment succeeded BUT it should have failed as it had an invalid invoice id of 0");
        }
Esempio n. 8
0
        public void ShouldGetOneInvoiceForKnownFile()
        {
            var accessToken = TestHelper.SignInAndGetAccessToken();
            var proxy = new InvoiceProxy(accessToken);
            var response = proxy.GetInvoice(Convert.ToInt32(_invoice1Id));

            Assert.IsNotNull(response);
            Assert.IsTrue(response.IsSuccessfull);
            Assert.IsNotNull(response.DataObject);
        }
Esempio n. 9
0
        public void ShouldBeAbleToGetInfoOnAllAttachmentsUsingWsAccessKey()
        {
            var proxy = new InvoiceProxy();

            var attachment = CreateTestAttachment();

            //Attach invoice Id to attachment and insert attachment.
            attachment.ItemIdAttachedTo = Convert.ToInt32(_invoice1Id);
            var insertResponse = proxy.AddAttachment(attachment);

            var attachmentId = insertResponse.DataObject.Id;

            Assert.IsTrue(attachmentId > 0);

            var getResponse = proxy.GetAllAttachmentsInfo(_invoice1Id);

            Assert.IsNotNull(getResponse);
            Assert.IsTrue(getResponse.IsSuccessfull);
            Assert.IsNotNull(getResponse.DataObject);
            Assert.IsNotNull(getResponse.DataObject.Attachments);
            Assert.IsTrue(getResponse.DataObject.Attachments.Count > 0);
        }
Esempio n. 10
0
        public void UpdatePurchaseWithServiceLayoutAllFieldsUpdated()
        {
            //Insert invoice.
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Service, transactionType: "P", emailContact: true, purchaseOrderNumber: string.Format("TestInv{0}", Guid.NewGuid()));
            var response = new InvoiceProxy().InsertInvoice(invoice);
            Assert.IsTrue(response.IsSuccessfull);

            var insertResult = response.DataObject;
            Assert.AreNotEqual(insertResult.InsertedEntityId, 0);
            var tranId = insertResult.InsertedEntityId;

            //Get the inserted invoice to pick up any default values which may have been assigned.
            var getInsertedResponse = new InvoiceProxy().GetInvoice(tranId);
            var insertedInvoice = getInsertedResponse.DataObject;

            //Get update invoice. The invoice just returned from GET is passed in to have the updated fields copied to it. This is so it can be compared to the
            //invoice returned after the update has occurred, to make sure all fields are equal.
            var updateInvoice = GetUpdatedInvoice(tranId, insertResult.LastUpdatedId, false, insertedInvoice);

            //Likewise the change is also made to the original inserted invoice for comparison later.
            updateInvoice.LineItems = new List<InvoiceTransactionLineItem>
            {
                new InvoiceTransactionLineItem
                {
                    Description = "updated line item",
                    AccountId = _IncomeAccountId2,
                    TaxCode = TaxCode.SaleInputTaxed,
                    TotalAmount = new decimal(100.00),
                    Tags = new List<string> { "update item tag 1", "update item tag 2" }
                }
            };

            var updateResponse = new InvoiceProxy().UpdateInvoice(tranId, updateInvoice);
            var updateResult = updateResponse.DataObject;

            Assert.IsFalse(updateResult.SentToContact);
            Assert.IsTrue(TestHelper.AssertDatetimesEqualWithVariance(updateResult.UtcLastModified.Date, DateTime.UtcNow.Date));
            Assert.IsNotNull(updateResult.LastUpdatedId);
            Assert.AreNotEqual(updateResult.LastUpdatedId.Trim(), string.Empty);

            //Get invoice after update.
            var getResponse = new InvoiceProxy().GetInvoice(tranId);
            Assert.IsNotNull(getResponse.DataObject);

            //Compare updated with original inserted invoice (which also now contains the updated changes).
            VerifyInvoicesAreEqual(updateInvoice, getResponse.DataObject);
        }
Esempio n. 11
0
        public void DeletePurchaseInvoiceWithItemLayout()
        {
            //Insert invoice.
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Item, transactionType: "S", emailContact: true);

            var proxy = new InvoiceProxy();
            var response = proxy.InsertInvoice(invoice);

            Assert.IsTrue(response.IsSuccessfull);

            var results = response.DataObject;

            Assert.AreNotEqual(results.InsertedEntityId, 0);
            var tranId = results.InsertedEntityId;

            var invProxy = new InvoiceProxy();

            var deleteResponse = invProxy.DeleteInvoice(tranId);

            Assert.IsTrue(deleteResponse.IsSuccessfull);
            //get invoice, verify it has been deleted.
            var getProxy = new InvoiceProxy();
            var getResponse = getProxy.GetInvoice(tranId);

            Assert.IsNull(getResponse.DataObject);
        }
Esempio n. 12
0
        public void GetSingleInvoiceWithInvoiceId()
        {
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Service, transactionType: "S", emailContact: false, invoiceNumber: string.Format("TestInv{0}", Guid.NewGuid()));

            var insertResponse = new InvoiceProxy().InsertInvoice(invoice);

            Assert.IsTrue(insertResponse.IsSuccessfull);

            var insertResult = insertResponse.DataObject;

            var tranid = insertResult.InsertedEntityId;

            Assert.IsTrue(tranid > 0);

            var response = new InvoiceProxy().GetInvoice(tranid);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.IsSuccessfull);
            Assert.IsNotNull(response.DataObject);
            Assert.IsNotNull(response.DataObject._links);
            Assert.IsTrue(response.DataObject._links.Count > 0);
        }
Esempio n. 13
0
        public void IndexedTransactionShouldMatchEntityData()
        {
            var searchProxy = new SearchProxy();
            var invoice = new InvoiceProxy().GetInvoice(_invoiceHelper.InvoiceId1.Value).DataObject;
            Assert.IsNotNull(invoice.BillingContactId, "Contact not found");
            var contact = new ContactProxy().GetContact(invoice.BillingContactId.Value).DataObject;

            var searchResults = searchProxy.Search(_invoiceHelper.InvoiceId1Summary, SearchScope.Transactions, 1, 100);
            Assert.IsNotNull(searchResults.DataObject);
            Assert.IsTrue(searchResults.DataObject.Transactions.Count > 0);
            var indexedTransaction = searchResults.DataObject.Transactions.First(x => x.Id == invoice.TransactionId);

            Assert.AreEqual(invoice.DueDate, indexedTransaction.DueDate);
            Assert.AreEqual(invoice.BillingContactOrganisationName, indexedTransaction.Company);
            Assert.AreEqual(contact.EmailAddress, ReplaceEm(indexedTransaction.ContactEmail));
            Assert.AreEqual(invoice.InvoiceNumber, indexedTransaction.InvoiceNumber);
            Assert.AreEqual(invoice.PurchaseOrderNumber, indexedTransaction.PurchaseOrderNumber);
            Assert.AreEqual(invoice.NotesExternal, indexedTransaction.ExternalNotes);
            Assert.AreEqual(invoice.NotesInternal, indexedTransaction.Notes);
            Assert.AreEqual(invoice.TransactionType, indexedTransaction.Type);
        }
Esempio n. 14
0
        public void DeleteSaleInvoiceWithServiceLayout()
        {
            //Insert invoice.
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Service, transactionType: "S", emailContact: true, invoiceNumber: string.Format("TestInv{0}", Guid.NewGuid()));

            var proxy = new InvoiceProxy();
            var response = proxy.InsertInvoice(invoice);

            Assert.IsTrue(response.IsSuccessfull);

            var results = response.DataObject;

            Assert.AreNotEqual(results.InsertedEntityId, 0);
            var tranId = results.InsertedEntityId;

            var invProxy = new InvoiceProxy();

            var deleteResponse = invProxy.DeleteInvoice(tranId);

            Assert.IsTrue(deleteResponse.IsSuccessfull);
            //get invoice, verify it has been deleted.
            var getProxy = new InvoiceProxy();
            var getResponse = getProxy.GetInvoice(tranId);

            Assert.IsNull(getResponse.DataObject);
        }
Esempio n. 15
0
        public void InsertSaleWithQuickPayment()
        {
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Service, transactionType: "S", emailContact: false, invoiceNumber: string.Format("TestInv{0}", Guid.NewGuid()));

            invoice.QuickPayment = new InvoiceQuickPaymentDetail
            {
                DatePaid = DateTime.Now.AddDays(-4),
                DateCleared = DateTime.Now.AddDays(-3),
                BankedToAccountId = _BankAccountId,
                Amount = new decimal(10.00),
                Reference = "Test quick payment reference",
                Summary = "Test quick payment summary"
            };

            var proxy = new InvoiceProxy();
            var response = proxy.InsertInvoice(invoice);

            Assert.IsTrue(response.IsSuccessfull);
            Assert.AreNotEqual(response.DataObject.InsertedEntityId, 0);

            //get invoice.
            var getResponse = proxy.GetInvoice(response.DataObject.InsertedEntityId);

            Assert.IsNotNull(getResponse.DataObject.PaymentCount);
            Assert.AreEqual(getResponse.DataObject.PaymentCount, (Int16)1);
            Assert.AreEqual(getResponse.DataObject.AmountPaid, new decimal(10.00));
            Assert.AreEqual(getResponse.DataObject.AmountOwed, (getResponse.DataObject.TotalAmount - getResponse.DataObject.AmountPaid));
        }
Esempio n. 16
0
        public void InsertSaleWithItemLayoutEmailToContactAndAutoNumberAndAutoPopulateFxRate()
        {
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Item, transactionType: "S", emailContact: true, autoPopulateFxRate: true);

            var proxy = new InvoiceProxy();
            var response = proxy.InsertInvoice(invoice);

            Assert.IsTrue(response.IsSuccessfull, string.Format("Inserting an item layout invoice has failed.{0}", ItemLayoutForbiddenMessage));

            var results = response.DataObject;

            Assert.IsNotNull(results.GeneratedInvoiceNumber);
            Assert.IsTrue(results.SentToContact);
            Assert.AreNotEqual(results.InsertedEntityId, 0);
            Assert.AreNotEqual(results.UtcLastModified, DateTime.MinValue);
            Assert.IsNotNull(results.LastUpdatedId);
            Assert.AreNotEqual(results.LastUpdatedId.Trim(), string.Empty);

            //get invoice.
            var getProxy = new InvoiceProxy();
            var getResponse = getProxy.GetInvoice(results.InsertedEntityId);

            Assert.IsNotNull(getResponse.DataObject);

            VerifyInvoicesAreEqual(invoice, getResponse.DataObject);
        }
Esempio n. 17
0
        public void InsertSaleWithAutoPopulateFxRateShouldNotUsePassedInFxRate()
        {
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Item, transactionType: "S", autoPopulateFxRate: true, fxRate: 99);

            var proxy = new InvoiceProxy();
            var response = proxy.InsertInvoice(invoice);

            Assert.IsTrue(response.IsSuccessfull, string.Format("Inserting an item layout invoice has failed.{0}", ItemLayoutForbiddenMessage));

            var results = response.DataObject;

            Assert.AreNotEqual(results.InsertedEntityId, 0);
            Assert.AreNotEqual(results.UtcLastModified, DateTime.MinValue);
            Assert.IsNotNull(results.LastUpdatedId);
            Assert.AreNotEqual(results.LastUpdatedId.Trim(), string.Empty);

            //get invoice.
            var getProxy = new InvoiceProxy();
            var getResponse = getProxy.GetInvoice(results.InsertedEntityId);

            Assert.IsNotNull(getResponse.DataObject);
            Assert.AreNotEqual(99, getResponse.DataObject.FxRate);
        }
Esempio n. 18
0
        public void InsertSaleAndCanUpdateUsingReturnedLastUpdateId()
        {
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Service, transactionType: "S", emailContact: false, invoiceNumber: string.Format("TestInv{0}", Guid.NewGuid()));

            var proxy = new InvoiceProxy();
            var response = proxy.InsertInvoice(invoice);

            Assert.IsTrue(response.IsSuccessfull);

            var results = response.DataObject;

            Assert.IsNull(results.GeneratedInvoiceNumber);
            Assert.IsFalse(results.SentToContact);
            Assert.AreNotEqual(results.InsertedEntityId, 0);
            Assert.AreNotEqual(results.UtcLastModified, DateTime.MinValue);
            Assert.AreNotEqual(results.LastUpdatedId, null);
            Assert.AreNotEqual(results.LastUpdatedId.Trim(), string.Empty);

            //get invoice.
            var getResponse = proxy.GetInvoice(results.InsertedEntityId);
            Assert.IsNotNull(getResponse.DataObject);

            // Do an Update
            var getInvoice = getResponse.DataObject;
            getInvoice.Summary = "Update 1";
            var updateResponse = proxy.UpdateInvoice(getInvoice.TransactionId.Value, getInvoice);
            Assert.IsTrue(updateResponse.IsSuccessfull);

            // Using the LastUpdatedId returned from the previous update, do another update
            getInvoice.Summary = "Update 2";
            getInvoice.LastUpdatedId = updateResponse.DataObject.LastUpdatedId;
            var updateResponse2 = proxy.UpdateInvoice(getInvoice.TransactionId.Value, getInvoice);
            Assert.IsTrue(updateResponse2.IsSuccessfull);
        }
Esempio n. 19
0
        public void InsertDifferentCurrencyForMultiCurrencyFile()
        {
            //Insert invoice.
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Service, transactionType: "S", currency: "USD", fxRate: new decimal(1.50));

            var proxy = new InvoiceProxy();
            var response = proxy.InsertInvoice(invoice);

            Assert.IsTrue(response.IsSuccessfull, string.Format("Inserting a multi currency invoice has failed.{0}", MultiCurrencyForbiddenMessage));

            var results = response.DataObject;

            Assert.AreNotEqual(results.InsertedEntityId, 0);
            Assert.AreNotEqual(results.UtcLastModified, DateTime.MinValue);
            Assert.AreNotEqual(results.LastUpdatedId, null);
            Assert.AreNotEqual(results.LastUpdatedId.Trim(), string.Empty);

            //get invoice.
            var getResponse = new InvoiceProxy().GetInvoice(results.InsertedEntityId);

            Assert.IsNotNull(getResponse.DataObject);

            VerifyInvoicesAreEqual(invoice, getResponse.DataObject);
            Assert.AreEqual(invoice.FxRate, getResponse.DataObject.FxRate);
        }
Esempio n. 20
0
        public void UpdateDifferentCurrencyForMultiCurrencyFile()
        {
            //Insert invoice.
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Service, transactionType: "S");
            var response = new InvoiceProxy().InsertInvoice(invoice);
            Assert.IsTrue(response.IsSuccessfull);

            var insertResult = response.DataObject;
            Assert.AreNotEqual(insertResult.InsertedEntityId, 0);
            var tranId = insertResult.InsertedEntityId;

            //Get the inserted invoice to pick up any default values which may have been assigned.
            var getInsertedResponse = new InvoiceProxy().GetInvoice(tranId);
            var insertedInvoice = getInsertedResponse.DataObject;

            //Update the currency of the invoice.
            insertedInvoice.Currency = "USD";
            insertedInvoice.FxRate = 1.5M;

            var updateResponse = new InvoiceProxy().UpdateInvoice(tranId, insertedInvoice);
            Assert.IsTrue(updateResponse.IsSuccessfull, string.Format("Updating invoice with a different currency has failed.{0}", MultiCurrencyForbiddenMessage));

            var updateResult = updateResponse.DataObject;
            Assert.IsFalse(updateResult.SentToContact);
            Assert.AreEqual(Convert.ToDateTime(updateResult.UtcLastModified).Date, DateTime.UtcNow.Date);
            Assert.IsNotNull(updateResult.LastUpdatedId);
            Assert.AreNotEqual(updateResult.LastUpdatedId.Trim(), string.Empty);

            //Get invoice after update.
            var getUpdatedResponse = new InvoiceProxy().GetInvoice(tranId);
            Assert.IsNotNull(getUpdatedResponse.DataObject);

            //Compare updated with original inserted invoice (which also now contains the updated changes).
            VerifyInvoicesAreEqual(insertedInvoice, getUpdatedResponse.DataObject);
            Assert.AreEqual(insertedInvoice.FxRate, getUpdatedResponse.DataObject.FxRate);
        }
Esempio n. 21
0
        public void UpdateSaleWithItemLayoutAllFieldsUpdated()
        {
            //Insert invoice.
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Item, transactionType: "S", emailContact: true, invoiceNumber: string.Format("TestInv{0}", Guid.NewGuid()));
            var response = new InvoiceProxy().InsertInvoice(invoice);
            Assert.IsTrue(response.IsSuccessfull, string.Format("Inserting an item layout invoice has failed.{0}", ItemLayoutForbiddenMessage));

            var insertResult = response.DataObject;
            Assert.AreNotEqual(insertResult.InsertedEntityId, 0);
            var tranId = insertResult.InsertedEntityId;

            //Get the inserted invoice to pick up any default values which may have been assigned.
            var getInsertedResponse = new InvoiceProxy().GetInvoice(tranId);
            var insertedInvoice = getInsertedResponse.DataObject;

            //Get update invoice. The invoice just returned from GET is passed in to have the updated fields copied to it. This is so it can be compared to the
            //invoice returned after the update has occurred, to make sure all fields are equal.
            var updateInvoice = GetUpdatedInvoice(tranId, insertResult.LastUpdatedId, true, insertedInvoice);

            //Likewise the change is also made to the original inserted invoice for comparison later.
            updateInvoice.LineItems = insertedInvoice.LineItems = new List<InvoiceTransactionLineItem>
            {
                new InvoiceTransactionLineItem
                        {
                            Description = "updated line item 1",
                            TaxCode = TaxCode.SaleInputTaxed,
                            Quantity = 20,
                            UnitPrice = new decimal(200.00),
                            PercentageDiscount = new decimal(15.00),
                            InventoryId =  _InventorySaleItemId2,
                            Tags = new List<string> {"updated item tag 1", "updated item tag 2"}
                            //Attributes = GetItemAttributes()
                        },
            };

            var updateResponse = new InvoiceProxy().UpdateInvoice(tranId, updateInvoice);
            var updateResult = updateResponse.DataObject;

            Assert.IsTrue(updateResult.SentToContact);
            Assert.AreEqual(Convert.ToDateTime(updateResult.UtcLastModified).Date, DateTime.UtcNow.Date);
            Assert.IsNotNull(updateResult.LastUpdatedId);
            Assert.AreNotEqual(updateResult.LastUpdatedId.Trim(), string.Empty);

            //Get invoice after update.
            var getResponse = new InvoiceProxy().GetInvoice(tranId);
            Assert.IsNotNull(getResponse.DataObject);

            //Compare updated with original inserted invoice (which also now contains the updated changes).
            VerifyInvoicesAreEqual(insertedInvoice, getResponse.DataObject);
        }
Esempio n. 22
0
        private InvoiceTransactionDetail GetTestInsertInvoice(string invoiceLayout, List<InvoiceTransactionLineItem> lineItems = null, string notesInternal = null,
            string notesExternal = null, InvoiceTradingTerms terms = null, List<FileAttachmentInfo> attachments = null, int? templateId = null,
            bool emailContact = false, Saasu.API.Core.Models.Email emailMessage = null, string currency = null, string invoiceNumber = null, string purchaseOrderNumber = null,
            string invoiceType = null, string transactionType = null, string summary = null, decimal? totalAmountInclTax = null, bool requiresFollowUp = false, DateTime? transactionDate = null,
            int? billingContactId = null, int? shippingContactId = null, List<string> tags = null, decimal? fxRate = null, string invoiceStatus = null,
            bool actuallyInsertAndVerifyResponse = false, bool autoPopulateFxRate = false)
        {
            var tranType = transactionType ?? "S";

            var invDetail = new InvoiceTransactionDetail
                {
                    LineItems = lineItems ?? GetInsertItems(invoiceLayout, tranType),
                    NotesInternal = notesInternal ?? "Test internal note",
                    NotesExternal = notesExternal ?? "Test external note",
                    Terms = terms ?? GetTradingTerms(),
                    Attachments = attachments ?? GetAttachments(),
                    TemplateId = templateId ?? GetTemplateUid(),
                    SendEmailToContact = emailContact,
                    EmailMessage = emailMessage ?? GetEmailMessage(),
                    Currency = currency ?? "AUD",
                    InvoiceNumber = invoiceNumber ?? AutoNumber,
                    PurchaseOrderNumber = purchaseOrderNumber ?? AutoNumber,
                    InvoiceType = invoiceType ?? "Tax Invoice",
                    TransactionType = tranType,
                    Layout = invoiceLayout,
                    Summary = summary ?? "Summary InsertInvoiceWithServiceItemsNoEmailToContact",
                    TotalAmount = totalAmountInclTax ?? new decimal(20.00),
                    IsTaxInc = true,
                    RequiresFollowUp = requiresFollowUp,
                    TransactionDate = transactionDate ?? DateTime.Now.AddDays(-10),
                    BillingContactId = billingContactId ?? _BillingContactId,
                    ShippingContactId = shippingContactId ?? _ShippingContactId,
                    FxRate = fxRate,
                    AutoPopulateFxRate = autoPopulateFxRate,
                    InvoiceStatus = invoiceStatus,
                    Tags = tags ?? new List<string> { "invoice header tag 1", "invoice header tag 2" }
                };

            if (actuallyInsertAndVerifyResponse)
            {
                var response = new InvoiceProxy().InsertInvoice(invDetail);

                Assert.IsNotNull(response, "Inserting an invoice did not return a response");
                Assert.IsTrue(response.IsSuccessfull, "Inserting an invoice was not successfull. Status code: " + ((int)response.StatusCode).ToString());
                Assert.IsNotNull(response.RawResponse, "No raw response returned as part of inserting an invoice");

                var serialized = response.DataObject;

                Assert.IsTrue(serialized.InsertedEntityId > 0, "Invoice insert did not return an InsertedEntityId > 0");

                invDetail.TransactionId = serialized.InsertedEntityId;
            }

            return invDetail;
        }
Esempio n. 23
0
        public void InsertSaleWithServiceItemsNoEmailToContact()
        {
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Service, transactionType: "S", emailContact: false, invoiceNumber: string.Format("TestInv{0}", Guid.NewGuid()));

            var response = new InvoiceProxy().InsertInvoice(invoice);

            Assert.IsTrue(response.IsSuccessfull);

            var results = response.DataObject;

            Assert.IsNull(results.GeneratedInvoiceNumber);
            Assert.IsFalse(results.SentToContact);
            Assert.AreNotEqual(results.InsertedEntityId, 0);
            Assert.AreNotEqual(results.UtcLastModified, DateTime.MinValue);
            Assert.AreNotEqual(results.LastUpdatedId, null);
            Assert.AreNotEqual(results.LastUpdatedId.Trim(), string.Empty);

            //get invoice.
            var getResponse = new InvoiceProxy().GetInvoice(results.InsertedEntityId);

            Assert.IsNotNull(getResponse.DataObject);

            VerifyInvoicesAreEqual(invoice, getResponse.DataObject);
        }
Esempio n. 24
0
        public void GetInvoicesFilterOnBillingContactId()
        {
            //Get Id of test contact associated with the invoice.
            var contactResponse = ContactTests.VerifyTestContactExistsOrCreate(contactType: Ola.RestClient.ContactType.Customer);

            var billingContactId = contactResponse.DataObject.Contacts[0].Id;

            //Create and insert test invoices for billing contact.
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Service, transactionType: "S", emailContact: false, billingContactId: billingContactId);
            var invoice2 = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Service, transactionType: "S", emailContact: false, billingContactId: billingContactId);

            var proxy = new InvoiceProxy();
            proxy.InsertInvoice(invoice);
            proxy.InsertInvoice(invoice2);

            AssertInvoiceProxy(billingContactId: contactResponse.DataObject.Contacts[0].Id);
        }
Esempio n. 25
0
        public void InsertAndGetPaymentForMultipleInvoiecs()
        {
            var invoice             = GetInvoiceTransaction01();
            var invoiceProxy        = new InvoiceProxy();
            var insertInvoiceResult = invoiceProxy.InsertInvoice(invoice);

            Assert.IsTrue(insertInvoiceResult.DataObject.InsertedEntityId > 0,
                          "There was an error creating the invoice for payment test.");

            var invoice01TransctionId = insertInvoiceResult.DataObject.InsertedEntityId;

            invoice             = GetInvoiceTransaction02();
            invoiceProxy        = new InvoiceProxy();
            insertInvoiceResult = invoiceProxy.InsertInvoice(invoice);

            Assert.IsTrue(insertInvoiceResult.DataObject.InsertedEntityId > 0,
                          "There was an error creating the invoice for payment test.");

            var invoice02TransactionId = insertInvoiceResult.DataObject.InsertedEntityId;

            var invoicePayment = new PaymentTransaction
            {
                TransactionDate = DateTime.Now,
                TransactionType = "SP",
                Currency        = "AUD",
                Summary         =
                    string.Format("Test Payment insert for multiple invoices"),
                PaymentAccountId = _bankAccount01Id,
                PaymentItems     = new List <PaymentItem>
                {
                    new PaymentItem
                    {
                        InvoiceTransactionId = invoice01TransctionId,
                        AmountPaid           = 110.00M
                    },

                    new PaymentItem
                    {
                        InvoiceTransactionId = invoice02TransactionId,
                        AmountPaid           = 150.00M
                    }
                }
            };

            var invoicePaymentProxy          = new PaymentProxy();
            var insertInvoicePaymentResponse = invoicePaymentProxy.InsertInvoicePayment(invoicePayment);

            Assert.IsNotNull(insertInvoicePaymentResponse);
            Assert.IsTrue(insertInvoicePaymentResponse.IsSuccessfull);
            Assert.IsNotNull(insertInvoicePaymentResponse.RawResponse);

            var insertInvoicePaymentResult = insertInvoicePaymentResponse.DataObject;


            Assert.IsTrue(insertInvoicePaymentResult.InsertedEntityId > 0,
                          string.Format("There was an error creating the invoice payment for Invoice Id {0}",
                                        insertInvoiceResult.DataObject.InsertedEntityId));

            var getInvoicePaymentResponse = invoicePaymentProxy.GetPayment(insertInvoicePaymentResult.InsertedEntityId);
            var getInvoicePaymentResult   = getInvoicePaymentResponse.DataObject;

            Assert.IsNotNull(getInvoicePaymentResult);
            Assert.IsTrue(getInvoicePaymentResult.TransactionId == insertInvoicePaymentResult.InsertedEntityId, "Incorrect payment transaction ID");
            Assert.AreEqual(260M, getInvoicePaymentResult.TotalAmount, "Incorrect payment amount.");
            Assert.IsTrue(getInvoicePaymentResult.PaymentItems.Count == 2, "Incorrect number of payment items.");

            var invoicePaymentItem01 =
                getInvoicePaymentResult.PaymentItems.Find(i => i.InvoiceTransactionId == invoice01TransctionId);
            var invoicePaymentItem02 =
                getInvoicePaymentResult.PaymentItems.Find(i => i.InvoiceTransactionId == invoice02TransactionId);

            Assert.IsNotNull(invoicePaymentItem01, string.Format("No payment item found for invoice transaction Id {0}", invoice01TransctionId));
            Assert.IsNotNull(invoicePaymentItem02, string.Format("No payment item found for invoice transaction Id {0}", invoice02TransactionId));
            Assert.AreEqual(110M, invoicePaymentItem01.AmountPaid, "Incorrect amount paid in payment item for invoice transaction Id {0}", invoice01TransctionId);
            Assert.AreEqual(150M, invoicePaymentItem02.AmountPaid, "Incorrect amount paid in payment item for invoice transaction Id {0}", invoice02TransactionId);
        }
Esempio n. 26
0
        public void InvalidCurrencyInsert()
        {
            //Insert invoice.
            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Service, transactionType: "S", currency: "TEST");

            var proxy = new InvoiceProxy();
            var response = proxy.InsertInvoice(invoice);

            Assert.IsFalse(response.IsSuccessfull);
            Assert.IsNotNull(response.RawResponse);
            Assert.IsTrue(response.RawResponse.Contains("Please include a valid currency"));
            Assert.IsNotNull(response.ReasonCode);
            Assert.AreEqual(response.ReasonCode.Trim().ToLower(), "bad request");
        }
Esempio n. 27
0
        public void UpdatePaymentForSingleInvoice()
        {
            var invoice             = GetInvoiceTransaction01();
            var invoiceProxy        = new InvoiceProxy();
            var insertInvoiceResult = invoiceProxy.InsertInvoice(invoice);

            Assert.IsTrue(insertInvoiceResult.DataObject.InsertedEntityId > 0,
                          "There was an error creating the invoice for payment test.");

            var invoicePayment = new PaymentTransaction
            {
                TransactionDate = DateTime.Now,
                TransactionType = "SP",
                Currency        = "AUD",
                Summary         =
                    string.Format("Test Update Payment for Inv# {0}",
                                  insertInvoiceResult.DataObject.GeneratedInvoiceNumber),
                PaymentAccountId = _bankAccount01Id,
                PaymentItems     = new List <PaymentItem>
                {
                    new PaymentItem
                    {
                        InvoiceTransactionId =
                            insertInvoiceResult.DataObject.InsertedEntityId,
                        AmountPaid = 30.00M
                    }
                }
            };

            var invoicePaymentProxy          = new PaymentProxy();
            var insertInvoicePaymentResponse = invoicePaymentProxy.InsertInvoicePayment(invoicePayment);

            Assert.IsNotNull(insertInvoicePaymentResponse);
            Assert.IsTrue(insertInvoicePaymentResponse.IsSuccessfull);
            Assert.IsNotNull(insertInvoicePaymentResponse.RawResponse);

            var insertedInvoicePaymentEntityId      = insertInvoicePaymentResponse.DataObject.InsertedEntityId;
            var insertedInvoicePaymentLastUpdatedId = insertInvoicePaymentResponse.DataObject.LastUpdatedId;

            Assert.IsTrue(insertedInvoicePaymentEntityId > 0,
                          string.Format("There was an error creating the invoice payment for Invoice Id {0}",
                                        insertInvoiceResult.DataObject.InsertedEntityId));

            invoicePayment = new PaymentTransaction
            {
                TransactionDate = DateTime.Now.Date,
                ClearedDate     = DateTime.Now.Date.AddDays(2).Date,
                TransactionType = "SP",
                Currency        = "AUD",
                Summary         =
                    string.Format("Test Update Payment for Inv# {0}",
                                  insertInvoiceResult.DataObject.GeneratedInvoiceNumber),
                PaymentAccountId = _bankAccount02Id,
                PaymentItems     = new List <PaymentItem>
                {
                    new PaymentItem
                    {
                        InvoiceTransactionId =
                            insertInvoiceResult.DataObject.InsertedEntityId,
                        AmountPaid = 60.00M
                    }
                },
                RequiresFollowUp = true,
                Notes            = "Update payment amount to $60",
                LastUpdatedId    = insertedInvoicePaymentLastUpdatedId
            };

            var updateInvoicePaymentResponse = invoicePaymentProxy.UpdateInvoicePayment(insertedInvoicePaymentEntityId,
                                                                                        invoicePayment);

            Assert.IsNotNull(updateInvoicePaymentResponse);
            Assert.IsTrue(updateInvoicePaymentResponse.IsSuccessfull);

            var getInvoicePaymentResponse = invoicePaymentProxy.GetPayment(insertedInvoicePaymentEntityId);
            var getInvoicePaymentResult   = getInvoicePaymentResponse.DataObject;

            Assert.IsNotNull(getInvoicePaymentResult);
            Assert.IsTrue(getInvoicePaymentResult.TransactionId == insertedInvoicePaymentEntityId, "Incorrect payment transaction ID.");
            Assert.AreEqual(DateTime.Now.Date, getInvoicePaymentResult.TransactionDate, "Incorrect payment date.");
            Assert.AreEqual(DateTime.Now.Date.AddDays(2), getInvoicePaymentResult.ClearedDate, "Incorrect cleared date.");
            Assert.AreEqual("AUD", getInvoicePaymentResult.Currency, "Incorrect invoice payment currency.");
            Assert.AreEqual("SP", getInvoicePaymentResult.TransactionType, "Incorrect payment transaction type.");
            Assert.AreEqual(string.Format("Test Update Payment for Inv# {0}", insertInvoiceResult.DataObject.GeneratedInvoiceNumber), getInvoicePaymentResult.Summary);
            Assert.AreEqual(60M, getInvoicePaymentResult.TotalAmount, "Incorrect payment amount.");
            Assert.IsTrue(getInvoicePaymentResult.PaymentItems.Count == 1, "Incorrect number of payment items.");
            Assert.AreEqual(_bankAccount02Id, getInvoicePaymentResult.PaymentAccountId, "Incorrect payment account");
            Assert.AreEqual("Update payment amount to $60", getInvoicePaymentResult.Notes, "Incorrect invoice payment notes.");
            Assert.IsTrue(getInvoicePaymentResult.PaymentItems.Count == 1, "Incorrect number of payment items.");
            Assert.IsTrue(getInvoicePaymentResult.RequiresFollowUp, "Incorrect requires follow up status.");
            var paymentItem =
                getInvoicePaymentResult.PaymentItems.Find(
                    i => i.InvoiceTransactionId == insertInvoiceResult.DataObject.InsertedEntityId);

            Assert.IsNotNull(paymentItem, "No payment item for invoice transaction Id {0}", insertInvoiceResult.DataObject.InsertedEntityId);
            Assert.AreEqual(60M, paymentItem.AmountPaid, "Incorrect amount paid in payment item for invoie transaction Id {0}", paymentItem.InvoiceTransactionId);
        }
Esempio n. 28
0
        public void ShouldBeAbleToAddSmallAttachmentUsingWsAccessKey()
        {
            var accessToken = TestHelper.SignInAndGetAccessToken();

            var proxy = new InvoicesProxy(accessToken);
            var response = proxy.GetInvoices();

            Assert.IsNotNull(response, "No response when getting invoices");
            Assert.IsTrue(response.IsSuccessfull, "Getting invoices failed. STatus code: " + ((int)response.StatusCode).ToString());
            Assert.IsTrue(response.DataObject.Invoices.Count > 0, "Number of invoices returned was not greater than 0");

            _testInvoiceId = response.DataObject.Invoices[0].TransactionId;

            var attachment = CreateTestAttachment();
            attachment.ItemIdAttachedTo = response.DataObject.Invoices[0].TransactionId.GetValueOrDefault();

            var addResponse = new InvoiceProxy().AddAttachment(attachment);

            Assert.IsNotNull(addResponse, "No response when adding an attachment");
            Assert.IsTrue(addResponse.IsSuccessfull, "Adding an attachment failed. STatus code: " + ((int)addResponse.StatusCode).ToString());
        }
Esempio n. 29
0
        public void ShouldBeAbleToDeleteAnAttachment()
        {
            ShouldBeAbleToAddSmallAttachmentUsingWsAccessKey();  // Ensure we add an attachment

            var proxy = new InvoiceProxy();
            var response = proxy.GetAllAttachmentsInfo(Convert.ToInt32(TestInvoiceId));
            Assert.IsTrue(response.IsSuccessfull && response.DataObject != null && response.DataObject.Attachments.Count > 0, "Getting all attachments failed. Status Code: " + ((int)response.StatusCode).ToString());

            var attachmentResponse = proxy.DeleteAttachment(response.DataObject.Attachments[0].Id);
            Assert.IsNotNull(attachmentResponse, "No response when deleting an attachment");
            Assert.IsTrue(attachmentResponse.IsSuccessfull, "Adding an attachment was not successfull. Status Code:" + ((int)attachmentResponse.StatusCode).ToString());
        }
Esempio n. 30
0
        public void ShouldBeAbleToGetAnAllAttachmentUsingOAuth()
        {
            ShouldBeAbleToAddSmallAttachmentUsingWsAccessKey();  // Ensure we add anattachment

            var accessToken = TestHelper.SignInAndGetAccessToken();
            var proxy = new InvoiceProxy(accessToken);
            var response = proxy.GetAllAttachmentsInfo(Convert.ToInt32(TestInvoiceId));

            Assert.IsNotNull(response);
            Assert.IsTrue(response.IsSuccessfull);
            Assert.IsNotNull(response.DataObject);
            Assert.IsNotNull(response.DataObject.Attachments);
            Assert.IsTrue(response.DataObject.Attachments.Count > 0);

            var attachmentResponse = proxy.GetAttachment(response.DataObject.Attachments[0].Id);
            Assert.IsNotNull(attachmentResponse);
            Assert.IsTrue(attachmentResponse.IsSuccessfull);
        }
Esempio n. 31
0
        public void TestPaging()
        {
            var invoice             = GetInvoiceTransaction01();
            var invoiceProxy        = new InvoiceProxy();
            var insertInvoiceResult = invoiceProxy.InsertInvoice(invoice);

            Assert.IsTrue(insertInvoiceResult.DataObject.InsertedEntityId > 0,
                          "There was an error creating the invoice for payment test.");

            var invoicePayment1 = new PaymentTransaction
            {
                TransactionDate = DateTime.Now,
                TransactionType = "SP",
                Currency        = "AUD",
                Summary         =
                    string.Format("Test Payment insert for Inv# {0}",
                                  insertInvoiceResult.DataObject.GeneratedInvoiceNumber),
                PaymentAccountId = _bankAccount01Id,
                PaymentItems     = new List <PaymentItem>
                {
                    new PaymentItem()
                    {
                        InvoiceTransactionId =
                            insertInvoiceResult.DataObject.InsertedEntityId,
                        AmountPaid = 50.00M
                    }
                }
            };


            var invoicePaymentProxy          = new PaymentProxy();
            var insertInvoicePaymentResponse = invoicePaymentProxy.InsertInvoicePayment(invoicePayment1);

            Assert.IsNotNull(insertInvoicePaymentResponse);
            Assert.IsTrue(insertInvoicePaymentResponse.IsSuccessfull);
            Assert.IsNotNull(insertInvoicePaymentResponse.RawResponse);

            var invoicePayment2 = new PaymentTransaction
            {
                TransactionDate = DateTime.Now,
                TransactionType = "SP",
                Currency        = "AUD",
                Summary         =
                    string.Format("Test Payment insert for Inv# {0}",
                                  insertInvoiceResult.DataObject.GeneratedInvoiceNumber),
                PaymentAccountId = _bankAccount01Id,
                PaymentItems     = new List <PaymentItem>
                {
                    new PaymentItem()
                    {
                        InvoiceTransactionId =
                            insertInvoiceResult.DataObject.InsertedEntityId,
                        AmountPaid = 60.00M
                    }
                }
            };

            insertInvoicePaymentResponse = invoicePaymentProxy.InsertInvoicePayment(invoicePayment2);

            Assert.IsNotNull(insertInvoicePaymentResponse);
            Assert.IsTrue(insertInvoicePaymentResponse.IsSuccessfull);
            Assert.IsNotNull(insertInvoicePaymentResponse.RawResponse);

            var paymentsProxy = new PaymentsProxy();

            var paymentsPage1 = paymentsProxy.GetPayments(1, 1, insertInvoiceResult.DataObject.InsertedEntityId, null, "SP", null, null, null, null, null, null, null);

            Assert.IsNotNull(paymentsPage1);
            Assert.IsNotNull(paymentsPage1.DataObject);
            Assert.AreEqual(paymentsPage1.DataObject.PaymentTransactions.Count, 1);

            var paymentsPage2 = paymentsProxy.GetPayments(2, 1, insertInvoiceResult.DataObject.InsertedEntityId, null, "SP", null, null, null, null, null, null, null);

            Assert.IsNotNull(paymentsPage2);
            Assert.IsNotNull(paymentsPage2.DataObject);
            Assert.AreEqual(paymentsPage2.DataObject.PaymentTransactions.Count, 1);
            Assert.AreNotEqual(paymentsPage1.DataObject.PaymentTransactions[0].TransactionId, paymentsPage2.DataObject.PaymentTransactions[0].TransactionId);

            //Test number of rows returned for page.
            var paymentsPage3 = paymentsProxy.GetPayments(1, 2, insertInvoiceResult.DataObject.InsertedEntityId, null, "SP", null, null, null, null, null, null, null);

            Assert.IsNotNull(paymentsPage3);
            Assert.IsNotNull(paymentsPage3.DataObject);
            Assert.AreEqual(paymentsPage3.DataObject.PaymentTransactions.Count, 2);
        }
Esempio n. 32
0
        public void EmailInvoiceToBillingContact()
        {
            var contactResponse = ContactTests.VerifyTestContactExistsOrCreate(contactType: Ola.RestClient.ContactType.Customer);

            var billingContactId = contactResponse.DataObject.Contacts[0].Id;

            var invoice = GetTestInsertInvoice(invoiceLayout: InvoiceLayout.Service, transactionType: "S", billingContactId: billingContactId, emailContact: false, invoiceNumber: string.Format("TestInv{0}", Guid.NewGuid()));
            var insertResponse = new InvoiceProxy().InsertInvoice(invoice);

            Assert.IsTrue(insertResponse.IsSuccessfull);

            var insertResult = insertResponse.DataObject;

            var tranid = insertResult.InsertedEntityId;

            Assert.IsTrue(tranid > 0);

            var response = new InvoiceProxy().EmailInvoice(tranid);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.IsSuccessfull);
            Assert.IsNotNull(response.DataObject);
            Assert.AreEqual("Invoice has been emailed.", response.DataObject.StatusMessage);
            Assert.IsNotNull(response.DataObject._links);
            Assert.IsTrue(response.DataObject._links.Count > 0);
        }