コード例 #1
0
        public UpdateCustomerResponse UpdateCustomer(UpdateCustomerRequest req)
        {
            var response = new UpdateCustomerResponse();

            try
            {
                if (req.PlanId.Length > 0)
                {
                    return(UpdateSubscription(req));
                }
                else
                {
                    // Update Customer
                    var myCustomer = new StripeCustomerUpdateOptions();

                    if (req.CreditCard.CardNumber.Trim().Length > 0)
                    {
                        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;
                        }
                    }

                    var            customerService = new StripeCustomerService();
                    StripeCustomer stripeCustomer  = customerService.Update(req.CustomerId, myCustomer);

                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return(response);
        }
コード例 #2
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!");                        
        }
コード例 #3
0
        public UpdateCustomerResponse UpdateSubscription(UpdateCustomerRequest req)
        {
            var response = new UpdateCustomerResponse();

            try
            {
                    // Update Customer
                    var myCustomer = new StripeCustomerUpdateSubscriptionOptions();

                    if (req.CreditCard.CardNumber.Trim().Length > 0)
                    {
                        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();
                    StripeSubscription result = customerService.UpdateSubscription(req.CustomerId, myCustomer);
                    
                    response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "Unable to update subscription: " + ex.Message;
            }

            return response;
        }
コード例 #4
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");                                
                
            }            
        }