var apiKey = 'TCW--------------irMBGDg';
var sharedSecret = 'xxxxx';
var resourcePath = 'fundstransfer/v1/pushfundstransactions'
var queryParams = 'apiKey='+apiKey;
let postBody = {
"surcharge": "11.2",
"senderAddress": "901 Metro Center Blvd",
"pointOfServiceData": {
"panEntryMode": "90",
"posConditionCode": "00",
"motoECIIndicator": "0"
},
"recipientPrimaryAccountNumber": "4104920120500001",
"colombiaNationalServiceData": {
"addValueTaxReturn": "10.00",
"taxAmountConsumption": "10.00",
"nationalNetReimbursementFeeBaseAmount": "20.00",
"addValueTaxAmount": "10.00",
"nationalNetMiscAmount": "10.00",
"countryCodeNationalService": "170",
"nationalChargebackReason": "11",
"emvTransactionIndicator": "1",
"nationalNetMiscAmountType": "A",
"costTransactionIndicator": "0",
"nationalReimbursementFee": "20.00"
},
"transactionIdentifier": "617020001849971",
"serviceProcessingType": {
"requestType": "01"
},
"acquiringBin": "408999",
"retrievalReferenceNumber": "412770451036",
"systemsTraceAuditNumber": "451018",
"senderName": "Mohammed Qasim",
"businessApplicationId": "AA",
"settlementServiceIndicator": "9",
"transactionCurrencyCode": "USD",
"recipientName": "rohan",
"sourceAmount": "123.12",
"senderCountryCode": "124",
"senderAccountNumber": "4104920120500002",
"amount": "124.05",
"localTransactionDateTime": "2024-07-17T12:00:00",
"purposeOfPayment": "purpose",
"cardAcceptor": {
"address": {
"country": "USA",
"zipCode": "94404",
"county": "San Mateo",
"state": "CA"
},
"idCode": "CA-IDCode-77765",
"name": "Visa Inc. USA-Foster City",
"terminalId": "TID-9999"
},
"senderReference": "",
"acquirerCountryCode": "840",
"sourceCurrencyCode": "840",
"senderCity": "Foster City",
"senderStateCode": "CA",
"merchantCategoryCode": "6012",
"sourceOfFundsCode": "05"
};
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,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'x-pay-token': xPayToken
},
body: postBody,
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(res);
});
res.send('Hello World ');
});
app.listen(3050, function () {
console.log('Example app listening on port 3050.');
}
------------------------------------------------------------------------
and this is the below result of code when ran(sensitive secrets edited in response):
path: '/visadirect/fundstransfer/v1/pushfundstransactions?apiKey=TCW--------------irMBGDg',
href: 'https://sandbox.api.visa.com/visadirect/fundstransfer/v1/pushfundstransactions?apiKey=TCW-----------...'
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
'x-pay-token': 'xv2:1721167116:77114500cb6d7727f0a9b17559781480542d45cd5b58a0e1857f66d41459cbeb',
'content-length': 1482
},
body: '{"surcharge":"11.2","senderAddress":"901 Metro Center Blvd","pointOfServiceData":{"panEntryMode":"90","posConditionCode":"00","motoECIIndicator":"0"},"recipientPrimaryAccountNumber":"4104920120500001","colombiaNationalServiceData":{"addValueTaxReturn":"10.00","taxAmountConsumption":"10.00","nationalNetReimbursementFeeBaseAmount":"20.00","addValueTaxAmount":"10.00","nationalNetMiscAmount":"10.00","countryCodeNationalService":"170","nationalChargebackReason":"11","emvTransactionIndicator":"1","nationalNetMiscAmountType":"A","costTransactionIndicator":"0","nationalReimbursementFee":"20.00"},"transactionIdentifier":"617020001849971","serviceProcessingType":{"requestType":"01"},"acquiringBin":"408999","retrievalReferenceNumber":"412770451036","systemsTraceAuditNumber":"451018","senderName":"Mohammed Qasim","businessApplicationId":"AA","settlementServiceIndicator":"9","transactionCurrencyCode":"USD","recipientName":"rohan","sourceAmount":"123.12","senderCountryCode":"124","senderAccountNumber":"4104920120500002","amount":"124.05","localTransactionDateTime":"2024-07-17T12:00:00","purposeOfPayment":"purpose","cardAcceptor":{"address":{"country":"USA","zipCode":"94404","county":"San Mateo","state":"CA"},"idCode":"CA-IDCode-77765","name":"Visa Inc. USA-Foster City","terminalId":"TID-9999"},"senderReference":"","acquirerCountryCode":"840","sourceCurrencyCode":"840","senderCity":"Foster City","senderStateCode":"CA","merchantCategoryCode":"6012","sourceOfFundsCode":"05"}',
agent: Agent {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
body: {
responseStatus: {
status: 401,
code: '9201',
severity: 'ERROR',
message: 'Token Validation Failed',
info: ''
}
}
please assist as we are planning to integrate this with live system