I'm passing a settled transaction Id along with my api login id and transaction key details. What's wrong with this?
My code snippet:
const { APIContracts, APIControllers } = require('authorizenet');
// Replace with your actual API credentials
const apiLoginId = variables.ApiId;
const transactionKey = variables.transactionKey;
// Set up merchant authentication
const merchantAuthenticationType = new APIContracts.MerchantAuthenticationType();
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
// Replace with the actual transaction ID
const transactionId = input.transactionId;
const getRequest = new APIContracts.GetTransactionDetailsRequest();
getRequest.setMerchantAuthentication(merchantAuthenticationType);
getRequest.setTransId(transactionId);
const ctrl = new APIControllers.GetTransactionDetailsController(getRequest.getJSON());
// Manually set the endpoint for production
ctrl.setEnvironment('https://api2.authorize.net/xml/v1/request.api');
ctrl.execute(() => {
const apiResponse = ctrl.getResponse();
if (apiResponse) {
if (apiResponse.getMessages().getResultCode() === APIContracts.MessageTypeEnum.OK) {
const transaction = apiResponse.getTransaction();
if (transaction.getCustomer()) {
const customerEmail = transaction.getCustomer().getEmail();
console.log('Customer Email:', customerEmail);
// Handle the customer email as needed
} else {
console.log('No customer information found for this transaction.');
}
} else {
const errorMessage = apiResponse.getMessages().getMessage()[0];
console.log('Result Code:', apiResponse.getMessages().getResultCode());
console.log('Error Code:', errorMessage.getCode());
console.log('Error Message:', errorMessage.getText());
}
} else {
console.log('Null Response.');
}
});
08-05-2024 08:27 PM