{"record":{"id":"cc8404001c2aa97c","repo":"calcom/cal.diy","slug":"paymentcreationfailure-cc8404","errorCode":"PaymentCreationFailure","errorMessage":"payment_not_created_error","messagePattern":"payment_not_created_error","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/app-store/btcpayserver/lib/PaymentService.ts","lineNumber":150,"sourceCode":"        fee: 0,\r\n        success: false,\r\n        refunded: false,\r\n        data: Object.assign(\r\n          {},\r\n          {\r\n            invoice: {\r\n              ...invoiceResponse,\r\n              isPaid: false,\r\n              attendee: { name: bookerName, email: bookerEmail },\r\n            },\r\n          }\r\n        ),\r\n      });\r\n      if (!paymentData) throw new Error(\"Failed to store Payment data\");\r\n      return paymentData;\r\n    } catch (error) {\r\n      log.error(\"BTCPay server: Payment could not be created\", bookingId, safeStringify(error));\r\n      throw new Error(ErrorCode.PaymentCreationFailure);\r\n    }\r\n  }\r\n\r\n  async update(): Promise<Payment> {\r\n    throw new Error(\"Method not implemented.\");\r\n  }\r\n  async refund(): Promise<Payment> {\r\n    throw new Error(\"BTCPay Server does not support automatic refunds for Bitcoin payments\");\r\n  }\r\n\r\n  async collectCard(\r\n    _payment: Pick<Prisma.PaymentUncheckedCreateInput, \"amount\" | \"currency\">,\r\n    _bookingId: number,\r\n    _bookerEmail: string,\r\n    _paymentOption: PaymentOption\r\n  ): Promise<Payment> {\r\n    throw new Error(\"Method not implemented\");\r\n  }\r","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/packages/app-store/btcpayserver/lib/PaymentService.ts#L132-L168","documentation":"Generic catch-all in `PaymentService.create()`: any error during invoice creation/persistence is logged via `log.error(... safeStringify(error))` and re-thrown as `new Error(ErrorCode.PaymentCreationFailure)` whose value is the string `\"payment_not_created_error\"`. The original cause is only in logs, not in the thrown error. `getServerErrorFromUnknown` maps this ErrorCode to a 500-class response.","triggerScenarios":"BTCPay invoice creation API call fails (network, auth, validation), the subsequent `bookingPaymentRepository`/payment-store write returns falsy (`!paymentData` triggers `\"Failed to store Payment data\"` caught here), a Zod schema parse fails on the invoice response, or any exception inside the try block.","commonSituations":"BTCPay Server unreachable during checkout; malformed invoice response after a BTCPay upgrade; DB write failure; expired/invalid BTCPay API key used by the payment service; the explicit `if (!paymentData) throw new Error(\"Failed to store Payment data\")` being the inner cause.","solutions":["Read the server logs for the `log.error(\"BTCPay server: Payment could not be created\", bookingId, ...)` line — the original error is there.","Confirm the BTCPay server URL, store id, and API key in the credential are valid and reachable.","If the inner cause is `\"Failed to store Payment data\"`, inspect the `createPayment`/repository call and the data passed to it.","Preserve the cause via `throw new Error(ErrorCode.PaymentCreationFailure, { cause: error })` so callers can diagnose without logs."],"exampleFix":"// before\n} catch (error) {\n  log.error(\"BTCPay server: Payment could not be created\", bookingId, safeStringify(error));\n  throw new Error(ErrorCode.PaymentCreationFailure);\n}\n\n// after\n} catch (error) {\n  log.error(\"BTCPay server: Payment could not be created\", bookingId, safeStringify(error));\n  throw new Error(ErrorCode.PaymentCreationFailure, { cause: error });\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isPaymentCreationFailure(e: unknown): boolean {\n  return e instanceof Error && e.message === \"payment_not_created_error\";\n}","tryCatchPattern":"try {\n  await paymentService.create();\n} catch (e) {\n  if (e instanceof Error && e.message === ErrorCode.PaymentCreationFailure) {\n    // surface a checkout-retryable error to the user; log full cause\n  }\n  throw e;\n}","preventionTips":["Preserve the cause with `new Error(code, { cause })` for diagnosis.","Validate the BTCPay credential (server URL, store id, API key) before invoking create().","Run payment creation idempotently so retries don't double-charge.","Test invoice creation against a BTCPay sandbox during CI."],"tags":["payment","error-handling","btcpay","checkout","swallowed-error"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}