Token validation failed

Soumith
Regular Visitor

Token validation failed

const express = require('express');
const fs = require('fs');
var https = require('https');
const request = require('request');
const app = express();
const bodyParser = require('body-parser')
var path = require('path');
var crypto = require('crypto');

app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(express.json());
app.use(bodyParser.urlencoded({extended: true}));


var apiKey = '********';
var sharedSecret = '*******';

var resourcePath = '/cardservices/v2/cards'
var queryParams = 'apiKey='+apiKey;
var postBody = {
"primaryAccountNumber": "41447732xx813351"
};

var data={
"primaryAccountNumber": "41447732xx813351"
};

app.get('/', (req, res) => {

var timestamp = Math.floor(Date.now() / 1000);
var preHashString = timestamp + resourcePath + queryParams + postBody;
var hashString = crypto.createHmac('sha256', sharedSecret).update(preHashString).digest('Hex');;
var xPayToken = 'xv2:' + timestamp + ':' + hashString;

console.log(preHashString);
console.log(xPayToken);

var options = {
hostname: 'sandbox.api.visa.com',
port: 443,
uri: 'https://sandbox.api.visa.com/dcas/cardservices/v2/cards?'+queryParams,
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'x-pay-token': xPayToken
},
json: true
};

console.log(options);

options.agent = new https.Agent(options);

request.post(options, (err, res, body) => {
if (err) {
return console.log(err);
}
console.log(`Status: ${res.statusCode}`);
console.log(body);
});
res.send(data);
});


app.listen(3050, function () {
console.log('Example app listening on port 3050.');
})

 

 

 

 

Can anybody point out what's wrong in the code

3 REPLIES 3
jenn_kh
Community Moderator

Re: Token validation failed

Thank you for reaching out, @Soumith! An agent is looking for a solution for you and will get back to you shortly. If any community members know a solution, please feel free to respond in this thread. -Jenn

Soumith
Regular Visitor

Re: Token validation failed

Please, can you find a solution to this, there has no response since the last monday

I_Doroteo3
Visa Developer Support Specialist

Re: Token validation failed

Hi @Soumith

 

If you are using DPS Card and Account Services API, this product uses Mutual (Two-Way) SSL Authentication and Channel Encryption (CE), not X-Pay Token. For more information on this, please visit this page: 

 

DPS Card and Account Services Authentication Method (visa.com)

 

Please let me know if you have additional questions.

 

Thanks, 

Illana