-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9521ad0
commit ceea632
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
samples/Mollie.WebApplication.Blazor/Models/PaymentLink/CreatePaymentLinkModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
86 changes: 86 additions & 0 deletions
86
samples/Mollie.WebApplication.Blazor/Pages/PaymentLink/Create.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |