public async Task <CreateCheckoutSessionResponseDto> CreateAsync(string stripeCustomerId, string auth0UserId, string priceId, string taxId) { var checkoutSessionResponseDto = new CreateCheckoutSessionResponseDto() { SessionId = Guid.NewGuid().ToString(), }; CheckoutSessionResponses.Add(checkoutSessionResponseDto); return(checkoutSessionResponseDto); }
public async Task <IActionResult> CreateCheckoutSession([FromBody] CreateCheckoutSessionRequestDto req) { var user = await _userManagementService.GetAuth0UserAsync(_jwtToken.UserId); string stripeCustomerId; if (String.IsNullOrEmpty(user.AppMetadata?.StripeCustomerId)) { var newCustomer = new CreateCustomerDto(_jwtToken.UserId, user.Name, user.Email); var customer = await _stripePaymentService.CreateCustomerAsync(newCustomer); stripeCustomerId = customer.Id; } else { var retrievedCustomer = await _stripePaymentService.GetCustomerAsync(user.AppMetadata.StripeCustomerId); if (retrievedCustomer.Subscription == null) { stripeCustomerId = user.AppMetadata.StripeCustomerId; } else { return(BadRequest(new ErrorResponseDto { ErrorMessage = new ErrorMessageDto { Message = "This user already has a subscription.", } })); } } try { CreateCheckoutSessionResponseDto checkoutSessionResponse = await _stripePaymentService.CreateCheckoutSessionAsync(stripeCustomerId, _jwtToken.UserId, req.PriceTier); return(Ok(checkoutSessionResponse)); } catch (StripeException e) { Console.WriteLine(e.StripeError.Message); return(BadRequest(new ErrorResponseDto { ErrorMessage = new ErrorMessageDto { Message = e.StripeError.Message, } })); } }