function validateComponents() {
  if (document.querySelector('#component_ach')) {
    const inputs = document.querySelectorAll('#component_ach > input');
    for (const input of inputs) {
      input.onchange = function () {
        validateCustomInputField(this);
      };
    }
  }
  if (document.querySelector('#dateOfBirthInput')) {
    document.querySelector('#dateOfBirthInput').onchange = function () {
      validateCustomInputField(this);
    };
  }

  let stateData;
  if (
    componentsObj[selectedMethod] &&
    componentsObj[selectedMethod].stateData
  ) {
    stateData = componentsObj[selectedMethod].stateData;
  } else {
    stateData = { paymentMethod: { type: selectedMethod } };
  }

  if (selectedMethod === 'ach') {
    const bankAccount = {
      ownerName: document.querySelector('#bankAccountOwnerNameValue').value,
      bankAccountNumber: document.querySelector('#bankAccountNumberValue')
        .value,
      bankLocationId: document.querySelector('#bankLocationIdValue').value,
    };
    stateData.paymentMethod = {
      ...stateData.paymentMethod,
      bankAccount,
    };
  } else if (selectedMethod === 'ratepay') {
    if (
      document.querySelector('#genderInput').value &&
      document.querySelector('#dateOfBirthInput').value
    ) {
      stateData.shopperName = {
        gender: document.querySelector('#genderInput').value,
      };
      stateData.dateOfBirth = document.querySelector('#dateOfBirthInput').value;
    }
  }
  document.querySelector('#adyenStateData').value = JSON.stringify(stateData);
}
/**
 * Assigns stateData value to the hidden stateData input field
 * so it's sent to the backend for processing
 */
Assigns stateData value to the hidden stateData input field
so it's sent to the backend for processing
Assigns stateData value to the hidden stateData input field so it ' s sent to the backend for processing
function validateComponents() {
  if (document.querySelector('#component_ach')) {
    const inputs = document.querySelectorAll('#component_ach > input');
    for (const input of inputs) {
      input.onchange = function () {
        validateCustomInputField(this);
      };
    }
  }
  if (document.querySelector('#dateOfBirthInput')) {
    document.querySelector('#dateOfBirthInput').onchange = function () {
      validateCustomInputField(this);
    };
  }
  let stateData;
  if (
    componentsObj[selectedMethod] &&
    componentsObj[selectedMethod].stateData
  ) {
    stateData = componentsObj[selectedMethod].stateData;
  } else {
    stateData = { paymentMethod: { type: selectedMethod } };
  }
  if (selectedMethod === 'ach') {
    const bankAccount = {
      ownerName: document.querySelector('#bankAccountOwnerNameValue').value,
      bankAccountNumber: document.querySelector('#bankAccountNumberValue')
        .value,
      bankLocationId: document.querySelector('#bankLocationIdValue').value,
    };
    stateData.paymentMethod = {
      ...stateData.paymentMethod,
      bankAccount,
    };
  } else if (selectedMethod === 'ratepay') {
    if (
      document.querySelector('#genderInput').value &&
      document.querySelector('#dateOfBirthInput').value
    ) {
      stateData.shopperName = {
        gender: document.querySelector('#genderInput').value,
      };
      stateData.dateOfBirth = document.querySelector('#dateOfBirthInput').value;
    }
  }
  document.querySelector('#adyenStateData').value = JSON.stringify(stateData);
}
function validateComponents ( ) { if ( document . querySelector ( '#component_ach' ) ) { const inputs = document . querySelectorAll ( '#component_ach > input' ) ; for ( const input of inputs ) { input . onchange = function ( ) { validateCustomInputField ( this ) ; } ; } } if ( document . querySelector ( '#dateOfBirthInput' ) ) { document . querySelector ( '#dateOfBirthInput' ) . onchange = function ( ) { validateCustomInputField ( this ) ; } ; } let stateData ; if ( componentsObj [ selectedMethod ] && componentsObj [ selectedMethod ] . stateData ) { stateData = componentsObj [ selectedMethod ] . stateData ; } else { stateData = { paymentMethod : { type : selectedMethod } } ; } if ( selectedMethod === 'ach' ) { const bankAccount = { ownerName : document . querySelector ( '#bankAccountOwnerNameValue' ) . value , bankAccountNumber : document . querySelector ( '#bankAccountNumberValue' ) . value , bankLocationId : document . querySelector ( '#bankLocationIdValue' ) . value , } ; stateData . paymentMethod = { ... stateData . paymentMethod , bankAccount , } ; } else if ( selectedMethod === 'ratepay' ) { if ( document . querySelector ( '#genderInput' ) . value && document . querySelector ( '#dateOfBirthInput' ) . value ) { stateData . shopperName = { gender : document . querySelector ( '#genderInput' ) . value , } ; stateData . dateOfBirth = document . querySelector ( '#dateOfBirthInput' ) . value ; } } document . querySelector ( '#adyenStateData' ) . value = JSON . stringify ( stateData ) ; }
Assigns stateData value to the hidden stateData input field
 so it's sent to the backend for processing
Assigns stateData value to the hidden stateData input field so it ' s sent to the backend for processing