public AmendResponseHolder DoTermsAndConditionsAmendment(String subscriptionId, DateTime effectiveDate, String termType, int initialTerm, int renewalTerm, AmendOptions ao = null, PreviewOptions po = null)
        {
            AmendRequest amendRequest = new AmendRequest();
            Amendment amendment = new Amendment();
            if (ao != null)
            {
                amendRequest.AmendOptions = ao;
            }
            if (po != null)
            {
                amendRequest.PreviewOptions = po;
            }

            amendment.Name = "T's and C's amendment";
            amendment.Type = "TermsAndConditions";
            amendment.ContractEffectiveDate = effectiveDate;
            amendment.ContractEffectiveDateSpecified = true;
            if(termType != null)
                amendment.TermType = termType;
            amendment.InitialTerm = initialTerm;
            amendment.InitialTermSpecified = true;
            amendment.RenewalTerm = renewalTerm;
            amendment.RenewalTermSpecified = true;
            amendment.SubscriptionId = subscriptionId;

            amendRequest.Amendments = new Amendment[] { amendment };
            return zs.Amend(new List<AmendRequest> { amendRequest })[0];
        }
        public AmendResponseHolder DoAddProductAmendment(String subscriptionId, DateTime effectiveDate, String productRatePlanId, AmendOptions ao = null, PreviewOptions po = null)
        {
            AmendRequest amendRequest = new AmendRequest();
            Amendment amendment = new Amendment();

            amendment.Name = "Add Product Amendment";
            amendment.Type = "NewProduct";
            amendment.ContractEffectiveDate = effectiveDate;
            amendment.ContractEffectiveDateSpecified = true;
            amendment.SubscriptionId = subscriptionId;

            RatePlanData ratePlanData = new RatePlanData();
            RatePlan ratePlan = new RatePlan();
            ratePlan.ProductRatePlanId = productRatePlanId;
            ratePlanData.RatePlan = ratePlan;

            amendment.RatePlanData = ratePlanData;
            if (ao != null)
            {
                amendRequest.AmendOptions = ao;
            }
            if (po != null)
            {
                amendRequest.PreviewOptions = po;
            }
            amendRequest.Amendments = new Amendment[] { amendment };
            return zs.Amend(new List<AmendRequest> { amendRequest })[0];
        }
        public void CanWeApplyElectronicPaymentToMultipleInvoices()
        {
            AmendOptions ao = new AmendOptions();
            ao.GenerateInvoiceSpecified = true;
            ao.GenerateInvoice = true;
            //make an account with multiple invoices
            SubscribeResponseHolder subRes = zth.MakeSubscription(false);
            AmendResponseHolder amendRes = sm.DoAddProductAmendment(subRes.SubRes.SubscriptionId, DateTime.Now, zth.CreateRatePlanToSubscribe(), ao);
            ResponseHolder invList = am.GetInvoicesForAccount(subRes.SubRes.AccountId);
            List<String> invIdsList = new List<String>();

            Decimal invAmount = 0;

            foreach (zObject z in invList.Objects)
            {
                Invoice inv = (Invoice)z;
                invAmount += (Decimal)inv.Amount;
                invIdsList.Add(inv.Id);
            }
            //get the payment method id
            ResponseHolder pmRes = am.GetCreditCardsForAccount(subRes.SubRes.AccountId);

            ResponseHolder createRes =  pm.ApplyPaymentToMultipleInvoices(subRes.SubRes.AccountId, invIdsList.ToArray(), pmRes.Objects[0].Id, invAmount, "Electronic");

            Assert.True(createRes.Success);
        }
 public void CanWeDoAddProductAmendment()
 {
     AmendOptions ao = new AmendOptions();
     ao.GenerateInvoiceSpecified = true;
     ao.GenerateInvoice = false;
     String subId = zth.MakeSubscription(true).SubRes.SubscriptionId;
     String productRatePlanId = zth.CreateRatePlanToSubscribe();
     AmendResponseHolder amendRes = sm.DoAddProductAmendment(subId, DateTime.Now, productRatePlanId, ao);
     Assert.True(amendRes.Success);
 }
        public AmendResponseHolder DoRenewalAmendment(String subscriptionId, DateTime effectiveDate, AmendOptions ao = null, PreviewOptions po = null)
        {
            AmendRequest amendRequest = new AmendRequest();
            Amendment amendment = new Amendment();
            if (ao != null)
            {
                amendRequest.AmendOptions = ao;
            }
            if (po != null)
            {
                amendRequest.PreviewOptions = po;
            }

            amendment.Name = "Renewal amendment";
            amendment.Type = "Renewal";
            amendment.ContractEffectiveDate = effectiveDate;
            amendment.ContractEffectiveDateSpecified = true;
            amendment.SubscriptionId = subscriptionId;

            amendRequest.Amendments = new Amendment[] { amendment };
            return zs.Amend(new List<AmendRequest> { amendRequest })[0];
        }
예제 #6
0
        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;
        }
예제 #7
0
        protected void btnGet_Click(object sender, EventArgs e)
        {
            AmendOptions   op          = new AmendOptions();
            AmendTransform amTransform = new AmendTransform();

            //Transformation
            if (!string.IsNullOrEmpty(txtWidth.Text) && !string.IsNullOrEmpty(txtHeight.Text))
            {
                int width  = int.Parse(txtWidth.Text);
                int height = int.Parse(txtHeight.Text);
                amTransform.Height(height);
                amTransform.Width(width);
                if (ddFit.SelectedValue != "0")
                {
                    switch (ddFit.SelectedValue)
                    {
                    case "1":
                        amTransform.Fit(Amend.FIT_XY);
                        break;

                    case "2":
                        amTransform.Fit(Amend.FIT_WIDTH);
                        break;

                    case "3":
                        amTransform.Fit(Amend.FIT_HEIGHT);
                        break;

                    case "4":
                        amTransform.Fit(Amend.FIT_FILL);
                        break;

                    case "5":
                        amTransform.Fit(Amend.FIT_INSIDE);
                        break;

                    case "6":
                        amTransform.Fit(Amend.FIT_FACE);
                        break;
                    }
                }
                if (ddAlign.SelectedValue != "0")
                {
                    switch (ddAlign.SelectedValue)
                    {
                    case "1":
                        amTransform.Align(Amend.LEFT);
                        break;

                    case "2":
                        amTransform.Align(Amend.RIGHT);
                        break;

                    case "3":
                        amTransform.Align(Amend.CENTER);
                        break;

                    case "4":
                        amTransform.Align(Amend.TOP);
                        break;

                    case "5":
                        amTransform.Align(Amend.BOTTOM);
                        break;
                    }
                }
                if (ddListColor.SelectedValue != "0")
                {
                    amTransform.Color(ddListColor.SelectedItem.Text);
                }
                if (!string.IsNullOrEmpty(txtOriginX.Text))
                {
                    amTransform.X(int.Parse(txtOriginX.Text));
                }
                if (!string.IsNullOrEmpty(txtOriginY.Text))
                {
                    amTransform.Y(int.Parse(txtOriginY.Text));
                }
            }
            else if (!string.IsNullOrEmpty(txtWidth.Text))
            {
                int width = int.Parse(txtWidth.Text);
                amTransform.Width(width);
            }
            else if (!string.IsNullOrEmpty(txtHeight.Text))
            {
                int height = int.Parse(txtHeight.Text);
                amTransform.Height(height);
            }
            op.Transform(amTransform);
            if (!string.IsNullOrEmpty(txtBright.Text))
            {
                op.Effects(new AmendEffects().Brightness(txtBright.Text));
            }
            if (!string.IsNullOrEmpty(txtContrast.Text))
            {
                op.Effects(new AmendEffects().Contrast(txtContrast.Text));
            }
            if (!string.IsNullOrEmpty(txtOverlayImage.Text))
            {
                AmendOverlay ov = new AmendOverlay();
                ov.image(txtOverlayImage.Text);
                if (!string.IsNullOrEmpty(txtOverlayPosX.Text) && !string.IsNullOrEmpty(txtOverlayPosY.Text))
                {
                    ov.x(int.Parse(txtOverlayPosX.Text));
                    ov.y(int.Parse(txtOverlayPosX.Text));
                }
                else if (!string.IsNullOrEmpty(txtOverlayPosX.Text))
                {
                    ov.x(int.Parse(txtOverlayPosX.Text));
                }
                else if (!string.IsNullOrEmpty(txtOverlayPosY.Text))
                {
                    ov.y(int.Parse(txtOverlayPosY.Text));
                }
                op.Overlay(ov);
            }
            if (!string.IsNullOrEmpty(txtOverlayText.Text))
            {
                AmendOverlay ov = new AmendOverlay();
                ov.text(txtOverlayText.Text);
                if (!string.IsNullOrEmpty(txtTextSize.Text))
                {
                    ov.size(int.Parse(txtTextSize.Text));
                }
                if (ddTextColor.SelectedValue != "0")
                {
                    ov.color(ddTextColor.SelectedItem.Text);
                }
                if (chkBold.Checked)
                {
                    ov.style(Amend.BOLD);
                }
                if (chkItalic.Checked)
                {
                    ov.style(Amend.ITALIC);
                }
                if (!string.IsNullOrEmpty(txtOverlayPosX.Text) && !string.IsNullOrEmpty(txtOverlayPosY.Text))
                {
                    ov.x(int.Parse(txtOverlayPosX.Text));
                    ov.y(int.Parse(txtOverlayPosY.Text));
                }
                else if (!string.IsNullOrEmpty(txtOverlayPosX.Text))
                {
                    ov.x(int.Parse(txtOverlayPosX.Text));
                }
                else if (!string.IsNullOrEmpty(txtOverlayPosY.Text))
                {
                    ov.y(int.Parse(txtOverlayPosY.Text));
                }
                op.Overlay(ov);
            }
            if (!string.IsNullOrEmpty(txtQuality.Text))
            {
                op.Quality(int.Parse(txtQuality.Text));
            }
            if (!string.IsNullOrEmpty(txtRadius.Text))
            {
                if (txtRadius.Text == "Max")
                {
                    op.Radius(Amend.MAX);
                }
                else
                {
                    op.Radius(int.Parse(txtRadius.Text));
                }
            }
            if (chkFlipX.Checked && chkFlipY.Checked)
            {
                op.Flip(Amend.XY);
            }
            else if (chkFlipX.Checked)
            {
                op.Flip(Amend.X);
            }
            else if (chkFlipY.Checked)
            {
                op.Flip(Amend.Y);
            }
            if (chkInvert.Checked)
            {
                op.Invert();
            }
            if (!string.IsNullOrEmpty(txtAngle.Text))
            {
                op.Rotate(int.Parse(txtAngle.Text));
            }
            op.GrayScale(chkGrayScale.Checked);
            if (!string.IsNullOrEmpty(ImageId))
            {
                Amend.Init().Load(ImageId, op).Into(Image1);
            }
            else if (!string.IsNullOrEmpty(ImageUrl))
            {
                Amend.Init().Fetch(ImageUrl, op).Into(Image1);
            }
        }