EmpyrNetwork / empyr_web

This repository contains both the Empyr Tracking and Hosted Fields libraries.
1 stars 3 forks source link

Hosted Field Error Handling #7

Closed ChrisSargent closed 5 years ago

ChrisSargent commented 5 years ago

Hey,

I seems in one of the latest updates the error handling for card errors on the hosted fields has changed.

We used to have this code:

const hostedFieldsPromise = (HostedFields, options) =>
  new Promise((resolve, reject) => {
    HostedFields.setup(options.clientId, 'custom', {
      onRegistered: resolve,
      onError: error => reject(new Error(error)),
      ...options
    });
  });

And we'd get card validation come through correctly as errors.

Now, if there is a card validation problem, it's calling the onRegistered method but with a response.err string. Hence, we've had to change to:

const hostedFieldsPromise = (HostedFields, options) =>
  new Promise((resolve, reject) => {
    HostedFields.setup(options.clientId, 'custom', {
      onRegistered: response => {
        const { err } = response;
        if (err) {
          return reject(new Error(err));
        }
        return resolve(response);
      },
      onError: error => reject(new Error(error)),
      ...options
    });
  });

This behaviour seems a little strange to resolve hit the onRegistered method when the card is not registered.

ChrisSargent commented 5 years ago

hey guys, sorry, my bad, it wasn't doing this at all :-) Closing

jcuzens commented 5 years ago

Glad it's working for you. Thanks for the update.