Sana Assistant (online)
Table of Contents

AddressValidationExtension reference

All address validation extensions have to be inherited from the AddressValidationExtension class which, in turn, inherits from the core Sana Commerce Cloud Extension class.

Class

Methods

ValidateAsync

Validates the provided address.

Sana calls this method and passes the instance of AddressValidationContext and the method returns an instance of AddressValidationResult that represents the result of the address validation operation.

public override Task<AddressValidationResult> ValidateAsync(AddressValidationContext context, CancellationToken cancellationToken)
{
    var response = /* calls 3rd party service to validate the address */;
    var address = response.SuggestedAddress;
    return Task.FromResult<AddressValidationResult?>(
      IsValid: response.Valid,
      SuggestedAddress: new(address.Address, address.Address2, address.ZipCode, address.City, address.CountryId, address.State));
}