protected void btnDelete_Click(object sender, EventArgs e) { UserAccount u = GetCorrectUser(); long storeId = this.MTApp.CurrentStore.Id; var billManager = new BillingManager(this.MTApp); var response = billManager.CancelSubscription(this.MTApp.CurrentStore.StripeCustomerId); MTApp.AccountServices.CancelStore(storeId, u.Id); Response.Redirect("http://www.merchanttribestores.com"); }
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"); } }