nopSolutions/nopCommerce · error · NopException

Failed to get customer's certificates

Error message

Failed to get customer's certificates

What it means

Thrown when ServiceClient.ListValidCertificatesForCustomerAsync(companyId, customerCode, country, region) returns null. Used to determine the customer's exemption status; a null result means Avalara gave no exemptionStatus payload, so exemption cannot be decided.

Source

Thrown at src/Plugins/Nop.Plugin.Tax.Avalara/Services/AvalaraTaxManager.cs:1663

    /// The task result contains the list of certificates
    /// </returns>
    public async Task<CertificateModel> GetValidCertificatesAsync(Customer customer, int storeId)
    {
        return (await HandleFunctionAsync(async () =>
        {
            if (_avalaraTaxSettings.CompanyId is null)
                throw new NopException("Company not selected");

            //create dummy order to get selected address
            var order = new Order { CustomerId = customer.Id };
            await PrepareOrderAddressesAsync(customer, order, storeId);
            var address = await GetTaxAddressAsync(order);
            var shipTo = await MapAddressAsync(address);

            //check exemption status
            var exemptionStatus = await ServiceClient
                .ListValidCertificatesForCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customer.Id.ToString(), shipTo.country, shipTo.region)
                ?? throw new NopException("Failed to get customer's certificates");

            var exempt = string.Equals(exemptionStatus.status, "Exempt", StringComparison.InvariantCultureIgnoreCase);
            return exempt ? exemptionStatus.certificate : null;
        })).Result;
    }

    /// <summary>
    /// Get all certificates linked to a customer
    /// </summary>
    /// <param name="customer">Customer</param>
    /// <returns>
    /// A task that represents the asynchronous operation
    /// The task result contains the list of certificates
    /// </returns>
    public async Task<List<CertificateModel>> GetCustomerCertificatesAsync(Customer customer)
    {
        return (await HandleFunctionAsync(async () =>
        {

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Check the shipTo address produced by MapAddressAsync has valid country and region values.
  2. Log the raw SDK response and HTTP status via HandleFunctionAsync to determine whether this is a not-found vs an API error.
  3. Consider treating a null exemptionStatus as 'not exempt' (return null certificate) instead of throwing.

Example fix

// before
var exemptionStatus = await ServiceClient
    .ListValidCertificatesForCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customer.Id.ToString(), shipTo.country, shipTo.region)
    ?? throw new NopException("Failed to get customer's certificates");

// after — degrade to non-exempt on missing status
var exemptionStatus = await ServiceClient
    .ListValidCertificatesForCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customer.Id.ToString(), shipTo.country, shipTo.region);
if (exemptionStatus is null) return null;
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(shipTo.country) || string.IsNullOrEmpty(shipTo.region))
    return null; // cannot query exemptions without country/region

Type guard

static bool CanQueryExemptions(Address a) => !string.IsNullOrEmpty(a?.Country) && !string.IsNullOrEmpty(a.Region);

Try / catch

try { return await GetValidCertificatesAsync(customer, storeId); }
catch (NopException ex) when (ex.Message.Contains("certificates"))
{ _logger.LogWarning(ex, "Exemption lookup failed; treating as non-exempt"); return null; }

Prevention

When it happens

Trigger: Certificate lookup for a customer in a country/region where Avalara returns no exemption status object; shipTo address missing country/region so the query is malformed; transient SDK failure.

Common situations: International customers where Avalara has no exemption program for the region; address mapping (MapAddressAsync) produced null country/region; the customer has no certificates but Avalara still returns null instead of an empty status.

Understand the failure class

Related errors


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/a4a02e4212f06188. Report an issue: GitHub.