public async Task <Customer> GetByEmail(string email) { try { #region GetCustomersList var CustomerOptions = new CustomerListOptions { Limit = 50, Email = email, //RnD about extra parameters //Created = DateTime.Now, //StartingAfter = DateTime.Now.ToString(), //EndingBefore = DateTime.Now.ToString(), }; var customerService = new CustomerService(); StripeList <Customer> stripeCustomersList = customerService.List(CustomerOptions); #endregion Customer stripeCustomer = new Customer(); if (stripeCustomersList.Any(x => x.Email.Equals(email))) { stripeCustomer = stripeCustomersList.FirstOrDefault(x => x.Email.Equals(email)); } return(stripeCustomer); } catch (StripeException e) { string errorMessage = ""; switch (e.StripeError.Error) { case "card_error": errorMessage = $"Card Error occurred on {e.StripeError.PaymentIntent.Id}, Error: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}"; break; case "api_error": errorMessage = $"API Error occurred: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}"; break; case "api_connection_error": errorMessage = $"API Connection Error occurred: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}"; break; case "invalid_request_error ": errorMessage = $"Invalid request Error occurred: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}"; break; default: errorMessage = $"Some Error occurred: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}"; break; } throw new InvalidOperationException(errorMessage); } }
public async Task <IActionResult> CreateCustomer(CreateCustomerCommand command) { Customer customer = new Customer(); #region GetCustomersList var CustomerOptions = new CustomerListOptions { Limit = 50, Email = command.Email }; var customerService = new CustomerService(); StripeList <Customer> customersList = customerService.List( CustomerOptions ); #endregion if (customersList.Any(x => x.Email.Equals(command.Email))) { var temp = customersList.FirstOrDefault(x => x.Email.Equals(command.Email)); customer.Id = temp.Id; } else { customer = customerService.Create(new CustomerCreateOptions { Email = command.Email }); } //CustomerId = customer.Id; //Fix the issue, till then return null return(null); //return Ok(new CreateCustomerCommandResult() { Payload = customer.Id }); }