Skip to content

Instantly share code, notes, and snippets.

@mzorec
Created June 16, 2020 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzorec/2dacc84d0d22e9d11fbf5ad5e9679948 to your computer and use it in GitHub Desktop.
Save mzorec/2dacc84d0d22e9d11fbf5ad5e9679948 to your computer and use it in GitHub Desktop.
Issue with
[Test, Explicit]
public async Task Debit()
{
var request = new Debit
{
Currency = "EUR",
SuccessUrl = "www.domain.si/successURL",
ErrorUrl = "www.domain.si/errorURL",
CancelUrl = "www.domain.si/cancelURL",
CallbackUrl = "www.domain.si/callbackURL",
Amount = "100.00",
MerchantTransactionId = "12348",
};
var byteArray = Encoding.ASCII.GetBytes("**:**);
DateTime timeSent = DateTime.Now;
var httpClient = new HttpClient();
var json = JsonConvert.SerializeObject(request);
string hmacValue;
using (HMACSHA512 hmac = new HMACSHA512(Encoding.UTF8.GetBytes("***")))
{
using (MD5 md5 = MD5.Create())
{
string md5xml = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(json))).Replace("-", string.Empty).ToLower();
string[] headerData = { "POST", "application/json", md5xml, timeSent.ToUniversalTime().ToString("r"), $"/api/v3/transaction/***/debit" };
var joinedHeaderData = string.Join("\n", headerData);
hmacValue = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(joinedHeaderData)));
}
}
httpClient.DefaultRequestHeaders.Add("X-Signature", hmacValue);
httpClient.DefaultRequestHeaders.Date = timeSent.ToUniversalTime();
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
IBankartClient client = new BankartClient(httpClient);
TransactionResponse response = await client.ProcessDebitAsync("***", request);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment