Skip to main content

Example

public class ImzoConfig
{
public string Api { get; set; }
public string ApiKey { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
}

public class ImzoHttpClient
{
private ImzoConfig _config;
private HttpClient _httpClient;

public ImzoHttpClient(ImzoConfig config)
{
_config = config;
_httpClient = new HttpClient();
Init();
}

public HttpClient Client => _httpClient;

private void Init()
{
string token = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{_config.UserName}:{_config.Password}"));
_httpClient.BaseAddress = new Uri(_config.Api);
_httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", token);
}
}

public class ImzoCreateResponseDto
{
public Guid RequestId { get; set; }
public string SecretKey { get; set; }
}

public class CommissionDocumentService
{
private readonly ImzoHttpClient _imzoHttpClient;
private readonly ImzoConfig _imzoConfig;

private const string RELATIVE_URL = "v1/SignRequest/Create";

public CommissionDocumentService(ImzoConfig config)
{
_imzoConfig = config;
_imzoHttpClient = new ImzoHttpClient(config);
}

public async Task<ImzoCreateResponseDto> PostSignRequestAsync(CommissionDocument docEntity)
{
var signRequestCreateDto = new ImzoCreateRequestDto()
{
ApiKey = _imzoConfig.ApiKey,
IsForceCreate = false,
TableId = docEntity.TableId,
DocumentId = docEntity.DocumentId,
DocumentType = "COMMISSION_CONCLUSION",
IsAllowMultiple = false,
SignData = JsonConvert.SerializeObject(docEntity),
PrintableLink = "https://testlink.uz/TestDocumentLink.pdf",
SignRequestUsers = docEntity.Members.Select(a =>
new ImzoCreateRequestUserDto
{
UserKey = a.Pinfl,
UserInfo = a.Person,
UserId = a.PersonId,
DocStatusId = StatusIdConst.SENT_TO_AGREE,
SignPriority = a.IsLeader ? 2 : 1, /* rais oxirida imzolashi kerak bo'lsa */
UserPhoneNumber = a.PhoneNumber
})
.ToList(),
SignRequestActionTypes = new List<ImzoCreateRequestActionDto>
{
new ImzoCreateRequestActionDto()
{
ActionTypeId = 2,
ActionTypeName = "Qabul qilish",
Translates = new List<ActionTranslateDto>
{
new ActionTranslateDto()
{
LanguageCode = "RU",
Name = "Принять"
},
new ActionTranslateDto()
{
LanguageCode = "UZ_CYRL",
Name = "Қабул қилиш"
},
new ActionTranslateDto()
{
LanguageCode = "UZ_LATN",
Name = "Qabul qilish"
},
new ActionTranslateDto()
{
LanguageCode = "EN",
Name = "Accept"
}
}
},
new ImzoCreateRequestActionDto()
{
ActionTypeId = 9,
ActionTypeName = "Rad etish",
Translates = new List<ActionTranslateDto>
{
new ActionTranslateDto()
{
LanguageCode = "RU",
Name = "Отклонить"
},
new ActionTranslateDto()
{
LanguageCode = "UZ_CYRL",
Name = "Рад этиш"
},
new ActionTranslateDto()
{
LanguageCode = "UZ_LATN",
Name = "Rad etish"
},
new ActionTranslateDto()
{
LanguageCode = "EN",
Name = "Reject"
}
}
}
},
SignatureMethodIds = new List<int> { SignatureMethodIdConst.E_IMZO }
};

ImzoCreateResponseDto? result = null;

var response = await _imzoHttpClient.Client.PostAsync(RELATIVE_URL, new StringContent(JsonConvert.SerializeObject(signRequestCreateDto), Encoding.UTF8, "application/json"));
if (response.IsSuccessStatusCode)
{
var responseAsString = await response.Content.ReadAsStringAsync();
result = JsonConvert.DeserializeObject<ImzoCreateResponseDto>(responseAsString);
}

Console.WriteLine($"Imzolash uchun havola: https://webimzo.uz/test/app?requestId={result.RequestId}&secretKey={result.SecretKey}");
return result;
}
}