{"record":{"id":"cd9c2be9a379c012","repo":"payloadcms/payload","slug":"failed-to-create-new-syncconfig-striperesourcet","errorCode":null,"errorMessage":"Failed to create new '${syncConfig.stripeResourceType}' resource in Stripe: ${msg}","messagePattern":"Failed to create new '(.+?)' resource in Stripe: (.+?)","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/plugin-stripe/src/hooks/createNewInStripe.ts","lineNumber":133,"sourceCode":"            // NOTE: Typed as \"any\" because the \"create\" method is not standard across all Stripe resources\n            const stripeResource = await stripe?.[syncConfig.stripeResourceType]?.create(\n              // @ts-expect-error\n              syncedFields,\n            )\n\n            if (logs) {\n              payload.logger.info(\n                `✅ Successfully created new '${syncConfig.stripeResourceType}' resource in Stripe with ID: '${stripeResource.id}'.`,\n              )\n            }\n\n            dataRef.stripeID = stripeResource.id\n\n            // IMPORTANT: this is to prevent sync in the \"afterChange\" hook\n            dataRef.skipSync = true\n          } catch (error: unknown) {\n            const msg = error instanceof Error ? error.message : error\n            throw new APIError(\n              `Failed to create new '${syncConfig.stripeResourceType}' resource in Stripe: ${msg}`,\n            )\n          }\n        }\n      }\n    }\n  }\n\n  return dataRef\n}\n","sourceCodeStart":115,"sourceCodeEnd":144,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/plugin-stripe/src/hooks/createNewInStripe.ts#L115-L144","documentation":"Thrown by the Stripe plugin's `createNewInStripe` before-validate hook during a Payload `create` operation when `stripe.[stripeResourceType].create(syncedFields)` rejects. The original Stripe SDK error message is interpolated into the APIError, so the cause (invalid params, auth, rate limit) is preserved.","triggerScenarios":"Creating a Payload document in a Stripe-synced collection whose `syncedFields` are rejected by Stripe (missing required field, invalid email, duplicate customer); `stripeSecretKey` is missing/wrong so the SDK throws an auth error; `stripeResourceType` does not have a `.create` method.","commonSituations":"`stripeSecretKey` not set in the plugin config or set to a test key in production; field mapping in `syncConfig.fields` produces an invalid Stripe object; Stripe API version drift between the SDK pin (`2022-08-01`) and required params; rate limiting from bulk imports.","solutions":["Read the `${msg}` suffix — it is the Stripe SDK error (e.g. 'No such customer', 'Invalid API key')","Verify `stripeSecretKey` in the plugin config matches the environment (test vs live)","Check the `syncConfig.fields` mapping produces a valid object for the `stripeResourceType.create` signature","Confirm `stripeResourceType` is a real Stripe resource that supports `.create` (e.g. `customers`, `products`, not `balance`)"],"exampleFix":"// before — wrong/missing secret key\nstripePlugin({ stripeSecretKey: process.env.STRIPE_KEY /* undefined */ })\n// after\nstripePlugin({ stripeSecretKey: process.env.STRIPE_SECRET_KEY! })","handlingStrategy":"try-catch","validationCode":"// Sanity-check the secret key and resource type at boot\nif (!process.env.STRIPE_SECRET_KEY) throw new Error('STRIPE_SECRET_KEY missing')\nif (typeof (stripe as any)[syncConfig.stripeResourceType]?.create !== 'function')\n  throw new Error(`${syncConfig.stripeResourceType} has no .create method`)","typeGuard":"import { APIError } from 'payload'\nfunction isStripeCreateError(e: unknown): e is APIError {\n  return e instanceof APIError && /^Failed to create new '.*' resource in Stripe:/.test(e.message)\n}","tryCatchPattern":"import { APIError } from 'payload'\ntry {\n  await payload.create({ collection: 'users', data })\n} catch (e) {\n  if (e instanceof APIError && /Failed to create new .* resource in Stripe/.test(e.message)) {\n    // e.message suffix is the Stripe SDK error; route to retry / user-facing message\n  }\n  throw e\n}","preventionTips":["Validate `stripeSecretKey` is set and matches the target environment (test vs live) at startup","Ensure every `sync[].stripeResourceType` is a real Stripe resource supporting `.create`","Add a dry-run integration test that creates a sample resource in Stripe test mode"],"tags":["stripe","webhook","sync","create","configuration"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}