86 lines
2.9 KiB
C#
86 lines
2.9 KiB
C#
using Back.Common;
|
|
using TaxCollectData.Library.Business;
|
|
using TaxCollectData.Library.Dto.Config;
|
|
using TaxCollectData.Library.Dto.Content;
|
|
using TaxCollectData.Library.Dto.Properties;
|
|
using TaxCollectData.Library.Dto.Transfer;
|
|
using TaxCollectData.Library.Enums;
|
|
|
|
namespace Back.Services
|
|
{
|
|
public class ActionTaxPayer : IDisposable
|
|
{
|
|
private string _UniqueMemory;
|
|
public ActionTaxPayer(string UniqueMemory, string PrivateKey)
|
|
{
|
|
#region TokenTax
|
|
if (!string.IsNullOrEmpty(UniqueMemory) && !string.IsNullOrEmpty(PrivateKey))
|
|
{
|
|
_UniqueMemory = UniqueMemory;
|
|
|
|
TaxApiService.Instance.Init(UniqueMemory,
|
|
new SignatoryConfig(PrivateKey, null),
|
|
new NormalProperties(ClientType.SELF_TSP), "https://tp.tax.gov.ir/req/api/");
|
|
TaxApiService.Instance.TaxApis.GetServerInformation();
|
|
}
|
|
#endregion
|
|
}
|
|
public string GenerateTaxid(string FactorNo, string InvoiceDate)
|
|
{
|
|
return TaxApiService.Instance.TaxIdGenerator.GenerateTaxId(_UniqueMemory,
|
|
Convert.ToInt64(FactorNo), InvoiceDate.ToMiladi());
|
|
}
|
|
|
|
public InquiryResultModel GetResultByUid(string uid)
|
|
{
|
|
if (!login())
|
|
return null;
|
|
var uidAndFiscalId = new UidAndFiscalId(uid, _UniqueMemory);
|
|
var inquiryResultModels = TaxApiService.Instance.TaxApis.InquiryByUidAndFiscalId(new() { uidAndFiscalId });
|
|
if (inquiryResultModels.Count > 0)
|
|
return inquiryResultModels[0];
|
|
return null;
|
|
}
|
|
public TaxCollectData.Library.Dto.HttpResponse<AsyncResponseModel> SendInvoice(InvoiceHeaderDto header, List<InvoiceBodyDto> InvoiceBody, PaymentDto payment)
|
|
{
|
|
if (!login())
|
|
return null;
|
|
return TaxApiService.Instance.TaxApis.SendInvoices(new List<InvoiceDto>()
|
|
{
|
|
new InvoiceDto()
|
|
{
|
|
Header =header,Body =InvoiceBody,Payments = new() {payment}
|
|
}
|
|
}
|
|
, null);
|
|
}
|
|
public EconomicCodeModel? GetEconomicCodeInformation(string Item)
|
|
{
|
|
return TaxApiService.Instance.TaxApis.GetEconomicCodeInformation(Item);
|
|
}
|
|
//-------------------internal
|
|
public bool login()
|
|
{
|
|
try
|
|
{
|
|
if (TaxApiService.Instance.TaxApis.GetToken() is null)
|
|
{
|
|
if(TaxApiService.Instance.TaxApis.RequestToken()==null)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|