Skip to content

Commit

Permalink
Release 2.2.0: Open Finance
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoliveiraGN committed Aug 31, 2023
1 parent c4d0b5b commit ec342a4
Show file tree
Hide file tree
Showing 12 changed files with 3,130 additions and 2,007 deletions.
78 changes: 78 additions & 0 deletions assets/css/open-finance.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
.swal2-html-container {
max-height: 350px;
overflow: hidden;
}

.gn-participants-list {

height: 300px;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
overflow-x: hidden;

}

.gn-participant-item {
width: 100%;
display: inline-flex;
padding: 6px;
}

.gn-participant {
margin-right: 5px;
border-radius: 5px;
}

.gn-participant:hover {
background: #f4f4f4;
cursor: pointer;
}

.gn-participant-logo {
width: 50px !important;
height: 50px !important;
align-self: center;
}

.gn-participant-name {
margin-left: auto;
align-self: center;
padding-right: 20px;
cursor: pointer;
}

.gn-hr {
border: 0;
height: 1px;
background-image: linear-gradient(to right, rgba(163, 163, 163, 0), rgba(163, 163, 163, 0.75), rgba(163, 163, 163, 0));
margin-bottom: 0;
}

.gn-of-search {
width: 80%;
padding: 10px;
border-color: rgba(163, 163, 163);
border-width: thin;
border-radius: 5px;
margin-bottom: 20px;
}

.gn-default-participant {
background: #f4f4f4;
cursor: pointer;
border-radius: 5px;
}

.gn-default-participant label {
margin-left: 10px;
align-self: end;
cursor: pointer;
}

.gn-of-edit {
margin-left: auto;
margin-right: 20px;
width: 25px;
height: 25px;
align-self: center;
}
Binary file added assets/img/edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/question.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
258 changes: 258 additions & 0 deletions assets/js/scripts-open-finance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
if ('undefined' == typeof participantsVector) {
let participantsVector
}


function showParticipants(apiData) {
participantsVector = apiData

jQuery('#gn-default-logo').show()
jQuery('#gn-participant-logo').hide()
jQuery('#gn-default-name').text('Escolha sua instituição')

let finalReturn = jQuery('<div></div>')

let searchInput = jQuery('<input type="text" placeholder="Digite o nome da sua Instituição.." id="gn-of-search" class="gn-of-search" onkeyup="filterParticipants()">')

finalReturn.append(searchInput)

let participantsList = jQuery("<div id='gn-participants-list' class='gn-participants-list'></div>")

apiData.forEach((participant, index) => {
let outerDiv = jQuery('<div class="gn-participant" onclick="selectParticipant(' + index + ')"></div>')
let participantItem = jQuery("<div class='gn-participant-item' ></div>")
let participantLogo = jQuery("<img class='gn-participant-logo' src='" + participant.logo + "' />")
let participantName = jQuery("<label class='gn-participant-name'>" + participant.nome + "</label>")

participantItem.append(participantLogo)
participantItem.append(participantName)
outerDiv.append(participantItem)
outerDiv.append('<hr class="gn-hr">')
participantsList.append(outerDiv)

});

finalReturn.append(participantsList)

Swal.fire({
title: 'Escolha sua Instituição',
html: finalReturn,
showCancelButton: false,
showConfirmButton: false
})


}


function filterParticipants() {
var input, filter, ul, li, a, i;
input = document.getElementById("gn-of-search");
filter = input.value.toUpperCase();
div = document.getElementById("gn-participants-list");
elements = div.getElementsByTagName("div");

for (i = 0; i < elements.length; i++) {
txtValue = elements[i].textContent || elements[i].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
elements[i].style.display = "";
} else {
elements[i].style.display = "none";
}
}
}

function selectParticipant(participantIndex) {
jQuery('#gn-default-logo').hide()
jQuery('#gn_of_participant').val(participantsVector[participantIndex].identificador)
jQuery('#gn-participant-logo').attr('src', participantsVector[participantIndex].logo)
jQuery('#gn-participant-logo').show()
jQuery('#gn-default-name').text(participantsVector[participantIndex].nome)

Swal.close()
jQuery("#place_order").prop("disabled", false)
}

if (document.getElementById('gn_open_finance_cpf_cnpj')) {
jQuery('#gn_open_finance_cpf_cnpj').keyup(
function () {
jQuery('#gn_open_finance_cpf_cnpj').val().length > 14 ? VMasker(document.querySelector("#gn_open_finance_cpf_cnpj")).maskPattern("99.999.999/9999-99") : VMasker(document.querySelector("#gn_open_finance_cpf_cnpj")).maskPattern("999.999.999-99");
}
)
jQuery('#gn_open_finance_cpf_cnpj').blur(
function () {
var cpf_cnpj = jQuery('#gn_open_finance_cpf_cnpj').val();

if (!validate_cpf_cnpj(cpf_cnpj)) {
jQuery('#gn_open_finance_cpf_cnpj').css('border', '1px solid red');
toastError("CPF/CNPJ Inválido");
} else {
jQuery('#gn_open_finance_cpf_cnpj').css('border', '1px solid green');
}
}
)

if (typeof jQuery('#billing_cpf').val() !== 'undefined') {


// cpf_cnpj Open Finance
if (typeof jQuery('#gn_open_finance_cpf_cnpj').val() !== 'undefined') {
jQuery('#gn_open_finance_cpf_cnpj').val(jQuery('#billing_cpf').val())
jQuery('#gn_field_open_finance_cpfcnpj').hide();
}

jQuery('#billing_cpf').keyup(function () {

if (typeof jQuery('#gn_open_finance_cpf_cnpj').val() !== 'undefined') {
// cpf_cnpj Open Finance
jQuery('#gn_open_finance_cpf_cnpj').val(jQuery('#billing_cpf').val())
jQuery('#gn_field_open_finance_cpfcnpj').hide();
}
}
)
}

if (typeof jQuery('#billing_cnpj').val() !== 'undefined') {
jQuery('#billing_cnpj').keyup(
function () {
// cpf_cnpj Open Finance
jQuery('#gn_open_finance_cpf_cnpj').val($('#billing_cnpj').val())
jQuery('#gn_field_open_finance_cpfcnpj').hide();
}
)
}

function toastError(msg) {
Swal.mixin(
{
toast: true,
position: 'top-right',
iconColor: 'white',
customClass: {
popup: 'colored-toast'
},
showConfirmButton: false,
timer: 5000,
timerProgressBar: true
}
).fire({ icon: 'error', title: msg })
}

function validate_cpf_cnpj(cpf_cnpj) {

cpf_cnpj = cpf_cnpj.trim().replace(/\./g, '').replace('-', '').replace('/', '');

if (cpf_cnpj < 11) {
return false;
}

if (cpf_cnpj.length == 11) {
var remnant, sum = 0;

for (i = 1; i <= 9; i++) {
sum = sum + parseInt(cpf_cnpj.substring(i - 1, i)) * (11 - i);
}
remnant = (sum * 10) % 11;

if ((remnant == 10) || (remnant == 11)) {
remnant = 0;
}
if (remnant != parseInt(cpf_cnpj.substring(9, 10))) {
return false;
}

sum = 0;

for (i = 1; i <= 10; i++) {
sum = sum + parseInt(cpf_cnpj.substring(i - 1, i)) * (12 - i);
}
remnant = (sum * 10) % 11;

if ((remnant == 10) || (remnant == 11)) {
remnant = 0;
}
if (remnant != parseInt(cpf_cnpj.substring(10, 11))) {
return false;
}
return true;

} else if (cpf_cnpj.length == 14) {
var tam = cpf_cnpj.length - 2
var numbers = cpf_cnpj.substring(0, tam);
var digits = cpf_cnpj.substring(tam);
var sum = 0;
var pos = tam - 7;

for (i = tam; i >= 1; i--) {
sum += numbers.charAt(tam - i) * pos--;
if (pos < 2) {
pos = 9;
}
}

var result = sum % 11 < 2 ? 0 : 11 - sum % 11;

if (result != digits.charAt(0)) {
return false;
}

tam = tam + 1;
numbers = cpf_cnpj.substring(0, tam);
sum = 0;
pos = tam - 7;

for (i = tam; i >= 1; i--) {
sum += numbers.charAt(tam - i) * pos--;
if (pos < 2) {
pos = 9;
}
}

result = sum % 11 < 2 ? 0 : 11 - sum % 11;

if (result != digits.charAt(1)) {
return false;
}

return true;
}

}

}



jQuery('form[name="checkout"]').submit(function () {
if (jQuery('#payment_method_WC_Gerencianet_Open_Finance').is(':checked')) {
let participant = jQuery('<div id="conteudo" class="gn-default-participant"></div>')
let participantLogo = jQuery("<img class='gn-participant-logo' src='" + jQuery("#gn-participant-logo").attr('src') + "' />")
let participantName = jQuery("<label class='gn-participant-name'>" + jQuery("#gn-default-name").html() + "</label>")

participant.append(participantLogo)
participant.append(participantName)

Swal.fire({
title: 'Você está sendo redirecionado para',
html: participant,
timer: 500000,
didOpen: () => {
Swal.showLoading()
},
willClose: () => {
return true
}
})
setTimeout(500000)
}

});

jQuery('input[name="payment_method"]').click(function () {
if (jQuery('#payment_method_WC_Gerencianet_Open_Finance').is(':checked') && jQuery("#gn_of_participant").val() == '') {
jQuery("#place_order").prop("disabled", true)

} else {
jQuery("#place_order").prop("disabled", false)
}
})
Loading

0 comments on commit ec342a4

Please sign in to comment.