Create() public method

public Create ( StripeCustomerCreateOptions createOptions, Stripe.StripeRequestOptions requestOptions = null ) : Stripe.StripeCustomer
createOptions StripeCustomerCreateOptions
requestOptions Stripe.StripeRequestOptions
return Stripe.StripeCustomer
Exemplo n.º 1
0
        public bool SaveCustomerByToken(string email, string stripeToken)
        {
            try
            {
                var customer = new StripeCustomerCreateOptions();
                customer.Email = email;
                //customer.Description = "Johnny Tenderloin ([email protected])";
                customer.TokenId = stripeToken;
                //customer.PlanId = *planId*;                          // only if you have a plan
                //customer.Coupon = *couponId*;                        // only if you have a coupon
                //customer.TrialEnd = DateTime.UtcNow.AddMonths(1);    // when the customers trial ends (overrides the plan if applicable)
                //customer.Quantity = 1;                               // optional, defaults to 1
                var customerService = new StripeCustomerService(Cohort.Site.Stripe.SecretKey);
                var stripeCustomer = customerService.Create(customer);
                // Create linkage between signup and customer for later charging

                return true;
            }
            catch (Exception)
            {
                // log 

                return false;
            }
        }
Exemplo n.º 2
0
        private async Task<string> ProcessSubscription(StripeChargeModel model)
        {
            //TODO
            if (model.Amount == 0)
            {
                model.Amount = 399;
            }

            var planId = "Up100PerMo";
            var secretKey = ConfigurationManager.AppSettings["StripeApiKey"];
            model.Card.TokenId = model.Id;

            return await Task.Run(() =>
            {
                var stripeCustomerCreateOptions = new StripeCustomerCreateOptions
                {
                    Email = model.Email,
                    PlanId = planId,
                    Card = model.Card,
                    Description = "Charged £3.99 for monthly up to 100",
                };
                var customerService = new StripeCustomerService(secretKey);
                var stripeCustomer = customerService.Create(stripeCustomerCreateOptions);

                return stripeCustomer.Id;
            });
        }
        public ActionResult About()
        {
            StripeConfiguration.SetApiKey("sk_test_JRb9hXgh80838IRQQTUHwJPP");

            var myCustomer = new StripeCustomerCreateOptions();

            // set these properties if it makes you happy
            myCustomer.Email = "*****@*****.**";
            myCustomer.Description = "teste stripe.net";



            // setting up the card
            myCustomer.Source = new StripeSourceOptions()
            {
                // set this property if using a token
                // TokenId = *tokenId *,

                Object = "card",
                // set these properties if passing full card details (do not
                // set these properties if you set TokenId)
                Number = "4242424242424242",
                ExpirationYear = "2022",
                ExpirationMonth = "10",
                AddressCountry = "IE",                // optional
                AddressLine1 = "24 Beef Flank St",    // optional
                AddressLine2 = "Apt 24",              // optional
                AddressCity = "Biggie Smalls",        // optional
                AddressState = "NC",                  // optional
                AddressZip = "27617",                 // optional
                Name = "Mateus Meatballs",               // optional
                Cvc = "1223",


            };

            myCustomer.PlanId = "2";                          // only if you have a plan
                                                              // myCustomer.TaxPercent = 20;                            // only if you are passing a plan, this tax percent will be added to the price.
                                                              //myCustomer.Coupon = *couponId *;                        // only if you have a coupon
                                                              //myCustomer.TrialEnd = DateTime.UtcNow.AddMonths(1);    // when the customers trial ends (overrides the plan if applicable)
            myCustomer.Quantity = 1;                         // optional, defaults to 1



            var customerService = new StripeCustomerService();

            StripeCustomer stripeCustomer = customerService.Create(myCustomer);


            return View();
        }
Exemplo n.º 4
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;
        }
        private void createCustomer()
        {
            string token = "" + Request.Form["stripeToken"];
            var myCustomer = new StripeCustomerCreateOptions();

            myCustomer.Email = "";
            myCustomer.Description = "";

            //Setting up card
            myCustomer.Source = new StripeSourceOptions()
            {
                TokenId = token
            };

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


            //Add to DB
            DbConn.dBWrite("EXEC CreateStripeID '" + stripeCustomer.Id + "', " + Session["ID"]);
        }
Exemplo n.º 6
0
        private StripeCustomer GetCustomer(NewDonationModel model, StripePlan plan)
        {
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var currentUser = manager.FindById(User.Identity.GetUserId());
            string userEmail = currentUser.Email;
            var myCustomer = new StripeCustomerCreateOptions
            {
                Email = userEmail,
                Description = currentUser.FirstName + currentUser.LastName,
                Source = new StripeSourceOptions()
                {
                    TokenId = model.Token
                }
            };

            myCustomer.PlanId = plan.Id;

            var customerService = new StripeCustomerService("sk_test_yPi2XADkAP3wiS1i6tkjErxZ");
            return customerService.Create(myCustomer);
        }
        public JsonResult ChangePlan(string organizationId, string planId, string stripeToken, string last4) {
            if (String.IsNullOrEmpty(organizationId) || !User.CanAccessOrganization(organizationId))
                throw new ArgumentException("Invalid organization id.", "organizationId"); // TODO: These should probably throw http Response exceptions.

            if (!Settings.Current.EnableBilling)
                return Json(new { Success = false, Message = "Plans cannot be changed while billing is disabled." });

            Organization organization = _repository.GetById(organizationId);
            if (organization == null)
                return Json(new { Success = false, Message = "Invalid OrganizationId." });

            BillingPlan plan = _billingManager.GetBillingPlan(planId);
            if (plan == null)
                return Json(new { Success = false, Message = "Invalid PlanId." });

            if (String.Equals(organization.PlanId, plan.Id) && String.Equals(BillingManager.FreePlan.Id, plan.Id))
                return Json(new { Success = true, Message = "Your plan was not changed as you were already on the free plan." });

            // Only see if they can downgrade a plan if the plans are different.
            string message;
            if (!String.Equals(organization.PlanId, plan.Id) && !_billingManager.CanDownGrade(organization, plan, User.UserEntity, out message))
                return Json(new { Success = false, Message = message });

            var customerService = new StripeCustomerService();

            try {
                // If they are on a paid plan and then downgrade to a free plan then cancel their stripe subscription.
                if (!String.Equals(organization.PlanId, BillingManager.FreePlan.Id) && String.Equals(plan.Id, BillingManager.FreePlan.Id)) {
                    if (!String.IsNullOrEmpty(organization.StripeCustomerId))
                        customerService.CancelSubscription(organization.StripeCustomerId);

                    organization.BillingStatus = BillingStatus.Trialing;
                    organization.RemoveSuspension();
                } else if (String.IsNullOrEmpty(organization.StripeCustomerId)) {
                    if (String.IsNullOrEmpty(stripeToken))
                        return Json(new { Success = false, Message = "Billing information was not set." });

                    organization.SubscribeDate = DateTime.Now;

                    StripeCustomer customer = customerService.Create(new StripeCustomerCreateOptions {
                        TokenId = stripeToken,
                        PlanId = planId,
                        Description = organization.Name
                    });

                    organization.BillingStatus = BillingStatus.Active;
                    organization.RemoveSuspension();
                    organization.StripeCustomerId = customer.Id;
                    if (customer.StripeCardList.StripeCards.Count > 0)
                        organization.CardLast4 = customer.StripeCardList.StripeCards[0].Last4;
                } else {
                    var update = new StripeCustomerUpdateSubscriptionOptions {
                        PlanId = planId
                    };
                    bool cardUpdated = false;

                    if (!String.IsNullOrEmpty(stripeToken)) {
                        update.TokenId = stripeToken;
                        cardUpdated = true;
                    }

                    customerService.UpdateSubscription(organization.StripeCustomerId, update);
                    if (cardUpdated)
                        organization.CardLast4 = last4;

                    organization.BillingStatus = BillingStatus.Active;
                    organization.RemoveSuspension();
                }

                _billingManager.ApplyBillingPlan(organization, plan, User.UserEntity);
                _repository.Update(organization);

                _notificationSender.PlanChanged(organization.Id);
            } catch (Exception e) {
                Log.Error().Exception(e).Message("An error occurred while trying to update your billing plan: " + e.Message).Report(r => r.MarkAsCritical()).Write();
                return Json(new { Success = false, Message = e.Message });
            }

            return Json(new { Success = true });
        }
        private async Task CreateCustomer(StripeModel model)
        {
            await Task.Run(() =>
            {
                // create customer based on validated token from stripe.js 
                var myCustomer = new StripeCustomerCreateOptions();

                // assign token to a credit card option for a user
                myCustomer.Card = new StripeCreditCardOptions()
                {
                    TokenId = model.Token
                };

                myCustomer.Email = User.Identity.Name;
                myCustomer.Description = User.Identity.Name;
                myCustomer.PlanId = model.SubscriptionType.ToString();
                myCustomer.Quantity = 1;
                
                // create customer in stripe service
                var customerService = new StripeCustomerService();
                StripeCustomer stripeCustomer = customerService.Create(myCustomer);

                // get subscription Id from created user
                var subscriptionID = stripeCustomer.StripeSubscriptionList.StripeSubscriptions.FirstOrDefault().Id;              
                       
             // save credit card optional details 
                StripeCustomerService customerServic = new StripeCustomerService();
                stripeCustomer = customerService.Get(stripeCustomer.Id);
                var cardId = stripeCustomer.StripeDefaultCardId; // get card id
                var myCard = new StripeCardUpdateOptions();

                myCard.Name = model.CardHolderName;
                myCard.AddressLine1 = model.AddressLine1;
                myCard.AddressLine2 = model.AddressLine2;
                myCard.AddressCity = model.AddressCity;
                myCard.AddressZip = model.AddressPostcode;
                myCard.AddressCountry = model.AddressCountry;

                var cardService = new StripeCardService();
                StripeCard stripeCard = cardService.Update(stripeCustomer.Id, cardId, myCard);
            //........................
                
                // record customer in database
                var cust = getCustomer();
                if(cust == null) // new users
                {
                    // get values to create a new record in StripeCustomer table
                    StripeCustomers customer = new StripeCustomers();
                
                    customer.CustomerName = User.Identity.Name;
                    customer.StripeCustomerID = stripeCustomer.Id;
                    customer.StripeSubscriptionID = subscriptionID;
                    customer.SubscriptionType = model.SubscriptionType.ToString();
                    customer.HasSubscription = true;
                    customer.Interval = "Monthly";
                    customer.StartDate = TimeConverter.ConvertToLocalTime(DateTime.Now, "GMT Standard Time");
                    if (model.SubscriptionType.ToString() == "standard")
                    {
                        customer.TrialValidUntil = currentTime.AddDays(30);
                    }
                    db.StripeCustomers.Add(customer);
                    }
                    else // user with db records
                    {
                        StripeCustomers newRecord = new StripeCustomers();

                        // take the data from current user
                        newRecord.StripeCustomerID = stripeCustomer.Id;
                        newRecord.CustomerName = User.Identity.Name;
                        newRecord.StripeSubscriptionID = subscriptionID;
                        newRecord.SubscriptionType = model.SubscriptionType.ToString();
                        newRecord.HasSubscription = true;
                        newRecord.Interval = "Monthly";
                        newRecord.StartDate = currentTime;
                        if (model.SubscriptionType.ToString() == "standard")
                        {
                            newRecord.TrialValidUntil = currentTime.AddDays(30);
                        }
                        db.StripeCustomers.Add(newRecord);

                        // delete customer's old record in database
                        db.StripeCustomers.Remove(cust);
                    }
                db.SaveChanges();
            });
        }
Exemplo n.º 9
0
        CustomerPayment ISubscriptionService.SaveCustomer(string id, ApplicationModel.Billing.CustomerPayment payment)
        {
            //Save Subscription Need to check first active vs new here
            var organization = this.organizationRepository.Find(payment.OrganizationId, null, null);
            var customerService = new StripeCustomerService();
            if (id != null && id != "null")
            {
                var myCustomer = InitializeUpdateCustomerOptions(payment);
                StripeCustomer stripeCustomer = customerService.Update(id, myCustomer);
            }
            else
            {
                var myCustomer = InitializeCreateSubscriptionOptions(payment);
                StripeCustomer stripeCustomer = customerService.Create(myCustomer);
                id = stripeCustomer.StripeSubscription.CustomerId;
                payment.CustomerId = id;
            }

            organization.Subscription.Status = SubscriptionStatus.ACTIVE;
            organization.Subscription.CustomerBillingId = id;
            if (!String.IsNullOrEmpty(payment.CardNumber))
            {
                organization.Subscription.ExpirationDate = payment.CardExpirationMonth + "/" + payment.CardExpirationYear;
                organization.Subscription.Last4Digits = payment.CardNumber.Substring(payment.CardNumber.Length - 4, 4);
            }
            organization.Subscription.HasTrialed = true;

            var svc = (ISubscriptionService)this;
            svc.SaveSubscription(organization);
            return payment;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a new customer record in Stripe for the given user
        /// NOTE: Save changes on the underlying context for the model after calling this method
        /// </summary>
        /// <param name="user"></param>
        public static void CreateCustomer(IStripeUser user, string paymentToken = null)
        {
            // Do not overwrite the user, ever
            if (user.HasPaymentInfo())
                return;

            var newCustomer = new StripeCustomerCreateOptions();

            newCustomer.Email = user.Email;

            if (paymentToken != null)
                newCustomer.Card = new StripeCreditCardOptions() { TokenId = paymentToken };

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

            // Set the accounting info
            user.PaymentSystemId = stripeCustomer.Id;

            System.Diagnostics.Trace.TraceInformation("Created customer in stripe: '{0}' with id '{1}", user.Email, user.PaymentSystemId);
        }
Exemplo n.º 11
0
        public ActionResult AddNewCard(string stripeToken)
        {
            bool tokenUsed = false;

            User userObj = (User)Session["user"];
            if (userObj.PrimaryUser == false)
                return RedirectToAction("Index", "Admin");
            var stripeCustomerID = accountRepo.Accounts.FirstOrDefault(aid => aid.ID == userObj.AccountID).StripeCustomerID;

            if (stripeCustomerID == null)
            {
                // create subscription and get subscription id
                var customerService = new StripeCustomerService();
                customerService.ApiKey = "sk_test_4Xusc3Meo8gniONh6dDRZvlp";

                var currentAccountDetails = accountRepo.Accounts.FirstOrDefault(aid => aid.ID == userObj.AccountID);

                var customer = new StripeCustomerCreateOptions();
                customer.PlanId = "Empty Plan";
                customer.Quantity = 1;
                customer.TokenId = stripeToken;
                customer.Email = userObj.Email;

                // Create subscription
                var subscriptionDetails = customerService.Create(customer);
                stripeCustomerID = subscriptionDetails.Id;

                // save StripeCustomerID
                currentAccountDetails.StripeCustomerID = stripeCustomerID;
                accountRepo.SaveAccount(currentAccountDetails);

                tokenUsed = true;
            }
            else
            {
                var card = new StripeCardService();
                card.ApiKey = "sk_test_4Xusc3Meo8gniONh6dDRZvlp";

                var cardOpt = new StripeCardCreateOptions();
                cardOpt.TokenId = stripeToken;

                var res = card.Create(stripeCustomerID, cardOpt);
            }

            return RedirectToAction("BillingOptions", "Admin", new { id = 1 });
        }
Exemplo n.º 12
0
    private StripeCustomer GetCustomer()
    {
        var mycust = new StripeCustomerCreateOptions();
        mycust.Email = "*****@*****.**";
        mycust.Description = "Rahul Pandey([email protected])";
        mycust.CardNumber = "4242424242424242";
        mycust.CardExpirationMonth = "11";
        mycust.CardExpirationYear = "2018";
        // mycust.PlanId = "100";
        mycust.CardCvc = "123";
        mycust.CardName = "Rahul Pandey";
        mycust.CardAddressCity = "ABC";
        mycust.CardAddressCountry = "USA";
        mycust.CardAddressLine1 = "asbcd";
        //mycust.TrialEnd = getrialend();
        var customerservice = new StripeCustomerService("sk_test_fSK5PInUME0uPQnz7LatVoN0");

        return customerservice.Create(mycust);
    }
Exemplo n.º 13
0
        private StripeCustomer CreateStripeCustomer(string apiKey, tbl_Orders order, StripeCheckoutModel model)
        {
            var myCustomer = new StripeCustomerCreateOptions
            {
                Email = order.CustomerEMail,
                Description = order.BillingFullName,
                CardNumber = model.CreditCardNumber,
                CardExpirationYear = model.ExpiryYear.ToString(),
                CardExpirationMonth = model.ExpiryMonth.ToString()
            };

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

            return stripeCustomer;
        }
Exemplo n.º 14
0
        private CreateInvoiceReturn ChargeStripeCheckoutPayment()
        {
            // Create the Stripe Request and get the data back.
            CreateInvoiceReturn output = new CreateInvoiceReturn();

            var myCustomer = new StripeCustomerCreateOptions();
            if (invoice.InvoiceBilling != null)
            {
                myCustomer.CardAddressCity = invoice.InvoiceBilling.City;
                myCustomer.CardAddressCountry = invoice.InvoiceBilling.Country;
                myCustomer.CardAddressLine1 = invoice.InvoiceBilling.Street;
                myCustomer.CardAddressState = invoice.InvoiceBilling.State;
                myCustomer.CardAddressZip = invoice.InvoiceBilling.Zip;
                myCustomer.Email = invoice.InvoiceBilling.Email;
            }

            myCustomer.TokenId = invoice.StripeToken;

            var myCharge = new StripeChargeCreateOptions();

            var customerService = new StripeCustomerService();

            StripeCustomer stripeCustomer = customerService.Create(myCustomer);

            // always set these properties
            //need to convert to cents because thats what stripe uses.
            myCharge.AmountInCents = (int)(invoice.FinancialData.TotalIncludingTax * 100);
            myCharge.Currency = invoice.Currency.ToString();

            // set this if you want to
            myCharge.Description = invoice.Note;

            // set this property if using a token
            myCharge.CustomerId = stripeCustomer.Id;
            myCharge.Capture = true;

            var chargeService = new StripeChargeService();
            StripeCharge stripeCharge = chargeService.Create(myCharge);

            output.InvoiceId = invoice.InvoiceId;
            output.Status = InvoiceStatus.Stripe_Customer_Created_And_Charged;
            invoice.InvoiceStatus = InvoiceStatus.Stripe_Customer_Created_And_Charged;
            return output;
        }
Exemplo n.º 15
0
        private StripeCustomer PerformStripeSubscriptionCheckout(CreateInvoiceReturn invoiceReturn)
        {
            try
            {
                var myCustomer = new StripeCustomerCreateOptions();
                if (invoice.InvoiceBilling != null)
                {
                    myCustomer.CardAddressCity = invoice.InvoiceBilling.City;
                    myCustomer.CardAddressCountry = invoice.InvoiceBilling.Country;
                    myCustomer.CardAddressLine1 = invoice.InvoiceBilling.Street;
                    myCustomer.CardAddressState = invoice.InvoiceBilling.State;
                    myCustomer.CardAddressZip = invoice.InvoiceBilling.Zip;
                    myCustomer.Email = invoice.InvoiceBilling.Email;
                }
                if (invoice.Subscription != null)
                {
                    myCustomer.TokenId = invoice.Subscription.ArticleNumber;
                    if (invoice.Subscription.SubscriptionPeriodStripe == SubscriptionPeriodStripe.Monthly)
                    {
                        myCustomer.PlanId = StripePlanNames.Monthly_Plan.ToString();
                    }
                    else if (invoice.Subscription.SubscriptionPeriodStripe == SubscriptionPeriodStripe.Six_Months)
                    {
                        myCustomer.PlanId = StripePlanNames.Six_Month_League_Subscription.ToString();
                    }
                    else if (invoice.Subscription.SubscriptionPeriodStripe == SubscriptionPeriodStripe.Three_Months)
                    {
                        myCustomer.PlanId = StripePlanNames.Three_Month_League_Subscription.ToString();
                    }
                    else if (invoice.Subscription.SubscriptionPeriodStripe == SubscriptionPeriodStripe.Yearly)
                    {
                        myCustomer.PlanId = StripePlanNames.Yearly_League_Subscription.ToString();
                    }
                    else if (invoice.Subscription.SubscriptionPeriodStripe == SubscriptionPeriodStripe.Monthly_RN_Sponsor)
                    {
                        myCustomer.PlanId = StripePlanNames.Monthly_RN_Sponsor.ToString();
                    }
                }
                //creates the customer
                //adds the subscription
                //charges the customer.
                var customerService = new StripeCustomerService();
                StripeCustomer stripeCustomer = customerService.Create(myCustomer);
                invoice.PaymentProviderCustomerId = stripeCustomer.Id;

                return stripeCustomer;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
                if (exception.Message.Contains("Your card was declined"))
                    invoiceReturn.Status = InvoiceStatus.Card_Was_Declined;
            }
            return null;
        }
Exemplo n.º 16
0
        public ActionResult Charge(string stripeToken, int quantities,string couponID)
        {
            decimal additionalPrice = 0;
            // get selected plan
            User userObj = (User)Session["user"];
            var planID = accountRepo.Accounts.FirstOrDefault(aid => aid.ID == userObj.AccountID).PlanID;

            // get selected plan details
            var selectedPlanName = planRepository.Plans.FirstOrDefault(pid => pid.ID == planID);

            // create subscription and get subscription id
            var customerService = new StripeCustomerService();
            customerService.ApiKey = "sk_test_4Xusc3Meo8gniONh6dDRZvlp";

            var currentAccountDetails = accountRepo.Accounts.FirstOrDefault(aid => aid.ID == userObj.AccountID);

            var customer = new StripeCustomerCreateOptions();
            customer.PlanId = selectedPlanName.Name;
            customer.Quantity = quantities;
            customer.TokenId = stripeToken;
            customer.Email = userObj.Email;
            if (couponID != "")
            {
                customer.CouponId = couponID;
            }

            // Create subscription
            try
            {
                var subscriptionDetails = customerService.Create(customer);
                var stripeCustomerID = subscriptionDetails.Id;

                // save StripeCustomerID
                currentAccountDetails.StripeCustomerID = stripeCustomerID;
                accountRepo.SaveAccount(currentAccountDetails);
                Session["account"] = currentAccountDetails;
                return Json(1, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                Session["paymentFailureNotifications"] = "card_declined";
                return RedirectToAction("BillingOptions", "Admin", new { id = 1 });
            }

            //return RedirectToAction("BillingOptions", "Admin", new { id = 1 });
        }
Exemplo n.º 17
-1
        /// <summary>
        ///     Implements <see cref="IStripeService.CreateCustomer"/>
        /// </summary>
        public string CreateCustomer(User user)
        {
            var myCustomer = new StripeCustomerCreateOptions
            {
                Email = user.Email,
                Description = $"{user.FirstName} {user.LastName} ({user.Email})"
            };

            var customerService = new StripeCustomerService();

            try
            {
                StripeCustomer customer = customerService.Create(myCustomer);
                return customer.Id;
            }
            catch (StripeException ex)
            {
                string exceptionMessage;
                StripeExceptionType type;

                if (ex.HttpStatusCode >= HttpStatusCode.InternalServerError
                    || (int)ex.HttpStatusCode == 429 /* Too Many Requests */
                    || (int)ex.HttpStatusCode == 402 /* Request Failed */)
                {
                    type = StripeExceptionType.ServiceError;
                    exceptionMessage = 
                        "An error occured while creating a customer account for you. Please try again later.";
                }
                else if (ex.HttpStatusCode == HttpStatusCode.Unauthorized)
                {
                    // Note: We want to log this as it means we don't have a valid API key
                    Debug.WriteLine("Stripe API Key is Invalid");
                    Debug.WriteLine(ex.Message);

                    type = StripeExceptionType.ApiKeyError;
                    exceptionMessage = "An error occured while talking to one of our backends. Sorry!";
                }
                else
                {
                    // Note: Log unknown errors
                    Debug.WriteLine(ex.HttpStatusCode);
                    Debug.WriteLine($"Stripe Type: {ex.StripeError.ErrorType}");
                    Debug.WriteLine($"Stripe Message: {ex.StripeError.Message}");
                    Debug.WriteLine($"Stripe Code: {ex.StripeError.Code}");
                    Debug.WriteLine($"Stripe Param: {ex.StripeError.Parameter}");

                    type = StripeExceptionType.UnknownError;
                    exceptionMessage = 
                        "An unknown error occured while creating a customer account for you. Please try again later.";
                }

                throw new StripeServiceException(exceptionMessage, type, ex);
            }
        }