Skip to content

Commit

Permalink
use new more optimized endpoint for integration (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-cronus authored Jun 28, 2024
1 parent 6a7a4b9 commit 599ea8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
6 changes: 2 additions & 4 deletions kyc/face/internal/threedivi/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type (
// Private API.
type (
applicant struct {
Code string `json:"code"`
LastValidationResponse *validationResponse `json:"lastValidationResponse"`
ApplicantID string `json:"applicantId"`
Status int `json:"status"`
Expand All @@ -43,10 +44,6 @@ type (
ValidationResponseID int `json:"validationResponseId"`
ResponseStatus int `json:"responseStatus"`
}
page[T any] struct {
Items []T `json:"items"`
Total uint64 `json:"total"`
}
)

const (
Expand All @@ -56,6 +53,7 @@ const (
metricOpenConnectionsLabelTCP = "default/tcp-gateway/tcp-listener"
statusPassed = 1
statusFailed = 2
codeApplicantNotFound = "120024"
)

var ( //nolint:gofumpt // .
Expand Down
23 changes: 11 additions & 12 deletions kyc/face/internal/threedivi/threedivi.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ func (*threeDivi) parseApplicant(user *users.User, bafApplicant *applicant) *use
} else if user.KYCStepsCreatedAt != nil && len(*user.KYCStepsCreatedAt) >= int(users.LivenessDetectionKYCStep) {
updUser.KYCStepsCreatedAt = user.KYCStepsCreatedAt
updUser.KYCStepsLastUpdatedAt = user.KYCStepsLastUpdatedAt
if user.KYCStepPassed != nil && (*user.KYCStepPassed == users.LivenessDetectionKYCStep || *user.KYCStepPassed == users.FacialRecognitionKYCStep) {
stepPassed := users.NoneKYCStep
updUser.KYCStepPassed = &stepPassed
}
(*updUser.KYCStepsCreatedAt)[stepIdx(users.FacialRecognitionKYCStep)] = nil
(*updUser.KYCStepsCreatedAt)[stepIdx(users.LivenessDetectionKYCStep)] = nil
(*updUser.KYCStepsLastUpdatedAt)[stepIdx(users.FacialRecognitionKYCStep)] = nil
Expand Down Expand Up @@ -269,16 +273,12 @@ func (t *threeDivi) searchIn3DiviForApplicant(ctx context.Context, userID users.
}
}).
SetRetryCondition(func(resp *req.Response, err error) bool {
return err != nil || (resp.GetStatusCode() != http.StatusOK)
return err != nil || (resp.GetStatusCode() != http.StatusOK && resp.GetStatusCode() != http.StatusNotFound)
}).
AddQueryParam("caller", "eskimo-hut").
AddQueryParam("Page", "1").
AddQueryParam("PageSize", "1").
AddQueryParam("TextFilter", userID).
SetHeader("Authorization", fmt.Sprintf("Bearer %v", t.cfg.ThreeDiVi.BAFToken)).
Get(fmt.Sprintf("%v/publicapi/api/v2/private/Applicants", t.cfg.ThreeDiVi.BAFHost)); err != nil {
Get(fmt.Sprintf("%v/publicapi/api/v2/private/Applicants/ByReferenceId/%v", t.cfg.ThreeDiVi.BAFHost, userID)); err != nil {
return nil, errors.Wrapf(err, "failed to match applicantId for userID:%v", userID)
} else if statusCode := resp.GetStatusCode(); statusCode != http.StatusOK {
} else if statusCode := resp.GetStatusCode(); statusCode != http.StatusOK && statusCode != http.StatusNotFound {
return nil, errors.Errorf("[%v]failed to match applicantIdfor userID:%v", statusCode, userID)
} else if data, err2 := resp.ToBytes(); err2 != nil {
return nil, errors.Wrapf(err2, "failed to read body of match applicantId request for userID:%v", userID)
Expand All @@ -288,14 +288,13 @@ func (t *threeDivi) searchIn3DiviForApplicant(ctx context.Context, userID users.
}

func (*threeDivi) extractApplicant(data []byte) (*applicant, error) {
var bafUsers page[applicant]
if jErr := json.Unmarshal(data, &bafUsers); jErr != nil {
var bafApplicant applicant
if jErr := json.Unmarshal(data, &bafApplicant); jErr != nil {
return nil, errors.Wrapf(jErr, "failed to decode %v into applicants page", string(data))
}
if len(bafUsers.Items) == 0 {
if bafApplicant.Code == codeApplicantNotFound {
return nil, errFaceAuthNotStarted
}
bafApplicant := &bafUsers.Items[0]
if bafApplicant.LastValidationResponse != nil {
timeFormat := "2006-01-02T15:04:05.999999"
var err error
Expand All @@ -304,5 +303,5 @@ func (*threeDivi) extractApplicant(data []byte) (*applicant, error) {
}
}

return bafApplicant, nil
return &bafApplicant, nil
}

0 comments on commit 599ea8c

Please sign in to comment.