{"record":{"id":"b66957f882248cf1","repo":"nopSolutions/nopCommerce","slug":"failed-to-download-certificate","errorCode":null,"errorMessage":"Failed to download certificate","messagePattern":"Failed to download certificate","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Plugins/Nop.Plugin.Tax.Avalara/Services/AvalaraTaxManager.cs","lineNumber":1710,"sourceCode":"\n    /// <summary>\n    /// Download a PDF file for the certificate\n    /// </summary>\n    /// <param name=\"certificateId\">The unique ID number of the certificate</param>\n    /// <returns>\n    /// A task that represents the asynchronous operation\n    /// The task result contains the file details\n    /// </returns>\n    public async Task<FileResult> DownloadCertificateAsync(int certificateId)\n    {\n        return (await HandleFunctionAsync(() =>\n        {\n            if (_avalaraTaxSettings.CompanyId is null)\n                throw new NopException(\"Company not selected\");\n\n            var file = ServiceClient\n                .DownloadCertificateImage(_avalaraTaxSettings.CompanyId.Value, certificateId, null, CertificatePreviewType.Pdf)\n                ?? throw new NopException(\"Failed to download certificate\");\n\n            return Task.FromResult(file);\n        })).Result;\n    }\n\n    /// <summary>\n    /// Get an existing invitation to upload certificates on the external website\n    /// </summary>\n    /// <param name=\"customer\">Customer</param>\n    /// <returns>\n    /// A task that represents the asynchronous operation\n    /// The task result contains the URL to redirect customer\n    /// </returns>\n    public async Task<string> GetInvitationAsync(Customer customer)\n    {\n        return (await HandleFunctionAsync(async () =>\n        {\n            if (_avalaraTaxSettings.CompanyId is null)","sourceCodeStart":1692,"sourceCodeEnd":1728,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Plugins/Nop.Plugin.Tax.Avalara/Services/AvalaraTaxManager.cs#L1692-L1728","documentation":"Thrown when ServiceClient.DownloadCertificateImage(companyId, certificateId, null, CertificatePreviewType.Pdf) returns null. The Avalara SDK returns null when the certificate image/PDF cannot be retrieved.","triggerScenarios":"Downloading a certificateId that no longer exists; the certificate has no PDF preview generated yet; insufficient permissions for the license key on that certificate; transient SDK failure.","commonSituations":"Stale certificateId in a link after the certificate was revoked/deleted in Avalara; CertCapture still processing the uploaded image (no PDF rendered yet); license key lacks download scope.","solutions":["Verify the certificateId still exists via ListCertificatesForCustomer before offering the download.","Check Avalara permissions for the configured license key (needs certificate read/download scope).","Retry after confirming the certificate has a generated preview in the Avalara admin UI."],"exampleFix":"// before\nvar file = ServiceClient\n    .DownloadCertificateImage(_avalaraTaxSettings.CompanyId.Value, certificateId, null, CertificatePreviewType.Pdf)\n    ?? throw new NopException(\"Failed to download certificate\");\n\n// after — verify existence and give a clearer error\nvar file = ServiceClient.DownloadCertificateImage(_avalaraTaxSettings.CompanyId.Value, certificateId, null, CertificatePreviewType.Pdf);\nif (file is null)\n    throw new NopException($\"Certificate {certificateId} not available for download (missing or not yet rendered)\");","handlingStrategy":"try-catch","validationCode":"var exists = (await ServiceClient.ListCertificatesForCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customerId.ToString(), null, null, null, null, null))?.value?.Any(c => c.id == certificateId) ?? false;\nif (!exists) return NotFound();","typeGuard":null,"tryCatchPattern":"try { return await DownloadCertificateAsync(certificateId); }\ncatch (NopException ex) when (ex.Message.Contains(\"Failed to download certificate\"))\n{ _logger.LogWarning(ex, \"Certificate {Id} unavailable\", certificateId); return NotFound(); }","preventionTips":["Confirm the certificate still exists before offering a download.","Check Avalara license-key scopes include certificate read.","Retry once for transient null responses."],"tags":["avalara","certcapture","pdf","null-response","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}