WayForPayCore 1.0.0

dotnet add package WayForPayCore --version 1.0.0
                    
NuGet\Install-Package WayForPayCore -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WayForPayCore" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WayForPayCore" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="WayForPayCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WayForPayCore --version 1.0.0
                    
#r "nuget: WayForPayCore, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WayForPayCore@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WayForPayCore&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=WayForPayCore&version=1.0.0
                    
Install as a Cake Tool

WayForPayCore

is a .NET Core library for integrating with the WayForPay payment system in ASP.NET Core MVC applications.

Getting Started

Configuration

Configure WayForPay settings using environment variables or in appsettings.json:

{
  "WayForPay": {
	"MerchantAccount": "your_account_name",
	"MerchantDomainName": "your.domain",
	"SecretKey": "YourVerySecreyKey",
	"ServiceUrl": "/payment/gate"
  }
}

Register the library:<br> Program.cs:

var builder = WebApplication.CreateBuilder(args);
builder.Services.Configure<MerchantSettings>(builder.Configuration.GetSection("WayForPay"));
builder.Services.AddWayForPay();

Create a PaymentController to handle payments<br>

Controllers/PaymentController.cs:

public class PaymentController : WayForPayController
{
private readonly ExampleDbContext _dbContext;

    public PaymentController(ExampleDbContext dbContext, IWfpRequestsHandler wfpRequestsHandler, IWfpPurchaseService purchaseService) 
        : base(wfpRequestsHandler, purchaseService)
    {
        _dbContext = dbContext;
    }

    [HttpPost]
    public async Task<IActionResult> Pay(Order order)
    {
        // Create Request settings
        PurchaseRequestSettings rs = 
            //Required Fields
            new(
                amount: amount, 
                currency: "EUR",
                productName: [order.Product.Name],
                productPrice: [order.Product.Price],
                productCount: [order.Quantity]
            ) 
            //Optional Fields
            {
                OrderReference = 
                ClientFirstName = order.User.Name,
                ClientEmail = order.User.Email
            };
        
        return RedirectToPayment(rs, new RedirectionPageSettings() {
            Title = "Example Store - Redirecting to payment page...",
            VisibleContent = "<p>Change it if you want.</p>"
        });
    }

    public override async Task<GateRequestResult> MerchantServiceEndpoint(GateRequestBody requestBody)
    {
        // Handle the request
        if (requestBody.TransactionStatus == "Approved") 
        {
            var order = _dbContext.Orders.First(o => o.Id == Convert.ToInt32(requestBody.OrderReference));
            order.Paid = true;
            await _dbContext.SaveChangesAsync();
        }
        if (requestBody.TransactionStatus == "Refunded") 
        {
            var order = _dbContext.Orders.First(o => o.Id == Convert.ToInt32(requestBody.OrderReference));
            order.Paid = false;
            await _dbContext.SaveChangesAsync();
        }
        // If not returned, WayForPay will try to send this request until it gets the correct response 
        return GateAccept(requestBody);
    }
}

Usage

Send a POST request to /Pay with order details to initiate payment. WayForPay will handle the payment and notify your service via MerchantServiceEndpoint. See the full usage in Examples

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.0 181 2/22/2025