From a64271559db959566a50c01485e023a4cf39f7de Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Tue, 21 Mar 2023 07:19:07 +0100 Subject: [PATCH] Update header --- ViesEntityModel.cs | 43 ++++---- ViesHttpRequest.cs | 127 +++++++++++------------ ViesQuery.cs | 39 ++++---- ViesQueryValidator.cs | 38 +++---- ViesResponseParser.cs | 40 ++++---- ViesResponseView.cs | 41 ++++---- ViesVatInfoMapper.cs | 227 +++++++++++++++++++++--------------------- 7 files changed, 281 insertions(+), 274 deletions(-) diff --git a/ViesEntityModel.cs b/ViesEntityModel.cs index d4fcd9b..f74ed08 100644 --- a/ViesEntityModel.cs +++ b/ViesEntityModel.cs @@ -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 (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 (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] // // // *********************************************************************** @@ -37,22 +37,27 @@ public class ViesEntityModel /// Business entity's country code of origin /// public string CountryCode { get; set; } = ""; + /// /// Business entity vat number /// public string VatNumber { get; set; } = ""; + /// /// Request date /// public DateTime RequestDate { get; set; } + /// /// Valid flag /// public bool Valid { get; set; } + /// /// Business entity name /// public string Name { get; set; } = ""; + /// /// Business entity address /// diff --git a/ViesHttpRequest.cs b/ViesHttpRequest.cs index b038a9e..3cddc79 100644 --- a/ViesHttpRequest.cs +++ b/ViesHttpRequest.cs @@ -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 (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 (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] // // // *********************************************************************** + using System.Net.Http; using System.Text; using System.Threading.Tasks; -namespace FCS.Lib.Vies +namespace FCS.Lib.Vies; + +/// +/// http request to vies registrar +/// +public class ViesHttpRequest { /// - /// http request to vies registrar + /// Async http request to vies registrar /// - public class ViesHttpRequest + /// + /// + /// + /// + /// Vies Response View model + /// + /// Service http://ec.europa.eu/taxation_customs/vies/services/checkVatService + public async Task GetResponseAsync(string endpoint, string countryCode, string vatNumber, + string userAgent) { - /// - /// Async http request to vies registrar - /// - /// - /// - /// - /// - /// Vies Response View model - /// - /// Service http://ec.europa.eu/taxation_customs/vies/services/checkVatService - public async Task GetResponseAsync(string endpoint, string countryCode, string vatNumber, string userAgent) + var xml = new StringBuilder(); + xml.Append( + ""); + xml.Append(""); + xml.Append(""); + xml.Append(""); + xml.Append($"{countryCode.ToUpperInvariant()}"); + xml.Append($"{vatNumber}"); + xml.Append(""); + xml.Append(""); + xml.Append(""); + + 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($""); - xml.Append($""); - xml.Append($""); - xml.Append($""); - xml.Append($"{countryCode.ToUpperInvariant()}"); - xml.Append($"{vatNumber}"); - xml.Append($""); - xml.Append($""); - xml.Append($""); - - 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 + }; } -} +} \ No newline at end of file diff --git a/ViesQuery.cs b/ViesQuery.cs index 8ccebdc..05bc66f 100644 --- a/ViesQuery.cs +++ b/ViesQuery.cs @@ -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 (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 (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] // // // *********************************************************************** + namespace FCS.Lib.Vies; /// diff --git a/ViesQueryValidator.cs b/ViesQueryValidator.cs index 5066077..ace3f9f 100644 --- a/ViesQueryValidator.cs +++ b/ViesQueryValidator.cs @@ -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 (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 (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] // // // *********************************************************************** diff --git a/ViesResponseParser.cs b/ViesResponseParser.cs index a89faa5..3f305ac 100644 --- a/ViesResponseParser.cs +++ b/ViesResponseParser.cs @@ -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 (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 (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] // // // *********************************************************************** @@ -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"), diff --git a/ViesResponseView.cs b/ViesResponseView.cs index 393d982..22b7273 100644 --- a/ViesResponseView.cs +++ b/ViesResponseView.cs @@ -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 (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 (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] // // // *********************************************************************** + using System.Net; namespace FCS.Lib.Vies; @@ -36,10 +37,12 @@ public class ViesResponseView /// http request status code /// public HttpStatusCode Code { get; set; } + /// /// boolean indicating success /// public bool IsSuccessStatusCode { get; set; } + /// /// response message /// diff --git a/ViesVatInfoMapper.cs b/ViesVatInfoMapper.cs index 5b92df0..31a06ec 100644 --- a/ViesVatInfoMapper.cs +++ b/ViesVatInfoMapper.cs @@ -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 (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 (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] // // // *********************************************************************** 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; + +/// +/// Vies vat info mapper +/// +public class ViesVatInfoMapper { /// - /// Vies vat info mapper + /// map vies response to Crm /// - public class ViesVatInfoMapper + /// + /// Vat Info Data Transfer Object + /// + /// + /// + /// + public VatInfoDto MapViesVatInfoDto(ViesEntityModel viesEntity) { - /// - /// map vies response to Crm - /// - /// - /// Vat Info Data Transfer Object - /// - /// - /// - /// - 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; } } \ No newline at end of file