diff --git a/src/ebanx.js b/src/ebanx.js index 890901e..024f906 100644 --- a/src/ebanx.js +++ b/src/ebanx.js @@ -335,6 +335,20 @@ EBANX.utils = (function () { } }, availableCountries: ['br', 'mx', 'co', 'ar', 'pe', 'cl', 'ec', 'bo', 'uy'].join(', '), + getErrorDataForPay: function (error) { + var data = { + publicIntegrationKey: EBANX.config.getPublishableKey(), + errorMessage: error.message + }; + + var resource = EBANX.utils.api.resources.fingerprintErrorResource(); + + return { + url: resource.url, + method: resource.method, + data: data + } + }, creditCardScheme: function (cardNumber) { EBANX.validator.card.validateNumber(cardNumber); @@ -420,6 +434,12 @@ EBANX.utils = (function () { url: utilsModule.api.path() + 'fingerprint/provider', method: 'get' }; + }, + fingerprintErrorResource: function () { + return { + url: utilsModule.api.path() + 'fingerprint/error', + method: 'post' + } } }; @@ -666,16 +686,27 @@ EBANX.deviceFingerprint = { }, getList: function (cb) { - EBANX.http.ajax - .request({ - url: EBANX.utils.api.resources.fingerPrintResource().url, - data: { - publicIntegrationKey: EBANX.config.getPublishableKey(), - country: EBANX.config.getCountry(), - origin: window.location.pathname, - } - }) - .always(cb); + try { + EBANX.http.ajax + .request({ + url: EBANX.utils.api.resources.fingerPrintResource().url, + data: { + publicIntegrationKey: EBANX.config.getPublishableKey(), + country: EBANX.config.getCountry(), + origin: window.location.pathname, + } + }) + .always(cb); + } catch (e) { + EBANX.utils.getErrorDataForPay(e); + this.notifyPayOnError(e); + } + }, + + notifyPayOnError: function(data) { + try { + EBANX.http.ajax.request(data); + } catch(e) {} }, saveProviderSessionList: function (providerSession) { diff --git a/src/ebanx.spec.js b/src/ebanx.spec.js index bad3055..7974acf 100644 --- a/src/ebanx.spec.js +++ b/src/ebanx.spec.js @@ -113,4 +113,22 @@ describe('Utils', () => { expect(brand).toEqual(expectedBrand); }); }); + describe('testGetDataForPayErrors', () => { + + it('returns the expected error object', (expectedMessage, errorObject) => { + const expectedErrorData = { + url: process.env.EBANX_API_SANDBOX + 'fingerprint/error', + method: 'post', + data: { + publicIntegrationKey: EBANX.config.getPublishableKey(), + errorMessage: 'EBANX.deviceFingerprint.setup - providersList is missing' + } + }; + const errorObject = {message: 'EBANX.deviceFingerprint.setup - providersList is missing', name: 'someErrorMessage' }; + const payDataForError = EBANX.utils.getErrorDataForPay(errorObject); + + expect(payDataForError.data.errorMessage).toEqual(expectedErrorData.data.errorMessage); + }); + + }) });