Beispiel #1
0
        protected void btnUpdateCreditCard_Click(object sender, EventArgs e)
        {
            if (!this.CreditCardInput1.IsValid())
            {
                this.MessageBox1.ShowWarning("Please check your credit card information is valid before attempting to update.");
                return;
            }

            UserAccount u = GetCorrectUser();
            
            var billManager = new BillingManager(this.MTApp);

            var updateRequest = new UpdateCustomerRequest();
            updateRequest.CreditCard = this.CreditCardInput1.GetCardData();
            updateRequest.CustomerId = this.MTApp.CurrentStore.StripeCustomerId;
            updateRequest.PostalCode = this.txtZipCode.Text.Trim();

            var res = billManager.UpdateCustomer(updateRequest);
            if (!res.Success)
            {
                this.MessageBox1.ShowWarning("Unable to update card: " + res.Message);
                return;
            }

            this.MessageBox1.ShowOk("Credit card information updated!");                        
        }
        private void GoToPlan(int planId)
        {
            var user = GetCorrectUser();
            var store = MTApp.CurrentStore;
            var billManager = new BillingManager(this.MTApp);

            if (store.Id == (long)planId)
            {
                this.MessageBox1.ShowInformation("You selected the same plan you're currently on. No change required.");
                return;
            }

            // Make sure you don't have too many items to downgrade
            if (!CheckMax(planId)) return;
                        
            if (store.StripeCustomerId.Trim().Length > 0)
            {
                if (planId == 0)
                {
                    billManager.CancelSubscription(store.StripeCustomerId);                    
                    MTApp.AccountServices.ChangePlan(store.Id, user.Id, planId, MTApp);
                    Response.Redirect("ChangePlan.aspx?ok=1");                                    
                }

                var updateRequest = new UpdateCustomerRequest();
                updateRequest.CustomerId = store.StripeCustomerId;
                updateRequest.PlanId = TranslatePlanId(planId);

                var updateResponse = billManager.UpdateCustomer(updateRequest);
                if (!updateResponse.Success)
                {
                    this.MessageBox1.ShowWarning("Unable to update plan: " + updateResponse.Message);
                    return;
                }                                    
                if (!MTApp.AccountServices.ChangePlan(store.Id, user.Id, planId, MTApp))
                {
                    this.MessageBox1.ShowWarning("Unable to change plans! Check with support.");
                    return;                    
                }

                Response.Redirect("ChangePlan.aspx?ok=1");                
            }
            else
            {            
                var createRequest = new CreateCustomerRequest();
                createRequest.CreditCard = this.CreditCardInput1.GetCardData();
                createRequest.PostalCode = this.txtZipCode.Text;
                createRequest.PlanId = TranslatePlanId(planId);
                createRequest.Name = store.Id + " - " + store.StoreName;
                createRequest.Email = user.Email.Replace("@","+store" + store.Id + "@");

                var createResponse = billManager.CreateCustomer(createRequest);
                if (!createResponse.Success)
                {
                    this.MessageBox1.ShowWarning("Unable to change plans: " + createResponse.Message);
                    return;
                }

                // Save customer subscription id
                store.StripeCustomerId = createResponse.NewCustomerId;
                MTApp.UpdateCurrentStore();

                // Change plan in MerchantTribe
                MTApp.AccountServices.ChangePlan(store.Id, user.Id, planId, MTApp);
                Response.Redirect("ChangePlan.aspx?ok=1");                                
                
            }            
        }