ACH Bank Transfer

Take a bank account payment via ACH Bank Transfer

Usage

index.html
HTML

<!-- Renders the "Connect Bank Account" button -->

<form>

  <button id="ach-button" type="button">Pay with Bank Account</button>

</form>

<!-- Configure the Web Payments SDK and the ACH payment method -->

<script type="text/javascript">

  async function main() {

    const payments = Square.payments(APPLICATION_ID, LOCATION_ID);

    const ach = await payments.ach({

      redirectURI: 'https://localhost:1780/',

      transactionId: '123',

    });



    ach.addEventListener('ontokenization', (event) => {

      const { tokenResult, error } = event.detail;

      if (error) {

        console.error(error);

      } else if (tokenResult.status === 'OK') {

        const token = tokenResult.token;

        console.log(`Payment token is ${token}`);

      }

    });



    function eventHandler(event) {

      event.preventDefault();



      try {

        ach.tokenize({

          accountHolderName: 'John Doe',

        });

      } catch (e) {

        console.error(e);

      }

    };



    const achButton = document.getElementById('ach-button');

    achButton.addEventListener('click', eventHandler);

  }



  main();

</script>

Payments

Returned by Square.payments(appId, locationId).

Use this object to instantiate Payment methods. Learn more on the Payments page.

Methods

payments.js
JS
JavaScript

const payments = Square.payments(appId, locationId);

ACH

The ACH Payment Method

When initializing the ACH payment method, the developer is expected to provide a redirectURI and transactionID.

Methods

aCH.js
JS
JavaScript

const ach = await payments.ach({

  redirectURI: 'https://localhost:1780/',

  transactionId: '123',

)};



const achButton = document.getElementById('ach-button')

const buyerNameField = document.getElementById('buyer-name-field');



ach.addEventListener('ontokenization', (event) => {

  const { tokenResult, error } = event.detail;



  if (error) {

    const errorMessage = `Tokenization failed with status: ${error}`;

    throw new Error(errorMessage);

  }



  if (tokenResult.status === 'OK') {

    console.log('got payment token: ', tokenResult.token);

  }

});



achButton.onclick = () => {

  try {

    ach.tokenize({ accountHolderName: buyerNameField.value });

  }

  catch (e) {

    // handle error

  }

}