I have been attempting to connect to Visa APIs using two-way SSL authentication. The .p12 file was manually created by integrating individual certificates and a private key downloaded from the Visa Developer Console. However, the connection fails with the error 401: Token validation failed. This post summarizes the steps I have taken and seeks guidance on proper implementation to resolve this issue.
The following certificates and private key were downloaded from Visa Developer Console:
The full_chain.pem file was created by concatenating the certificates in the following order:
------------------------------------------------------------------------------------------------------------------------------------------
Get-Content SBX-2024-Prod-Inter.pem | Out-File -FilePath full_chain.pem -Encoding ascii
Get-Content SBX-2024-Prod-Root.pem | Out-File -FilePath full_chain.pem -Append -Encoding ascii
Get-Content DigiCertGlobalRootCA.pem | Out-File -FilePath full_chain.pem -Append -Encoding ascii
-------------------------------------------------------------------------------------------------------------------------------------------
Using full_chain.pem, the private key, and the client certificate, the .p12 file was created as follows:
-------------------------------------------------------------------------------------------------------------------------------------------
openssl pkcs12 -export \
-inkey key_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pem \
-in cert.pem \
-certfile full_chain.pem \
-out visa_certificate.p12
-------------------------------------------------------------------------------------------------------------------------------------------
he following request consistently fails with 401: Token validation failed.
-------------------------------------------------------------------------------------------------------------------------------------------
const https = require('https');
const axios = require('axios');
const fs = require('fs');
const cert = fs.readFileSync('cert.pem');
const key = fs.readFileSync('key.pem');
const ca = fs.readFileSync('ca.pem');
const agent = new https.Agent({ cert, key, ca });
const username = 'VISA_API_USERNAME';
const password = 'VISA_API_PASSWORD';
const credentials = Buffer.from(`${username}:${password}`).toString('base64');
async function testVisaAPI() {
try {
const response = await axios.post(
'https://sandbox.api.visa.com/pop/v1/notification/generate',
{ messageId: 'test123', notificationType: 'payment_success' },
{
httpsAgent: agent,
headers: {
'Authorization': `Basic ${credentials}`,
'Content-Type': 'application/json',
},
}
);
console.log('API Response:', response.data);
} catch (error) {
console.error('API Error:', error.response ? error.response.data : error.message);
}
}
testVisaAPI();
----------------------------------------------------------------------------------------------------------------------------------------
Questions
Was the .p12 file, which includes the certificate chain, created correctly?
Are there any missing steps or errors in the OpenSSL procedure?
Are there additional configurations or authentication flows required beyond Basic Authentication (Authorization: Basic <Base64>)?
Is the current endpoint (https://sandbox.api.visa.com/pop/v1/notification/generate) correct?
Request for Guidance
I would greatly appreciate your insights and suggestions. If you have experience resolving similar issues or successfully connecting to Visa APIs, your guidance would be invaluable. Thank you!
Hi @FintechStiory, Thank you for reaching out. An agent will get back to you as soon as possible. Until then, if any community member has information that may be helpful, feel free to reply in this thread.