2022-04-01 12:09:45 +02:00
|
|
|
|
// ***********************************************************************
|
|
|
|
|
// Assembly : FCS.Lib.Vies
|
|
|
|
|
// Author : FH
|
|
|
|
|
// Created : 04-01-2022
|
|
|
|
|
//
|
|
|
|
|
// Last Modified By : FH
|
|
|
|
|
// Last Modified On : 04-01-2022
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
// <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>
|
|
|
|
|
// <summary></summary>
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace FCS.Lib.Vies
|
|
|
|
|
{
|
|
|
|
|
public class ViesHttpRequest
|
|
|
|
|
{
|
2022-04-03 11:20:36 +02:00
|
|
|
|
// "http://ec.europa.eu/taxation_customs/vies/services/checkVatService"
|
2022-04-02 18:48:14 +02:00
|
|
|
|
public async Task<ViesResponseView> GetResponseAsync(string endpoint, string countryCode, string vatNumber, string userAgent)
|
2022-04-01 12:09:45 +02:00
|
|
|
|
{
|
|
|
|
|
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", "");
|
2022-04-02 18:48:14 +02:00
|
|
|
|
viesRequest.Headers.Add("User-Agent", userAgent);
|
2022-04-01 12:09:45 +02:00
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|