Exemplo n.º 1
0
        public CreateCustomerResponse CreateCustomer(CreateCustomerRequest req)
        {
            var response = new CreateCustomerResponse();

            try
            {
                var myCustomer = new StripeCustomerCreateOptions();

                myCustomer.Email = req.Email;
                myCustomer.Description = req.Name;

                // set these properties if using a card
                myCustomer.CardNumber = req.CreditCard.CardNumber;
                myCustomer.CardExpirationYear = req.CreditCard.ExpirationYear.ToString();
                myCustomer.CardExpirationMonth = req.CreditCard.ExpirationMonth.ToString();
                myCustomer.CardAddressCountry = "US";                 // optional
                //myCustomer.CardAddressLine1 = "24 Beef Flank St";   // optional
                //myCustomer.CardAddressLine2 = "Apt 24";             // optional
                //myCustomer.CardAddressState = "NC";                 // optional
                myCustomer.CardAddressZip = req.PostalCode; //        // optional
                myCustomer.CardName = req.CreditCard.CardHolderName;  // optional
                if (req.CreditCard.SecurityCode.Length > 0)
                {
                    myCustomer.CardCvc = req.CreditCard.SecurityCode;
                }

                myCustomer.PlanId = req.PlanId;

                var customerService = new StripeCustomerService();
                StripeCustomer stripeCustomer = customerService.Create(myCustomer);

                if (stripeCustomer.Id.Length > 0)
                {
                    response.NewCustomerId = stripeCustomer.Id;
                    response.Success = true;                    
                }
                else
                {
                    response.Success = false;
                    response.Message = "Unable to get new customer Id";
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            
            return response;
        }
Exemplo n.º 2
0
        public CreateCustomerResponse CreateCustomer(CreateCustomerRequest req)
        {
            var response = new CreateCustomerResponse();

            try
            {
                var myCustomer = new StripeCustomerCreateOptions();

                myCustomer.Email       = req.Email;
                myCustomer.Description = req.Name;

                // set these properties if using a card
                myCustomer.CardNumber          = req.CreditCard.CardNumber;
                myCustomer.CardExpirationYear  = req.CreditCard.ExpirationYear.ToString();
                myCustomer.CardExpirationMonth = req.CreditCard.ExpirationMonth.ToString();
                myCustomer.CardAddressCountry  = "US";                // optional
                //myCustomer.CardAddressLine1 = "24 Beef Flank St";   // optional
                //myCustomer.CardAddressLine2 = "Apt 24";             // optional
                //myCustomer.CardAddressState = "NC";                 // optional
                myCustomer.CardAddressZip = req.PostalCode;                //        // optional
                myCustomer.CardName       = req.CreditCard.CardHolderName; // optional
                if (req.CreditCard.SecurityCode.Length > 0)
                {
                    myCustomer.CardCvc = req.CreditCard.SecurityCode;
                }

                myCustomer.PlanId = req.PlanId;

                var            customerService = new StripeCustomerService();
                StripeCustomer stripeCustomer  = customerService.Create(myCustomer);

                if (stripeCustomer.Id.Length > 0)
                {
                    response.NewCustomerId = stripeCustomer.Id;
                    response.Success       = true;
                }
                else
                {
                    response.Success = false;
                    response.Message = "Unable to get new customer Id";
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
Exemplo n.º 3
0
        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");                                
                
            }            
        }