...
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Back.Common;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using TaxCollectData.Library.Business;
|
||||
using TaxCollectData.Library.Dto.Config;
|
||||
using TaxCollectData.Library.Dto.Content;
|
||||
@@ -8,32 +9,23 @@ using TaxCollectData.Library.Enums;
|
||||
|
||||
namespace Back.Services
|
||||
{
|
||||
public class ActionTaxPayer : IDisposable
|
||||
public class ActionTaxPayer
|
||||
{
|
||||
private string _UniqueMemory;
|
||||
public ActionTaxPayer(string UniqueMemory, string PrivateKey)
|
||||
private string _PrivateKey;
|
||||
private readonly servCompany _servCompany;
|
||||
public ActionTaxPayer(servCompany servCompany)
|
||||
{
|
||||
#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
|
||||
_servCompany = servCompany;
|
||||
}
|
||||
public string GenerateTaxid(string FactorNo, string InvoiceDate)
|
||||
{
|
||||
return TaxApiService.Instance.TaxIdGenerator.GenerateTaxId(_UniqueMemory,
|
||||
Convert.ToInt64(FactorNo), InvoiceDate.ToMiladi());
|
||||
}
|
||||
|
||||
public InquiryResultModel GetResultByUid(string uid)
|
||||
public async Task<InquiryResultModel> GetResultByUid(int CompanyID, string uid)
|
||||
{
|
||||
if (!login())
|
||||
if (!await login(CompanyID))
|
||||
return null;
|
||||
var uidAndFiscalId = new UidAndFiscalId(uid, _UniqueMemory);
|
||||
var inquiryResultModels = TaxApiService.Instance.TaxApis.InquiryByUidAndFiscalId(new() { uidAndFiscalId });
|
||||
@@ -41,45 +33,58 @@ namespace Back.Services
|
||||
return inquiryResultModels[0];
|
||||
return null;
|
||||
}
|
||||
public TaxCollectData.Library.Dto.HttpResponse<AsyncResponseModel> SendInvoice(InvoiceHeaderDto header, List<InvoiceBodyDto> InvoiceBody, PaymentDto payment)
|
||||
public async Task<TaxCollectData.Library.Dto.HttpResponse<AsyncResponseModel>> SendInvoice(int CompanyID,InvoiceHeaderDto header, List<InvoiceBodyDto> InvoiceBody, PaymentDto payment)
|
||||
{
|
||||
if (!login())
|
||||
if (!await login(CompanyID))
|
||||
return null;
|
||||
return TaxApiService.Instance.TaxApis.SendInvoices(new List<InvoiceDto>()
|
||||
return await TaxApiService.Instance.TaxApis.SendInvoicesAsync(new List<InvoiceDto>()
|
||||
{
|
||||
new InvoiceDto()
|
||||
new()
|
||||
{
|
||||
Header =header,Body =InvoiceBody,Payments = new() {payment}
|
||||
}
|
||||
}
|
||||
, null);
|
||||
}
|
||||
public EconomicCodeModel? GetEconomicCodeInformation(string Item)
|
||||
public async Task<EconomicCodeModel?> GetEconomicCodeInformation(string Item)
|
||||
{
|
||||
return TaxApiService.Instance.TaxApis.GetEconomicCodeInformation(Item);
|
||||
return await TaxApiService.Instance.TaxApis.GetEconomicCodeInformationAsync(Item);
|
||||
}
|
||||
//-------------------internal
|
||||
public bool login()
|
||||
public async Task<bool> login(int CompanyID)
|
||||
{
|
||||
try
|
||||
{
|
||||
#region TokenTax
|
||||
var resquth = await _servCompany.GetTaxAuth(CompanyID);
|
||||
if (string.IsNullOrEmpty(resquth.UniqueMemory) || string.IsNullOrEmpty(resquth.PrivateKey))
|
||||
return false;
|
||||
|
||||
if (!string.IsNullOrEmpty(resquth.UniqueMemory) && !string.IsNullOrEmpty(resquth.PrivateKey))
|
||||
{
|
||||
_UniqueMemory = resquth.UniqueMemory;
|
||||
_PrivateKey = resquth.PrivateKey;
|
||||
TaxApiService.Instance.Init(_UniqueMemory,
|
||||
new SignatoryConfig(_PrivateKey, null),
|
||||
new NormalProperties(ClientType.SELF_TSP), "https://tp.tax.gov.ir/req/api/");
|
||||
await TaxApiService.Instance.TaxApis.GetServerInformationAsync();
|
||||
}
|
||||
#endregion
|
||||
|
||||
if (TaxApiService.Instance.TaxApis.GetToken() is null)
|
||||
{
|
||||
if(TaxApiService.Instance.TaxApis.RequestToken()==null)
|
||||
return false;
|
||||
if (await TaxApiService.Instance.TaxApis.RequestTokenAsync() == null)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user