Requirements
.NET
You have the following options to choose from:
- .NET Core 2.0 or later
- .NET Framework 4.6.1 and later
- Mono 5.4+
- Xamarin.iOS 10.14+
- Xamarin.Mac 3.8+
- Xamarin.Android 8.0+
- Universal Windows Platform 10.0.16299+
- Unity 2018.1+
GitHub
Press here to view the solution uploaded in GitHub with the instructions for configuring the sample applications and unit tests project.
NuGet
Press here to view the NuGet dependencies.
Initializing the SDK
There are three ways to initialize the .NET SDK:
- Initialize a new instance of the SafeCharge wrapper with SafeCharge’s default value for
HttpClient
and default server information.var safecharge = new Safecharge( "<your merchantKey>", "<your merchantId>", "<your merchantSiteId>", "<your server host value>", HashAlgorithmType.SHA256);
- Initialize a new instance of the SafeCharge wrapper with default
Merchantinfo
data and SafeCharge’s default server information.var merchantInfo = new MerchantInfo( "<your merchantKey>", "<your merchantId>", "<your merchantSiteId>", "<your server host value>", HashAlgorithmType.SHA256); var safecharge = new Safecharge(merchantInfo);
- Initialize a new instance of the SafeCharge wrapper with
HttpClient
configured and with server information.var safecharge = new Safecharge( "<configured HttpClient>", new MerchantInfo( "<your merchantKey>", "<your merchantId>", "<your merchantSiteId>", "<your server host value>", HashAlgorithmType.SHA256));
Running Your First Request
You only need to set up a HTTP Client and to provide the SafeCharge API host to the request executor and then you can start building requests and send them to the SafeCharge API.
Sample Request
using System; using System.IO; using Microsoft.Extensions.Configuration; using Safecharge.Model; using Safecharge.Request; using Safecharge.Utils; using Safecharge.Utils.Enum; namespace Safecharge.Sample { class Program { static void Main() { var reqExecutor = new SafechargeRequestExecutor(); var merchantInfo = new MerchantInfo( "<your merchantKey>", "<your merchantId>", "<your merchantSiteId>", ApiConstants.IntegrationHost, HashAlgorithmType.SHA256); var getSessionTokenRequest = new GetSessionTokenRequest(merchantInfo); var response = reqExecutor.GetSessionToken(getSessionTokenRequest).GetAwaiter().GetResult(); Console.WriteLine("Received session token: " + response.SessionToken); Console.WriteLine("Reason: " + response.Reason); } } }