X-PAY-TOKEN Generation Challenge for CyberSpace API

ezamarichard
Regular Contributor

X-PAY-TOKEN Generation Challenge for CyberSpace API

Dear Team

 

Can somebody help me with the Query String and the resource_path of this url

https://sandbox.api.visa.com/cybersource/v2/payments

 

i have been trying to post data to cyberspace Api

string QS = "apikey=" + ConfigurationManager.apiKey;
requestURL = "https://sandbox.api.visa.com/cybersource/v2/payments?" + QS
Here is what i want

string message = timestamp + resource_path + query_string + request_body

as per the above line of code

am able to get the timestamp (UTC) using this method

private static string getTimestamp()
        {
            long timeStamp = ((long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds) / 1000;
            return timeStamp.ToString();
        }

// what i use to generate the xpay token

private static string getXPayToken(string resourcePath, string queryString, string requestBody)
        {
            string timestamp = getTimestamp();
            string sourceString = timestamp + resourcePath + queryString + requestBody;
            string hash = getHash(sourceString);
            string token = "xv2:" + timestamp + ":" + hash;
            return token;
        }

and here is the getHash method

private static string getHash(string data)
        {
            var hashString = new HMACSHA256(Encoding.ASCII.GetBytes(ConfigurationManager.sharedSecret));
            var hashbytes = hashString.ComputeHash(Encoding.ASCII.GetBytes(data));
            string digest = String.Empty;

            foreach (byte b in hashbytes)
            {
                digest += b.ToString("x2");
            }

            return digest;
        }

 

i still get UnAuthorised error code

Token validation failed

Thanks

3 REPLIES 3
API_Managers
Visa Developer Support Specialist

Re: X-PAY-TOKEN Generation Challenge for CyberSpace API

Hi @ezamarichard,

 

If you're receiving a 401 - 9501 Token Validation Failed code error, please make sure that if you're using your own API key (and SSL) then you should be using your own data. Please use the following video to help resolve your error regarding the x-pay-token. https://www.youtube.com/watch?v=RZ7zlDA89xE

 

If you’re still receiving an error, please send the response request of the error received, screenshot and the Correlation ID. 

 

Below are the steps to get the Correlation ID using a Google Chrome browser.

1>Open Chrome menu.

2>Click on More tools then Developer tools.

3>Check the box to Preserve Log for the Network Tab.

4>Then try to click on the add API link.

5>You can find the Correlation ID in the network log for add API call.

 




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.

ezamarichard
Regular Contributor

Re: X-PAY-TOKEN Generation Challenge for CyberSpace API

https://sandbox.api.visa.com/cybersource/v2/payments?apikey=xxxx

posting is now giving me

NotFound

yet this link works

 

API_Managers
Visa Developer Support Specialist

Re: X-PAY-TOKEN Generation Challenge for CyberSpace API

Hi @ezamarichard,                             

 

In order for us to further investigate the issue, can you please provide more information on the error you have received? Please send the response request of the error received, screenshot and the Correlation ID. 
 
Below are the steps to get the Correlation ID using a Google Chrome browser.
1>Open Chrome menu.
2>Click on More tools then Developer tools.
3>Check the box to Preserve Log for the Network Tab.
4>Then try to click on the add API link.
5>You can find the Correlation ID in the network log for add API call.

 




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.