public ProductCatalogManagerTests()
 {
     zs = new ZuoraService(Settings.API_USERNAME, Settings.API_PASSWORD, Settings.API_ENDPOINT);
     pcm = new ProductCatalogManager(zs, Settings.CATALOG_CACHE_PATH);
     zth = new ZuoraTestHelper();
 }
        protected void DoAction(object sender, EventArgs e)
        {
            zs = (ZuoraService)Session["zs"];
            AccountManager am = new AccountManager(zs);
            PaymentManager pm = new PaymentManager(zs);
            ProductCatalogManager pcm = new ProductCatalogManager(zs,   "C:\\localCache.txt");
            SubscriptionManager sm = new SubscriptionManager(zs);

            if (zs != null)
            {
                var operation = ddl1.SelectedValue;

                if (operation == "Create Account")
                {
                    result.Text += "<br/>";
                    Account acc = new Account();
                    acc.Name = AccountName.Text;
                    acc.BillCycleDaySpecified = true;
                    acc.BillCycleDay = Convert.ToInt16(BillCycleDay.Text);
                    acc.Currency = Currency.Text;
                    acc.PaymentTerm = PaymentTermDropDown.SelectedValue;
                    acc.Batch = Batch.Text;

                    Contact con = new Contact();
                    con.Address1 = Address1.Text;
                    con.Address2 = Address2.Text;
                    con.City = City.Text;
                    con.State = State.Text;
                    con.LastName = LastName.Text;
                    con.FirstName = FirstName.Text;
                    con.Country = Country.Text;
                    con.PostalCode = Zip.Text;

                    var res = am.CreateAccount(acc, con);
                    result.Text += res.Success ? res.Id : res.Message;
                }
                else if (operation == "Create Child Account And Increase Credit Balance")
                {
                    result.Text += "<br/>";

                    Account acc = new Account();
                    acc.Name = AccountName.Text;
                    acc.BillCycleDaySpecified = true;
                    acc.BillCycleDay = Convert.ToInt16(BillCycleDay.Text);
                    acc.Currency = Currency.Text;
                    acc.PaymentTerm = PaymentTermDropDown.SelectedValue;
                    acc.Batch = Batch.Text;

                    Contact con = new Contact();
                    con.Address1 = Address1.Text;
                    con.Address2 = Address2.Text;
                    con.City = City.Text;
                    con.State = State.Text;
                    con.LastName = LastName.Text;
                    con.FirstName = FirstName.Text;
                    con.Country = Country.Text;
                    con.PostalCode = Zip.Text;

                    var res = am.CreateChildAccountAndIncreaseCreditBalance(acc, ParentAccountId.Text, con, Convert.ToDecimal(AmountBox.Text));
                    result.Text += res.Success ? res.Id : res.Message;
                }
                else if (operation == "Cancel Credit Balance Adjustment On Invoice")
                {
                    result.Text += "<br/>";
                    var res = pm.CancelCreditBalanceAdjustmentOnInvoice(InvoiceId.Text);
                    result.Text += res.Success ? res.Id : res.Message;
                }
                else if (operation == "Get Invoices For Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetInvoicesForAccount(AccountId.Text);
                    //string FIELDS_INVOICE = "Id, AccountId, AdjustmentAmount, Amount, AmountWithoutTax, Balance, Comments, CreatedDate, DueDate, IncludesOneTime, IncludesRecurring, IncludesUsage, InvoiceDate, InvoiceNumber, LastEmailSentDate, PaymentAmount, PostedDate, RefundAmount, Source, SourceId, Status, TargetDate, TaxAmount, TaxExemptAmount, TransferredToAccounting, UpdatedDate";
                    //var res = zs.Query("");
                    if (res.Success)
                    {
                        result.Text += "<br/>";
                        if (res.Objects != null)
                        {
                            foreach (zObject zo in res.Objects)
                            {
                                Invoice inv = (Invoice)zo;
                                result.Text += "Invoice Number: " + inv.InvoiceNumber + " Invoice Amount: " + inv.Amount + " Status: " + inv.Status + "<br/>";
                            }
                        }
                        else
                        {
                            result.Text += res.Message;
                        }
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get Refunds For Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetRefundsForAccount(AccountId.Text);
                    if (res.Success)
                    {
                        result.Text += "<br/>";
                        if (res.Objects != null)
                        {
                            foreach (zObject zo in res.Objects)
                            {
                                Refund refund = (Refund)zo;
                                result.Text += "Refund Id: " + refund.Id + " Refund Amount: " + refund.Amount + "<br/>";
                            }
                        }
                        else
                        {
                            result.Text += res.Message;
                        }
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get Credit Balance Adjustments For Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetCreditBalanceAdjustmentsForAccount(AccountId.Text);
                    if (res.Success)
                    {
                        result.Text += "<br/>";
                        if (res.Objects != null)
                        {
                            foreach (zObject zo in res.Objects)
                            {
                                CreditBalanceAdjustment cba = (CreditBalanceAdjustment)zo;
                                result.Text += "CBA Id: " + cba.Id + " CBA Amount: " + cba.Amount + "<br/>";
                            }
                        }
                        else
                        {
                            result.Text += res.Message;
                        }
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get Credit Cards For Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetCreditCardsForAccount(AccountId.Text);
                    if (res.Success)
                    {
                        result.Text += "<br/>";
                        if (res.Objects != null)
                        {
                            foreach (zObject zo in res.Objects)
                            {
                                PaymentMethod payMethod = (PaymentMethod)zo;
                                result.Text += "PM Id: " + payMethod.Id + " PM Type: " + payMethod.Type + "<br/>";
                            }
                        }
                        else
                        {
                            result.Text += res.Message;
                        }
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get PO For Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetPOForAccount(AccountId.Text);
                    result.Text += "PO: " + res;
                }
                else if (operation == "Get Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetAccount(AccountId.Text);
                    if (res.Success && res.Objects != null)
                    {
                        Account acc = (Account)res.Objects[0];
                        result.Text += "Account Name: " + acc.Name + "<br/>";
                        result.Text += "Account Credit Balance: " + acc.CreditBalance + "<br/>";
                    }
                    else
                    {
                        result.Text += res.Message;
                    }

                }
                else if (operation == "Get Contact")
                {
                    var res = am.GetContact(AccountId.Text);

                    if (res.Success && res.Objects != null)
                    {
                        result.Text += "<br/>";
                        foreach (zObject zo in res.Objects)
                        {
                            Contact con = (Contact)zo;
                            result.Text += "Contact First Name: " + con.FirstName + "<br/>";
                            result.Text += "Contact Last Name: " + con.LastName + "<br/>";
                            result.Text += "Contact Email: " + con.WorkEmail + "<br/>";
                        }
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Change Invoice Template")
                {
                    result.Text += "<br/>";
                    var res = am.ChangeInvoiceTemplate(AccountId.Text, InvoiceTemplateId.Text);
                    if (res.Success)
                    {
                        result.Text += res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Does Account Name Exist In Zuora")
                {
                    result.Text += "<br/>";
                    var res = am.DoesAccountNameExistInZuora(AccountName.Text);
                    result.Text += "Account Exists? " + res;
                }
                else if (operation == "Get Child Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetChildAccount(AccountId.Text);
                    if (res.Success && res.Objects != null)
                    {
                        Account acc = (Account)res.Objects[0];
                        result.Text += "Account Name: " + acc.Name + "<br/>";
                        result.Text += "Account Credit Balance: " + acc.CreditBalance + "<br/>";
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Set Parent Account")
                {
                    result.Text += "<br/>";
                    var res = am.SetParentAccount(ParentAccountId.Text, AccountId.Text);
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get Single Invoice")
                {
                    result.Text += "<br/>";
                    //var res = am.GetSingleInvoice(InvoiceId.Text);
                    //var res = zs.Query("SELECT id, status FROM Invoice WHERE Id = '" + InvoiceId.Text + "'").FirstOrDefault<Invoice>();
                    Boolean withBody = false;
                    //string FIELDS_INVOICE = "Id, AccountId, AdjustmentAmount, Amount, AmountWithoutTax, Balance, Comments, CreatedDate, DueDate, IncludesOneTime, IncludesRecurring, IncludesUsage, InvoiceDate, InvoiceNumber, LastEmailSentDate, PaymentAmount, PostedDate, RefundAmount, Source, SourceId, Status, TargetDate, TaxAmount, TaxExemptAmount, TransferredToAccounting, UpdatedDate";
                    string FIELDS_INVOICE = "Id, AccountId, AdjustmentAmount, Amount, AmountWithoutTax, Balance, Comments, CreatedDate, DueDate, IncludesOneTime, IncludesRecurring, IncludesUsage, InvoiceDate, InvoiceNumber, LastEmailSentDate, PaymentAmount, PostedDate, RefundAmount, Status";
                    var query = string.Format("SELECT {0} FROM invoice WHERE Id = '{1}'", FIELDS_INVOICE, InvoiceId.Text);
                    var res = zs.Query(query);
                    if (res.Success && res.Objects != null)
                    {
                        result.Text += "Success: " + res.Id;
                        result.Text += "Invoice Amount: " + ((Invoice)res.Objects[0]).Amount;
                        result.Text += " Status: " + ((Invoice)res.Objects[0]).Status;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Increase Credit Balance")
                {
                    var res = pm.IncreaseCreditBalance(AccountId.Text, Convert.ToDecimal(AmountBox.Text));
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Apply Credit Balance To Invoice")
                {
                    var res = pm.ApplyCreditBalanceToInvoice(InvoiceId.Text, Convert.ToDecimal(AmountBox.Text));
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Refund Electronic Payment")
                {
                    result.Text += "<br/>";
                    var res = pm.RefundElectronicPayment(PaymentId.Text, Convert.ToDecimal(RefundAmount.Text));
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Decrease Credit Balance")
                {
                    result.Text += "<br/>";
                    var res = pm.DecreaseCreditBalance(AccountId.Text, Convert.ToDecimal(AmountBox.Text));
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Apply Payment To Invoice")
                {
                    result.Text += "<br/>";
                    var res = pm.ApplyPaymentToInvoice(AccountId.Text, InvoiceId.Text, PaymentMethodId.Text, Convert.ToDecimal(PaymentAmount.Text),PaymentMethodType.SelectedValue );
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Refund External Payment")
                {
                    result.Text += "<br/>";
                    var res = pm.RefundExternalPayment(PaymentId.Text, Convert.ToDecimal(RefundAmount.Text), PaymentMethodType.SelectedValue, Convert.ToDateTime(RefundDate.Text) );
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get Product Catalog")
                {
                    result.Text += "<br/>";
                    var res = pcm.GetProductCatalog();
                    if (res != null)
                    {
                        result.Text += "Success: " + "<br/>";
                        foreach (var ph in res)
                        {
                            result.Text += "<b>Product Name:</b>" + ph.Product.Name + "<br/>";
                            foreach (var prph in ph.ProductRatePlans)
                            {
                                result.Text += "<b>Product Rate Plan Name:</b>" + prph.ProductRatePlan.Name + "<br/>";
                            }
                        }
                    }
                    else
                    {
                        result.Text += "Error";
                    }
                }
                else if (operation == "Get Rate Plan By Name")
                {
                    result.Text += "<br/>";
                    var res = pcm.GetProductRatePlanByName(Name.Text);
                    if (res != null)
                    {
                        result.Text += "Success: " + res.ProductRatePlan.Name;
                    }
                    else
                    {
                        result.Text += "Didn't find";
                    }
                }
                else if (operation == "Disable Rate Plan")
                {
                    result.Text += "<br/>";
                    var res = pcm.DisableRatePlan(ProductRatePlanId.Text, Convert.ToDateTime(DisableDate.Text));
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get Product By Name")
                {
                    result.Text += "<br/>";
                    var res = pcm.GetProductByName(Name.Text);
                    if (res != null)
                    {
                        result.Text += "Success: " + res.Product.Name;
                    }
                    else
                    {
                        result.Text += "Didn't Find";
                    }
                }
                else if (operation == "Create Product")
                {
                    result.Text += "<br/>";
                    Constants.ProductType pt = new Constants.ProductType();
                    if (ProductType.Text == "Application")
                    {
                        pt = Constants.ProductType.Application;
                    }
                    else if (ProductType.Text == "iCredits")
                    {
                        pt = Constants.ProductType.iCredits;
                    }
                    else if (ProductType.Text == "Storage")
                    {
                        pt = Constants.ProductType.Storage;
                    }

                    var res = pcm.CreateProduct(Name.Text, pt, SKU.Text, Description.Text);
                    if (res != null)
                    {
                        result.Text += "Success: " + res.Product.Id;
                    }
                    else
                    {
                        result.Text += "Error";
                    }
                }
                else if (operation == "Create Rate Plan With One Time Charge")
                {
                    Product prod = new Product();
                    prod.Id = ProductId.Text;
                    result.Text += "<br/>";
                    var res = pcm.CreateRatePlanWithOneTimeCharge(prod, Name.Text, Convert.ToDecimal(Price.Text));
                    if (res != null)
                    {
                        result.Text += "Success: " + res.ProductRatePlan.Id;
                    }
                    else
                    {
                        result.Text += "Error";
                    }
                }
                else if (operation == "Delete Rate Plan")
                {
                    pcm.DeleteRatePlan(IdToDelete.Text);
                }
                else if (operation == "Delete Product")
                {
                    pcm.DeleteProduct(IdToDelete.Text);
                }
                else if (operation == "Change Price For Product")
                {
                    List<ResponseHolder> resps = pcm.ChangePriceForProduct(ProductRatePlanChargeId.Text, new decimal[] { Convert.ToDecimal(Price.Text) }, "USD");
                    result.Text += "<br/>";
                    foreach (ResponseHolder resp in resps)
                    {
                        if (resp.Success)
                        {
                            result.Text += resp.Id;
                        }
                        else
                        {
                            result.Text += resp.Message;
                        }
                    }
                }
                else if (operation == "Subscribe")
                {
                    result.Text += "<br/>";
                    Account acc = new Account();
                    acc.Name = AccountName.Text;
                    acc.BillCycleDaySpecified = true;
                    acc.BillCycleDay = Convert.ToInt16(BillCycleDay.Text);
                    acc.Currency = Currency.Text;
                    acc.PaymentTerm = PaymentTermDropDown.SelectedValue;
                    acc.Batch = Batch.Text;

                    Contact con = new Contact();
                    con.Address1 = Address1.Text;
                    con.Address2 = Address2.Text;
                    con.City = City.Text;
                    con.State = State.Text;
                    con.LastName = LastName.Text;
                    con.FirstName = FirstName.Text;
                    con.Country = Country.Text;
                    con.PostalCode = Zip.Text;

                    DateTime date = Convert.ToDateTime(SubscriptionDate.Text);

                    Subscription sub = new Subscription();
                    sub.ContractAcceptanceDateSpecified = true;
                    sub.ContractAcceptanceDate = date;
                    sub.ServiceActivationDateSpecified = true;
                    sub.ServiceActivationDate = date;
                    sub.ContractEffectiveDateSpecified = true;
                    sub.ContractEffectiveDate = date;

                    sub.TermType = SubscriptionTermType.Text;
                    if (SubscriptionTermType.Text == "TERMED")
                    {
                        sub.InitialTermSpecified = true;
                        sub.InitialTerm = 12;
                        sub.RenewalTermSpecified = true;
                        sub.RenewalTerm = 12;
                    }

                    PreviewOptions po = new PreviewOptions();
                    po.EnablePreviewModeSpecified = false;
                    po.EnablePreviewMode = false;

                    SubscribeOptions so = new SubscribeOptions();
                    so.GenerateInvoiceSpecified = false;
                    so.GenerateInvoice = false;
                    so.ProcessPaymentsSpecified = false;
                    so.ProcessPayments = false;

                    ProductRatePlanHolder prph = pcm.GetProductRatePlanByName(ProductRatePlanName.Text);

                    SubscribeResponseHolder resp = sm.Subscribe( acc, con, null, new List<ProductRatePlanHolder> { prph }, sub, po, so);

                    if (resp.Success)
                    {
                        result.Text += resp.SubRes.AccountId;
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }

                }
                else if (operation == "Subscribe With Existing Account")
                {
                    result.Text += "<br/>";
                    DateTime date = Convert.ToDateTime(SubscriptionDate.Text);

                    Subscription sub = new Subscription();
                    sub.ContractAcceptanceDateSpecified = true;
                    sub.ContractAcceptanceDate = date;
                    sub.ServiceActivationDateSpecified = true;
                    sub.ServiceActivationDate = date;
                    sub.ContractEffectiveDateSpecified = true;
                    sub.ContractEffectiveDate = date;

                    sub.TermType = SubscriptionTermType.Text;
                    if (SubscriptionTermType.Text == "TERMED")
                    {
                        sub.InitialTermSpecified = true;
                        sub.InitialTerm = 12;
                        sub.RenewalTermSpecified = true;
                        sub.RenewalTerm = 12;
                    }

                    PreviewOptions po = new PreviewOptions();
                    po.EnablePreviewModeSpecified = false;
                    po.EnablePreviewMode = false;

                    SubscribeOptions so = new SubscribeOptions();
                    so.GenerateInvoiceSpecified = false;
                    so.GenerateInvoice = false;
                    so.ProcessPaymentsSpecified = false;
                    so.ProcessPayments = false;

                    ProductRatePlanHolder prph = pcm.GetProductRatePlanByName(ProductRatePlanName.Text);

                    SubscribeResponseHolder resp = sm.SubscribeWithExisitingAccount(AccountId.Text, new List<ProductRatePlanHolder>{prph}, sub, po, so);
                    if (resp.Success)
                    {
                        result.Text += resp.SubRes.AccountId;
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if (operation == "Do Add Product Amendment")
                {
                    AmendOptions ao = new AmendOptions();
                    ao.GenerateInvoiceSpecified = false;
                    ao.GenerateInvoice = false;

                    ao.ProcessPaymentsSpecified = true;
                    ao.ProcessPayments = false;

                    PreviewOptions po = new PreviewOptions();
                    po.EnablePreviewModeSpecified = false;
                    po.EnablePreviewMode = false;

                    AmendResponseHolder resp = sm.DoAddProductAmendment(SubscriptionId.Text, Convert.ToDateTime(AmendmentStartDate.Text), ProductRatePlanId.Text, ao, po);
                    if (resp.Success)
                    {
                        result.Text += resp.AmendRes.AmendmentIds[0];
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if (operation == "Do Renewal Amendment")
                {
                    AmendOptions ao = new AmendOptions();
                    ao.GenerateInvoiceSpecified = true;
                    ao.GenerateInvoice = false;

                    ao.ProcessPaymentsSpecified = true;
                    ao.ProcessPayments = false;

                    PreviewOptions po = new PreviewOptions();
                    po.EnablePreviewModeSpecified = false;
                    po.EnablePreviewMode = false;

                    AmendResponseHolder resp = sm.DoRenewalAmendment(SubscriptionId.Text, Convert.ToDateTime(AmendmentStartDate.Text), ao, po);
                    if (resp.Success)
                    {
                        result.Text += resp.AmendRes.AmendmentIds[0];
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if (operation == "Do Terms And Conditions Amendment")
                {
                    AmendOptions ao = new AmendOptions();
                    ao.GenerateInvoiceSpecified = true;
                    ao.GenerateInvoice = false;

                    ao.ProcessPaymentsSpecified = true;
                    ao.ProcessPayments = false;

                    PreviewOptions po = new PreviewOptions();
                    po.EnablePreviewModeSpecified = false;
                    po.EnablePreviewMode = false;

                    AmendResponseHolder resp = sm.DoTermsAndConditionsAmendment(
                                                    SubscriptionId.Text,
                                                    Convert.ToDateTime(AmendmentStartDate.Text),
                                                    SubscriptionTermType.SelectedValue,
                                                    Convert.ToInt32(InitialTerm.Text),
                                                    Convert.ToInt32(RenewalTerm.Text),
                                                    ao,
                                                    po
                                               );
                    if (resp.Success)
                    {
                        result.Text += resp.AmendRes.AmendmentIds[0];
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if (operation == "Get Subscription And Charge Info")
                {
                    SubscriptionInfoHolder sih = sm.GetSubscriptionAndChargeInfo(SubscriptionId.Text);
                    if (sih.Success)
                    {
                        result.Text += "<b>SubId:</b>" + sih.Subscription.Id + "<br/>";
                        foreach (RatePlan rp in sih.RatePlanList)
                        {
                            result.Text += "<b>RP Name:</b>" + rp.Name + "<br/>";
                        }
                    }
                    else
                    {
                        result.Text += sih.Message;
                    }
                }
                else if (operation == "Update Contact")
                {
                    ResponseHolder resp = am.UpdateContact(AccountId.Text, LastName.Text, FirstName.Text, Address1.Text, City.Text, State.Text, Zip.Text, Country.Text);

                    if (resp.Success)
                    {
                        result.Text += resp.Id;
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if(operation == "Get Credit Cards")
                {
                    ResponseHolder resp = am.GetCreditCardsPaymentMethods(AccountId.Text);

                    if (resp.Success)
                    {
                        foreach (zObject zo in resp.Objects)
                        {
                            PaymentMethod paymentMethod = (PaymentMethod)zo;
                            result.Text += "Payment Method: " + paymentMethod.Id + "<br/>";
                        }
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if (operation == "Get Invoices PDF For Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetInvoicesForAccount(AccountId.Text);
                    //string FIELDS_INVOICE = "Id, AccountId, AdjustmentAmount, Amount, AmountWithoutTax, Balance, Comments, CreatedDate, DueDate, IncludesOneTime, IncludesRecurring, IncludesUsage, InvoiceDate, InvoiceNumber, LastEmailSentDate, PaymentAmount, PostedDate, RefundAmount, Source, SourceId, Status, TargetDate, TaxAmount, TaxExemptAmount, TransferredToAccounting, UpdatedDate";
                    //var res = zs.Query("");
                    if (res.Success)
                    {
                        result.Text += "<br/>";
                        if (res.Objects != null)
                        {
                            Invoice invoice = (Invoice) res.Objects[0];
                            foreach (zObject zo in res.Objects)
                            {
                                Invoice inv = (Invoice)zo;
                                if (inv.CreatedDate > invoice.CreatedDate)
                                {
                                    invoice = inv;
                                }
                                result.Text += "Invoice Number: " + inv.InvoiceNumber + " Invoice Amount: " + inv.Amount + " Status: " + inv.Status + "<br/>";
                            }

                            Invoice invRes = (Invoice)am.GetInvoicePDFForAccount(invoice.Id).Objects[0];
                            var invoiceBody = invRes.Body;

                            Byte[] bytes = System.Convert.FromBase64String(invoiceBody.ToString());

                            string pathString = @"C:\Users\sxuereb\Documents\Invoices";
                            string fileName = invRes.InvoiceNumber +".pdf";
                            pathString = System.IO.Path.Combine(pathString, fileName);

                            if (!System.IO.File.Exists(pathString))
                            {
                                using (System.IO.FileStream fs = System.IO.File.Create(pathString))
                                {
                                    for (int i = 0; i < bytes.Length; i++)
                                    {
                                        fs.WriteByte(bytes[i]);
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("File \"{0}\" already exists.", fileName);
                                return;
                            }

                        }
                        else
                        {
                            result.Text += res.Message;
                        }
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                /*else if(operation == "Get Current Subscription")
                {
                    ResponseHolder resp = sm.GetCurrentSubscription(AccountId.Text);

                    if (resp.Success)
                    {

                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if(operation == "New Credit Card")
                {

                }*/
                else if (operation == "Delete Payment Method")
                {
                    List<ResponseHolder> resp = am.DeletePaymentMethod(PaymentMethodId.Text);

                    if (resp[0].Success)
                    {
                        result.Text += "Successfully Deleted Payment Method.";
                    }
                    else
                    {
                        result.Text += resp[0].Message;
                    }
                }

            }
            else
            {
                result.Text += "Please Login" + "<br/>";
            }

            ddl1.SelectedIndex = 0;
        }