Update header

This commit is contained in:
Frede Hundewadt 2023-03-21 07:19:07 +01:00
parent 243989f3b4
commit a64271559d
7 changed files with 281 additions and 274 deletions

View file

@ -1,25 +1,25 @@
// ***********************************************************************
// Assembly : FCS.Lib.Vies
// Author : FH
// Created : 04-01-2022
//
// Last Modified By : FH
// Last Modified On : 04-01-2022
// Author : fhdk
// Created : 2023 01 19 10:41
//
// Last Modified By: fhdk
// Last Modified On : 2023 03 14 09:16
// ***********************************************************************
// <copyright file="ViesEntityModel.cs" company="">
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// <copyright file="ViesEntityModel.cs" company="FCS">
// Copyright (C) 2023-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright>
// <summary></summary>
// ***********************************************************************
@ -37,22 +37,27 @@ public class ViesEntityModel
/// Business entity's country code of origin
/// </summary>
public string CountryCode { get; set; } = "";
/// <summary>
/// Business entity vat number
/// </summary>
public string VatNumber { get; set; } = "";
/// <summary>
/// Request date
/// </summary>
public DateTime RequestDate { get; set; }
/// <summary>
/// Valid flag
/// </summary>
public bool Valid { get; set; }
/// <summary>
/// Business entity name
/// </summary>
public string Name { get; set; } = "";
/// <summary>
/// Business entity address
/// </summary>

View file

@ -1,79 +1,80 @@
// ***********************************************************************
// Assembly : FCS.Lib.Vies
// Author : FH
// Created : 04-01-2022
//
// Last Modified By : FH
// Last Modified On : 04-01-2022
// Author : fhdk
// Created : 2022 12 17 13:33
//
// Last Modified By: fhdk
// Last Modified On : 2023 03 14 09:16
// ***********************************************************************
// <copyright file="ViesHttpRequest.cs" company="">
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// <copyright file="ViesHttpRequest.cs" company="FCS">
// Copyright (C) 2022-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright>
// <summary></summary>
// ***********************************************************************
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace FCS.Lib.Vies
namespace FCS.Lib.Vies;
/// <summary>
/// http request to vies registrar
/// </summary>
public class ViesHttpRequest
{
/// <summary>
/// http request to vies registrar
/// Async http request to vies registrar
/// </summary>
public class ViesHttpRequest
/// <param name="endpoint"></param>
/// <param name="countryCode"></param>
/// <param name="vatNumber"></param>
/// <param name="userAgent"></param>
/// <returns>Vies Response View model</returns>
/// <see cref="ViesResponseView"/>
/// <remarks>Service http://ec.europa.eu/taxation_customs/vies/services/checkVatService</remarks>
public async Task<ViesResponseView> GetResponseAsync(string endpoint, string countryCode, string vatNumber,
string userAgent)
{
/// <summary>
/// Async http request to vies registrar
/// </summary>
/// <param name="endpoint"></param>
/// <param name="countryCode"></param>
/// <param name="vatNumber"></param>
/// <param name="userAgent"></param>
/// <returns>Vies Response View model</returns>
/// <see cref="ViesResponseView"/>
/// <remarks>Service http://ec.europa.eu/taxation_customs/vies/services/checkVatService</remarks>
public async Task<ViesResponseView> GetResponseAsync(string endpoint, string countryCode, string vatNumber, string userAgent)
var xml = new StringBuilder();
xml.Append(
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:ec.europa.eu:taxud:vies:services:checkVat:types\">");
xml.Append("<soapenv:Header/>");
xml.Append("<soapenv:Body>");
xml.Append("<urn:checkVat>");
xml.Append($"<urn:countryCode>{countryCode.ToUpperInvariant()}</urn:countryCode>");
xml.Append($"<urn:vatNumber>{vatNumber}</urn:vatNumber>");
xml.Append("</urn:checkVat>");
xml.Append("</soapenv:Body>");
xml.Append("</soapenv:Envelope>");
using var content = new StringContent(xml.ToString(), Encoding.UTF8, "text/xml");
using var client = new HttpClient();
using var viesRequest = new HttpRequestMessage(HttpMethod.Post, endpoint);
viesRequest.Headers.Add("SOAPAction", "");
viesRequest.Headers.Add("User-Agent", userAgent);
viesRequest.Content = content;
var response = await client.SendAsync(viesRequest).ConfigureAwait(true);
var xmlResult = await response.Content.ReadAsStringAsync().ConfigureAwait(true);
return new ViesResponseView
{
var xml = new StringBuilder();
xml.Append($"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:ec.europa.eu:taxud:vies:services:checkVat:types\">");
xml.Append($"<soapenv:Header/>");
xml.Append($"<soapenv:Body>");
xml.Append($"<urn:checkVat>");
xml.Append($"<urn:countryCode>{countryCode.ToUpperInvariant()}</urn:countryCode>");
xml.Append($"<urn:vatNumber>{vatNumber}</urn:vatNumber>");
xml.Append($"</urn:checkVat>");
xml.Append($"</soapenv:Body>");
xml.Append($"</soapenv:Envelope>");
using var content = new StringContent(xml.ToString(), Encoding.UTF8, "text/xml");
using var client = new HttpClient();
using var viesRequest = new HttpRequestMessage(HttpMethod.Post, endpoint);
viesRequest.Headers.Add("SOAPAction", "");
viesRequest.Headers.Add("User-Agent", userAgent);
viesRequest.Content = content;
var response = await client.SendAsync(viesRequest).ConfigureAwait(true);
var xmlResult = await response.Content.ReadAsStringAsync().ConfigureAwait(true);
return new ViesResponseView
{
Code = response.StatusCode,
IsSuccessStatusCode = response.IsSuccessStatusCode,
Message = xmlResult
};
}
Code = response.StatusCode,
IsSuccessStatusCode = response.IsSuccessStatusCode,
Message = xmlResult
};
}
}
}

View file

@ -1,28 +1,29 @@
// ***********************************************************************
// Assembly : FCS.Lib.Vies
// Author : FH
// Created : 04-01-2022
//
// Last Modified By : FH
// Last Modified On : 04-01-2022
// Author : fhdk
// Created : 2023 01 19 10:41
//
// Last Modified By: fhdk
// Last Modified On : 2023 03 14 09:16
// ***********************************************************************
// <copyright file="ViesQuery.cs" company="">
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// <copyright file="ViesQuery.cs" company="FCS">
// Copyright (C) 2023-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright>
// <summary></summary>
// ***********************************************************************
namespace FCS.Lib.Vies;
/// <summary>

View file

@ -1,25 +1,25 @@
// ***********************************************************************
// Assembly : FCS.Lib.Vies
// Author : FH
// Created : 04-01-2022
//
// Last Modified By : FH
// Last Modified On : 04-01-2022
// Author : fhdk
// Created : 2022 12 17 13:33
//
// Last Modified By: fhdk
// Last Modified On : 2023 03 14 09:16
// ***********************************************************************
// <copyright file="ViesQueryValidator.cs" company="">
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// <copyright file="ViesQueryValidator.cs" company="FCS">
// Copyright (C) 2022-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright>
// <summary></summary>
// ***********************************************************************

View file

@ -1,25 +1,25 @@
// ***********************************************************************
// Assembly : FCS.Lib.Vies
// Author : FH
// Created : 04-01-2022
//
// Last Modified By : FH
// Last Modified On : 04-01-2022
// Author : fhdk
// Created : 2023 01 19 10:41
//
// Last Modified By: fhdk
// Last Modified On : 2023 03 14 09:16
// ***********************************************************************
// <copyright file="ViesResultParser.cs" company="">
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// <copyright file="ViesResponseParser.cs" company="FCS">
// Copyright (C) 2023-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright>
// <summary></summary>
// ***********************************************************************
@ -46,7 +46,7 @@ public class ViesResponseParser
var xml = XDocument.Parse(responseData);
var x = xml.Descendants().Where(c => c.Name.LocalName == "checkVatResponse")
.Select(x => new ViesEntityModel()
.Select(x => new ViesEntityModel
{
CountryCode = (string)x.Element(x.Name.Namespace + "countryCode"),
VatNumber = (string)x.Element(x.Name.Namespace + "vatNumber"),

View file

@ -1,28 +1,29 @@
// ***********************************************************************
// Assembly : FCS.Lib.Vies
// Author : FH
// Created : 04-01-2022
//
// Last Modified By : FH
// Last Modified On : 04-01-2022
// Author : fhdk
// Created : 2022 12 17 13:33
//
// Last Modified By: fhdk
// Last Modified On : 2023 03 14 09:16
// ***********************************************************************
// <copyright file="ViesResponseView.cs" company="">
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// <copyright file="ViesResponseView.cs" company="FCS">
// Copyright (C) 2022-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright>
// <summary></summary>
// ***********************************************************************
using System.Net;
namespace FCS.Lib.Vies;
@ -36,10 +37,12 @@ public class ViesResponseView
/// http request status code
/// </summary>
public HttpStatusCode Code { get; set; }
/// <summary>
/// boolean indicating success
/// </summary>
public bool IsSuccessStatusCode { get; set; }
/// <summary>
/// response message
/// </summary>

View file

@ -1,139 +1,136 @@
// ***********************************************************************
// Assembly : FCS.Lib.Virk
// Author : FH
// Created : 02-21-2022
//
// Last Modified By : FH
// Last Modified On : 02-24-2022
// Assembly : FCS.Lib.Vies
// Author : fhdk
// Created : 2023 02 02 11:05
//
// Last Modified By: fhdk
// Last Modified On : 2023 03 14 09:16
// ***********************************************************************
// <copyright file="VrCvrMapper.cs" company="FCS">
// Copyright (C) 2022 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the Affero GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Affero GNU General Public License for more details.
//
// You should have received a copy of the Affero GNU General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html]
// <copyright file="ViesVatInfoMapper.cs" company="FCS">
// Copyright (C) 2023-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq.Expressions;
using FCS.Lib.Common;
namespace FCS.Lib.Vies
namespace FCS.Lib.Vies;
/// <summary>
/// Vies vat info mapper
/// </summary>
public class ViesVatInfoMapper
{
/// <summary>
/// Vies vat info mapper
/// map vies response to Crm
/// </summary>
public class ViesVatInfoMapper
/// <param name="viesEntity"></param>
/// <returns>Vat Info Data Transfer Object</returns>
/// <see cref="VatInfoDto"/>
/// <see cref="ViesEntityModel"/>
/// <see cref="VatState"/>
/// <see cref="TimeFrame"/>
public VatInfoDto MapViesVatInfoDto(ViesEntityModel viesEntity)
{
/// <summary>
/// map vies response to Crm
/// </summary>
/// <param name="viesEntity"></param>
/// <returns>Vat Info Data Transfer Object</returns>
/// <see cref="VatInfoDto"/>
/// <see cref="ViesEntityModel"/>
/// <see cref="VatState"/>
/// <see cref="TimeFrame"/>
public VatInfoDto MapViesVatInfoDto(ViesEntityModel viesEntity)
var addressBlock = viesEntity.Address.Split('\n');
var coName = "";
var address = "";
var zip = "";
var city = "";
var i = 0;
if (viesEntity.CountryCode == "SE" && addressBlock.Length > 0)
{
var addressBlock = viesEntity.Address.Split('\n');
var coName = "";
var address = "";
var zip = "";
var city = "";
var i = 0;
if (viesEntity.CountryCode == "SE" && addressBlock.Length > 0)
if (addressBlock.Length > 1)
{
if (addressBlock.Length > 1)
{
coName = addressBlock[i];
i++;
}
try
{
address = addressBlock[i].Normalize();
}
catch
{
address = "fejl";
}
if (addressBlock.Length > 2)
{
i++;
zip = addressBlock[i].Normalize().Substring(0, 6).Replace(" ", "");
city = addressBlock[i].Normalize().Substring(7).Trim();
}
}
else
{
if (addressBlock.Length > 1)
{
coName = addressBlock[i].Normalize();
i++;
}
try
{
address = addressBlock[i].Normalize();
}
catch
{
address = "fejl";
}
if (addressBlock.Length > 1)
{
i++;
zip = addressBlock[i].Substring(0, 5).Replace(" ", "");
city = addressBlock[i].Substring(5).Trim();
}
coName = addressBlock[i];
i++;
}
// generate return object
var c = new VatInfoDto
try
{
Name = viesEntity.Name.Normalize(),
Address = address,
VatNumber = viesEntity.VatNumber,
City = city,
ZipCode = zip,
RequestDate = DateTime.Now.ToString(CultureInfo.InvariantCulture)
};
address = addressBlock[i].Normalize();
}
catch
{
address = "fejl";
}
c.States.Add(new VatState
if (addressBlock.Length > 2)
{
State = viesEntity.Valid ? "NORMAL" : "LUKKET",
LastUpdate = $"{viesEntity.RequestDate:yyyy-MM-dd}",
TimeFrame = new TimeFrame
{
EndDate = "NA",
StartDate = "NA"
}
});
c.LifeCycles.Add(new LifeCycle
{
LastUpdate = $"{viesEntity.RequestDate:yyyy-MM-dd}",
TimeFrame = new TimeFrame
{
StartDate = "NN",
EndDate = "NN"
}
});
return c;
i++;
zip = addressBlock[i].Normalize().Substring(0, 6).Replace(" ", "");
city = addressBlock[i].Normalize().Substring(7).Trim();
}
}
else
{
if (addressBlock.Length > 1)
{
coName = addressBlock[i].Normalize();
i++;
}
try
{
address = addressBlock[i].Normalize();
}
catch
{
address = "fejl";
}
if (addressBlock.Length > 1)
{
i++;
zip = addressBlock[i].Substring(0, 5).Replace(" ", "");
city = addressBlock[i].Substring(5).Trim();
}
}
// generate return object
var c = new VatInfoDto
{
Name = viesEntity.Name.Normalize(),
Address = address,
VatNumber = viesEntity.VatNumber,
City = city,
ZipCode = zip,
RequestDate = DateTime.Now.ToString(CultureInfo.InvariantCulture)
};
c.States.Add(new VatState
{
State = viesEntity.Valid ? "NORMAL" : "LUKKET",
LastUpdate = $"{viesEntity.RequestDate:yyyy-MM-dd}",
TimeFrame = new TimeFrame
{
EndDate = "NA",
StartDate = "NA"
}
});
c.LifeCycles.Add(new LifeCycle
{
LastUpdate = $"{viesEntity.RequestDate:yyyy-MM-dd}",
TimeFrame = new TimeFrame
{
StartDate = "NN",
EndDate = "NN"
}
});
return c;
}
}