Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webhook code sample to example project #395

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading