{"record":{"id":"284a409fe3551b5f","repo":"medusajs/medusa","slug":"invalid-data-284a40","errorCode":"invalid_data","errorMessage":"Gift card does not have a store credit account","messagePattern":"Gift card does not have a store credit account","errorType":"validation","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/plugins/loyalty/src/workflows/gift-cards/workflows/claim-gift-card.ts","lineNumber":57,"sourceCode":" *   },\n *   customer: {\n *     has_account: true,\n *     // other customer properties...\n *   },\n * })\n */\nexport const validateClaimGiftCardInputStep = createStep(\n  \"validate-claim-gift-card-input\",\n  async function (args: {\n    giftCard: ModuleGiftCard & {\n      store_credit_account: { id: string; code: string }\n    }\n    customer: CustomerDTO\n  }) {\n    const { giftCard, customer } = args\n\n    if (!giftCard.store_credit_account?.id) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        \"Gift card does not have a store credit account\"\n      )\n    }\n\n    if (!giftCard.store_credit_account.code) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        \"Gift card does not have a store credit account code\"\n      )\n    }\n\n    if (!customer.has_account) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        \"Only customers with an account can claim a gift card\"\n      )\n    }","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/plugins/loyalty/src/workflows/gift-cards/workflows/claim-gift-card.ts#L39-L75","documentation":"Validation in claim-gift-card workflow's transform: the gift card exists but its store_credit_account is missing or has no id. Claiming converts the gift card's value into a store credit account, so an account must already be linked to the card.","triggerScenarios":"Calling claim-gift-card workflow for a gift card that was created without an associated store credit account, or when the query config forgot to select the store_credit_account relation so it resolves to undefined.","commonSituations":"Gift cards created via direct module inserts or seed scripts that skip account creation; querying with fields that omit 'store_credit_account.*'; cards created before a plugin version that auto-created accounts.","solutions":["Ensure the gift card query includes store_credit_account.id in fields","Create/attach a store credit account for the gift card (redeem or the account-creation flow) before claiming","Upgrade the loyalty plugin so newly created gift cards always get a store credit account"],"exampleFix":"// before\nfields: [\"id\", \"code\"]\n// after\nfields: [\"id\", \"code\", \"store_credit_account.id\", \"store_credit_account.code\"]","handlingStrategy":"validation","validationCode":"const { data } = await query.graph({ entity: \"gift_card\", filters: { id }, fields: [\"id\", \"store_credit_account.id\", \"store_credit_account.code\"] })\nif (!data[0]?.store_credit_account?.id) throw new Error(\"Gift card has no store credit account\")","typeGuard":"const hasStoreCreditAccount = (gc: any): gc is { store_credit_account: { id: string; code: string } } =>\n  !!gc?.store_credit_account?.id","tryCatchPattern":null,"preventionTips":["Always include store_credit_account.* in gift card query fields","Create accounts at gift card creation time via plugin hooks"],"tags":["medusa","loyalty","gift-card","store-credit","validation"],"backgroundTag":"missing-related-entity","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}