Egov.Integrations.MPay.Soap
10.0.2
Prefix Reserved
dotnet add package Egov.Integrations.MPay.Soap --version 10.0.2
NuGet\Install-Package Egov.Integrations.MPay.Soap -Version 10.0.2
<PackageReference Include="Egov.Integrations.MPay.Soap" Version="10.0.2" />
<PackageVersion Include="Egov.Integrations.MPay.Soap" Version="10.0.2" />
<PackageReference Include="Egov.Integrations.MPay.Soap" />
paket add Egov.Integrations.MPay.Soap --version 10.0.2
#r "nuget: Egov.Integrations.MPay.Soap, 10.0.2"
#:package Egov.Integrations.MPay.Soap@10.0.2
#addin nuget:?package=Egov.Integrations.MPay.Soap&version=10.0.2
#tool nuget:?package=Egov.Integrations.MPay.Soap&version=10.0.2
Egov.Integrations.MPay.Soap
A .NET library that helps service providers integrate with MPay, the eGov payment service, using the SOAP protocol. It is built for ASP.NET Core 10.0+ applications and takes care of the protocol plumbing: it verifies the signature of incoming MPay requests, signs your responses, and builds the redirect addresses that send a payer to MPay.
Table of Contents
- How It Works
- Prerequisites
- Installation
- Configuration
- Usage
- Error Handling
- Migrating from Age.Integrations.MPay.Soap
- Testing
- Contributing
- Code of Conduct
- AI Assistance
- License
How It Works
- Your application sends the payer to MPay with a redirect address built by
IMPayClient. - MPay calls your SOAP endpoint (mapped with
MapMPaySoap) to read the order (GetOrderDetails) and, after the payment, to confirm it (ConfirmOrderPayment). - The library validates the WS-Security signature and timestamp of every request against the MPay certificate, calls your
IMPayServiceProvider, and signs the response with your service certificate.
A GET on the endpoint returns the WSDL of the service.
Prerequisites
- .NET 10.0 or later
- A service certificate (with private key) registered in MPay
- The public certificate of MPay (
.cer)
Installation
Install the package from NuGet:
dotnet add package Egov.Integrations.MPay.Soap
Or via the Package Manager Console:
Install-Package Egov.Integrations.MPay.Soap
Note: This package depends on Egov.Extensions.Configuration for certificate loading.
Configuration
Add the following section to your appsettings.json:
{
"MPay": {
"ServiceCertificatePath": "Files/Certificates/service-provider.pfx",
"ServiceCertificatePassword": "your-certificate-password",
"MPayCertificatePath": "Files/Certificates/mpay.cer",
"ServiceRootUrl": "https://service.example.md",
"MPayRootUrl": "https://testmpay.gov.md"
}
}
| Option | Required | Description |
|---|---|---|
ServiceCertificatePath / ServiceCertificatePassword |
Yes* | Your service certificate with its private key, used to sign responses. |
MPayCertificatePath |
Yes | The MPay public certificate, used to validate request signatures. |
ServiceRootUrl |
Yes | The public root URL of your application. Also used to resolve relative return URLs and to write the endpoint address in the WSDL. |
MPayRootUrl |
For redirects | The root URL of MPay. Only needed to build redirect addresses. |
MessageTimeToLive |
No | Lifetime of the timestamp on signed messages. Default: 5 minutes. |
AllowedClockSkew |
No | Clock skew tolerated when checking request timestamps. Default: 10 minutes. |
* Not needed when you use the shared system certificate (see below). ServiceCertificate and MPayCertificate can also be assigned directly as X509Certificate2 objects.
To reuse the shared system certificate from Egov.Extensions.Configuration as the service certificate, register it and pass useDefaultServiceProviderCertificate: true:
builder.Services.AddSystemCertificate(builder.Configuration.GetSection("Certificate"));
builder.Services.AddMPaySoap<MyServiceProvider>(builder.Configuration.GetSection("MPay"), useDefaultServiceProviderCertificate: true);
Usage
1. Implement the Service Provider
Implement IMPayServiceProvider. It is resolved per request, so it can use scoped services such as a DbContext.
public class MyServiceProvider : IMPayServiceProvider
{
public const string ServiceId = "12345";
public Task<IList<OrderDetails>> GetOrderDetails(OrderDetailsQuery query)
{
// Look the order up by query.ServiceID / query.OrderKey. Return an empty list when it does not exist.
IList<OrderDetails> orders =
[
new OrderDetails
{
ServiceID = ServiceId,
OrderKey = query.OrderKey,
Currency = CurrencyCode.MDL,
Status = OrderStatus.Active,
TotalAmountDue = 100m,
Lines = [new OrderLine { LineID = "1", AmountDue = 100m }]
}
];
return Task.FromResult(orders);
}
public Task ConfirmOrderPayment(PaymentConfirmation confirmation, string signedConfirmation)
{
// Validate the confirmation and mark the order as paid. Throw to reject it.
// Store signedConfirmation (the original signed SOAP request) as proof of payment,
// in the same transaction that updates the order.
return Task.CompletedTask;
}
}
Throwing from either method makes the library answer MPay with a SOAP fault carrying the exception message.
2. Register and Map the Endpoint
builder.Services.AddMPaySoap<MyServiceProvider>(builder.Configuration.GetSection("MPay"));
var app = builder.Build();
app.MapMPaySoap("/api/ServiceProvider.svc");
Give MPay the full address of this endpoint (ServiceRootUrl + the pattern above) when registering your service.
3. Redirect the Payer to MPay
Inject IMPayClient:
// One order. The return URL is optional and relative to ServiceRootUrl.
var address = mpayClient.BuildRedirectAddress(MyServiceProvider.ServiceId, orderKey, "payments/done");
return Redirect(address);
To pay several orders at once, exactly one of them must be the main order:
var address = mpayClient.BuildMultipleOrdersRedirectAddress(new MultipleOrdersDetails
{
Orders =
[
new SingleOrderDetails { ServiceID = "12345", OrderKey = "ORDER-1", IsMainOrder = true },
new SingleOrderDetails { ServiceID = "67890", OrderKey = "ORDER-2" }
],
ReturnUrl = "payments/done"
}, isRelativeUrl: true);
Error Handling
| Exception | Scenario |
|---|---|
ArgumentNullException |
serviceID or orderKey is blank in BuildRedirectAddress |
ApplicationException |
MPayRootUrl is not configured, or the multiple-orders model is invalid (no orders, not exactly one main order, ServiceID not 5 characters, OrderKey longer than 36 characters or containing disallowed characters) |
ApplicationException (at startup) |
A certificate path or password is invalid, or ServiceRootUrl is missing |
Failures while handling an MPay request (invalid signature, expired timestamp, unknown action, exception in your provider) are returned to MPay as a SOAP 1.1 fault with HTTP status 500.
Migrating from Age.Integrations.MPay.Soap
| Before | Now | |
|---|---|---|
| Package | Age.Integrations.MPay.Soap |
Egov.Integrations.MPay.Soap |
| Namespace | Age.Integrations.MPay.Soap |
Egov.Integrations.MPay.Soap |
| Configuration package | Age.Extensions.Configuration |
Egov.Extensions.Configuration |
| Target framework | .NET 8 | .NET 10 |
Update the package reference and the using directives; the registration API (AddMPaySoap, MapMPaySoap) and the wire protocol are unchanged. Other differences to be aware of:
- Nullable reference types are enabled. Mandatory text and list members of the model classes (for example
OrderDetails.OrderKey,OrderDetails.Lines) are nowrequired, so the compiler tells you when one is left unset. MPaySoapOptionscertificate and URL properties are nullable; they are validated when the options are first used.- Multiple-orders validation no longer depends on
Newtonsoft.Json.Schema(its free tier limits validations per hour). The same rules are enforced and the redirect payload is serialised withSystem.Text.Json; the resulting JSON is unchanged. - Signing no longer fails when
MessageTimeToLiveisTimeSpan.Zero.
Testing
dotnet test src/Egov.Integrations.MPay.Soap.sln
The Egov.Integrations.MPay.Soap.Tests project covers redirect-address building, certificate loading, signature creation and validation, and the full SOAP pipeline (signed request in, provider call, signed response out). Tests generate throwaway certificates at run time.
The src/Test project is a runnable sample application. Its Files/Certificates/ServiceProviderSampleCertificate.pfx is a self-signed sample and must never be used outside local experiments.
Contributing
Contributions are welcome! Please read CONTRIBUTING.md for guidelines on how to get started.
Code of Conduct
This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code.
AI Assistance
This repository contains an AGENTS.md file with instructions and context for AI coding agents to assist in development, ensuring consistency in code style and project structure.
License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Egov.Extensions.Configuration (>= 10.0.5)
- System.Security.Cryptography.Xml (>= 10.0.14)
- System.ServiceModel.Primitives (>= 10.0.652802)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.