Skip to content

Commit

Permalink
Merge pull request #1 from vsilva472/feature/frontend
Browse files Browse the repository at this point in the history
Feature/frontend
  • Loading branch information
vsilva472 authored Oct 13, 2022
2 parents 4f1e3f1 + fd1f6cc commit 3039209
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

Um pacote com recursos para facilitar a implementação de pagamentos via **PagTesouro** (o novo gateway de pagamentos do governo federal) em sistemas Laravel.


<a href="https://github.com/vsilva472/laravel-pagtesouro"><img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/vsilva472/laravel-pagtesouro"></a>
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/vsilva472/laravel-pagtesouro">
<img alt="GitHub Release Date" src="https://img.shields.io/github/release-date/vsilva472/laravel-pagtesouro">
<img alt="GitHub all releases" src="https://img.shields.io/github/downloads/vsilva472/laravel-pagtesouro/total">
<img alt="GitHub release (latest by date)" src="https://img.shields.io/github/downloads/vsilva472/laravel-pagtesouro/v1.0.0/total">
<img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/vsilva472/laravel-pagtesouro">


## Documentação
Toda a documentação está disponível nas [Páginas da Wiki](https://github.com/vsilva472/laravel-pagtesouro/wiki), nós recomendamos que você a leia com calma e ao finalizar, siga os tutoriais para implementar uma aplicação em localhost com as funcionalidades de [Pagamentos](https://github.com/vsilva472/laravel-pagtesouro/wiki/Criando-pagamentos-(exemplo-completo)) e [Notificação de Pagamento](https://github.com/vsilva472/laravel-pagtesouro/wiki/Notifica%C3%A7%C3%A3o-de-Pagamento-(Exemplo-completo)).

Expand Down
Empty file added resources/.gitkeep
Empty file.
65 changes: 65 additions & 0 deletions resources/assets/js/pagtesouro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
function PagTesouroIframe () {
this.sandbox = false;
this.domains = { homol: 'https://valpagtesouro.tesouro.gov.br', prod: 'https://pagtesouro.tesouro.gov.br' };

this.setCss();
this.setJavascript();
}

PagTesouroIframe.prototype.inSandbox = function () {
this.sandbox = true;
return this;
};

PagTesouroIframe.prototype.setCss = function () {
var head = document.querySelector('head');
var style = document.createElement('style');
style.innerText = '.iframe-epag { margin: 0; padding: 0; border: 0; width: 1px; min-width: 100%;}';
head.appendChild(style);

return this;
};

PagTesouroIframe.prototype.setJavascript = function () {
var head = document.querySelector('head');
var script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.6.6/iframeResizer.min.js';
head.appendChild(script);
};

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 = () => iFrameResize({ heightCalculationMethod: "documentElementOffset" }, ".iframe-epag");

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

PagTesouroIframe.prototype.isPagTesouroDomain = function (url) {
return (url.indexOf(this.domains.prod) == 0
|| url.indexOf(this.domains.homol) == 0
);
};

PagTesouroIframe.prototype.handleEvent = function (callback) {
if (!callback) return;

let origin = this.sandbox
? this.domains.homol
: this.domains.prod;

window.addEventListener("message", function (event) {
if (event.origin !== origin) return;
if (event.data === "EPAG_FIM") callback();
}, false);
};
6 changes: 5 additions & 1 deletion src/Providers/PagTesouroServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ protected function loadConfigs()
{
$configPath = $this->packagePath('config/pagtesouro.php');
$this->mergeConfigFrom($configPath, 'pagtesouro');
$this->publishes([$configPath => config_path('pagtesouro.php')], 'pagtesouro');

$this->publishes([
$configPath => config_path('pagtesouro.php'),
$this->packagePath('resources/assets') => public_path('vendor/pagtesouro')
], 'pagtesouro');
}

/**
Expand Down

0 comments on commit 3039209

Please sign in to comment.