I have used the below code to call the Refund API but I am getting an "Unauthorized" error message from my response.
var signatureParm = "host: apitest.cybersource.com\ndate: Fri, 11 Feb 2022 11:20:01 GMT\n(request-target): post /pts/v2/payments/\nDigest: SHA-256=GFGglopxVLr1+05sP1SZk1S/Rk33NcyaqlePMQ2r4ZQ=\nv-c-merchant-id: powernop"; var signatureHash = GenerateSignatureFromParams(signatureParm, secretKey);
using (var httpClient = new HttpClient()) { using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://apitest.cybersource.com/pts/v2/payments/644576113097666300000/refunds")) { request.Headers.TryAddWithoutValidation("host", "apitest.cybersource.com"); request.Headers.TryAddWithoutValidation("Signature", "keyid=\"" + keyId + "\", algorithm=\"HmacSHA256\", headers=\"host (request-target) digest v-c-merchant-id\", signature=\"" + signatureHash + "\""); request.Headers.TryAddWithoutValidation("digest", "SHA-256=GFGglopxVLr1+05sP1SZk1S/Rk33NcyaqlePMQ2r4ZQ="); request.Headers.TryAddWithoutValidation("v-c-merchant-id", "powernop"); request.Headers.TryAddWithoutValidation("v-c-date", "Fri, 11 Feb 2022 11:20:01 GMT"); request.Content = new StringContent("{\n \"clientReferenceInformation\": {\n \"code\": \"TC50171_3\"\n },\n \"orderInformation\": {\n \"amountDetails\": {\n \"totalAmount\": \"10\",\n \"currency\": \"USD\"\n }\n }\n}"); request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); var response = httpClient.SendAsync(request).Result; } }
Please help on this issue. If i set signatureHash key manually from my api dashboard then its working fine. now how to generate this dynamically. Please help me on this issue.
Solved! Go to Solution
Hi @sangeetshah,
Please reach out to CyberSource Support using the phone number below for further assistance.
CyberSource Support
800-709-7779
Thanks for the solution.