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);
        }
Example #2
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;
        }