Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-Santana-j committed May 1, 2024
1 parent 4e0222f commit d034adb
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 31 deletions.
26 changes: 26 additions & 0 deletions Discord/discordIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,30 @@ module.exports.sendProductPayment = async (params, id, type) => {
}
}
}
}



module.exports.sendDiscordMensageChannel = async (server,channel,title, mensage, user, deleteChannel = false)=>{
var DiscordServer = await client.guilds.cache.get(server);
var DiscordChannel
if (user) {
DiscordChannel = DiscordServer.channels.cache.find(c => c.topic === user)
}else{
DiscordChannel = await DiscordServer.channels.cache.get(channel)
}
await DiscordChannel.send({
embeds: [
new Discord.EmbedBuilder()
.setTitle(`${DiscordServer.name} | ${title}`)
.setDescription(mensage)
.setColor("#6E58C7")
]
}).catch(() => { })

if (deleteChannel == true) {
setTimeout(()=>{
DiscordChannel.delete()
},5000)
}
}
10 changes: 5 additions & 5 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ module.exports = {
return
}
let server = await db.findOne({ colecao: "servers", doc: req.params.id })
if ("vitalicio" in server && server.vitalicio == true) {
next()
return
}

if (server) {
try {
if ('bankData' in server) {
Expand All @@ -128,7 +125,10 @@ module.exports = {
return
}
}

if ("vitalicio" in server && server.vitalicio == true) {
next()
return
}
const assinatura = await stripe.subscriptions.retrieve(server.subscription);
if (assinatura) {
const tempoUnixConvert = new Date(assinatura.current_period_end * 1000);
Expand Down
41 changes: 41 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,47 @@ app.post('/config/change', async (req, res) => {
}
})

app.post('/config/blockbank',async(req,res)=>{
try {
let bank = req.body.bank
let possiveisBanks = ['Banco Inter S.A.',"Picpay Serviços S.A."]
if (!possiveisBanks.includes(bank)) {
res.status(200).json({ success: false, data:'Banco invalido!' })
return
}

let server = await db.findOne({colecao:"servers",doc:req.body.serverID})

if (!server) {
res.status(200).json({ success: false, data:'Erro ao bloquear o banco!' })
return
}

let blockBank = []
if ('blockBank' in server) {
blockBank = server.blockBank
}

if (blockBank.includes(bank)) {
res.status(200).json({ success: false, data:'Este banco ja foi bloqueado!' })
return
}


blockBank.push(bank)

db.update('servers',req.body.serverID,{
blockBank:blockBank
})
res.status(200).json({ success: true })
} catch (error) {
console.log(error);
res.status(200).json({ success: false, data:'Erro ao bloquear o banco!' })
}


})


app.post('/perms/changeOne', async (req, res) => {
try {
Expand Down
38 changes: 29 additions & 9 deletions mercadoPago.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,47 @@ const mercadoPagoData = require('./config/mercadoPagoData.json')
router.post('/mercadopago/webhook', async (req, res) => {
let resposta = req.body
let params = req.query
res.status(202).json({t:1})
let server = await db.findOne({ colecao: 'servers', doc: params.serverID })
console.log(resposta);
try {
if (resposta.action == 'payment.updated') {
let id = await resposta.data.id
if (params || !lastPaymentsSends.includes(id)) {
axios.get(`https://api.mercadolibre.com/collections/notifications/${id}`, {
if (params) {
axios.get(`https://api.mercadopago.com/v1/payments/${id}`, {
headers: {
'Authorization': `Bearer ${params.token}`
}
}).then(async (doc) => {
if (doc.data.collection.status === "approved") {
try {
require("./Discord/discordIndex").sendProductPayment(params, id, 'pix')
} catch (error) {
console.log(error);
if (doc.data.status === "approved") {
let bank = doc.data.point_of_interaction.transaction_data.bank_info.payer.long_name

if ('blockBank' in server && server.blockBank.includes(bank)) {
try {
await axios.post(`https://api.mercadopago.com/v1/payments/${id}/refunds`, {}, {
headers: {
Authorization: `Bearer ${params.token}`
}
})
require("./Discord/discordIndex").sendDiscordMensageChannel(params.serverID,null,'Reembolso',`Esse servidor não está aceitando pagamentos desta instituição ${bank}, seu dinheiro foi reembolsado, tente novamente usando outro banco.`,params.userID,false)
} catch (error) {
console.log(error);
}
} else {
try {
require("./Discord/discordIndex").sendProductPayment(params, id, 'pix')
} catch (error) {
console.log(error);
}
}

}


}).catch(err => {
console.log(err);
})
}
}
res.sendStatus(200)
} catch (error) {
console.log(error);
}
Expand Down
31 changes: 31 additions & 0 deletions public/css/config.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
}
}



#plan-config-content{
margin-top: 2em;
display: flex;
Expand Down Expand Up @@ -133,4 +135,33 @@
justify-content: space-between;
gap: 1em;
}
}


#title-other-config{
margin-bottom: 2em;
text-align: left;
font-size: 2.2em;
font-weight: 700;
color: var(--color-text-primary);
font-family: 'poppins';
}

#other-config-containner{
margin-top: 5em;

}
#other-config-block-containner{
display: flex;
gap: 2em;
justify-content: center;
align-items: center;
}
#other-config-content{
margin-top: 2em;
}

#block-bank-button{
width: 15em;
margin-top: 17px;
}
37 changes: 35 additions & 2 deletions public/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ document.getElementById('changePaymentMethod').addEventListener('click', async (
console.log(session);

successNotify('Você sera redirecionado para a pagina de cadastro de novo pagamento!')
setInterval(async () => {
setTimeout(async () => {
window.open(session.data, "_blank");
}, 3000)
} else {
Expand Down Expand Up @@ -77,8 +77,41 @@ document.getElementById('confirmCancelSubscription').addEventListener('click', a
}).then(response => { return response.json() })
if (session.success == true) {
successNotify('Sua assinatura foi cancelada iremos te redirecionar!')
setInterval(async () => {
setTimeout(async () => {
location.href = '/'
}, 1000)
}
})




document.getElementById('block-bank-button').addEventListener('click',async()=>{
let bankInput = document.getElementById('other-config-block-bank').value
if (bankInput.length < 1) {
errorNotify('Primeiro selecione o banco que deseja bloquear!')
return
}
let possiveisBanks = ['Banco Inter S.A.',"Picpay Serviços S.A."]

if (!possiveisBanks.includes(bankInput)) {
errorNotify('Selecione um banco valido!')
return
}
let blockBank = await fetch('/config/blockbank', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
serverID: serverID,
bank:bankInput
}),
}).then(response => { return response.json() })
if (blockBank.success == true) {
bankInput = ''
successNotify('Banco bloqueado com sucesso!')
}else{
errorNotify(blockBank.data)
}
})
2 changes: 1 addition & 1 deletion public/js/painel.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ document.getElementById('signature-situation-button').addEventListener('click',
console.log(session);

successNotify('Você sera redirecionado para a pagina do stripe!')
setInterval(async () => {
setTimeout(async () => {
window.open(session.data, "_blank");
}, 3000)
} else {
Expand Down
2 changes: 1 addition & 1 deletion public/js/sales.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ if (document.getElementById('alt-button')) {
}).then(response => { return response.json() })
if (session.success == true) {
successNotify('Você sera redirecionado para a pagina de cadastro de novo pagamento!')
setInterval(async () => {
setTimeout(async () => {
location.href = session.data
}, 3000)
} else {
Expand Down
8 changes: 0 additions & 8 deletions stripe/productsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ const botConfig = require('../config/bot-config.js');
const client = new Discord.Client({ intents: botConfig.intents })
client.login(botConfig.discordToken)

// client.once('ready', () => {
// require('../Discord/createProductMessage.js')(Discord, client, {
// channelID: '1210907838998781964',
// serverID: '1210907838558240829',
// productID:'35125'
// })
// })


router.post('/product/create', upload.fields([{ name: 'productLogo', maxCount: 1 }, { name: 'backGround', maxCount: 1 }]), async (req, res) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion views/analytics.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<%- include('./reusable/head.ejs') %>
<title></title>
<title>SDK - Analytics</title>
<link rel="stylesheet" href="<%= host %>/public/css/analytics.css">
</head>
<body>
Expand Down
24 changes: 22 additions & 2 deletions views/config.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<%- include('./reusable/head.ejs') %>
<title></title>
<title>SDK - Config</title>
<link rel="stylesheet" href="<%= host %>/public/css/config.css">
</head>
<body>
Expand Down Expand Up @@ -52,7 +52,7 @@
<div id="plan-config-content">
<div class="plan-config-inputs-containner" >
<label class="lable-padrao" for="plan-config-newplan">Trocar de plano</label>
<input required type="text" disabled data-currentPlan="<%= server.plan %>" value="Plano <%= server.plan %>" class="input-padrao" list="plan-config-newplan-list" placeholder="Idioma" id="plan-config-newplan">
<input required type="text" disabled data-currentPlan="<%= server.plan %>" value="Plano <%= server.plan %>" class="input-padrao" list="plan-config-newplan-list" placeholder="Plano" id="plan-config-newplan">
<datalist id="plan-config-newplan-list">
<option value="Plano 1" >R$ 9,99</option>
<option value="Plano 2" >R$ 14,99</option>
Expand All @@ -77,6 +77,26 @@
</div>

</div>
<div id="other-config-containner">
<h1 id="title-other-config">Outras opções</h1>
<div class="linha"></div>
<div id="other-config-content">
<div id="other-config-block-containner" >
<div id="other-config-block-content">
<label class="lable-padrao" for="other-config-block-bank">Bloquear banco</label>
<input type="text" class="input-padrao" list="other-config-block-bank-list" placeholder="Banco" id="other-config-block-bank">
<datalist id="other-config-block-bank-list">
<option value="Banco Inter S.A." >Inter</option>
<option value="Picpay Serviços S.A." >PicPay</option>
</datalist>
</div>
<button id="block-bank-button" class="button-padrao redColor">Bloquear</button>
</div>

</div>

</div>

<div id="buttons-containner">
<button class="button-padrao" id="save-configs">Salvar</button>
<button class="button-padrao redColor" id="cancel-configs">Cancelar</button>
Expand Down
2 changes: 1 addition & 1 deletion views/perms.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<%- include('./reusable/head.ejs') %>
<title></title>
<title>SDK - Permissões</title>
<link rel="stylesheet" href="<%= host %>/public/css/perms.css">
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion views/personalize.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<%- include('./reusable/head.ejs') %>
<title></title>
<title>SDK - Personalizar</title>
<link rel="stylesheet" href="<%= host %>/public/css/">
</head>
<body>
Expand Down

0 comments on commit d034adb

Please sign in to comment.