69 lines
2.2 KiB
Go
69 lines
2.2 KiB
Go
package kyc
|
|
|
|
import (
|
|
"nixcn-cms/internal/exception"
|
|
"nixcn-cms/service/service_kyc"
|
|
"nixcn-cms/utils"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// @Summary Create KYC Session
|
|
// @Description Initializes a KYC process (CNRid or Passport) and returns the status or redirect URI.
|
|
// @Tags KYC
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param payload body service_kyc.KycSessionData true "KYC session data (Type and Base64 Identity)"
|
|
// @Success 200 {object} utils.RespStatus{data=service_kyc.KycSessionResponse} "Session created successfully"
|
|
// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid input or decode failed"
|
|
// @Failure 403 {object} utils.RespStatus{data=nil} "Missing User ID"
|
|
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error / KYC Service Error"
|
|
// @Security ApiKeyAuth
|
|
// @Router /kyc/session [post]
|
|
func (self *KycHandler) Session(c *gin.Context) {
|
|
userIdFromHeaderOrig, ok := c.Get("user_id")
|
|
if !ok {
|
|
errorCode := new(exception.Builder).
|
|
SetStatus(exception.StatusUser).
|
|
SetService(exception.ServiceKyc).
|
|
SetEndpoint(exception.EndpointKycServiceSession).
|
|
SetType(exception.TypeCommon).
|
|
SetOriginal(exception.CommonErrorMissingUserId).
|
|
Throw(c).
|
|
String()
|
|
utils.HttpResponse(c, 403, errorCode)
|
|
return
|
|
}
|
|
|
|
var sessionData service_kyc.KycSessionData
|
|
if err := c.ShouldBindJSON(&sessionData); err != nil {
|
|
errorCode := new(exception.Builder).
|
|
SetStatus(exception.StatusUser).
|
|
SetService(exception.ServiceKyc).
|
|
SetEndpoint(exception.EndpointKycServiceSession).
|
|
SetType(exception.TypeCommon).
|
|
SetOriginal(exception.CommonErrorInvalidInput).
|
|
SetError(err).
|
|
Throw(c).
|
|
String()
|
|
utils.HttpResponse(c, 400, errorCode)
|
|
return
|
|
}
|
|
|
|
sessionData.UserId = userIdFromHeaderOrig.(string)
|
|
|
|
kycPayload := &service_kyc.KycSessionPayload{
|
|
Context: c,
|
|
Data: &sessionData,
|
|
}
|
|
|
|
result := self.svc.SessionKyc(kycPayload)
|
|
|
|
if result.Common.Exception.Original != exception.CommonSuccess {
|
|
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String())
|
|
return
|
|
}
|
|
|
|
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String(), result.Data)
|
|
}
|