Skip to content

Commit

Permalink
Merge pull request #19 from ibanity/new-einvoicing-webhook
Browse files Browse the repository at this point in the history
New eInvoicing webhook
  • Loading branch information
damienbr authored Jul 5, 2024
2 parents 5510e43 + 0618f48 commit b9b58f1
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/Client/Webhooks/Models/eInvoicing/InboundDocumentNew.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Runtime.Serialization;

namespace Ibanity.Apis.Client.Webhooks.Models.eInvoicing
{
/// <summary>
/// A webhook payload delivered whenever there is a new document available.
/// </summary>
#pragma warning disable CA1711 // Identifiers should not have incorrect suffix
public class InboundDocumentNew : JsonApi.Data, IWebhookEvent
#pragma warning restore CA1711 // Identifiers should not have incorrect suffix
{
/// <summary>
/// Unique identifier of the associated document.
/// </summary>
[DataMember(Name = "documentId", EmitDefaultValue = false)]
public Guid DocumentId { get; set; }

/// <summary>
/// Unique identifier of the associated supplier.
/// </summary>
[DataMember(Name = "supplierId", EmitDefaultValue = false)]
public Guid SupplierId { get; set; }

/// <summary>
/// When this notification was created.
/// </summary>
[DataMember(Name = "createdAt", EmitDefaultValue = false)]
public DateTimeOffset CreatedAt { get; set; }
}

/// <summary>
/// A webhook payload delivered whenever there is a new document available.
/// </summary>
#pragma warning disable CA1711 // Identifiers should not have incorrect suffix
public class NestedInboundDocumentNew : PayloadData<InboundDocumentNewAttributes, InboundDocumentNewRelationships>
#pragma warning restore CA1711 // Identifiers should not have incorrect suffix
{
/// <inheritdoc />
public override IWebhookEvent Flatten() =>
new InboundDocumentNew
{
Id = Id,
Type = Type,
DocumentId = Guid.Parse(Relationships.Document.Data.Id),
SupplierId = Guid.Parse(Relationships.Supplier.Data.Id),
CreatedAt = Attributes.CreatedAt
};
}

/// <summary>
/// Payload attributes delivered whenever there is a new document available.
/// </summary>
public class InboundDocumentNewAttributes
{
/// <summary>
/// When this notification was created.
/// </summary>
[DataMember(Name = "createdAt", EmitDefaultValue = false)]
public DateTimeOffset CreatedAt { get; set; }
}

/// <summary>
/// Payload relationships delivered whenever there is a new document available.
/// </summary>
public class InboundDocumentNewRelationships
{
/// <summary>
/// A Peppol Inbound Document reference.
/// </summary>
[DataMember(Name = "document", EmitDefaultValue = false)]
public Relationship Document { get; set; }

/// <summary>
/// A Supplier reference.
/// </summary>
[DataMember(Name = "supplier", EmitDefaultValue = false)]
public Relationship Supplier { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Runtime.Serialization;

namespace Ibanity.Apis.Client.Webhooks.Models.eInvoicing
{
/// <summary>
/// A webhook payload delivered whenever a peppol registration is updated to registered or registration-failed.
/// </summary>
public class PeppolRegistrationsUpdated : JsonApi.Data, IWebhookEvent
{
/// <summary>
/// Unique identifier of the associated supplier.
/// </summary>
[DataMember(Name = "supplierId", EmitDefaultValue = false)]
public Guid SupplierId { get; set; }

/// <summary>
/// When this notification was created.
/// </summary>
[DataMember(Name = "createdAt", EmitDefaultValue = false)]
public DateTimeOffset CreatedAt { get; set; }
}

/// <summary>
/// A webhook payload delivered whenever a peppol registration is updated to registered or registration-failed.
/// </summary>
public class NestedPeppolRegistrationsUpdated : PayloadData<PeppolRegistrationsUpdatedAttributes, PeppolRegistrationsUpdatedRelationships>
{
/// <inheritdoc />
public override IWebhookEvent Flatten() =>
new PeppolRegistrationsUpdated
{
Id = Id,
Type = Type,
SupplierId = Guid.Parse(Relationships.Supplier.Data.Id),
CreatedAt = Attributes.CreatedAt
};
}

/// <summary>
/// Payload attributes delivered whenever a peppol registration is updated to registered or registration-failed.
/// </summary>
public class PeppolRegistrationsUpdatedAttributes
{
/// <summary>
/// When this notification was created.
/// </summary>
[DataMember(Name = "createdAt", EmitDefaultValue = false)]
public DateTimeOffset CreatedAt { get; set; }
}

/// <summary>
/// Payload relationships delivered whenever a peppol registration is updated to registered or registration-failed.
/// </summary>
public class PeppolRegistrationsUpdatedRelationships
{
/// <summary>
/// A Supplier reference.
/// </summary>
[DataMember(Name = "supplier", EmitDefaultValue = false)]
public Relationship Supplier { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/Client/Webhooks/WebhooksService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class WebhooksService : IWebhooksService
{
private static readonly IReadOnlyDictionary<string, Type> Types = new Dictionary<string, Type>
{
{ "eInvoicing.inbound.document.new", typeof(Payload<Models.eInvoicing.NestedInboundDocumentNew>) },
{ "eInvoicing.peppol.registrations.updated", typeof(Payload<Models.eInvoicing.NestedPeppolRegistrationsUpdated>) },
{ "pontoConnect.synchronization.succeededWithoutChange", typeof(Payload<Models.PontoConnect.NestedSynchronizationSucceededWithoutChange>) },
{ "pontoConnect.synchronization.failed", typeof(Payload<Models.PontoConnect.NestedSynchronizationFailed>) },
{ "pontoConnect.account.detailsUpdated", typeof(Payload<Models.PontoConnect.NestedAccountDetailsUpdated>) },
Expand Down

0 comments on commit b9b58f1

Please sign in to comment.