An implementation of the SaferPay.Net library, updated to target .NET 8.0 / .NET 10.0 and to use RestSharp instead of HttpClient. Every method is available in both sync and async form.
It tracks the JSON API v1.52 (reference). Test cards and usage are documented on the SaferPay integration guide.
- Multi-targets
.NET 8.0and.NET 10.0 HttpClientreplaced byRestSharp- Tracks the latest JSON API,
v1.52 BaseUrireplaced by aSandBoxflag (the base URL is derived from it)- Simpler constructors and property descriptions taken from the API docs
- String properties converted to enums
- Interface channels and extension methods for the most common calls
IsSuccessandErroron every result object- Example console app included in the solution
- Payment Page:
Initialize,Assert - Transaction:
Initialize,Authorize,QueryPaymentMeans,AdjustAmount,AuthorizeDirect,AuthorizeReferenced,Capture,MultipartCapture,AssertCapture,MultipartFinalize,Refund,AssertRefund,RefundDirect,Cancel,RedirectPayment,AssertRedirectPayment,Inquire,AlternativePayment,QueryAlternativePayment,DccInquiry - Secure Card Data:
Insert,AssertInsert,InsertDirect,Update,Delete,Inquire - Batch:
Close - Omni Channel:
InsertAlias,AcquireTransaction - Management API:
Licensing CustomerLicense,PaymentPageConfig GetConfigurations,SaferpayFieldsAccessToken CreateAccessToken,SaferpayFieldsAccessToken DeleteAccessToken,SecurePayGate Create/Get/Delete SingleUsePaymentLink,Terminal GetTerminal,Terminals GetTerminals,TransactionReporting GetTransactions
Either configure the global settings and pull a client from them:
SaferPay.Config.Settings.Default.CustomerId = "CustomerId";
SaferPay.Config.Settings.Default.TerminalId = "TerminalId";
SaferPay.Config.Settings.Default.Username = "ApiUserName";
SaferPay.Config.Settings.Default.Password = "ApiPassword";
SaferPay.Config.Settings.Default.SandBox = true;
ISaferPayClient client = SaferPay.Config.Settings.Client();Or build one directly:
ISaferPayClient client = new SaferPayClient("CustomerId", "TerminalId", "UserName", "Password", sandBox: true);string orderId = "123456";
var request = new InitializePaymentPageRequest
{
TerminalId = TestConfig.TerminalId,
Payment = new Payment(123.45M, "TRY", orderId),
ReturnUrl = $"{TestConfig.WebPage}payment-page?orderId={orderId}",
};var result = await client.InitializePaymentPageAsync(request);
// sync equivalent:
// var result = client.InitializePaymentPage(request);Every call returns a result exposing IsSuccess, the typed response and an Error object:
if (result != null && result.IsSuccess) {
Console.WriteLine(result.Json()); // success
}
else if (result != null) {
Console.WriteLine(result.Error.Json()); // API returned an error
}
else {
Console.WriteLine("Request failed."); // null / transport error
}Each API group is also reachable as a typed channel on the client, which keeps related calls together:
ITransaction transaction = client.Transaction;
var request = new InitializeRequest(
TestConfig.TerminalId, 123.45M, "TRY", orderId,
$"{TestConfig.WebPage}transaction?orderId={orderId}")
.SetCard("9010004150000009", 12, 30, "123", "Card Holder Name");
var result = await transaction.InitializeAsync(request);
// sync: transaction.Initialize(request);The result is handled exactly as shown in step 4.
The solution ships two test projects at the repository root:
-
SaferPay.Tests: automated xUnit suite (Unit+ sandboxIntegration). Run it with:dotnet test SaferPay.Tests/SaferPay.Tests.csprojIntegration tests hit
test.saferpay.comwith the public Viwo sandbox account by default. Override it with theSAFERPAY_CUSTOMER_ID,SAFERPAY_TERMINAL_ID,SAFERPAY_USERNAMEandSAFERPAY_PASSWORDenvironment variables, or setSAFERPAY_SKIP_INTEGRATION=1for a fully offline run. -
SaferPay.Test: interactive console playground that demonstrates the API end to end. SeeSaferPay.Test/README.md.
See CHANGELOG.md for the full version history.