Skip to content

Commit

Permalink
Add example controller to catch webhook requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Viincenttt committed Sep 1, 2024
1 parent 025090e commit 19ad4e6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
27 changes: 27 additions & 0 deletions samples/Mollie.WebApplication.Blazor/Api/PaymentController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using Mollie.Api.Client.Abstract;
using Mollie.Api.Models.Payment.Response;

namespace Mollie.WebApplication.Blazor.Api;

[ApiController]
[Route("api/payment")]
public class PaymentController : ControllerBase {
private readonly ILogger<PaymentController> _logger;
private readonly IPaymentClient _paymentClient;

public PaymentController(ILogger<PaymentController> logger, IPaymentClient paymentClient) {
_logger = logger;
_paymentClient = paymentClient;
}

[HttpPost]
public async Task<ActionResult> Webhook([FromForm] string id) {
PaymentResponse payment = await _paymentClient.GetPaymentAsync(id);
_logger.LogInformation("Webhook called for PaymentId={PaymentId}, PaymentStatus={Status}",
id,
payment.Status);

return Ok();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class CreatePaymentModel {
[Url]
public required string RedirectUrl { get; set; }

[Url]
public string? WebhookUrl { get; set; }

[Required]
public required string Description { get; set; }

Expand Down
11 changes: 11 additions & 0 deletions samples/Mollie.WebApplication.Blazor/Pages/Payment/Create.razor
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
</InputText>
</div>

<div class="form-group">
<label for="redirect-url">Webhook url</label>
<InputText
id="redirect-url"
class="form-control"
@bind-Value="_model.WebhookUrl">
</InputText>
</div>

<div class="form-group">
<label for="description">Description</label>
<InputText
Expand Down Expand Up @@ -100,6 +109,7 @@
Amount = 10.00m,
Currency = "EUR",
RedirectUrl = "https://www.mollie.com/",
WebhookUrl = null,
Description = "A payment from the example application",
SequenceType = SequenceType.OneOff
};
Expand All @@ -111,6 +121,7 @@
await PaymentClient.CreatePaymentAsync(new PaymentRequest {
Amount = new Amount(_model.Currency, _model.Amount),
RedirectUrl = _model.RedirectUrl,
WebhookUrl = _model.WebhookUrl,
Description = _model.Description,
CustomerId = _model.CustomerId,
SequenceType = _model.SequenceType,
Expand Down
2 changes: 1 addition & 1 deletion samples/Mollie.WebApplication.Blazor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
app.UseStaticFiles();

app.UseRouting();

app.MapControllers();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

Expand Down

0 comments on commit 19ad4e6

Please sign in to comment.