Skip to content

Commit

Permalink
Updates 2021 07 14 (#7)
Browse files Browse the repository at this point in the history
* Use explicit names in MultipartFormDataContent for evaluation creation

* Update event for payment balances

* Added AmountOutOfBound to *FailureReason enums

* Added PaymentId to PaymentAuthorization and AuthorizationId to Payment

* Simplify use of EnumMemberAttribute value or the default value

* Check that Scope, Provider and Name are provided when creating evaluation

* Phone and Password should only be added if they are not null

* Use explicit naming for description, tags and metadata in MultipartFormDataContent when creating evaluations

* Replace balance.updated -> payment_balances.updated

* Added src/Directory.Build.props

* Added Directory.Build.targets

* Deprecate Tags in favour of Metadata
  • Loading branch information
mburumaxwell authored Jul 14, 2021
1 parent 5260614 commit e59c3be
Show file tree
Hide file tree
Showing 27 changed files with 149 additions and 57 deletions.
18 changes: 18 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>
<!-- Leave this file here, even if it's empty. It stops chaining imports. -->

<!-- In Directory.Build.targets because default items are added after Directory.Build.props is imported, causing invalid duplicate entries. -->
<ItemGroup Condition="Exists( '$(MSBuildProjectDirectory)\Properties\Resources.resx' )">
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>

<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
34 changes: 34 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project>
<!-- Chain up to the next file (can be copy-pasted to either Directory.Build.props or Directory.Build.targets) -->
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., '$(MSBuildThisFileName)$(MSBuildThisFileExtension)'))\$(MSBuildThisFileName)$(MSBuildThisFileExtension)" />

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Deterministic>true</Deterministic>
<Company>Tingle Software Limited</Company>
<!--<IsPackable>true</IsPackable>-->
</PropertyGroup>

<PropertyGroup>
<!-- Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>

<!-- Embed source files that are not tracked by the source control manager in the PDB -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>

<!-- Build symbol package (.snupkg) to distribute the PDB containing Source Link -->
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<PropertyGroup>
<VersionPrefix Condition="'$(GITVERSION_NUGETVERSION)' != ''">$(GITVERSION_NUGETVERSION)</VersionPrefix>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

</Project>
17 changes: 2 additions & 15 deletions src/Falu/Core/BasicListOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace Falu.Core
{
Expand Down Expand Up @@ -58,19 +57,7 @@ internal virtual IDictionary<string, string> PopulateQueryValues(IDictionary<str
internal static string ConvertDate(DateTimeOffset d) => d.ToString("o");
internal static string ConvertInt32(int i) => i.ToString();
internal static string ConvertInt64(long i) => i.ToString();
internal static string ConvertEnum<T>(T e) where T : Enum
{
// Give priority to EnumMemberAttribute
var memInfo = typeof(T).GetMember(e.ToString());
var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false)
.OfType<EnumMemberAttribute>()
.FirstOrDefault();

return attr?.Value ?? e.ToString().ToLowerInvariant();
}
internal static string ConvertEnumList<T>(IList<T> list) where T : Enum
{
return string.Join(",", list.Select(l => ConvertEnum(l)));
}
internal static string ConvertEnum<T>(T e) where T : Enum => e.GetEnumMemberAttrValueOrDefault();
internal static string ConvertEnumList<T>(IList<T> list) where T : Enum => string.Join(",", list.Select(l => ConvertEnum(l)));
}
}
1 change: 1 addition & 0 deletions src/Falu/Core/IHasTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface IHasTags
/// <summary>
/// Set of values that you can attach to an object. This can be useful for searching.
/// </summary>
[System.Obsolete(MessageStrings.TagsDeprecated)]
public List<string>? Tags { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Falu/Evaluations/EvaluationPatchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class EvaluationPatchModel : IHasDescription, IHasMetadata, IHasTags
public Dictionary<string, string>? Metadata { get; set; }

/// <inheritdoc/>
[System.Obsolete(MessageStrings.TagsDeprecated)]
public List<string>? Tags { get; set; }
}
}
40 changes: 29 additions & 11 deletions src/Falu/Evaluations/EvaluationsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,45 +84,63 @@ public virtual async Task<ResourceResponse<Evaluation>> CreateAsync(EvaluationCr
CancellationToken cancellationToken = default)
{
if (evaluation is null) throw new ArgumentNullException(nameof(evaluation));
if (evaluation.Scope is null) throw new InvalidOperationException($"{nameof(evaluation.Scope)} cannot be null.");
if (evaluation.Provider is null) throw new InvalidOperationException($"{nameof(evaluation.Provider)} cannot be null.");
if (string.IsNullOrWhiteSpace(evaluation.Name))
{
throw new InvalidOperationException($"{nameof(evaluation.Name)} cannot be null or whitespace.");
}

var content = new MultipartFormDataContent
{
// populate fields of the model as key value pairs
{ new StringContent(evaluation.Currency), nameof(evaluation.Currency) },
{ new StringContent(evaluation.Scope.ToString()), nameof(evaluation.Scope) },
{ new StringContent(evaluation.Provider.ToString()), nameof(evaluation.Provider) },
{ new StringContent(evaluation.Name), nameof(evaluation.Name) },
{ new StringContent(evaluation.Phone), nameof(evaluation.Phone) },
{ new StringContent(evaluation.Password), nameof(evaluation.Password) },
{ new StringContent(evaluation.Currency), "currency" },
{ new StringContent(evaluation.Scope?.GetEnumMemberAttrValueOrDefault()), "scope" },
{ new StringContent(evaluation.Provider?.GetEnumMemberAttrValueOrDefault()), "provider" },
{ new StringContent(evaluation.Name), "name" },

// populate the file stream
{ new StreamContent(evaluation.Content), "File", evaluation.FileName },
{ new StreamContent(evaluation.Content), "file", evaluation.FileName },
};

// Add phone if provided
if (!string.IsNullOrWhiteSpace(evaluation.Phone))
{
content.Add(new StringContent(evaluation.Phone), "phone");
}

// Add password if provided
if (!string.IsNullOrWhiteSpace(evaluation.Password))
{
content.Add(new StringContent(evaluation.Password), "password");
}

// Add description if provided
if (!string.IsNullOrWhiteSpace(evaluation.Description))
{
content.Add(new StringContent(evaluation.Description), nameof(evaluation.Description));
content.Add(new StringContent(evaluation.Description), "description");
}

// Add tags if provided
#pragma warning disable CS0618 // Type or member is obsolete
var tags = evaluation.Tags;
if (tags != null)
{
for (var i = 0; i < tags.Count; i++)
{
content.Add(new StringContent(tags[i]), $"{nameof(evaluation.Tags)}[{i}]");
content.Add(new StringContent(tags[i]), $"tags[{i}]");
}
}
#pragma warning restore CS0618 // Type or member is obsolete

// Add metadata if provided
var metadata = evaluation.Metadata?.ToList();
if (metadata != null)
{
for (var i = 0; i < metadata.Count; i++)
{
content.Add(new StringContent(metadata[i].Key), $"{nameof(evaluation.Metadata)}[{i}].Key");
content.Add(new StringContent(metadata[i].Value), $"{nameof(evaluation.Metadata)}[{i}].Value");
content.Add(new StringContent(metadata[i].Key), $"metadata[{i}].Key");
content.Add(new StringContent(metadata[i].Value), $"metadata[{i}].Value");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Falu/Events/WebhookEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class WebhookEvent<TObject> : IHasId, IHasCreated, IHasMetadata, IHasWork
public DateTimeOffset Created { get; set; }

/// <summary>
/// Type of event (e.g. payment.updated, balance.updated, etc.).
/// Type of event (e.g. payment.updated, payment_balances.updated, etc.).
/// Possible values are available in <see cref="Webhooks.EventTypes"/>.
/// </summary>
public string? Type { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Falu/Events/WebhookEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class WebhookEventData<TObject>
{
/// <summary>
/// Object containing the API resource relevant to the event.
/// For example, a <c>balance.updated</c> event will have a full balance object.
/// For example, a <c>payment_balances.updated</c> event will have a full balance object.
/// </summary>
public TObject? Object { get; set; }

Expand Down
18 changes: 18 additions & 0 deletions src/Falu/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Linq;
using System.Runtime.Serialization;

namespace System.Collections.Generic
{
internal static class EnumExtensions
{
public static string GetEnumMemberAttrValueOrDefault<T>(this T enumVal) where T : Enum
{
var memInfo = typeof(T).GetMember(enumVal.ToString());
var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false)
.OfType<EnumMemberAttribute>()
.FirstOrDefault();

return attr?.Value ?? enumVal.ToString().ToLowerInvariant();
}
}
}
27 changes: 0 additions & 27 deletions src/Falu/Falu.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Deterministic>true</Deterministic>
<!--<IsPackable>true</IsPackable>-->
<Description>The official client library for Falu. (https://falu.io)</Description>
<Company>Tingle Software Limited</Company>
<Authors>Tingle Software Limited</Authors>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,26 +14,4 @@
<PackageReference Include="Tingle.Extensions.JsonPatch" Version="3.4.2" />
</ItemGroup>

<PropertyGroup>
<!-- Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>

<!-- Embed source files that are not tracked by the source control manager in the PDB -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>

<!-- Build symbol package (.snupkg) to distribute the PDB containing Source Link -->
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<PropertyGroup>
<VersionPrefix Condition="'$(GITVERSION_NUGETVERSION)' != ''">$(GITVERSION_NUGETVERSION)</VersionPrefix>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/Falu/MessageStreams/MessageStreamPatchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class MessageStreamPatchModel : IHasDescription, IHasMetadata, IHasTags
public Dictionary<string, string>? Metadata { get; set; }

/// <inheritdoc/>
[System.Obsolete(MessageStrings.TagsDeprecated)]
public List<string>? Tags { get; set; }
}
}
7 changes: 7 additions & 0 deletions src/Falu/MessageStrings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Falu
{
internal class MessageStrings
{
public const string TagsDeprecated = "Tags have been deprecated and scheduled to be removed in a future API update. Migrate to using Metadata.";
}
}
1 change: 1 addition & 0 deletions src/Falu/MessageTemplates/MessageTemplatePatchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class MessageTemplatePatchModel : IHasDescription, IHasMetadata, IHasTags
public Dictionary<string, string>? Metadata { get; set; }

/// <inheritdoc/>
[System.Obsolete(MessageStrings.TagsDeprecated)]
public List<string>? Tags { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Falu/Messages/MessagePatchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class MessagePatchModel : IHasMetadata, IHasTags
public Dictionary<string, string>? Metadata { get; set; }

/// <inheritdoc/>
[System.Obsolete(MessageStrings.TagsDeprecated)]
public List<string>? Tags { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/Falu/PaymentAuthorizations/PaymentAuthorization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public class PaymentAuthorization : PaymentAuthorizationPatchModel, IHasId, IHas
/// </summary>
public PaymentMpesaDetails? Mpesa { get; set; }

/// <summary>
/// Identifier of the payment created after the authorization is approved and closed.
/// </summary>
public string? PaymentId { get; set; }

/// <inheritdoc/>
public string? WorkspaceId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class PaymentAuthorizationPatchModel : IHasMetadata, IHasTags
public Dictionary<string, string>? Metadata { get; set; }

/// <inheritdoc/>
[System.Obsolete(MessageStrings.TagsDeprecated)]
public List<string>? Tags { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Falu/PaymentReversals/PaymentReversalFailureReason.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public enum PaymentReversalFailureReason
[EnumMember(Value = "authentication_error")]
AuthenticationError,

///
[EnumMember(Value = "amount_out_of_bound")]
AmountOutOfBound,

///
Timeout,

Expand Down
1 change: 1 addition & 0 deletions src/Falu/PaymentReversals/PaymentReversalPatchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class PaymentReversalPatchModel : IHasDescription, IHasMetadata, IHasTags
public Dictionary<string, string>? Metadata { get; set; }

/// <inheritdoc/>
[System.Obsolete(MessageStrings.TagsDeprecated)]
public List<string>? Tags { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/Falu/Payments/Payment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class Payment : PaymentPatchModel, IHasId, IHasCurrency, IHasCreated, IHa
/// </summary>
public DateTimeOffset? Succeeded { get; set; }

/// <summary>
/// Identifier of the authorization, if the payment passed through a flow requiring authorization.
/// </summary>
public string? AuthorizationId { get; set; }

/// <summary>
/// The type of the Payment.
/// An additional property is populated on the Payment with a name matching this value.
Expand Down
4 changes: 4 additions & 0 deletions src/Falu/Payments/PaymentFailureReason.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public enum PaymentFailureReason
[EnumMember(Value = "authentication_error")]
AuthenticationError,

///
[EnumMember(Value = "amount_out_of_bound")]
AmountOutOfBound,

///
Timeout,

Expand Down
1 change: 1 addition & 0 deletions src/Falu/Payments/PaymentPatchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class PaymentPatchModel : IHasDescription, IHasMetadata, IHasTags
public Dictionary<string, string>? Metadata { get; set; }

/// <inheritdoc/>
[System.Obsolete(MessageStrings.TagsDeprecated)]
public List<string>? Tags { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Falu/TransferReversals/TransferReversalFailureReason.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public enum TransferReversalFailureReason
[EnumMember(Value = "authentication_error")]
AuthenticationError,

///
[EnumMember(Value = "amount_out_of_bound")]
AmountOutOfBound,

///
Timeout,

Expand Down
1 change: 1 addition & 0 deletions src/Falu/TransferReversals/TransferReversalPatchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class TransferReversalPatchModel : IHasDescription, IHasMetadata, IHasTag
public Dictionary<string, string>? Metadata { get; set; }

/// <inheritdoc/>
[System.Obsolete(MessageStrings.TagsDeprecated)]
public List<string>? Tags { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Falu/Transfers/TransferFailureReason.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public enum TransferFailureReason
[EnumMember(Value = "authentication_error")]
AuthenticationError,

///
[EnumMember(Value = "amount_out_of_bound")]
AmountOutOfBound,

///
Timeout,

Expand Down
1 change: 1 addition & 0 deletions src/Falu/Transfers/TransferPatchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class TransferPatchModel : IHasDescription, IHasMetadata, IHasTags
public Dictionary<string, string>? Metadata { get; set; }

/// <inheritdoc/>
[System.Obsolete(MessageStrings.TagsDeprecated)]
public List<string>? Tags { get; set; }
}
}
Loading

0 comments on commit e59c3be

Please sign in to comment.