Skip to content

Commit

Permalink
Improve payment request success URL parsing. (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
sipsorcery authored Nov 13, 2024
1 parent 71da120 commit e966d6c
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/NoFrixion.MoneyMoov/Models/PaymentRequests/PaymentRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

using System.ComponentModel.DataAnnotations;
using NoFrixion.MoneyMoov.Extensions;
using LanguageExt;

namespace NoFrixion.MoneyMoov.Models;

Expand Down Expand Up @@ -375,23 +376,30 @@ public bool HasWebHook()
return !string.IsNullOrEmpty(SuccessWebHookUrl);
}

public Uri GetSuccessWebhookUri()
public Either<NoFrixionProblem, Uri> GetSuccessWebhookUri()
{
if (string.IsNullOrEmpty(SuccessWebHookUrl))
if (string.IsNullOrWhiteSpace(SuccessWebHookUrl))
{
return new Uri(MoneyMoovConstants.WEBHOOK_BLACKHOLE_URI);
}
else
{
var successWebHookUri = new UriBuilder(SuccessWebHookUrl);

string successParams = $"id={ID}&orderid={OrderID ?? string.Empty}";

successWebHookUri.Query = string.IsNullOrEmpty(successWebHookUri.Query)
? successParams
: successWebHookUri.Query + "&" + successParams;

return successWebHookUri.Uri;
if (Uri.TryCreate(SuccessWebHookUrl, UriKind.Absolute, out Uri? uri))
{
var successWebHookUri = new UriBuilder(uri);

string successParams = $"id={ID}&orderid={OrderID ?? string.Empty}";

successWebHookUri.Query = string.IsNullOrEmpty(successWebHookUri.Query)
? successParams
: successWebHookUri.Query + "&" + successParams;

return successWebHookUri.Uri;
}
else
{
return new NoFrixionProblem($"The success web hook URL {SuccessWebHookUrl} for payment request ID {ID} is not a valid URL.");
}
}
}

Expand Down

0 comments on commit e966d6c

Please sign in to comment.