Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/mobility-core/src/Kernel/External/Verification/Idfy/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Kernel.External.Verification.Idfy.Client
extractGSTImage,
extractAadhaarImage,
nameCompare,
faceCompare,
getTask,
VerifyDLAPI,
VerifyRCAPI,
Expand All @@ -32,6 +33,7 @@ module Kernel.External.Verification.Idfy.Client
ExtractRCAPI,
ExtractAadhaarImage,
NameCompareAPI,
FaceCompareAPI,
)
where

Expand Down Expand Up @@ -275,6 +277,34 @@ extractAadhaarImage apiKey accountId url req = callIdfyAPI url task "extractAadh
(Just accountId)
req

type FaceCompareAPI =
"v3" :> "tasks" :> "sync" :> "compare" :> "face"
:> Header "api-key" ApiKey
:> Header "account-id" AccountId
:> ReqBody '[JSON] FaceCompareRequest
:> Post '[JSON] FaceCompareResponse

faceCompareAPI :: Proxy FaceCompareAPI
faceCompareAPI = Proxy

faceCompare ::
( MonadFlow m,
CoreMetrics m
) =>
ApiKey ->
AccountId ->
BaseUrl ->
FaceCompareRequest ->
m FaceCompareResponse
faceCompare apiKey accountId url req = callIdfyAPI url task "faceCompare" faceCompareAPI
where
task =
T.client
faceCompareAPI
(Just apiKey)
(Just accountId)
req

type NameCompareAPI =
"v3" :> "tasks" :> "sync" :> "compare" :> "ind_names"
:> Header "api-key" ApiKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type RCVerificationRequest = IdfyRequest RCVerificationData

type NameCompareRequest = IdfyRequest NameCompareRequestBody

type FaceCompareRequest = IdfyRequest FaceCompareRequestBody

data IdfyRequest a = IdfyRequest
{ task_id :: Text,
group_id :: Text,
Expand Down Expand Up @@ -90,3 +92,9 @@ data NameCompareRequestBody = NameCompareRequestBody
percentage :: Maybe Bool
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)

data FaceCompareRequestBody = FaceCompareRequestBody
{ document1 :: Text,
document2 :: Text
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type IdfyResult = Output DLVerificationOutput RCVerificationOutput

type NameCompareResponse = IdfyResponse NameCompareResponseData

type FaceCompareResponse = IdfyResponse FaceCompareResponseData

data IdfyResponse a = IdfyResponse
{ action :: Text,
completed_at :: UTCTime,
Expand Down Expand Up @@ -421,3 +423,18 @@ newtype NameCompareResponseData = NameCompareResponseData
{ match_output :: NameMatchOutput
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)

data FaceImage = FaceImage
{ face_detected :: Bool,
face_quality :: Text
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)

data FaceCompareResponseData = FaceCompareResponseData
{ image_1 :: FaceImage,
image_2 :: FaceImage,
is_a_match :: Bool,
match_score :: Int,
review_recommended :: Bool
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)
15 changes: 15 additions & 0 deletions lib/mobility-core/src/Kernel/External/Verification/Interface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Kernel.External.Verification.Interface
verifySdkResp,
getTask,
nameCompare,
faceCompare,
)
where

Expand Down Expand Up @@ -204,6 +205,20 @@ extractAadhaarImage serviceConfig req = case serviceConfig of
HyperVergeVerificationConfig _ -> throwError $ InternalError "Not Implemented!"
HyperVergeVerificationConfigRCDL _ -> throwError $ InternalError "Not Implemented!"

faceCompare ::
( EncFlow m r,
CoreMetrics m
) =>
VerificationServiceConfig ->
FaceCompareReq ->
m FaceCompareResp
faceCompare serviceConfig req = case serviceConfig of
IdfyConfig cfg -> Idfy.faceCompare cfg req
GovtDataConfig -> throwError $ InternalError "Not Implemented!"
FaceVerificationConfig _ -> throwError $ InternalError "Not Implemented!"
HyperVergeVerificationConfig _ -> throwError $ InternalError "Not Implemented!"
HyperVergeVerificationConfigRCDL _ -> throwError $ InternalError "Not Implemented!"

nameCompare ::
( EncFlow m r,
CoreMetrics m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Kernel.External.Verification.Interface.Idfy
convertDLOutputToDLVerificationOutput,
convertRCOutputToRCVerificationResponse,
nameCompare,
faceCompare,
)
where

Expand Down Expand Up @@ -292,6 +293,29 @@ extractAadhaarImage cfg req = do
{ extractedAadhaar = resp.result
}

faceCompare ::
( EncFlow m r,
CoreMetrics m
) =>
IdfyCfg ->
FaceCompareReq ->
m FaceCompareResp
faceCompare cfg req = do
let url = cfg.url
apiKey <- decrypt cfg.apiKey
accountId <- decrypt cfg.accountId
let reqData =
Idfy.FaceCompareRequestBody
{ document1 = req.document1,
document2 = req.document2
}
idfyReq <- buildIdfyRequest req.driverId reqData
resp <- Idfy.faceCompare apiKey accountId url idfyReq
pure
FaceCompareResp
{ faceComparedData = resp.result
}

nameCompare ::
( EncFlow m r,
CoreMetrics m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,15 @@ newtype NameCompareResp = NameCompareResp
{ nameComparedData :: Maybe Idfy.NameCompareResponseData
}
deriving (Show, Generic, FromJSON, ToJSON, ToSchema)

data FaceCompareReq = FaceCompareReq
{ document1 :: Text,
document2 :: Text,
driverId :: Text
}
deriving (Show, Generic, FromJSON, ToJSON, ToSchema)

newtype FaceCompareResp = FaceCompareResp
{ faceComparedData :: Maybe Idfy.FaceCompareResponseData
}
deriving (Show, Generic, FromJSON, ToJSON, ToSchema)