This repository is an implementation of the SaferPay.Net library, with updates to use .NetCore 8.0 and RestSharp instead of HttpClient. All methods have been extended with sync and async calls.
The implementation is based on the latest version of the JSON API, v1.52, which can be found at the following URL: http://saferpay.github.io/jsonapi/#ChapterTransaction
You can find Test Cards and explanation of usage at: https://docs.saferpay.com/home/integration-guide/testing-and-go-live#visa-and-v-pay
Create Test Account
https://test.saferpay.com/BO/SignUp
Login Test Account
https://test.saferpay.com/BO/Login
- Upgrade to
.NetCore 8.0 - HttpClient has been replaced by
RestSharp - Updated to use the latest version of the JSON API,
v1.52 - Replaced
BaseUriwithSandBoxmode. BaseUri is now generated based on SandBox mode for testing or live environments. - Updated and improved constructors for easier usage.
- Added descriptions to Properties based on the API documentation.
- Converted string properties to Enum values.
- Added Examples and Test Console App in the Solution.
- Added Interface Channels for ease of usage.
- Added Extensions for the most used methods for direct use in the client.
- Added
IsSuccessandErrorproperties in ResultObject. - Updated all enum values, models, and interfaces.
Implemented all methods:
- Payment Page Methods:
Initialize,Assert - Transaction Methods:
Initialize,Authorize,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 - Saferpay Management API:
Licensing CustomerLicense,PaymentPageConfig GetConfigurations,SaferpayFieldsAccessToken CreateAccessToken,SaferpayFieldsAccessToken DeleteAccessToken,SecurePayGate Create SingleUsePaymentLink,SecurePayGate SingleUsePaymentLink,SecurePayGate Delete SingleUsePaymentLink,Terminal GetTerminal,Terminals GetTerminals,TransactionReporting GetTransactions
Define Settings;
SaferPay.Config.Settings.Default.Username = "ApiUserName";
SaferPay.Config.Settings.Default.Password = "ApiPassword";
SaferPay.Config.Settings.Default.TerminalId = "TerminalId";
SaferPay.Config.Settings.Default.CustomerId = "CustomerId";
SaferPay.Config.Settings.Default.SandBox = true;Get Client Instance;
ISaferPayClient Client = SaferPay.Config.Settings.Client();Initialize request for Payment Page;
string OrderID = "123456";
InitializePaymentPageRequest req = new InitializePaymentPageRequest();
req.TerminalId = TestConfig.TerminalId;
req.Payment = new Payment(123.45M, "TRY", OrderID);
req.ReturnUrl = $"{TestConfig.WebPage}payment-page?orderId={OrderID}";Call Api Async;
var result = await Client.InitializePaymentPageAsync(req);
if (result != null && result.IsSuccess)
{
// Success
Console.Write("Response Successful : ");
Console.WriteLine(result.Json());
}
else if (result != null)
{
// Failed
Console.Write("Response Failed : ");
Console.WriteLine(result.Error.Json());
}
else
{
// Error
Console.Write("Error !");
}Call Api Sync;
var result = Client.InitializePaymentPage(req);
if (result != null && result.IsSuccess)
{
// Success
Console.Write("Response Successful : ");
Console.WriteLine(result.Json());
} else if(result != null)
{
// Failed
Console.Write("Response Failed : ");
Console.WriteLine(result.Error.Json());
} else
{
// Error
Console.Write("Error !");
}Initialize the ApiClient;
ISaferPayClient Client = new SaferPayClient("CustomerId", "TerminalId", "UserName", "PassWord", true);Get Interface Channel to use, example based on Transaction;
ITransaction payment = Client.Transaction;Created Credit Card request;
string OrderID = "123456";
InitializeRequest req = new InitializeRequest(TestConfig.TerminalId, 123.45M, "TRY", OrderID, $"{TestConfig.WebPage}transaction?orderId={OrderID}").SetCard("9010004150000009", 12, 30, "123", "Card Holder Name");Call Api Async;
var result = await payment.InitializeAsync(req);
if (result != null && result.IsSuccess)
{
// Success
Console.Write("Response Successful : ");
Console.WriteLine(result.Json());
}
else if (result != null)
{
// Failed
Console.Write("Response Failed : ");
Console.WriteLine(result.Error.Json());
}
else
{
// Error
Console.Write("Error !");
}Call Api Sync;
var result = payment.Initialize(req);
if (result != null && result.IsSuccess)
{
// Success
Console.Write("Response Successful : ");
Console.WriteLine(result.Json());
} else if(result != null)
{
// Failed
Console.Write("Response Failed : ");
Console.WriteLine(result.Error.Json());
} else
{
// Error
Console.Write("Error !");
}v1.52.01
- Updated library target framework to
.NET 8.0 - Removed unsupported
.NET 6.0and legacy test runtime targets - Improved overall package compatibility with current and future .NET runtimes
- Fixed recursive
Dispose()implementation causingStackOverflowException - Fixed missing
_jsonSerializerSettingsinitialization in the 4-argument constructor - Improved
RestClientlifecycle management to prevent socket/resource leaks under load - Fixed exception rethrow handling to preserve original stack traces
- Normalized
CreditCardExpirationyear handling across constructor, setters and parsing - Fixed
CreditCardExpiration.Parse()producing invalidMMYYYYvalues instead ofMMYY - Improved
CreditCardExpiration.ToString()formatting consistency - Updated package metadata and NuGet packaging configuration
- Improved GitHub Actions build, validation and NuGet publishing workflow
- Updated package validation and build pipeline for
.NET 8 - General reliability, maintainability and runtime compatibility improvements
v1.52
- Updated to use the latest version of the JSON API,
v1.52 - Added
Saferpay Management API. - Added
PaymentPage GetConfigurationsmethod to Saferpay Management API - Added
WITH_SUCCESSFUL_THREE_DS_CHALLENGEas a valid value for the field Condition - Added
MastercardTLIDto theIssuerReferencecontainer in the response - removed
PayerIdfrom thePayPalcontainer
v1.51
- Updated to use the latest version of the JSON API,
v1.51 - added
PAYPALas valid value for field Type inAlias/Insert - added
ONLINE_CHALLENGEDas valid value for field Type of containerCheckinAlias/Insert - removed
OK_AUTHENTICATEDas valid value from fieldResultof containerCheckResult. - removed
INVOICEas valid value fromPaymentMethodsinPaymentPage/Initialize - added fields
AuthenticatedandAuthenticationTypeto containerAuthenticationResult. Removed fieldResultfrom container in return. - added field
FundingSourceto containerCard - field
CountryCodein containerForeignRetaileris now mandatory.
v1.50
- Updated to use the latest version of the JSON API,
v1.50 - Added value
ONLINE_STRONGto Type in theCheckcontainer and added new containerExternalThreeDSinAlias/InsertDirect - Added
GIFTCARDas valid value for the fieldPaymentMethods - Introduced a new function to provide Dynamic Currency Conversion (
DCC) inquiry details for your customer:Transaction\DccInquiry - The payment methods
GIROPAY,PAYDIREKT,SOFORTandWLCRYPTOPAYMENTSare no longer supported. Transaction/AuthorizeDirectis extended with the new subcontainerDCC, which references the response fromTransaction/DccInquiryand payer's decision whether he accepts or declinesDCCoffer- Added
WEROas valid value for the fieldPaymentMethods - Added
HolderNameandIBANto the BankAccount container inPaymentPage/Assert Transaction/RefundDirectis extended with the new subcontainerBankAccount. This is a required container for PostFinance Instant Payout
v1.46
- Updated to use the latest version of the JSON API,
v1.46 - Added new subcontainer
ExternalThreeDSto containerAuthentication. This affects the following requests:Transaction/AuthorizeDirect - Updated
AuthorizeDirectmethod to use the newExternalThreeDSsubcontainer.
v1.45.01
- Added
REKAas alternative payment method toPaymentPagePaymentMethods.