From 9ec777be36e52812239aebf19d1c1d5862b63ddc Mon Sep 17 00:00:00 2001 From: "aditya.siregar" Date: Tue, 15 Oct 2024 14:03:20 +0700 Subject: [PATCH] Update Furtuna Payment VA Linkqu --- infra/furtuna.development.yaml | 2 +- internal/handlers/http/linqu/order.go | 71 +++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 internal/handlers/http/linqu/order.go diff --git a/infra/furtuna.development.yaml b/infra/furtuna.development.yaml index e2d07b3..849caf0 100644 --- a/infra/furtuna.development.yaml +++ b/infra/furtuna.development.yaml @@ -47,7 +47,7 @@ linkqu: signature_key: "LinkQu@2020" username: "LI307GXIN" pin: "2K2NPCBBNNTovgB" - callback_url: "https://furtuna-be.app-dev.altru.id/api/linkqu/callback" + callback_url: "https://furtuna-be.app-dev.altru.id/api/v1/linkqu/callback" brevo: api_key: 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 diff --git a/internal/handlers/http/linqu/order.go b/internal/handlers/http/linqu/order.go new file mode 100644 index 0000000..ae31f44 --- /dev/null +++ b/internal/handlers/http/linqu/order.go @@ -0,0 +1,71 @@ +package mdtrns + +import ( + "furtuna-be/internal/handlers/request" + "furtuna-be/internal/handlers/response" + "furtuna-be/internal/services" + "github.com/gin-gonic/gin" + "net/http" +) + +type Handler struct { + service services.Order +} + +func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) { + route := group.Group("/midtrans") + + route.POST("/callback", h.Callback) +} + +func NewHandler(service services.Order) *Handler { + return &Handler{ + service: service, + } +} + +func (h *Handler) Callback(c *gin.Context) { + var callbackData request.MidtransCallbackRequest + if err := c.ShouldBindJSON(&callbackData); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + + validStatuses := []string{"settlement", "expire", "deny", "cancel", "capture", "failure"} + + isValidStatus := false + for _, status := range validStatuses { + if callbackData.TransactionStatus == status { + isValidStatus = true + break + } + } + + if !isValidStatus { + c.JSON(http.StatusOK, response.BaseResponse{ + Success: true, + Status: http.StatusOK, + Message: "", + }) + return + } + + err := h.service.ProcessCallback(c, callbackData.ToEntity()) + + if err != nil { + c.JSON(http.StatusUnauthorized, response.BaseResponse{ + Success: false, + Status: http.StatusBadRequest, + Message: err.Error(), + Data: nil, + }) + return + } + + c.JSON(http.StatusOK, response.BaseResponse{ + Success: true, + Status: http.StatusOK, + Message: "order", + }) + +}