considering code below, I'm getting succeful on vpd/helloworld, but this error on every single other api (AFT; OCT; QUERY)
const express = require('express');
const fs = require('fs');
var https = require('https');
const axios = require('axios');
const request = require('request');
const app = express();
const bodyParser = require('body-parser')
var path = require('path');
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(express.json());
app.use(bodyParser.urlencoded({extended: true}));
var username = 'xxxx';
var password = 'yyyy';
const keyPath = path.join(__dirname, 'certs', 'key.pem');
const certPath = path.join(__dirname, 'certs', 'cert.pem');
const caPath = path.join(__dirname, 'certs', 'SBX-2024-Prod-Root.pem');
app.get('/', async (req, res) => {
try{
const agent = new https.Agent({
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
//ca: fs.readFileSync(caFile),
//rejectUnauthorized: true
});
httpsAgent: agent,
auth: {
username,
password
},
headers: {
'Accept': 'application/json'
}
});
console.log(`Status: ${response.status}`);
console.log(response.data);
res.json(response.data);
}catch(error){
console.error('Error:', error.message);
res.status(500).json({ error: error.message });
}
/*
request.get(options, (err, res, body) => {
if (err) {
return console.log(err);
}
console.log(`Status: ${res.statusCode}`);
console.log(body);
});
res.send('Hello World');*/
});
app.get('/query', async (req, res) => {
try{
const agent = new https.Agent({
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
//ca: fs.readFileSync(caFile),
//rejectUnauthorized: true
});
httpsAgent: agent,
auth: {
username,
password
},
headers: {
'Accept': 'application/json'
}
});
console.log(`Status: ${response.status}`);
console.log(response.data);
res.json(response.data);
}catch(error){
if (error.response) {
console.error('Visa API Error:', error.response.status, error.response.data);
} else {
console.error('Request Error:', error.message);
}
res.status(500).json({ error: error.message });
}
});
app.get('/create', async (req, res) => {
try{
const agent = new https.Agent({
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
ca: fs.readFileSync(caPath),
rejectUnauthorized: false
});
const requestBody = {
amount: "100.00", // Monto en la moneda indicada
currencyCode: "840", // Código de moneda (USD = 840)
transactionIdentifier: "381228649430015", // Número único de transacción
sourceAccountNumber: "4005520000011126", // Tarjeta de origen (debe ser válida en sandbox)
sourceCountryCode: "USA",
senderName: "John Doe",
senderAddress: "123 Main Street",
senderCity: "San Francisco",
senderStateCode: "CA",
senderPostalCode: "94105",
senderCountryCode: "USA",
senderReference: "Ref123456",
recipientName: "Jane Doe",
recipientPrimaryAccountNumber: "4957030420210496", // Tarjeta de destino
acquiringBin: "408999",
acquirerCountryCode: "840",
retrievalReferenceNumber: "330000550000", // RRN único (debe ser válido)
systemsTraceAuditNumber: "451000", // Identificador único para Visa
businessApplicationId: "PP", // "PP" para pagos, "FD" para transferencias a débito
transactionCurrencyCode: "840",
merchantCategoryCode: "6012",
senderAccountNumber: "4005520000011126", // Tarjeta de origen
senderPhoneNumber: "6504320000"
};
const options = {
method: 'post',
httpsAgent: agent,
auth: {
username,
password
},
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
data: requestBody
};
const response = await axios(options);
console.log(`Status: ${response.status}`);
console.log(response.data);
res.json(response.data);
}catch(error){
if (error.response) {
console.error('Visa API Error:', error.response.status, error.response.data);
} else {
console.error('Request Error:', error.message);
}
res.status(500).json({ error: error.message });
}
});
app.listen(3050, function () {
console.log('Example app listening on port 3050.');
})