Cyber Source X-pay-token error

Solved! Go to solution
Utopia-FinTech
Regular Visitor

Cyber Source X-pay-token error

Greeting dear Visa,

 

I was working with the cyber source API for Nodejs. And I tried the HelloWorld example which I got in generating an x-pay-token help page.

Below is my code for Nodejs please correct me if I did something wrong.  I keep getting this error message:  Request failed with status code 401.

 

 

/** @format */
var crypto = require("crypto");
var axios = require("axios");
var timestamp = Math.floor(Date.now() / 1000);
var resourcePath = "helloworld";
var apiKey = "OWFECRD910WIV3CNEYAT21VsR4ucglJU4qQeoeZ8cTXYFJYM0";
var postBody = "";
var sharedSecret = "4YlGCGOwldgSkgBrzNYseXuVu@m1woZzQrR#h56f";
var preHashString = timestamp + resourcePath + apiKey + postBody;
var hashString = crypto
  .createHmac("SHA256"sharedSecret)
  .update(preHashString)
  .digest("hex");
var xPayToken = "xv2:" + timestamp + ":" + hashString;
console.log(xPayToken);
//
const sendRequest = async () => {
  try {
    const response = await axios({
      method: "get",
      headers: { "Content-Type": "application/json""x-pay-token": xPayToken },
      params: {
        apiKey: apiKey,
      },
    });
    console.log(response);
    //
  } catch (error) {
    console.log(error);
  }
};
sendRequest();
 
 
 
Thanks in advance. 
3 REPLIES 3
API_Products
Visa Developer Support Specialist

Re: Cyber Source X-pay-token error

Hey @Utopia-FinTech,

 
Currently, the only method to properly query the CyberSource Payments sandbox is creating a merchant account directly with CyberSource:
 
https://developer.cybersource.com 

 

Luckily, their site also provides an easy to use method to test their account credentials:
 
https://developer.cybersource.com/api/reference/api-reference.html 
 
Additionally, here are the following links for sample code:  https://github.com/CyberSource/cybersource-rest-samples-java/blob/master/src/main/java/samples/payme...

 

 

 




Thanks,

Diana



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

Utopia-FinTech
Regular Visitor

Re: Cyber Source X-pay-token error

Thanks for that. I tried the CyberSource Api and works fine and easy to use. 

Hark
Helper

Re: Cyber Source X-pay-token error

Thanks@diana