233 lines
8.4 KiB
Go
233 lines
8.4 KiB
Go
package handlers
|
|
|
|
import (
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// CreateSantimPayPaymentHandler initializes a payment session with SantimPay.
|
|
//
|
|
// @Summary Create SantimPay Payment Session
|
|
// @Description Generates a payment URL using SantimPay and returns it to the client.
|
|
// @Tags SantimPay
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param request body domain.GeneratePaymentURLRequest true "SantimPay payment request payload"
|
|
// @Success 200 {object} domain.Response
|
|
// @Failure 400 {object} domain.ErrorResponse
|
|
// @Failure 500 {object} domain.ErrorResponse
|
|
// @Router /api/v1/santimpay/payment [post]
|
|
func (h *Handler) InititateSantimPayPaymentHandler(c *fiber.Ctx) error {
|
|
var req domain.GeneratePaymentURLRequest
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{
|
|
Error: err.Error(),
|
|
Message: "Failed to process your request",
|
|
})
|
|
}
|
|
|
|
paymentURL, err := h.santimpaySvc.InitiatePayment(req)
|
|
if err != nil {
|
|
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{
|
|
Error: err.Error(),
|
|
Message: "Failed to initiate SantimPay payment session",
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "SantimPay payment URL generated successfully",
|
|
Data: paymentURL,
|
|
Success: true,
|
|
StatusCode: fiber.StatusOK,
|
|
})
|
|
}
|
|
|
|
// ProcessSantimPayCallbackHandler handles incoming SantimPay payment callbacks.
|
|
//
|
|
// @Summary Process SantimPay Payment Callback
|
|
// @Description Processes a callback from SantimPay, updates transfer status, and credits user wallet if payment was successful.
|
|
// @Tags SantimPay
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param request body domain.SantimPayCallbackPayload true "SantimPay callback payload"
|
|
// @Success 200 {object} domain.Response
|
|
// @Failure 400 {object} domain.ErrorResponse
|
|
// @Failure 500 {object} domain.ErrorResponse
|
|
// @Router /api/v1/santimpay/callback [post]
|
|
func (h *Handler) ProcessSantimPayCallbackHandler(c *fiber.Ctx) error {
|
|
var payload domain.SantimPayCallbackPayload
|
|
if err := c.BodyParser(&payload); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{
|
|
Error: err.Error(),
|
|
Message: "Invalid callback payload",
|
|
})
|
|
}
|
|
|
|
if err := h.santimpaySvc.ProcessCallback(c.Context(), payload); err != nil {
|
|
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{
|
|
Error: err.Error(),
|
|
Message: "Failed to process SantimPay callback",
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "SantimPay callback processed successfully",
|
|
Data: nil,
|
|
Success: true,
|
|
StatusCode: fiber.StatusOK,
|
|
})
|
|
}
|
|
|
|
// ProcessSantimPayDirectPaymentHandler initializes a direct payment session with SantimPay.
|
|
//
|
|
// @Summary Process SantimPay Direct Payment
|
|
// @Description Initiates a direct payment request with SantimPay and returns the response.
|
|
// @Tags SantimPay
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param request body domain.GeneratePaymentURLRequest true "SantimPay direct payment request payload"
|
|
// @Success 200 {object} domain.Response
|
|
// @Failure 400 {object} domain.ErrorResponse
|
|
// @Failure 500 {object} domain.ErrorResponse
|
|
// @Router /api/v1/santimpay/direct-payment [post]
|
|
func (h *Handler) ProcessSantimPayDirectPaymentHandler(c *fiber.Ctx) error {
|
|
var req domain.GeneratePaymentURLRequest
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{
|
|
Error: err.Error(),
|
|
Message: "Invalid direct payment request payload",
|
|
})
|
|
}
|
|
|
|
response, err := h.santimpaySvc.ProcessDirectPayment(c.Context(), req)
|
|
if err != nil {
|
|
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{
|
|
Error: err.Error(),
|
|
Message: "Failed to process SantimPay direct payment",
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "SantimPay direct payment processed successfully",
|
|
Data: response,
|
|
Success: true,
|
|
StatusCode: fiber.StatusOK,
|
|
})
|
|
}
|
|
|
|
// GetSantimPayB2CPartnersHandler retrieves all available SantimPay B2C payout partners.
|
|
//
|
|
// @Summary Get SantimPay B2C Partners
|
|
// @Description Fetches a list of available B2C payout partners (e.g., Telebirr, Mpesa, Banks) from SantimPay.
|
|
// @Tags SantimPay
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} domain.Response
|
|
// @Failure 500 {object} domain.ErrorResponse
|
|
// @Router /api/v1/santimpay/b2c/partners [get]
|
|
func (h *Handler) GetSantimPayB2CPartnersHandler(c *fiber.Ctx) error {
|
|
partners, err := h.santimpaySvc.GetB2CPartners(c.Context())
|
|
if err != nil {
|
|
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{
|
|
Error: err.Error(),
|
|
Message: "Failed to fetch SantimPay B2C partners",
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "SantimPay B2C partners retrieved successfully",
|
|
Data: partners,
|
|
Success: true,
|
|
StatusCode: fiber.StatusOK,
|
|
})
|
|
}
|
|
|
|
// ProcessSantimPayB2CWithdrawalHandler processes a B2C (Withdrawal) transaction with SantimPay.
|
|
//
|
|
// @Summary Process SantimPay B2C Withdrawal
|
|
// @Description Initiates a B2C withdrawal request with SantimPay and returns the response.
|
|
// @Tags SantimPay
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param request body domain.GeneratePaymentURLRequest true "SantimPay B2C withdrawal request payload"
|
|
// @Success 200 {object} domain.Response
|
|
// @Failure 400 {object} domain.ErrorResponse
|
|
// @Failure 500 {object} domain.ErrorResponse
|
|
// @Router /api/v1/santimpay/b2c-withdrawal [post]
|
|
func (h *Handler) ProcessSantimPayB2CWithdrawalHandler(c *fiber.Ctx) error {
|
|
var req domain.GeneratePaymentURLRequest
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{
|
|
Error: err.Error(),
|
|
Message: "Invalid B2C withdrawal request payload",
|
|
})
|
|
}
|
|
|
|
// Extract userId from context/session (adapt based on your auth flow)
|
|
userId, ok := c.Locals("userId").(int64)
|
|
if !ok {
|
|
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{
|
|
Error: "missing userId in context",
|
|
Message: "Could not process withdrawal without user ID",
|
|
})
|
|
}
|
|
|
|
response, err := h.santimpaySvc.ProcessB2CWithdrawal(c.Context(), req, userId)
|
|
if err != nil {
|
|
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{
|
|
Error: err.Error(),
|
|
Message: "Failed to process SantimPay B2C withdrawal",
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "SantimPay B2C withdrawal processed successfully",
|
|
Data: response,
|
|
Success: true,
|
|
StatusCode: fiber.StatusOK,
|
|
})
|
|
}
|
|
|
|
// CheckSantimPayTransactionStatusHandler checks the status of a SantimPay transaction.
|
|
//
|
|
// @Summary Check SantimPay Transaction Status
|
|
// @Description Retrieves the real-time status of a transaction from SantimPay.
|
|
// @Tags SantimPay
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param request body domain.TransactionStatusRequest true "Transaction status request payload"
|
|
// @Success 200 {object} domain.Response
|
|
// @Failure 400 {object} domain.ErrorResponse
|
|
// @Failure 500 {object} domain.ErrorResponse
|
|
// @Router /api/v1/santimpay/transaction-status [post]
|
|
func (h *Handler) CheckSantimPayTransactionStatusHandler(c *fiber.Ctx) error {
|
|
var req domain.TransactionStatusRequest
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{
|
|
Error: err.Error(),
|
|
Message: "Invalid transaction status request payload",
|
|
})
|
|
}
|
|
|
|
// Optional: extract fullParams from request, default to true if not provided
|
|
fullParams := true
|
|
if req.FullParams == nil {
|
|
req.FullParams = &fullParams
|
|
}
|
|
|
|
response, err := h.santimpaySvc.CheckTransactionStatus(c.Context(), req)
|
|
if err != nil {
|
|
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{
|
|
Error: err.Error(),
|
|
Message: "Failed to check SantimPay transaction status",
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
|
Message: "SantimPay transaction status retrieved successfully",
|
|
Data: response,
|
|
Success: true,
|
|
StatusCode: fiber.StatusOK,
|
|
})
|
|
}
|