@@ -30,6 +30,45 @@ type CheckinResult struct {
|
||||
}
|
||||
|
||||
func (self *EventServiceImpl) Checkin(payload *CheckinPayload) (result *CheckinResult) {
|
||||
attendandeData, err := new(data.Attendance).
|
||||
GetAttendanceByEventIdAndUserId(payload.Context, payload.Data.EventId, payload.UserId)
|
||||
if err != nil {
|
||||
result = &CheckinResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceCheckin).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorDatabase).
|
||||
SetError(err).
|
||||
Throw(payload.Context),
|
||||
},
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
eventData, err := new(data.Event).
|
||||
GetEventById(payload.Context, payload.Data.EventId)
|
||||
|
||||
if attendandeData.KycId == uuid.Nil && eventData.EnableKYC == true {
|
||||
result = &CheckinResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceCheckin).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(err).
|
||||
Throw(payload.Context),
|
||||
},
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
attendance := &data.Attendance{UserId: payload.UserId}
|
||||
code, err := attendance.GenCheckinCode(payload.Context, payload.Data.EventId)
|
||||
if err != nil {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
type EventJoinData struct {
|
||||
EventId string `json:"event_id"`
|
||||
KycId string `json:"kyc_id"`
|
||||
UserId string `json:"user_id" swaggerignore:"true"`
|
||||
Role string `json:"role" swaggerignore:"true"`
|
||||
State string `json:"state" swaggerignore:"true"`
|
||||
@@ -30,7 +31,6 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even
|
||||
var err error
|
||||
|
||||
attendenceData := new(data.Attendance)
|
||||
eventData := new(data.Event)
|
||||
|
||||
eventId, err := uuid.Parse(payload.Data.EventId)
|
||||
if err != nil {
|
||||
@@ -53,19 +53,41 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even
|
||||
return
|
||||
}
|
||||
|
||||
if !eventData.EndTime.Before(time.Now()) {
|
||||
eventData, err := new(data.Event).GetEventById(payload.Context, eventId)
|
||||
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceJoin).
|
||||
SetType(exception.TypeSpecific).
|
||||
SetOriginal(exception.EventJoinEventInvalid).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorDatabase).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &EventJoinResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 403,
|
||||
HttpCode: 500,
|
||||
Exception: exception,
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if eventData.EnableKYC == true && payload.Data.KycId == "" {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceJoin).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(nil).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &EventJoinResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
}
|
||||
@@ -94,8 +116,94 @@ func (self *EventServiceImpl) JoinEvent(payload *EventJoinPayload) (result *Even
|
||||
return
|
||||
}
|
||||
|
||||
attendenceData.SetEventId(eventId)
|
||||
if eventData.EnableKYC == true && payload.Data.KycId != "" {
|
||||
kycId, err := uuid.Parse(payload.Data.KycId)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceJoin).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorUuidParseFailed).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &EventJoinResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
kycData, err := new(data.Kyc).GetByKycId(payload.Context, &kycId)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceJoin).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorDatabase).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &EventJoinResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: exception,
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if kycData.UserId != userId {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceJoin).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &EventJoinResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
attendenceData.SetKycId(kycData.KycId)
|
||||
}
|
||||
|
||||
if !eventData.EndTime.Before(time.Now()) {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceJoin).
|
||||
SetType(exception.TypeSpecific).
|
||||
SetOriginal(exception.EventJoinEventInvalid).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &EventJoinResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 403,
|
||||
Exception: exception,
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
attendenceData.SetUserId(userId)
|
||||
attendenceData.SetEventId(eventId)
|
||||
attendenceData.SetRole("notmal")
|
||||
attendenceData.SetState("success")
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ func (self *EventServiceImpl) ListEvents(payload *EventListPayload) (result *Eve
|
||||
|
||||
var offset string
|
||||
if payload.Offset == nil || *payload.Offset == "" {
|
||||
exc := new(exception.Builder).
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceList).
|
||||
@@ -41,7 +41,7 @@ func (self *EventServiceImpl) ListEvents(payload *EventListPayload) (result *Eve
|
||||
return &EventListResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exc,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
251
service/service_kyc/query_kyc.go
Normal file
251
service/service_kyc/query_kyc.go
Normal file
@@ -0,0 +1,251 @@
|
||||
package service_kyc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"nixcn-cms/data"
|
||||
"nixcn-cms/internal/exception"
|
||||
"nixcn-cms/internal/kyc"
|
||||
"nixcn-cms/service/shared"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type KycQueryData struct {
|
||||
KycId string `json:"kyc_id"`
|
||||
}
|
||||
|
||||
type KycQueryPayload struct {
|
||||
Context context.Context
|
||||
Data *KycQueryData
|
||||
}
|
||||
|
||||
type KycQueryResponse struct {
|
||||
Status string `json:"status"` // success | pending | failed
|
||||
}
|
||||
|
||||
type KycQueryResult struct {
|
||||
Common shared.CommonResult
|
||||
Data *KycQueryResponse
|
||||
}
|
||||
|
||||
func (self *KycServiceImpl) QueryKyc(payload *KycQueryPayload) (result *KycQueryResult) {
|
||||
var err error
|
||||
|
||||
sessionState, err := kyc.GetSessionState(payload.Context, self.PassportReaderSessionId)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceQuery).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycQueryResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if sessionState == kyc.StateApproved {
|
||||
sessionDetails, err := kyc.GetSessionDetails(payload.Context, self.PassportReaderSessionId)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceQuery).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycQueryResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var kycInfo = kyc.PassportResp{
|
||||
GivenNames: sessionDetails.GivenNames,
|
||||
Surname: sessionDetails.Surname,
|
||||
Nationality: sessionDetails.Nationality,
|
||||
DateOfBirth: sessionDetails.DateOfBirth,
|
||||
DocumentType: sessionDetails.DocumentType,
|
||||
DocumentNumber: sessionDetails.DocumentNumber,
|
||||
ExpiryDate: sessionDetails.ExpiryDate,
|
||||
}
|
||||
|
||||
if kycInfo.DocumentType != "PASSPORT" || kycInfo.DocumentNumber != self.PassportId {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceQuery).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycQueryResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
encodedKycInfo, err := kyc.EncodeAES(kycInfo)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceQuery).
|
||||
SetType(exception.TypeSpecific).
|
||||
SetOriginal(exception.KycQueryFailed).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycQueryResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
kycId, err := uuid.Parse(payload.Data.KycId)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointKycServiceQuery).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorUuidParseFailed).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycQueryResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var updates = map[string]any{
|
||||
"kyc_info": kycInfo,
|
||||
}
|
||||
|
||||
err = new(data.Kyc).
|
||||
SetKycInfo(*encodedKycInfo).
|
||||
UpdateByKycID(payload.Context, &kycId, updates)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceQuery).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorDatabase).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycQueryResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceQuery).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonSuccess).
|
||||
SetError(nil).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycQueryResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 200,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: &KycQueryResponse{
|
||||
Status: "success",
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if sessionState == kyc.StateCreated || sessionState == kyc.StateInitiated || sessionState == kyc.StateCompleted {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceQuery).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonSuccess).
|
||||
SetError(nil).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycQueryResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 200,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: &KycQueryResponse{
|
||||
Status: "pending",
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if sessionState == kyc.StateFailed || sessionState == kyc.StateAborted || sessionState == kyc.StateRejected {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceQuery).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonSuccess).
|
||||
SetError(nil).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycQueryResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 200,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: &KycQueryResponse{
|
||||
Status: "failed",
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
15
service/service_kyc/service.go
Normal file
15
service/service_kyc/service.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package service_kyc
|
||||
|
||||
type KycService interface {
|
||||
SessionKyc(*KycSessionPayload) *KycSessionResult
|
||||
QueryKyc(*KycQueryPayload) *KycQueryResult
|
||||
}
|
||||
|
||||
type KycServiceImpl struct {
|
||||
PassportId string `json:"passport_id"`
|
||||
PassportReaderSessionId int `json:"passport_reader_session_id"`
|
||||
}
|
||||
|
||||
func NewKycService() KycService {
|
||||
return &KycServiceImpl{}
|
||||
}
|
||||
400
service/service_kyc/session_kyc.go
Normal file
400
service/service_kyc/session_kyc.go
Normal file
@@ -0,0 +1,400 @@
|
||||
package service_kyc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"nixcn-cms/data"
|
||||
"nixcn-cms/internal/exception"
|
||||
"nixcn-cms/internal/kyc"
|
||||
"nixcn-cms/service/shared"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// cnrid: {"legal_name":"", "resident_id":""}
|
||||
// passport: {"id": ""}
|
||||
type KycSessionData struct {
|
||||
Type string `json:"type"` // cnrid | passport
|
||||
Identity string `json:"identity"` // base64 json
|
||||
UserId string `json:"user_id" swaggerignore:"true"`
|
||||
}
|
||||
|
||||
type KycSessionPayload struct {
|
||||
Context context.Context
|
||||
Data *KycSessionData
|
||||
}
|
||||
|
||||
type KycSessionResponse struct {
|
||||
Status string `json:"status"` // success | processing
|
||||
KycId *string `json:"kyc_id"`
|
||||
RedirectUri *string `json:"redirect_uri"`
|
||||
}
|
||||
|
||||
type KycSessionResult struct {
|
||||
Common shared.CommonResult
|
||||
Data *KycSessionResponse
|
||||
}
|
||||
|
||||
func (self *KycServiceImpl) SessionKyc(payload *KycSessionPayload) (result *KycSessionResult) {
|
||||
var err error
|
||||
|
||||
decodedIdentityByte, err := base64.StdEncoding.DecodeString(payload.Data.Identity)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorBase64DecodeFailed).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
switch payload.Data.Type {
|
||||
case "cnrid":
|
||||
var info kyc.CNRidInfo
|
||||
if err := json.Unmarshal(decodedIdentityByte, &info); err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorJsonDecodeFailed).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
kycInfo := kyc.CNRidInfo{
|
||||
LegalName: info.LegalName,
|
||||
ResidentId: info.ResidentId,
|
||||
}
|
||||
|
||||
aliCloudAuth, err := kyc.CNRidMD5AliEnc(&kycInfo)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInternal).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
kycResult, err := kyc.AliId2MetaVerify(aliCloudAuth)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInternal).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if *kycResult != "1" {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeSpecific).
|
||||
SetOriginal(exception.KycSessionFailed).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := uuid.Parse(payload.Data.UserId)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceJoin).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorUuidParseFailed).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
encodedKycInfo, err := kyc.EncodeAES(kycInfo)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeSpecific).
|
||||
SetOriginal(exception.KycSessionFailed).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
kycIdOrig, err := new(data.Kyc).
|
||||
SetType("cnrid").
|
||||
SetUserId(userId).
|
||||
SetKycInfo(*encodedKycInfo).
|
||||
Create(payload.Context)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorDatabase).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
kycId := kycIdOrig.String()
|
||||
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonSuccess).
|
||||
SetError(nil).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 200,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: &KycSessionResponse{
|
||||
Status: "success",
|
||||
KycId: &kycId,
|
||||
RedirectUri: nil,
|
||||
},
|
||||
}
|
||||
|
||||
case "passport":
|
||||
var info kyc.PassportInfo
|
||||
if err := json.Unmarshal(decodedIdentityByte, &info); err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorJsonDecodeFailed).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
self.PassportId = info.ID
|
||||
|
||||
sessionResponse, err := kyc.CreateSession(payload.Context)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInternal).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
self.PassportReaderSessionId = sessionResponse.ID
|
||||
|
||||
userId, err := uuid.Parse(payload.Data.UserId)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusServer).
|
||||
SetService(exception.ServiceEvent).
|
||||
SetEndpoint(exception.EndpointEventServiceJoin).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorUuidParseFailed).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
kycIdOrig, err := new(data.Kyc).
|
||||
SetType("passport").
|
||||
SetUserId(userId).
|
||||
Create(payload.Context)
|
||||
if err != nil {
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorDatabase).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 500,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
kycId := kycIdOrig.String()
|
||||
kycBaseURL := "https://passportreader.app/open"
|
||||
kycUrl, _ := url.Parse(kycBaseURL)
|
||||
kycQuery := kycUrl.Query()
|
||||
kycQuery.Set("token", sessionResponse.Token)
|
||||
kycUrl.RawQuery = kycQuery.Encode()
|
||||
|
||||
redirectUri := kycUrl.String()
|
||||
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonSuccess).
|
||||
SetError(nil).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 200,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: &KycSessionResponse{
|
||||
Status: "processing",
|
||||
KycId: &kycId,
|
||||
RedirectUri: &redirectUri,
|
||||
},
|
||||
}
|
||||
|
||||
default:
|
||||
exception := new(exception.Builder).
|
||||
SetStatus(exception.StatusUser).
|
||||
SetService(exception.ServiceKyc).
|
||||
SetEndpoint(exception.EndpointKycServiceSession).
|
||||
SetType(exception.TypeCommon).
|
||||
SetOriginal(exception.CommonErrorInvalidInput).
|
||||
SetError(err).
|
||||
Throw(payload.Context)
|
||||
|
||||
result = &KycSessionResult{
|
||||
Common: shared.CommonResult{
|
||||
HttpCode: 400,
|
||||
Exception: exception,
|
||||
},
|
||||
Data: nil,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user