Idempotence

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();