Skip to content

Commit

Permalink
throwing exception when domain is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
vsilva472 committed Oct 13, 2022
1 parent 32e7c45 commit fd1f6cc
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions resources/assets/js/pagtesouro.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,28 @@ PagTesouroIframe.prototype.setJavascript = function () {
head.appendChild(script);
};

PagTesouroIframe.prototype.render = function (element, callback) {
var url = element.getAttribute('data-payment-url');
var iframe = document.createElement('iframe');

this.validateDomain(url);
PagTesouroIframe.prototype.render = function (selector, callback) {
var element = document.querySelector(selector);
var url = element.getAttribute('data-payment-url');
var iframe = document.createElement('iframe');

if(!this.isPagTesouroDomain(url)) throw new Error('Invalid domain data-payment-url attribute');

iframe.setAttribute('class', 'iframe-epag');
iframe.setAttribute('scrolling', 'no');
iframe.setAttribute('src', url);

element.appendChild(iframe);

iframe.onload = function () {
iFrameResize({ heightCalculationMethod: "documentElementOffset" }, ".iframe-epag");
};
iframe.onload = () => iFrameResize({ heightCalculationMethod: "documentElementOffset" }, ".iframe-epag");

if (callback) this.handleEvent(callback);
};

PagTesouroIframe.prototype.validateDomain = function (url) {
if (url.indexOf(this.domains.prod) == 0
PagTesouroIframe.prototype.isPagTesouroDomain = function (url) {
return (url.indexOf(this.domains.prod) == 0
|| url.indexOf(this.domains.homol) == 0
) throw new Error('Invalid domain data-payment-url attribute');
);
};

PagTesouroIframe.prototype.handleEvent = function (callback) {
Expand Down

0 comments on commit fd1f6cc

Please sign in to comment.