{"record":{"id":"d447b9b89a0df856","repo":"calcom/cal.diy","slug":"failed-to-create-a-customer-on-stripe","errorCode":null,"errorMessage":"Failed to create a customer on Stripe.","messagePattern":"Failed to create a customer on Stripe\\.","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apps/api/v2/src/modules/stripe/stripe.service.ts","lineNumber":176,"sourceCode":"\n    const stripeAccount = await stripeInstance.accounts.retrieve(stripeKeyObject?.stripe_user_id);\n\n    // both of these should be true for an account to be fully active\n    if (!stripeAccount.payouts_enabled || !stripeAccount.charges_enabled) {\n      throw new BadRequestException(\"Stripe account is not an active account\");\n    }\n\n    return {\n      status: SUCCESS_STATUS,\n    };\n  }\n\n  async generateTeamCheckoutSession(pendingPaymentTeamId: number, ownerId: number) {\n    const stripe = this.getStripe();\n    const customer = await this.getStripeCustomerIdFromUserId(ownerId);\n\n    if (!customer) {\n      throw new BadRequestException(\"Failed to create a customer on Stripe.\");\n    }\n\n    const session = await stripe.checkout.sessions.create({\n      customer,\n      mode: \"subscription\",\n      allow_promotion_codes: true,\n      success_url: `${this.webAppUrl}/api/teams/api/create?session_id={CHECKOUT_SESSION_ID}`,\n      cancel_url: `${this.webAppUrl}/settings/my-account/profile`,\n      line_items: [\n        {\n          /** We only need to set the base price and we can upsell it directly on Stripe's checkout  */\n          price: this.teamMonthlyPriceId,\n          /**Initially it will be just the team owner */\n          quantity: 1,\n        },\n      ],\n      customer_update: {\n        address: \"auto\",","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/modules/stripe/stripe.service.ts#L158-L194","documentation":"Thrown by StripeService.generateTeamCheckoutSession when getStripeCustomerIdFromUserId returns null for the team owner. That helper returns null if the user has no email or if no Stripe customer id can be obtained; the session cannot be created without a customer, so the request is rejected as 400 BadRequest.","triggerScenarios":"Initiating a team checkout (e.g. upgrading/creating a team) for an owner whose user record has no email, or for whom Stripe customer creation/lookup failed upstream, so getStripeCustomerIdFromUserId resolves to null.","commonSituations":"The owner's account has no verified email. Stripe customer creation failed earlier due to bad keys or a network error and the null propagated. The user was created via an SSO/invite flow that left email blank. Stripe is misconfigured in this environment.","solutions":["Ensure the team owner has a valid email on their user profile before starting checkout.","Verify Stripe keys are configured and reachable so customer creation succeeds.","Retry checkout; if it persists, inspect server logs for the upstream customer-creation failure."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"async function ensureOwnerReadyForCheckout(api, ownerId: number) {\n  const user = await api.getUser(ownerId);\n  if (!user?.email) throw new Error('Team owner needs a verified email before checkout');\n}","typeGuard":"function ownerHasEmail(user: { email?: string | null } | null): boolean {\n  return !!user?.email;\n}","tryCatchPattern":"try {\n  const { url } = await api.generateTeamCheckoutSession(teamId, ownerId);\n  window.location.href = url;\n} catch (e) {\n  if (e.status === 400 && /Failed to create a customer/.test(e.message)) {\n    surfaceToUser('We could not start checkout. Confirm your email and try again.');\n  } else throw e;\n}","preventionTips":["Ensure the team owner has a valid email on their profile before enabling checkout.","Verify Stripe keys are configured and Stripe is reachable so customer creation succeeds.","Log the underlying customer-creation failure server-side to distinguish no-email vs Stripe error."],"tags":["stripe","customer","teams","api-v2","checkout"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}