Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E00001 Stuck with this error #99

Open
allencazar opened this issue Jan 30, 2025 · 0 comments
Open

E00001 Stuck with this error #99

allencazar opened this issue Jan 30, 2025 · 0 comments

Comments

@allencazar
Copy link

allencazar commented Jan 30, 2025

Issue: Authorize.Net API Integration - E00001 Error

Hello, I have the following code for creating a transaction request to Authorize.Net using their SDK:

const merchantAuthenticationType = new APIContracts.MerchantAuthenticationType();
merchantAuthenticationType.setName(process.env.AUTHORIZE_NET_API_LOGIN_ID || '');
merchantAuthenticationType.setTransactionKey(process.env.AUTHORIZE_NET_TRANSACTION_KEY || '');
console.log('Merchant Authentication setup complete.');

const creditCard = new APIContracts.CreditCardType();
creditCard.setCardNumber('4242424242424242');
creditCard.setExpirationDate('0842');
creditCard.setCardCode('999');
console.log('Credit Card setup complete.', creditCard);

const paymentType = new APIContracts.PaymentType();
paymentType.setCreditCard(creditCard);

const transactionRequestType = new APIContracts.TransactionRequestType();
transactionRequestType.setTransactionType(APIContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION);
transactionRequestType.setAmount(100); // Test amount (nxAmount used if needed)
transactionRequestType.setPayment(paymentType);
console.log('Transaction request setup complete.');

const createRequest = new APIContracts.CreateTransactionRequest();
createRequest.setMerchantAuthentication(merchantAuthenticationType);
createRequest.setTransactionRequest(transactionRequestType);
console.log('Transaction request created. Ready for API call.');

// Clean up null or undefined fields to prevent XML serialization issues
cleanRequest(createRequest);

// Log the cleaned request object
console.log('Cleaned Transaction Request Object:', createRequest);

const ctrl = new APIControllers.CreateTransactionController(createRequest);

// Wrap API call in Promise for async handling
const result = await new Promise((resolve, reject) => {
    console.log('Calling Authorize.Net API...');
    ctrl.execute(() => {
        const apiResponse = ctrl.getResponse();
        console.log('Received API response:', apiResponse);

        const response = new APIContracts.CreateTransactionResponse(apiResponse);
        const responseMessages = response.getMessages().getMessage();
        console.log('Response Messages:', responseMessages);

        if (response.getMessages().getResultCode() === APIContracts.MessageTypeEnum.OK) {
            console.log('Transaction successful, returning transaction ID.');
            resolve(
                NextResponse.json(
                    { message: response.getTransactionResponse().getTransId() },
                    { status: 200 }
                )
            );
        } else {
            console.log('Transaction failed with error:', response.getMessages().getMessage()[0].getText());
            reject(
                NextResponse.json(
                    { message: response.getMessages().getMessage()[0].getText() },
                    { status: 400 }
                )
            );
        }
    });
});

and I get the following error:

Error: E00001 - "JSON root object has multiple properties."

logs as follows:

Merchant Authentication setup complete.
Credit Card setup complete. CreditCardType {
  cardNumber: '4242424242424242',
  expirationDate: '0842',
  cardCode: '999',
  isPaymentToken: null,
  cryptogram: null,
  tokenRequestorName: null,
  tokenRequestorId: null,
  tokenRequestorEci: null
}
Transaction request setup complete.
Transaction request created. Ready for API call.
Cleaned Transaction Request Object: CreateTransactionRequest {
  merchantAuthentication: MerchantAuthenticationType {
    name: 'xxxxxxx',
    transactionKey: 'xxxxxxx',
    sessionToken: null,
    password: null,
    impersonationAuthentication: null,
    fingerPrint: null,
    clientKey: null,
    accessToken: null,
    mobileDeviceId: null
  },
  transactionRequest: TransactionRequestType {
    transactionType: 'authCaptureTransaction',
    amount: 100,
    currencyCode: null,
    payment: PaymentType {
      creditCard: [CreditCardType],
      bankAccount: null,
      trackData: null,
      encryptedTrackData: null,
      payPal: null,
      opaqueData: null,
      emv: null,
      dataSource: null
    },
    profile: null,
    solution: null,
    callId: null,
    terminalNumber: null,
    authCode: null,
    refTransId: null,
    splitTenderId: null,
    order: null,
    lineItems: null,
    tax: null,
    duty: null,
    shipping: null,
    taxExempt: null,
    poNumber: null,
    customer: null,
    billTo: null,
    shipTo: null,
    customerIP: null,
    cardholderAuthentication: null,
    retail: null,
    employeeId: null,
    transactionSettings: null,
    userFields: null,
    surcharge: null,
    merchantDescriptor: null,
    subMerchant: null,
    tip: null,
    processingOptions: null,
    subsequentAuthInformation: null,
    otherTax: null,
    shipFrom: null,
    authorizationIndicatorType: null
  }
}
Calling Authorize.Net API...
Received API response: { messages: { resultCode: 'Error', message: [ [Object] ] } }
Response Messages: [
  {
    code: 'E00001',
    text: "JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifying a DeserializeRootElementName. Path 'transactionRequest', line 1, position 282."
  }
]

I appreciate any help.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant