I unable to call the refund api

Solved! Go to solution
sangeetshah
Dabbler

I unable to call the refund api

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.

2 REPLIES 2
API_Managers
Visa Developer Support Specialist

Re: I unable to call the refund api

Hi @sangeetshah,

 

Please reach out to CyberSource Support using the phone number below for further assistance.

 

CyberSource Support
800-709-7779

 




Thanks,

Tee



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

PatriciaLopez
Newbie

Re: I unable to call the refund api

Thanks for the solution.