Skip to content
Merged
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
32 changes: 32 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 @@ -20,6 +20,7 @@ module Kernel.External.Verification.Idfy.Client
verifyBankAccountAsync,
verifyPanAadhaarLinkAsync,
verifyUdyamAadhaarAsync,
verifyCRCAsync,
validateImage,
extractRCImage,
extractDLImage,
Expand All @@ -34,6 +35,7 @@ module Kernel.External.Verification.Idfy.Client
VerifyBankAccountAPI,
VerifyPanAadhaarLinkAPI,
VerifyUdyamAadhaarAPI,
VerifyCRCAPI,
ValidateImage,
ExtractDLImage,
ExtractPanImage,
Expand Down Expand Up @@ -272,6 +274,36 @@ verifyUdyamAadhaarAsync apiKey accountId url req = callIdfyAPI url task "verifyU
(Just accountId)
req

type VerifyCRCAPI =
"v3" :> "tasks" :> "async" :> "verify_with_source" :> "ind_court_record"
:> Header "api-key" ApiKey
:> Header "account-id" AccountId
:> ReqBody '[JSON] CRCVerificationRequest
:> Post '[JSON] IdfySuccess

verifyCRCAPI :: Proxy VerifyCRCAPI
verifyCRCAPI = Proxy

verifyCRCAsync ::
( MonadFlow m,
CoreMetrics m,
HasRequestId r,
MonadReader r m
) =>
ApiKey ->
AccountId ->
BaseUrl ->
CRCVerificationRequest ->
m IdfySuccess
verifyCRCAsync apiKey accountId url req = callIdfyAPI url task "verifyCRCAsync" verifyCRCAPI
where
task =
T.client
verifyCRCAPI
(Just apiKey)
(Just accountId)
req

type ExtractUdyogAadhaarAPI =
"v3" :> "tasks" :> "async" :> "extract" :> "ind_udyog_aadhaar"
:> Header "api-key" ApiKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Data.OpenApi
fromAesonOptions,
genericDeclareNamedSchema,
)
import Data.Time.Calendar (Day)
import EulerHS.Prelude
import Kernel.Utils.JSON (stripPrefixUnderscoreIfAny)

Expand Down Expand Up @@ -47,6 +48,8 @@ type UdyogAadhaarExtractionRequest = IdfyRequest UdyogAadhaarExtractionData

type NameCompareRequest = IdfyRequest NameCompareRequestBody

type CRCVerificationRequest = IdfyRequest CRCVerificationData

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

data CRCVerificationData = CRCVerificationData
{ entity_type :: Text,
entity_type_details :: CRCEntityDetails
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)

data CRCEntityDetails = CRCEntityDetails
{ name :: Text,
father_name :: Maybe Text,
dob :: Maybe Day,
address :: Maybe Text,
pan_number :: Maybe Text
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import qualified Data.Aeson as A
import Data.OpenApi hiding (email, name)
import Data.Text as T
import EulerHS.Prelude hiding (state)
import qualified Kernel.External.Verification.Types as VT
import Kernel.Types.App ()
import Kernel.Utils.JSON
import Kernel.Utils.Time
Expand Down Expand Up @@ -66,6 +67,8 @@ instance FromJSON VerificationResponse where
parseJSON @(IdfyResponse (SourceOutput UdyogAadhaarOutput)) val <&> mapIdfyResponse UdyogAadhaarResult
Just "udyam_aadhaar" ->
parseJSON @(IdfyResponse (SourceOutput UdyamAadhaarOutput)) val <&> mapIdfyResponse UdyamAadhaarResult
Just "ind_court_record" ->
parseJSON @(IdfyResponse (SourceOutput VT.CRCVerificationResponse)) val <&> mapIdfyResponse CRCResult
Just docType ->
fail $ "Unable to decode document type: " <> T.unpack docType
Nothing ->
Expand All @@ -81,6 +84,7 @@ instance ToJSON VerificationResponse where
Just (PanAadhaarLinkResult res) -> toJSON @(IdfyResponse (SourceOutput PanAadhaarLinkOutput)) IdfyResponse {result = Just res, ..}
Just (UdyogAadhaarResult res) -> toJSON @(IdfyResponse (SourceOutput UdyogAadhaarOutput)) IdfyResponse {result = Just res, ..}
Just (UdyamAadhaarResult res) -> toJSON @(IdfyResponse (SourceOutput UdyamAadhaarOutput)) IdfyResponse {result = Just res, ..}
Just (CRCResult res) -> toJSON @(IdfyResponse (SourceOutput VT.CRCVerificationResponse)) IdfyResponse {result = Just res, ..}
Nothing -> toJSON @(IdfyResponse (ExtractionOutput RCVerificationOutput)) IdfyResponse {result = Nothing, ..}

mapIdfyResponse :: forall a b. (a -> b) -> IdfyResponse a -> IdfyResponse b
Expand All @@ -97,6 +101,7 @@ data IdfyResult
| PanAadhaarLinkResult (SourceOutput PanAadhaarLinkOutput)
| UdyogAadhaarResult (SourceOutput UdyogAadhaarOutput)
| UdyamAadhaarResult (SourceOutput UdyamAadhaarOutput)
| CRCResult (SourceOutput VT.CRCVerificationResponse)
deriving (Show)

type NameCompareResponse = IdfyResponse NameCompareResponseData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Kernel.External.Verification.Interface.Idfy
verifyBankAccountAsync,
verifyPanAadhaarLinkAsync,
verifyUdyamAadhaarAsync,
verifyCRCAsync,
validateImage,
extractRCImage,
extractUdyogAadhaarAsync,
Expand Down Expand Up @@ -208,6 +209,35 @@ verifyUdyamAadhaarAsync cfg req = do
idfySuccess <- Idfy.verifyUdyamAadhaarAsync apiKey accountId url idfyReq
pure $ VerifyAsyncResp {requestId = idfySuccess.request_id, requestor = VT.Idfy, transactionId = Nothing}

verifyCRCAsync ::
( EncFlow m r,
CoreMetrics m,
HasRequestId r,
MonadReader r m
) =>
IdfyCfg ->
VerifyCRCReq ->
m VerifyCRCAsyncResp
verifyCRCAsync cfg req = do
let url = cfg.url
apiKey <- decrypt cfg.apiKey
accountId <- decrypt cfg.accountId
let reqData =
Idfy.CRCVerificationData
{ entity_type = VT.crcEntityTypeToText req.entityType,
entity_type_details =
Idfy.CRCEntityDetails
{ name = req.name,
father_name = req.fatherName,
dob = req.dob,
address = req.address,
pan_number = req.panNumber
}
}
idfyReq <- buildIdfyRequest req.driverId reqData
idfySuccess <- Idfy.verifyCRCAsync apiKey accountId url idfyReq
pure $ VerifyAsyncResp {requestId = idfySuccess.request_id, requestor = VT.Idfy, transactionId = Nothing}

verifyRCAsync ::
( EncFlow m r,
CoreMetrics m,
Expand Down Expand Up @@ -521,6 +551,7 @@ getTask cfg req updateResp = do
PanAadhaarLinkResult (SourceOutput out) -> PanAadhaarLinkResp $ convertPanAadhaarLinkOutputToPanAadhaarLinkVerification out
UdyamAadhaarResult (SourceOutput out) -> UdyamAadhaarResp $ convertUdyamAadhaarOutputToUdyamAadhaarVerification out
UdyogAadhaarResult (SourceOutput out) -> UdyogAadhaarResp $ convertUdyogAadhaarOutputToUdyogAadhaarVerification out
CRCResult (SourceOutput out) -> CRCResp out

convertDLOutputToDLVerificationOutput :: DLVerificationOutput -> DLVerificationOutputInterface
convertDLOutputToDLVerificationOutput DLVerificationOutput {..} =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Kernel.External.Verification.Interface.Types
)
where

import Data.Time.Calendar (Day)
import Deriving.Aeson
import EulerHS.Prelude
import qualified Kernel.External.Verification.Digilocker.Types as DigiTypes
Expand Down Expand Up @@ -87,6 +88,17 @@ data VerifyUdyamAadhaarAsyncReq = VerifyUdyamAadhaarAsyncReq
}
deriving stock (Show, Generic)

data VerifyCRCReq = VerifyCRCReq
{ name :: Text,
fatherName :: Maybe Text,
dob :: Maybe Day,
address :: Maybe Text,
panNumber :: Maybe Text,
entityType :: VT.CRCEntityType,
driverId :: Text
}
deriving stock (Show, Generic)

data VerifyDLSyncResp = VerifyDLSyncResp
{ requestId :: Maybe Text,
requestor :: VT.VerificationService,
Expand Down Expand Up @@ -118,6 +130,8 @@ type VerifyPanAadhaarLinkAsyncResp = VerifyAsyncResp

type VerifyUdyamAadhaarAsyncResp = VerifyAsyncResp

type VerifyCRCAsyncResp = VerifyAsyncResp

data VerifyRCReq = VerifyRCReq
{ rcNumber :: Text,
driverId :: Text,
Expand Down Expand Up @@ -272,7 +286,7 @@ data GetTaskReq = GetTaskReq
}
deriving (Generic, FromJSON, ToJSON, Show)

data GetTaskResp = RCResp VT.RCVerificationResponse | DLResp DLVerificationOutputInterface | PanResp VT.PanVerificationResponse | GstResp VT.GstVerificationResponse | BankAccountResp VT.BankAccountVerificationResponse | PanAadhaarLinkResp VT.PanAadhaarLinkResponse | UdyogAadhaarResp VT.UdyogAadhaarVerificationResponse | UdyamAadhaarResp VT.UdyamAadhaarVerificationResponse
data GetTaskResp = RCResp VT.RCVerificationResponse | DLResp DLVerificationOutputInterface | PanResp VT.PanVerificationResponse | GstResp VT.GstVerificationResponse | BankAccountResp VT.BankAccountVerificationResponse | PanAadhaarLinkResp VT.PanAadhaarLinkResponse | UdyogAadhaarResp VT.UdyogAadhaarVerificationResponse | UdyamAadhaarResp VT.UdyamAadhaarVerificationResponse | CRCResp VT.CRCVerificationResponse
deriving (Generic, FromJSON, ToJSON, Show)
Comment thread
bytedex marked this conversation as resolved.

data DLVerificationOutputInterface = DLVerificationOutputInterface
Expand Down
37 changes: 37 additions & 0 deletions lib/mobility-core/src/Kernel/External/Verification/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import EulerHS.Prelude hiding (state)
import Kernel.Beam.Lib.UtilsTH (mkBeamInstancesForEnumAndList)
import qualified Kernel.Prelude as KP
import Kernel.Storage.Esqueleto (derivePersistField)
import Kernel.Utils.JSON (constructorsToLowerOptions, constructorsWithSnakeCase)

data VerificationService = Idfy | InternalScripts | GovtData | HyperVerge | HyperVergeRCDL | DigiLocker | Tten | Morth
deriving (Show, Read, Eq, Ord, Generic, ToJSON, FromJSON, ToSchema)
Expand Down Expand Up @@ -181,3 +182,39 @@ data PanAadhaarLinkResponse = PanAadhaarLinkResponse
status :: Maybe Text
}
deriving (Show, FromJSON, ToJSON, Generic, ToSchema)

data CRCEntityType = Individual | Business
deriving (Show, Read, Eq, Ord, Generic)

instance ToJSON CRCEntityType where
toJSON = A.genericToJSON constructorsToLowerOptions

instance FromJSON CRCEntityType where
parseJSON = A.genericParseJSON constructorsToLowerOptions

instance ToSchema CRCEntityType where
declareNamedSchema = genericDeclareNamedSchema $ fromAesonOptions constructorsToLowerOptions

-- | Entity type value expected by the Idfy CRC API request.
crcEntityTypeToText :: CRCEntityType -> Text
crcEntityTypeToText Individual = "individual"
crcEntityTypeToText Business = "business"

data CRCVerificationResponse = CRCVerificationResponse
{ caseDetailsLink :: Maybe Text,
numberOfCases :: Maybe Int,
reportDownloadLink :: Maybe Text,
riskSummary :: Maybe Text,
riskType :: Maybe Text,
status :: Maybe Text
}
deriving (Show, Generic)

instance FromJSON CRCVerificationResponse where
parseJSON = A.genericParseJSON constructorsWithSnakeCase

instance ToJSON CRCVerificationResponse where
toJSON = A.genericToJSON constructorsWithSnakeCase

instance ToSchema CRCVerificationResponse where
declareNamedSchema = genericDeclareNamedSchema $ fromAesonOptions constructorsWithSnakeCase
Loading