Skip to content

Commit

Permalink
feat
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio Brasileiro authored and Fabio Brasileiro committed Nov 19, 2024
1 parent c970f40 commit 6f9b8df
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
18 changes: 10 additions & 8 deletions src/controllers/authController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import 'dotenv/config'

import { PrismaClient, UserRole } from '@prisma/client' // Importação do enum UserRole
import bcrypt from 'bcrypt'
import jwt from 'jsonwebtoken'
Expand Down Expand Up @@ -150,25 +152,25 @@ const getMenuForRole = (role: any) => {
route: '/products',
children: [
{ label: 'View Products', route: '/products/view' },
{ label: 'Categories', route: '/products/categories' },
// { label: 'Categories', route: '/products/categories' },
// Admin-only routes
...(role === UserRole.ADMIN
? [
{
label: 'Add Product',
label: 'Gerenciamento de produtos',
route: '/products/add',
adminOnly: true,
},
{
label: 'Edit Product',
label: 'Pagamentos',
route: '/products/edit',
adminOnly: true,
},
{
label: 'Delete Product',
route: '/products/delete',
adminOnly: true,
},
// {
// label: 'Delete Product',
// route: '/products/delete',
// adminOnly: true,
// },
]
: []),
],
Expand Down
26 changes: 26 additions & 0 deletions src/controllers/hook.payment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,29 @@ const updatePaymentStatus = async (paymentDetails: any) => {
throw new Error('Erro ao atualizar ou criar pagamento no banco.')
}
}
export const checkPaymentStatus = async (req:Request, res: Response) => {
const paymentId = req.params.paymentId;
const accessToken = process.env.PROD_ACCESS_TOKEN;

if (!accessToken) {
return res.status(500).json({ error: 'Access token não configurado.' });
}

try {
const response = await axios.get(
`https://api.mercadopago.com/v1/payments/${paymentId}`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
);

// Retorna o status do pagamento para o frontend
const { status, status_detail } = response.data;
res.json({ status, status_detail });
} catch (error) {
console.error('Erro ao verificar status do pagamento:', (error as Error).message);
res.status(500).json({ error: 'Erro ao verificar status do pagamento.' });
}
}
14 changes: 3 additions & 11 deletions src/routes/paymentRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express from 'express'
import { createPayment } from '../controllers/paymentController'
import { webHook } from '@/controllers/hook.payment.controller'
import { checkPaymentStatus, webHook } from '@/controllers/hook.payment.controller'

const router = express.Router()

Expand All @@ -9,15 +9,7 @@ router.post('/', createPayment)

router.post('/webhook', webHook)

router.get('/simulate-payment', async (req, res) => {
try {
// Chamando a função de simulação de pagamento PIX
// await simulatePixPayment();
res.send('Simulação de pagamento com PIX realizada com sucesso!')
} catch (error) {
console.error('Erro ao simular o pagamento:', error)
res.status(500).send('Erro ao simular pagamento')
}
})
// Endpoint para verificar o status do pagamento
router.get('/check-payment-status/:paymentId', checkPaymentStatus);

export default router

0 comments on commit 6f9b8df

Please sign in to comment.