Smart2Pay SDK .NET Configuration

First you need to create and initialize a HttpClient configured to accept JSON responses and also an Authentication Provider (using the Site ID and API Key obtained for your test merchant account).

The HttpClient Builder enables the below mandatory and optional configuration points. The only mandatory configuration point is AuthenticationProvider, the next configuration points are optional and let you have more control over the services.

Use HttpClient Builder to obtain a HttpClient Object, which you can use to initialize the services.

Please create only one HttpClient and use it for the entire life of your apllication. For more information, please visit:


Our API supports idempotence for safely retrying requests and guarantees that the operation is performed only once. For example, if you create a card payment that fails due to a network connection error, you can retry the request with the same idempotence key to guarantee that only a single card payment is created.

The SDK by default uses Guid.NewGuid().ToString() to generate Unique Keys. We strongly recommend to generate your own Unique Keys using V4 UUIDs or another appropriately random string.

For card payments we’ll always send back the same response for requests made with the same key, and keys can’t be reused with different request parameters. Keys expire after 24 hours.

This is how you can plug in your Unique Key Generator:

var uniqueKeyGenerator = new Func<string>(() => {/* write your custom unique key generator logic and return a string */});
var httpClientBuilder = new HttpClientBuilder(() => AuthenticationConfiguration).WithIdempotencyKeyGenerator(uniqueKeyGenerator);

After you perform a Create Payment this is how you can obtain the Unique Key:

var createPaymentResult = await paymentService.InitiatePaymentAsync(paymentRequest);
var uniquKey = createPaymentResult.HttpRequest.Headers.GetIdempotencyToken();


By default the SDK supports Automatic Retries with Exponential Delay and Circuit Breaker.

The default configuration values for Retry and Circuit Breaker are the following:

Retry Configuration
Retry Count 3 Retries 3 times
DelayExponentialFactor 2 Wait time between retries is Math.Pow(2, retryAttempt)
Circuit Breaker Configuration
CircuitBreaker FailureThreshold 0.7 Break on >=70% actions result in handled exception
SamplingDuration TimeSpan.FromSeconds(60) Over any 60 seconds period
MinimumThroughput 16 Provided at least 16 actions in the 60 seconds period
DurationOfBreak TimeSpan.FromSeconds(60) Break for 60 seconds

If you want to change these values you will have to create your own Resilience configuration reference:

var configuration = new ResilienceConfiguration
            Retry = new RetryConfiguration
                Count = 5, // Retries 3 times
                DelayExponentialFactor = 5 // Wait time between retries is Math.Pow(2, retryAttempt)
            CircuitBreaker = new CircuitBreakerConfiguration
                FailureThreshold = 0.5, // Break on >=50% actions result in handled exceptions
                SamplingDuration = TimeSpan.FromSeconds(30), // over any 30 seconds period
                MinimumThroughput = 10, // provided at least 10 actions in the 30 seconds period.
                DurationOfBreak = TimeSpan.FromSeconds(90) // Break for 90 seconds.

var httpClientBuilder = new HttpClientBuilder(() => AuthenticationConfiguration).WithResilienceConfiguration(configuration);