cancel
Showing results for 
Search instead for 
Did you mean: 

E00003 has invalid child element 'clientId' in namespace but its not there

sorry if this is duplicate but it never shows up in my portal so doing it again 

I am sending error, request, and code the only thing i changed in code is i am removing null fields from request if i dont i get E00001 

I removed key for safety 

Request before cleaned (gives e00001 if i send this )

CreateCustomerPaymentProfileRequest {
merchantAuthentication: MerchantAuthenticationType {
name: '738NxuRnzC5',
transactionKey: '.......'
},
clientId: null,
refId: null,
customerProfileId: '931248561',
paymentProfile: CustomerPaymentProfileType {
customerType: null,
billTo: CustomerAddressType {
firstName: 'james',
lastName: 'farmer',
company: null,
address: '123 daddy ln',
city: 'dd',
state: 'sc',
zip: '25808',
country: 'USA',
phoneNumber: '8048158190',
faxNumber: null,
email: 'beentwiceiraq@gmail.com'
},
payment: PaymentType {
creditCard: null,
bankAccount: null,
trackData: null,
encryptedTrackData: null,
payPal: null,
opaqueData: [OpaqueDataType],
emv: null,
dataSource: null
},
driversLicense: null,
taxId: null,
defaultPaymentProfile: true,
subsequentAuthInformation: null
},
validationMode: 'testMode'
}

Request after cleaned 

{ "_request": { "createCustomerPaymentProfileRequest": { "merchantAuthentication": { "name": "738NxuRnzC5", "transactionKey": "......" }, "customerProfileId": "931248211", "paymentProfile": { "billTo": { "firstName": "james", "lastName": "farmer", "address": "123 daddy ln", "city": "dd", "state": "sc", "zip": "25808", "country": "USA", "phoneNumber": "8048158190", "email": "beentwiceiraq@gmail.com" }, "payment": { "opaqueData": { "dataDescriptor": "COMMON.ACCEPT.INAPP.PAYMENT", "dataValue": "eyjjb2rlijointbfml8wnjawmduzrjvbrdi0rkvdrdven0fgntlerdaymdi1mumwm0rcmjk1ntc4ndq0mzc5m0e2otc5nzk3njqyrkmxnky4mzmzmju0ouy1oeu4mzy3mefdqkzcnevbrueznje1req3qzdeiiwidg9rzw4ioii5nzq5mtqzmty3mjq0mdi4mja0njayiiwidii6ijeumsj9" } }, "defaultPaymentProfile": true } } }, "_response": null, "_endpoint": "https://apitest.authorize.net/xml/v1/request.api" }

Error

"The element 'createCustomerPaymentProfileRequest' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'clientId' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.

Code

const { APIContracts, APIControllers } = require('authorizenet');

const merchantAuthentication = new APIContracts.MerchantAuthenticationType();
 
merchantAuthentication.setName(process.env.AUTHORIZENET_API_LOGIN_ID_SANDBOX);
merchantAuthentication.setTransactionKey(process.env.AUTHORIZENET_TRANSACTION_KEY_SANDBOX);


async function createCustomerProfile(email) {
  return new Promise((resolve, reject) => {
    const refId = 'ref' + Date.now();

    const customerProfile = new APIContracts.CustomerProfileType();
    customerProfile.setDescription('Subscription');
    customerProfile.setMerchantCustomerId('M_' + Date.now());
    customerProfile.setEmail(email);

    const createRequest = new APIContracts.CreateCustomerProfileRequest();
    createRequest.setProfile(customerProfile);
    createRequest.setMerchantAuthentication(merchantAuthentication);
    createRequest.setRefId(refId);

    const controller = new APIControllers.CreateCustomerProfileController(createRequest.getJSON());
    controller.setEnvironment('https://apitest.authorize.net/xml/v1/request.api'); // Sandbox
// or
//controller.setEnvironment('https://api.authorize.net/xml/v1/request.api'); // Production

    controller.execute(() => {
      const apiResponse = controller.getResponse();
      const response = new APIContracts.CreateCustomerProfileResponse(apiResponse);

      if (
        response &&
        response.getMessages().getResultCode() === APIContracts.MessageTypeEnum.OK
      ) {
        resolve(response.getCustomerProfileId());
      } else {
        const errorMessages = response.getMessages().getMessage();
        reject(new Error(errorMessages[0].getText()));
      }
    });
  });
}

function createPaymentProfile(customerProfileId, opaqueData, billingInfo,Email) {
  return new Promise((resolve, reject) => {
             const opaque = new APIContracts.OpaqueDataType();
             opaque.setDataDescriptor(opaqueData.dataDescriptor);
             opaque.setDataValue(opaqueData.dataValue);
             console.log("opaqe",opaque);


             const payment = new APIContracts.PaymentType();
             payment.setOpaqueData(opaque);
            // const payment = {
            //     opaqueData: {
            //       dataDescriptor: opaqueData.dataDescriptor,
            //       dataValue: opaqueData.dataValue
            //     }
            //   };
             console.log("payment",payment);



            const billTo = new APIContracts.CustomerAddressType();
            billTo.setFirstName(billingInfo.firstName);
            billTo.setLastName(billingInfo.lastName);
            billTo.setAddress(billingInfo.address);
            billTo.setCity(billingInfo.city);
            billTo.setState(billingInfo.state);
            billTo.setZip(billingInfo.zip);
            billTo.setCountry(billingInfo.country);
            billTo.setPhoneNumber(billingInfo.phone);
            billTo.setEmail(Email);
           // billTo.faxNumber = undefined;
           // billTo.company = undefined;

            console.log("bill to",billTo);
            const paymentProfile = new APIContracts.CustomerPaymentProfileType();
           // paymentProfile.setCustomerType(APIContracts.CustomerTypeEnum.INDIVIDUAL);
            paymentProfile.setPayment(payment);
            paymentProfile.setBillTo(billTo);
            paymentProfile.setDefaultPaymentProfile(true);
            console.log("paymentpro",paymentProfile);
            const request = new APIContracts.CreateCustomerPaymentProfileRequest();
            request.setMerchantAuthentication(merchantAuthentication);
            request.setCustomerProfileId(customerProfileId);
            request.setPaymentProfile(paymentProfile);
            //request.setValidationMode(APIContracts.ValidationModeEnum.LIVEMODE);
            request.setValidationMode(APIContracts.ValidationModeEnum.TESTMODE);
            console.log("request",request);
           

            const rawRequest = request.getJSON(); // or any object you're building
           // console.log("raw request",request.getJSON());
            const cleanedRequest = removeNulls(rawRequest);
            //const cleanedRequest = rawRequest;
            console.log("cleaned request",JSON.stringify(cleanedRequest));
            const controller = new APIControllers.CreateCustomerPaymentProfileController(cleanedRequest);
           controller.setEnvironment('https://apitest.authorize.net/xml/v1/request.api'); // Sandbox

            //controller.setEnvironment('https://api.authorize.net/xml/v1/request.api'); // Production
            console.log("controller",JSON.stringify(controller));
            controller.execute(() => {
                                    try {
                                        const apiResponse = controller.getResponse();
                                        console.log("Raw API Response:", apiResponse);
                                        console.log("API Response:", JSON.stringify(apiResponse));
                                        const response = new APIContracts.CreateCustomerPaymentProfileResponse(apiResponse);

                                        if (
                                        response &&
                                        response.getMessages().getResultCode() === APIContracts.MessageTypeEnum.OK
                                        ) {
                                        console.log("Payment Profile ID:", response.getCustomerPaymentProfileId());
                                        resolve(response.getCustomerPaymentProfileId());
                                        } else {
                                        const errorMessages = response.getMessages().getMessage();
                                        errorMessages.forEach((msg, index) => {
                                            console.error(`Error ${index + 1}: Code=${msg.getCode()}, Text=${msg.getText()}`);
                                        });
                                        reject(new Error(errorMessages[0].getText()));
                                        }
                                    } catch (err) {
                                        console.error("Execution Error:", err);
                                        reject(err);
                                    }
                                    });
  });
}

function deleteCustomerProfile(customerProfileId) {
  return new Promise((resolve) => {
    const request = new APIContracts.DeleteCustomerProfileRequest();
    request.setMerchantAuthentication(merchantAuthentication);
    request.setCustomerProfileId(customerProfileId);

    const controller = new APIControllers.DeleteCustomerProfileController(request.getJSON());
   controller.setEnvironment('https://apitest.authorize.net/xml/v1/request.api'); // Sandbox
// or
//controller.setEnvironment('https://api.authorize.net/xml/v1/request.api'); // Production
    controller.execute(() => resolve());
  });
}

//used ot remove nulls
function removeNulls(obj) {
  if (Array.isArray(obj)) {
    return obj
      .map(v => removeNulls(v))
      .filter(v => v !== null && v !== undefined);
  } else if (typeof obj === 'object' && obj !== null) {
    const cleaned = {};
    for (const key in obj) {
      const value = removeNulls(obj[key]);
      if (value !== null && value !== undefined) {
        cleaned[key] = value;
      }
    }
    return cleaned;
  }
  return obj;
}

exports.postNewCustomer = async (event) => {
  console.log("Start New Billing Profiles");

  let body;
  try {
    body = JSON.parse(event.body || '{}');
  } catch (err) {
    return {
      statusCode: 400,
      body: JSON.stringify({ error: 'Invalid JSON in request body' }),
    };
  }

  const { email, opaqueData, billingInfo } = body;

  if (
    !email ||
    !opaqueData ||
    !opaqueData.dataDescriptor ||
    !opaqueData.dataValue ||
    !billingInfo ||
    !billingInfo.firstName
  ) {
    return {
      statusCode: 400,
      body: JSON.stringify({ error: 'Missing required fields' }),
    };
  }

  console.log(email);
  console.log(opaqueData);
  console.log(billingInfo);

  let customerProfileId = null;

  try {
    customerProfileId = await createCustomerProfile(email);
    console.log(customerProfileId);
    const paymentProfileId = await createPaymentProfile(customerProfileId, opaqueData, billingInfo,email);
    console.log(paymentProfileId);
    return {
      statusCode: 201,
      body: JSON.stringify({
        message: 'Customer and payment profile created',
        customerProfileId,
        paymentProfileId,
      }),
    };
  } catch (error) {
    if (customerProfileId) {
      await deleteCustomerProfile(customerProfileId);
    }

    console.error('Error:', error.message);
    return {
      statusCode: 500,
      body: JSON.stringify({ error: error.message || 'Internal error' }),
    };
  }
};

 

1 ACCEPTED SOLUTION

Accepted Solutions

SO i narrowed it down to the when i use it i gives me e00001 code i am no longer removing nulls as that was casuing the other error 

opaqueData

if i just put credit card in there is no issue but when i use 

opaqueData token from accpet it breaks using default visa 4111111111111111
 
I used the default token still same issue 
 opaque.setDataValue("947147125C0159A2E053C01010AC2F5C");
 

View solution in original post

1 REPLY 1

SO i narrowed it down to the when i use it i gives me e00001 code i am no longer removing nulls as that was casuing the other error 

opaqueData

if i just put credit card in there is no issue but when i use 

opaqueData token from accpet it breaks using default visa 4111111111111111
 
I used the default token still same issue 
 opaque.setDataValue("947147125C0159A2E053C01010AC2F5C");