| | | 1 | | namespace Syki.Back.Domain.Webhooks; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Chamada de Webhook |
| | | 5 | | /// </summary> |
| | | 6 | | public class WebhookCall |
| | | 7 | | { |
| | 0 | 8 | | public int Id { get; set; } |
| | 0 | 9 | | public int InstitutionId { get; set; } |
| | 0 | 10 | | public int WebhookId { get; set; } |
| | 0 | 11 | | public string Payload { get; set; } |
| | 0 | 12 | | public WebhookEventType EventType { get; set; } |
| | 0 | 13 | | public WebhookCallStatus Status { get; set; } |
| | 0 | 14 | | public int AttemptsCount { get; set; } |
| | 0 | 15 | | public DateTime CreatedAt { get; set; } |
| | 0 | 16 | | public List<WebhookCallAttempt> Attempts { get; set; } |
| | | 17 | | |
| | 0 | 18 | | private WebhookCall() { } |
| | | 19 | | |
| | 0 | 20 | | public WebhookCall( |
| | 0 | 21 | | int institutionId, |
| | 0 | 22 | | int webhookId, |
| | 0 | 23 | | object data, |
| | 0 | 24 | | WebhookEventType eventType) |
| | | 25 | | { |
| | 0 | 26 | | InstitutionId = institutionId; |
| | 0 | 27 | | WebhookId = webhookId; |
| | 0 | 28 | | Payload = (new { EventType = eventType, Data = data }).Serialize(); |
| | 0 | 29 | | EventType = eventType; |
| | 0 | 30 | | CreatedAt = DateTime.UtcNow; |
| | 0 | 31 | | } |
| | | 32 | | |
| | | 33 | | public void Success(int statusCode, string response) |
| | | 34 | | { |
| | 0 | 35 | | AttemptsCount++; |
| | 0 | 36 | | Status = WebhookCallStatus.Success; |
| | 0 | 37 | | Attempts.Add(new WebhookCallAttempt(Id, WebhookCallAttemptStatus.Success, statusCode, response)); |
| | 0 | 38 | | } |
| | | 39 | | |
| | | 40 | | public void Failed(int statusCode, string response) |
| | | 41 | | { |
| | 0 | 42 | | Status = WebhookCallStatus.Error; |
| | 0 | 43 | | Attempts.Add(new WebhookCallAttempt(Id, WebhookCallAttemptStatus.Error, statusCode, response)); |
| | | 44 | | |
| | 0 | 45 | | AttemptsCount++; |
| | 0 | 46 | | } |
| | | 47 | | } |