PaymentRequired 1.0.1
Prefix ReservedSee the version list below for details.
dotnet add package PaymentRequired --version 1.0.1
NuGet\Install-Package PaymentRequired -Version 1.0.1
<PackageReference Include="PaymentRequired" Version="1.0.1" />
paket add PaymentRequired --version 1.0.1
#r "nuget: PaymentRequired, 1.0.1"
// Install PaymentRequired as a Cake Addin #addin nuget:?package=PaymentRequired&version=1.0.1 // Install PaymentRequired as a Cake Tool #tool nuget:?package=PaymentRequired&version=1.0.1
Payment Required
This library intend to add a simple interface to your API, if a client of a Software-as-a-Service (SaaS) has their payments in order.
A middleware component is added to the middleware pipeline, and is injected with a instance of an object that implements IPaymentRequiredValidator with your "business rules" validation.
The response of the API will be either the result of the service if everything is OK, or a ProblemDetails with the description of the exception.
Configuration
1- Create an class that implements IPaymentRequiredValidator
public sealed class NoPaymentIsRequiredValidator : IPaymentRequiredValidator
{
private readonly PaymentRequiredResponse _paymentRequiredResponse;
public NoPaymentIsRequiredValidator()
{
this._paymentRequiredResponse = new NoPaymentIsRequiredResponseNullObject();
}
public bool IsPaymentRequired()
{
return _paymentRequiredResponse.IsPaymentRequired;
}
public PaymentRequiredResponse ValidatePaymentRequired(HttpContext context)
{
// implement your own business logic
// ...
return _paymentRequiredResponse;
}
}
2- Add IPaymentRequiredValidator to Dependency Injection Container
We need to inject IPaymentRequiredValidator, one of the PaymentRequiredMiddleware dependencies.
// ... previous application configurations and dependencies
builder.Services.AddScoped<IPaymentRequiredValidator, NoPaymentIsRequiredValidator>();
// ... even more application configurations.
3- Add PaymentRequiredMiddleware to middleware pipeline
Add PaymentRequiredMiddleware into the pipeline, between UseAuthentication and UseAuthorization. You need to identify your "client" in order to verify if payment is due or not.
app.UseAuthentication();
app.UseMiddleware<PaymentRequiredMiddleware>();
app.UseAuthorization();
Credits
- @masterzdran
Attribution
Payment method icons created by Freepik - Flaticon
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.0 | 194 | 7/19/2023 |
1.0.2-alpha.7cd82a8d29cc601... | 308 | 4/3/2023 |
1.0.1 | 423 | 7/1/2022 |
1.0.1-alpha.ba645cef278cf4d... | 139 | 7/5/2022 |