{"record":{"id":"0d11acd49a589db2","repo":"calcom/cal.diy","slug":"payment-not-found","errorCode":null,"errorMessage":"Payment not found","messagePattern":"Payment not found","errorType":"http","errorClass":"HttpCode","httpStatus":204,"severity":"warning","filePath":"packages/app-store/alby/api/webhook.ts","lineNumber":74,"sourceCode":"        amount: true,\n        bookingId: true,\n        booking: {\n          select: {\n            user: {\n              select: {\n                credentials: {\n                  where: {\n                    type: \"alby_payment\",\n                  },\n                },\n              },\n            },\n          },\n        },\n      },\n    });\n\n    if (!payment) throw new HttpCode({ statusCode: 204, message: \"Payment not found\" });\n    const key = payment.booking?.user?.credentials?.[0].key;\n    if (!key) throw new HttpCode({ statusCode: 204, message: \"Credentials not found\" });\n\n    const parseCredentials = albyCredentialKeysSchema.safeParse(key);\n    if (!parseCredentials.success) {\n      console.error(parseCredentials.error);\n      throw new HttpCode({ statusCode: 500, message: \"Credentials not valid\" });\n    }\n\n    const credentials = parseCredentials.data;\n\n    const albyInvoice = await parseInvoice(bodyAsString, parsedHeaders, credentials.webhook_endpoint_secret);\n    if (!albyInvoice) throw new HttpCode({ statusCode: 204, message: \"Invoice not found\" });\n    if (albyInvoice.amount !== payment.amount) {\n      throw new HttpCode({ statusCode: 400, message: \"invoice amount does not match payment amount\" });\n    }\n\n    const traceContext = distributedTracing.createTrace(\"alby_webhook\", {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/packages/app-store/alby/api/webhook.ts#L56-L92","documentation":"Thrown when no Payment row matches uid === parsedPayload.metadata.payer_data.referenceId. The reference id embedded in the invoice's payer data does not correspond to any payment recorded by this cal.com instance. Returns HTTP 204 so Svix does not keep retrying.","triggerScenarios":"Webhook delivered before prisma.payment.create committed; payment belongs to a different DB/instance sharing the secret; referenceId tampered; payment row was deleted.","commonSituations":"Race between invoice creation and webhook delivery; multi-instance deployment with separate DBs; DB restore where payment rows were lost.","solutions":["Look up the payment table for the given referenceId (uid) to confirm it exists.","Ensure invoice creation (prisma.payment.create) is committed before the webhook can arrive, or rely on Svix redelivery.","Confirm a single DB instance owns this webhook secret to avoid cross-instance lookups."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const payment = await prisma.payment.findFirst({\n  where: { uid: parsedPayload.metadata.payer_data.referenceId },\n});\nif (!payment) {\n  // return 204; rely on Svix redelivery after create commits\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Commit prisma.payment.create before the invoice can be paid/webhook fired.","Keep one DB instance owning a given webhook secret.","Tolerate eventual-consistency: return 204 so Svix redelivers."],"tags":["alby","webhook","payment","race-condition"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}