{"record":{"id":"198bd310443e68cc","repo":"payloadcms/payload","slug":"failed-to-delete-stripe-document-with-id-doc-s","errorCode":null,"errorMessage":"Failed to delete Stripe document with ID: '${doc.stripeID}': ${msg}","messagePattern":"Failed to delete Stripe document with ID: '(.+?)': (.+?)","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/plugin-stripe/src/hooks/deleteFromStripe.ts","lineNumber":63,"sourceCode":"        const found = await stripe?.[syncConfig.stripeResourceType]?.retrieve(doc.stripeID)\n\n        if (found) {\n          await stripe?.[syncConfig.stripeResourceType]?.del(doc.stripeID)\n          if (logs) {\n            payload.logger.info(\n              `✅ Successfully deleted Stripe document with ID: '${doc.stripeID}'.`,\n            )\n          }\n        } else {\n          if (logs) {\n            payload.logger.info(\n              `- Stripe document with ID: '${doc.stripeID}' not found, skipping...`,\n            )\n          }\n        }\n      } catch (error: unknown) {\n        const msg = error instanceof Error ? error.message : error\n        throw new APIError(`Failed to delete Stripe document with ID: '${doc.stripeID}': ${msg}`)\n      }\n    }\n  }\n}\n","sourceCodeStart":45,"sourceCodeEnd":68,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/plugin-stripe/src/hooks/deleteFromStripe.ts#L45-L68","documentation":"Thrown by the Stripe plugin's `deleteFromStripe` after-delete hook when either `stripe.[stripeResourceType].retrieve(stripeID)` or `.del(stripeID)` rejects. The original Stripe SDK error message is appended so the cause is visible. Note: a missing Stripe resource is NOT an error — the hook logs and skips — this throw is for genuine failures (auth, network, invalid ID format).","triggerScenarios":"Deleting a Payload document whose `stripeID` points to a resource Stripe refuses to delete (e.g. a customer with an active subscription); `stripeSecretKey` invalid; `stripeResourceType` does not support `.retrieve`/`.del`; network failure mid-call.","commonSituations":"`stripeSecretKey` rotated but plugin config not updated; deleting a Stripe customer that still has subscriptions/invoices (Stripe rejects); `stripeResourceType` misconfigured to a non-deletable resource; stale `stripeID` left over from a deleted Stripe resource that the retrieve call cannot reach due to permissions.","solutions":["Read the `${msg}` suffix — it names the Stripe error (e.g. 'Cannot delete customer with active subscription')","Resolve the upstream Stripe constraint (close subscriptions, etc.) before deleting the Payload doc","Verify `stripeSecretKey` is valid for the account that owns the resource","Confirm `stripeResourceType` supports `.retrieve` and `.del`"],"exampleFix":"// before — customer still has subscription, Stripe rejects delete\nawait payload.delete({ collection: 'users', id })\n// after — cancel subscriptions first\nawait stripe.subscriptions.cancel(sub.id)\nawait payload.delete({ collection: 'users', id })","handlingStrategy":"try-catch","validationCode":"// Before deleting, confirm the Stripe resource can be deleted (e.g. customer has no subs)\nif (stripeResourceType === 'customers') {\n  const subs = await stripe.customers.listSubscriptions(stripeID)\n  if (subs.data.length) throw new Error('customer has active subscriptions — cancel first')\n}","typeGuard":"import { APIError } from 'payload'\nfunction isStripeDeleteError(e: unknown): e is APIError {\n  return e instanceof APIError && /^Failed to delete Stripe document with ID:/.test(e.message)\n}","tryCatchPattern":"import { APIError } from 'payload'\ntry {\n  await payload.delete({ collection: 'users', id })\n} catch (e) {\n  if (e instanceof APIError && /Failed to delete Stripe document/.test(e.message)) {\n    // suffix holds the Stripe reason; resolve the upstream constraint (cancel subs, etc.)\n  }\n  throw e\n}","preventionTips":["Keep `stripeSecretKey` in sync across environments","Ensure `stripeResourceType` supports `.retrieve` and `.del`","Resolve Stripe-side constraints (active subscriptions, unpaid invoices) before deleting the Payload doc"],"tags":["stripe","delete","sync","configuration"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}