diff --git a/src/FaluSdk/FaluClientOptions.cs b/src/FaluSdk/FaluClientOptions.cs index 605389fd..c1429b7f 100644 --- a/src/FaluSdk/FaluClientOptions.cs +++ b/src/FaluSdk/FaluClientOptions.cs @@ -35,15 +35,12 @@ public class FaluClientOptions internal static JsonSerializerOptions GetSerializerOptions() { - if (serializerOptions is null) + serializerOptions ??= new(JsonSerializerDefaults.Web) { - serializerOptions = new(JsonSerializerDefaults.Web) - { - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - AllowTrailingCommas = true, - ReadCommentHandling = JsonCommentHandling.Skip, - }; - } + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + AllowTrailingCommas = true, + ReadCommentHandling = JsonCommentHandling.Skip, + }; return serializerOptions; } diff --git a/src/FaluSdk/Messages/Message.cs b/src/FaluSdk/Messages/Message.cs index b1f3b80d..9d19ad81 100644 --- a/src/FaluSdk/Messages/Message.cs +++ b/src/FaluSdk/Messages/Message.cs @@ -55,11 +55,6 @@ public class Message : MessagePatchModel, IHasId, IHasCreated, IHasUpdated, IHas /// public int Segements { get; set; } - /// - /// Provider used for the message. - /// - public MessageProvider? Provider { get; set; } - /// /// Schedule information for the message. /// @@ -70,6 +65,11 @@ public class Message : MessagePatchModel, IHasId, IHasCreated, IHasUpdated, IHas /// public DateTimeOffset? Sent { get; set; } + /// + /// If present, this property tells you the error encountered when processing the message. + /// + public MessageError? Error { get; set; } + /// /// Time at which the message was delivered. /// This is dependent on the underlying provider. diff --git a/src/FaluSdk/Messages/MessageError.cs b/src/FaluSdk/Messages/MessageError.cs new file mode 100644 index 00000000..66d9008b --- /dev/null +++ b/src/FaluSdk/Messages/MessageError.cs @@ -0,0 +1,16 @@ +namespace Falu.Messages; + +/// +public class MessageError +{ + /// + /// A short machine-readable string giving the reason for message failure. + /// + public string? Code { get; set; } + + /// + /// A human-readable message that explains the reason for message failure. + /// These message can be shown to your user. + /// + public string? Message { get; set; } +} diff --git a/src/FaluSdk/Messages/MessageProvider.cs b/src/FaluSdk/Messages/MessageProvider.cs deleted file mode 100644 index d7a3d372..00000000 --- a/src/FaluSdk/Messages/MessageProvider.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Falu.Messages; - -/// -/// Details about the provider used to send a message. -/// -public class MessageProvider -{ - /// - /// Unique identifier for the request as provided by the provider. - /// - [JsonPropertyName("request_id")] - public string? RequestId { get; set; } - - /// - /// The error message from the provider. - /// - public string? Error { get; set; } -} diff --git a/src/FaluSdk/Messages/MessagesServiceClient.cs b/src/FaluSdk/Messages/MessagesServiceClient.cs index 39be5453..281d85ca 100644 --- a/src/FaluSdk/Messages/MessagesServiceClient.cs +++ b/src/FaluSdk/Messages/MessagesServiceClient.cs @@ -7,6 +7,7 @@ namespace Falu.Messages; public class MessagesServiceClient : BaseServiceClient, ISupportsListing, ISupportsRetrieving, + //ISupportsCreation, ISupportsUpdating, ISupportsCanceling, ISupportsRedaction @@ -49,14 +50,14 @@ public virtual Task> GetAsync(string id, return GetResourceAsync(id, options, cancellationToken); } - /// Send a message. + /// Create a message. /// /// Options to use for the request. /// /// - public virtual Task> SendAsync(MessageCreateRequest message, - RequestOptions? options = null, - CancellationToken cancellationToken = default) + public virtual Task> CreateAsync(MessageCreateRequest message, + RequestOptions? options = null, + CancellationToken cancellationToken = default) { if (message is null) throw new ArgumentNullException(nameof(message)); message.Template?.Model?.GetType().EnsureAllowedForMessageTemplateModel(); @@ -64,6 +65,19 @@ public virtual Task> SendAsync(MessageCr return CreateResourceAsync(message, options, cancellationToken); } + /// Send a message. + /// + /// Options to use for the request. + /// + /// + [Obsolete("Use 'CreateAsync(...)' instead.")] + public virtual Task> SendAsync(MessageCreateRequest message, + RequestOptions? options = null, + CancellationToken cancellationToken = default) + { + return CreateAsync(message, options, cancellationToken); + } + /// Update a message. /// Unique identifier for the message. /// diff --git a/src/FaluSdk/Webhooks/EventTypes.cs b/src/FaluSdk/Webhooks/EventTypes.cs index fee04bed..0a6bfd31 100644 --- a/src/FaluSdk/Webhooks/EventTypes.cs +++ b/src/FaluSdk/Webhooks/EventTypes.cs @@ -3,7 +3,7 @@ /// public static class EventTypes { - #region Evaluation + #region Evaluations /// /// Occurs whenever an evaluation is created. @@ -42,7 +42,7 @@ public static class EventTypes #endregion - #region IdentityVerifications + #region Identity Verifications /// /// Occurs whenever an identity verification is created. @@ -135,7 +135,7 @@ public static class EventTypes #endregion - #region MessageTemplates + #region Message Templates /// /// Occurs whenever a message template is created. @@ -182,7 +182,7 @@ public static class EventTypes #endregion - #region PaymentAuthorizations + #region Payment Authorizations /// /// Occurs whenever a payment authorization is requested. @@ -201,7 +201,7 @@ public static class EventTypes #endregion - #region PaymentRefunds + #region Payment Refunds /// /// Occurs whenever a payment refund is created. @@ -249,7 +249,7 @@ public static class EventTypes #endregion - #region TransferReversals + #region Transfer Reversals /// /// Occurs whenever a transfer reversal is created. diff --git a/tests/FaluSdk.Tests/Clients/MessagesServiceClientTests.cs b/tests/FaluSdk.Tests/Clients/MessagesServiceClientTests.cs index fa6f5e65..519566a5 100644 --- a/tests/FaluSdk.Tests/Clients/MessagesServiceClientTests.cs +++ b/tests/FaluSdk.Tests/Clients/MessagesServiceClientTests.cs @@ -92,7 +92,7 @@ await TestAsync(handler, async (client) => [Theory] [MemberData(nameof(RequestOptionsData))] - public async Task SendAsync_Works(RequestOptions options) + public async Task CreateAsync_Works(RequestOptions options) { var handler = CreateAsync_Handler(options); @@ -103,7 +103,7 @@ await TestAsync(handler, async (client) => To = new[] { Data!.To!, }, Body = Data!.Body }; - var response = await client.Messages.SendAsync(model, options); + var response = await client.Messages.CreateAsync(model, options); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotNull(response.Resource);