Skip to content

Commit

Permalink
[t-25blSFMd] notify pay about various errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jack1012t committed Jan 19, 2022
1 parent 3a98d6a commit 4713398
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
51 changes: 41 additions & 10 deletions src/ebanx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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'
}
}
};

Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions src/ebanx.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

})
});

0 comments on commit 4713398

Please sign in to comment.