Skip to content

Library for VAT lookup using Danish VIRK registry service

License

Notifications You must be signed in to change notification settings

FCS-TECH/fcs-virk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fcs-virk

Sample controller action

public async Task<IHttpActionResult> GetCvrData([FromUri] VrQuery query)
{
    if (!ModelState.IsValid)
        return BadRequest(ModelState);

    if (!VrQueryValidator.ValidateVrQuery(query))
        return BadRequest($"invalid request");

    // cvr endpoint
    var cvrLookupUrl = $"{Settings.CvrLookupUrl}";

    // auth
    var auth = $"{Settings.CvrCredentials}";

    // initialize result object
    var result = new List<CvrInfo>();

    // map query to json object
    var queryMapper = new VrQueryMapper();
    var queryObject = queryMapper.VrMapQuery(query);

    // execute request
    var vrReqest = new VrHttpRequest();
    var vrResponseView = await vrReqest.GetResponseAsync(cvrLookupUrl,
        JsonConvert.SerializeObject(queryObject, Formatting.None), auth);

    // intermediate parser
    var vrParser = new VrResponseParser();
    var vrVirksomheder = vrParser.ParseVrResponse(vrResponseView.Message);

    // validate wheter to continue or return empty result
    var found = vrVirksomheder.Any();
    if (!found)
        return Ok(result);

    // final mapping
    var cvrMapper = new VrCvrMapper();
    result = vrVirksomheder.Select(c => cvrMapper.MapVrToCvr(c)).ToList();

    // return result
    return Ok(result);
}

About

Library for VAT lookup using Danish VIRK registry service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages