{"record":{"id":"52460afa4e0d824e","repo":"bitwarden/server","slug":"provider-plan-not-found","errorCode":null,"errorMessage":"Provider plan not found.","messagePattern":"Provider plan not found\\.","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"bitwarden_license/src/Commercial.Core/Billing/Providers/Services/ProviderBillingService.cs","lineNumber":175,"sourceCode":"                    Currency = \"USD\",\n                    Description = $\"Unused, prorated time for client organization with ID {organization.Id}.\"\n                });\n        }\n\n        await eventService.LogProviderOrganizationEventAsync(\n            providerOrganization,\n            EventType.ProviderOrganization_Added);\n    }\n\n    public async Task ChangePlan(ChangeProviderPlanCommand command)\n    {\n        var (provider, providerPlanId, newPlanType) = command;\n\n        var providerPlan = await providerPlanRepository.GetByIdAsync(providerPlanId);\n\n        if (providerPlan == null)\n        {\n            throw new BadRequestException(\"Provider plan not found.\");\n        }\n\n        if (providerPlan.PlanType == newPlanType)\n        {\n            return;\n        }\n\n        var subscription = await subscriberService.GetSubscriptionOrThrow(provider);\n\n        var oldPriceId = ProviderPriceAdapter.GetPriceId(provider, subscription, providerPlan.PlanType);\n        var newPriceId = ProviderPriceAdapter.GetPriceId(provider, subscription, newPlanType);\n\n        providerPlan.PlanType = newPlanType;\n        await providerPlanRepository.ReplaceAsync(providerPlan);\n\n        var oldSubscriptionItem = subscription.Items.SingleOrDefault(x => x.Price.Id == oldPriceId);\n\n        var updateOptions = new SubscriptionUpdateOptions","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/bitwarden/server/blob/e93b962371d80964556f5590c6615f5160a437a1/bitwarden_license/src/Commercial.Core/Billing/Providers/Services/ProviderBillingService.cs#L157-L193","documentation":"Thrown by ProviderBillingService.ChangePlan when providerPlanRepository.GetByIdAsync(providerPlanId) returns null. The referenced provider plan does not exist (deleted, wrong ID, or not yet created). BadRequestException (HTTP 400).","triggerScenarios":"Calling ChangePlan with a providerPlanId that does not match any ProviderPlan row; passing a provider's ID where a plan ID is expected; referencing a plan from a different provider.","commonSituations":"Stale plan ID cached in the UI; a provider whose plans were reset/recreated; client confusion between providerId and providerPlanId; an ID copied from another environment.","solutions":["Look up the provider's current plans and use the live providerPlanId before calling ChangePlan.","Verify providerPlan.ProviderId matches the intended provider.","If no plan exists, create the provider plan first."],"exampleFix":"// before\nawait providerBillingService.ChangePlan(new ChangeProviderPlanCommand(provider, planIdGuess, newType));\n\n// after\nvar plan = await providerPlanRepository.GetByProviderAsync(provider.Id)\n    .FirstOrDefault(p => p.PlanType == currentType);\nif (plan == null) return NotFound(\"Provider plan not found.\");\nawait providerBillingService.ChangePlan(new ChangeProviderPlanCommand(provider, plan.Id, newType));","handlingStrategy":"validation","validationCode":"var plan = await providerPlanRepository.GetByIdAsync(providerPlanId);\nif (plan == null) return NotFound(\"Provider plan not found.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Look up the live providerPlanId for the provider before calling ChangePlan.","Distinguish providerId from providerPlanId in payloads."],"tags":["billing","provider","plan","lookup","bad-request"],"backgroundTag":null,"analyzedSha":"e93b962371d80964556f5590c6615f5160a437a1","analyzedAt":"2026-08-13T14:22:19.382Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}