Skip to content

Commit

Permalink
Add PaymentLink create page
Browse files Browse the repository at this point in the history
  • Loading branch information
Viincenttt committed Jul 22, 2024
1 parent 9521ad0 commit ceea632
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations;
using Mollie.Api.Models;
using Mollie.WebApplication.Blazor.Framework.Validators;

namespace Mollie.WebApplication.Blazor.Models.PaymentLink;

public class CreatePaymentLinkModel {
[Required]
[Range(0.01, 1000, ErrorMessage = "Please enter an amount between 0.01 and 1000")]
[DecimalPlaces(2)]
public required decimal Amount { get; set; }

[Required]
[StaticStringList(typeof(Currency))]
public required string Currency { get; set; }

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

[Required]
[Url]
public string? RedirectUrl { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
@page "/paymentlink/create"

@using Mollie.Api.Client
@using Mollie.Api.Models.PaymentLink.Request
@using Mollie.WebApplication.Blazor.Models.PaymentLink

@inject IPaymentLinkClient PaymentLinkClient
@inject NavigationManager NavigationManager

<h3>Create new payment link</h3>

<ApiExceptionDisplay Exception="_apiException"></ApiExceptionDisplay>

<EditForm Model="_model" OnValidSubmit="@OnSave" class="col-md-6">
<DataAnnotationsValidator />
<ValidationSummary />

<div class="form-group">
<label for="amount">Amount</label>
<InputNumber
id="amount"
class="form-control"
@bind-Value="_model.Amount">
</InputNumber>
</div>

<div class="form-group">
<label for="currency">Currency</label>
<InputSelect
id="currency"
class="form-control"
@bind-Value="_model.Currency">
@foreach (string currency in StaticStringListBuilder.GetStaticStringList(typeof(Currency))) {
<option value="@currency">@currency</option>
}
</InputSelect>
</div>

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

<div class="form-group">
<label for="description">Description</label>
<InputText
id="description"
class="form-control"
@bind-Value="_model.Description">
</InputText>
</div>

<input type="submit" name="Save" value="Save" class="btn btn-primary mt-2"/>
</EditForm>

@code {
private MollieApiException? _apiException;

private CreatePaymentLinkModel _model = new() {
Amount = 10.00m,
Currency = "EUR",
RedirectUrl = "https://www.mollie.com/",
Description = "A payment from the example application"
};

private async Task OnSave() {
try {
_apiException = null;

await PaymentLinkClient.CreatePaymentLinkAsync(new PaymentLinkRequest {
Amount = new Amount(_model.Currency, _model.Amount),
RedirectUrl = _model.RedirectUrl,
Description = _model.Description
});

NavigationManager.NavigateTo("/paymentlink/overview");
}
catch (MollieApiException e) {
_apiException = e;
}
}
}

0 comments on commit ceea632

Please sign in to comment.