Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Makefile
*_test.go
*.test

# Reference code (analysis only)
evo que funciona*/
ANALISE-CORRECOES-CAROUSEL-PIX.md

# Manager/dist é necessário - serve arquivos estáticos do frontend React
# Não excluir - precisa estar na imagem final para ser acessado via /manager

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ coverage.*
.idea/
.vscode/
.DS_Store
evo que funciona botõtes carossel pix etc para analise/
1 change: 1 addition & 0 deletions pkg/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (r *Routes) AssignRoutes(eng *gin.Engine) {
routes.POST("/button", r.jidValidationMiddleware.ValidateNumberFieldWithFormatJid(), r.sendHandler.SendButton)
routes.POST("/list", r.jidValidationMiddleware.ValidateNumberFieldWithFormatJid(), r.sendHandler.SendList)
routes.POST("/carousel", r.jidValidationMiddleware.ValidateNumberFieldWithFormatJid(), r.sendHandler.SendCarousel)
routes.POST("/pix", r.jidValidationMiddleware.ValidateNumberFieldWithFormatJid(), r.sendHandler.SendPix)
routes.POST("/status/text", r.sendHandler.SendStatusText)
routes.POST("/status/media", r.sendHandler.SendStatusMedia)
}
Expand Down
67 changes: 67 additions & 0 deletions pkg/sendMessage/handler/send_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type SendHandler interface {
SendButton(ctx *gin.Context)
SendList(ctx *gin.Context)
SendCarousel(ctx *gin.Context)
SendPix(ctx *gin.Context)
SendStatusText(ctx *gin.Context)
SendStatusMedia(ctx *gin.Context)
}
Expand Down Expand Up @@ -655,6 +656,72 @@ func (s *sendHandler) SendCarousel(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{"message": "success", "data": message})
}

// Send a PIX payment message
// @Summary Send a PIX payment message
// @Description Send a PIX payment interactive message via WhatsApp
// @Tags Send Message
// @Accept json
// @Produce json
// @Param message body send_service.PixStruct true "PIX payment data"
// @Success 200 {object} gin.H "success"
// @Failure 400 {object} gin.H "Error on validation"
// @Failure 500 {object} gin.H "Internal server error"
// @Router /send/pix [post]
func (s *sendHandler) SendPix(ctx *gin.Context) {
getInstance := ctx.MustGet("instance")

instance, ok := getInstance.(*instance_model.Instance)
if !ok {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "instance not found"})
return
}

var data *send_service.PixStruct
err := ctx.ShouldBindBodyWithJSON(&data)
if err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

if data.Number == "" {
ctx.JSON(http.StatusBadRequest, gin.H{"error": "phone number is required"})
return
}

if data.HeaderTitle == "" {
ctx.JSON(http.StatusBadRequest, gin.H{"error": "headerTitle is required"})
return
}

if data.BodyText == "" {
ctx.JSON(http.StatusBadRequest, gin.H{"error": "bodyText is required"})
return
}

if data.MerchantName == "" {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As validações de MerchantName, PixKey e KeyType estão presentes tanto no send_handler.go quanto no send_service.go.

Sugestão: Mover a lógica de validação para um método de domínio ou usar tags de validação do Gin (binding:"required") na struct PixStruct. Isso simplifica o handler e garante que o service seja testável isoladamente.

ctx.JSON(http.StatusBadRequest, gin.H{"error": "merchantName is required"})
return
}

if data.PixKey == "" {
ctx.JSON(http.StatusBadRequest, gin.H{"error": "pixKey is required"})
return
}

if data.KeyType == "" {
ctx.JSON(http.StatusBadRequest, gin.H{"error": "keyType is required (CPF, CNPJ, EMAIL, PHONE, EVP)"})
return
}

message, err := s.sendMessageService.SendPix(data, instance)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

ctx.JSON(http.StatusOK, gin.H{"message": "success", "data": message})
}

// Send a text status message
// @Summary Send a WhatsApp text status
// @Description Send a WhatsApp text status to status@broadcast
Expand Down
Loading
Loading