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