{"record":{"id":"a88ed3a41f6bfdb4","repo":"nopSolutions/nopCommerce","slug":"anonymous-checkout-is-not-allowed","errorCode":null,"errorMessage":"Anonymous checkout is not allowed","messagePattern":"Anonymous checkout is not allowed","errorType":"validation","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/Orders/OrderProcessingService.cs","lineNumber":573,"sourceCode":"\r\n    /// <summary>\r\n    /// Prepare and validate customer\r\n    /// </summary>\r\n    /// <param name=\"details\">PlaceOrder container</param>\r\n    /// <param name=\"processPaymentRequest\">payment info holder</param>\r\n    /// <param name=\"currentCurrency\">The working currency</param>\r\n    /// <returns>A task that represents the asynchronous operation</returns>\r\n    /// <exception cref=\"NopException\">Validation problems</exception>\r\n    protected virtual async Task PrepareAndValidateCustomerAsync(PlaceOrderContainer details, ProcessPaymentRequest processPaymentRequest, Currency currentCurrency)\r\n    {\r\n        details.Customer = await _customerService.GetCustomerByIdAsync(processPaymentRequest.CustomerId);\r\n\r\n        if (details.Customer == null)\r\n            throw new ArgumentException(\"Customer is not set\");\r\n\r\n        //check whether customer is guest\r\n        if (await _customerService.IsGuestAsync(details.Customer) && !_orderSettings.AnonymousCheckoutAllowed)\r\n            throw new NopException(\"Anonymous checkout is not allowed\");\r\n\r\n        //customer currency\r\n        var currencyTmp = await _currencyService.GetCurrencyByIdAsync(details.Customer.CurrencyId ?? 0);\r\n        var customerCurrency = currencyTmp != null && currencyTmp.Published && await _storeMappingService.AuthorizeAsync(currencyTmp) ? currencyTmp : currentCurrency;\r\n        var primaryStoreCurrency = await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId);\r\n        details.CustomerCurrencyCode = customerCurrency.CurrencyCode;\r\n        details.CustomerCurrencyRate = customerCurrency.Rate / primaryStoreCurrency.Rate;\r\n\r\n        //customer language\r\n        details.CustomerLanguage = await _languageService.GetLanguageByIdAsync(details.Customer.LanguageId ?? 0);\r\n        if (details.CustomerLanguage == null || !details.CustomerLanguage.Published || !await _storeMappingService.AuthorizeAsync(details.CustomerLanguage))\r\n            details.CustomerLanguage = await _workContext.GetWorkingLanguageAsync();\r\n    }\r\n\r\n    /// <summary>\r\n    /// Prepare details to place order based on the recurring payment.\r\n    /// </summary>\r\n    /// <param name=\"processPaymentRequest\">Process payment request</param>\r","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Orders/OrderProcessingService.cs#L555-L591","documentation":"Thrown by PrepareAndValidateCustomerAsync during the standard PlaceOrder flow when the customer is a guest (IsGuestAsync returns true) and _orderSettings.AnonymousCheckoutAllowed is false. This enforces the store's policy on whether guest (non-registered) customers can complete purchases. If disabled, customers must register and log in before placing an order.","triggerScenarios":"A guest user (not logged in) attempts to check out while the 'Anonymous checkout allowed' setting is disabled in Order settings. The setting was changed from true to false after guest customers added items to their carts. A customer's session lost authentication and they reverted to guest status mid-checkout.","commonSituations":"B2B stores that require account registration. Admin disabled anonymous checkout to improve order tracking or comply with regulations. Session timeout caused an authenticated customer's session to expire, reverting them to guest status. A custom integration passing a guest CustomerId to PlaceOrder.","solutions":["Enable anonymous checkout in admin: Configuration > Settings > Order settings > 'Anonymous checkout allowed'.","Require the customer to register/log in before reaching the payment step.","Extend session timeout or implement a 'keep alive' to prevent mid-checkout authentication loss.","In custom integrations, ensure the ProcessPaymentRequest.CustomerId refers to a registered (non-guest) customer."],"exampleFix":"// before (admin): orderSettings.AnonymousCheckoutAllowed = false\n// after: orderSettings.AnonymousCheckoutAllowed = true;\nawait _settingService.SaveSettingAsync(orderSettings, x => x.AnonymousCheckoutAllowed);","handlingStrategy":"validation","validationCode":"// Before PlaceOrder, check guest + anonymous checkout policy\nvar customer = await _customerService.GetCustomerByIdAsync(processPaymentRequest.CustomerId);\nif (await _customerService.IsGuestAsync(customer) && !_orderSettings.AnonymousCheckoutAllowed)\n{\n    _notificationService.ErrorNotification(\"Please register or log in to complete your order.\");\n    return RedirectToRoute(\"Login\");\n}","typeGuard":"async Task<bool> CanCheckoutAsync(ICustomerService svc, Customer c, bool anonAllowed) =>\n    !await svc.IsGuestAsync(c) || anonAllowed;","tryCatchPattern":"try\n{\n    var result = await _orderProcessingService.PlaceOrderAsync(processPaymentRequest);\n}\ncatch (NopException ex) when (ex.Message == \"Anonymous checkout is not allowed\")\n{\n    return RedirectToRoute(\"Login\");\n}","preventionTips":["Check anonymous checkout policy early in the checkout flow and redirect guests to login/register.","If enabling/disabling anonymous checkout, communicate the change to customers beforehand.","Extend session timeout or add keep-alive to prevent mid-checkout authentication loss.","In custom integrations, ensure ProcessPaymentRequest.CustomerId refers to a registered customer when anonymous checkout is disabled."],"tags":["nopcommerce","anonymous-checkout","guest","authentication","business-rule","order-processing"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}