Error handling

User input error

Some events allow errors to be recovered (for example TOKEN_FAIL or OnChange events). These non-critical errors returned in these events allow you to adapt your interface. Here is an example of error handling based on user input:

  (event) => {
        const error = event?.detail?.error;
        if(error) {
            myCustomButton.disabled = true;
        } else {
            myCustomButton.disabled = false;

paygreenjs.attachEventListener(paygreenjs.Events.TOKEN_FAIL, (event) => {
  console.error('Fail to tokenize card: ', event?.detail);

Other error

As soon as an unexpected error occurs in the payment flow, PGJS dispatches an event ERROR:

paygreenjs.attachEventListener(paygreenjs.Events.ERROR, (event) => {
    console.error('Your custom error handling', event?.detail);