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
58 changes: 58 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 @@ -15,6 +15,8 @@
module Kernel.External.Verification.Idfy.Client
( verifyDLAsync,
verifyRCAsync,
verifyPanAsync,
verifyGstAsync,
validateImage,
extractRCImage,
extractDLImage,
Expand Down Expand Up @@ -107,6 +109,62 @@ verifyRCAsync apiKey accountId url req = callIdfyAPI url task "verifyRCAsync" ve
(Just accountId)
req

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

verifyPanAPI :: Proxy VerifyPanAPI
verifyPanAPI = Proxy

verifyPanAsync ::
( MonadFlow m,
CoreMetrics m
) =>
ApiKey ->
AccountId ->
BaseUrl ->
PanVerificationRequest ->
m IdfySuccess
verifyPanAsync apiKey accountId url req = callIdfyAPI url task "verifyPanAsync" verifyPanAPI
where
task =
T.client
verifyPanAPI
(Just apiKey)
(Just accountId)
req

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

verifyGstAPI :: Proxy VerifyGstAPI
verifyGstAPI = Proxy

verifyGstAsync ::
( MonadFlow m,
CoreMetrics m
) =>
ApiKey ->
AccountId ->
BaseUrl ->
GstVerificationRequest ->
m IdfySuccess
verifyGstAsync apiKey accountId url req = callIdfyAPI url task "verifyGstAsync" verifyGstAPI
where
task =
T.client
verifyGstAPI
(Just apiKey)
(Just accountId)
req

type ValidateImage =
"v3" :> "tasks" :> "sync" :> "validate" :> "document"
:> Header "api-key" ApiKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type AadharVerificationReqest = IdfyRequest AadharVerificationData

type RCVerificationRequest = IdfyRequest RCVerificationData

type PanVerificationRequest = IdfyRequest PanVerificationData

type GstVerificationRequest = IdfyRequest GstVerificationData

type NameCompareRequest = IdfyRequest NameCompareRequestBody

data IdfyRequest a = IdfyRequest
Expand Down Expand Up @@ -77,6 +81,20 @@ data RCVerificationData = RCVerificationData
{rc_number :: Text, _a :: Maybe Text}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)

data PanVerificationData = PanVerificationData
{ id_number :: Text,
full_name :: Text,
dob :: Text
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)

data GstVerificationData = GstVerificationData
{ gstin :: Text,
filing_details :: Bool,
e_invoice_details :: Bool
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)

data AadharVerificationData = AadharVerificationData
{ document1 :: Text,
document2 :: Maybe Text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Kernel.External.Verification.Idfy.Types.Response where
import Data.Aeson hiding (Error)
import qualified Data.Aeson as A
import Data.OpenApi hiding (name)
import Data.Text as T
import EulerHS.Prelude hiding (state)
import Kernel.Types.App ()
import Kernel.Utils.JSON
Expand All @@ -35,11 +36,44 @@ type GSTExtractionResponse = IdfyResponse (ExtractionOutput GSTExtractionOutput)

type AadhaarExtractionResponse = IdfyResponse AadhaarResult

type VerificationResponse = IdfyResponse IdfyResult

type VerificationResponseList = [IdfyResponse IdfyResult]

type IdfyResult = Output DLVerificationOutput RCVerificationOutput
newtype VerificationResponse = VerificationResponse (IdfyResponse IdfyResult)

instance FromJSON VerificationResponse where
parseJSON val = do
mbDocType :: Maybe Text <- withObject "VerificationResponse" (\o -> o .:? "type") val
VerificationResponse <$> case mbDocType of
Just "ind_driving_license" ->
parseJSON @(IdfyResponse (SourceOutput DLVerificationOutput)) val <&> mapIdfyResponse DLResult
Just "ind_pan" ->
parseJSON @(IdfyResponse (SourceOutput PanVerificationOutput)) val <&> mapIdfyResponse PanResult
Just "ind_gst_certificate" ->
parseJSON @(IdfyResponse (SourceOutput GstVerificationOutput)) val <&> mapIdfyResponse GstResult
Just "ind_rc" ->
parseJSON @(IdfyResponse (ExtractionOutput RCVerificationOutput)) val <&> mapIdfyResponse RCResult
Just docType ->
fail $ "Unable to decode document type: " <> T.unpack docType
Nothing ->
parseJSON @(IdfyResponse (ExtractionOutput RCVerificationOutput)) val <&> mapIdfyResponse RCResult

instance ToJSON VerificationResponse where
toJSON (VerificationResponse IdfyResponse {..}) = case result of
Just (DLResult res) -> toJSON @(IdfyResponse (SourceOutput DLVerificationOutput)) IdfyResponse {result = Just res, ..}
Just (PanResult res) -> toJSON @(IdfyResponse (SourceOutput PanVerificationOutput)) IdfyResponse {result = Just res, ..}
Just (GstResult res) -> toJSON @(IdfyResponse (SourceOutput GstVerificationOutput)) IdfyResponse {result = Just res, ..}
Just (RCResult res) -> toJSON @(IdfyResponse (ExtractionOutput RCVerificationOutput)) IdfyResponse {result = Just res, ..}
Nothing -> toJSON @(IdfyResponse (ExtractionOutput RCVerificationOutput)) IdfyResponse {result = Nothing, ..}

mapIdfyResponse :: forall a b. (a -> b) -> IdfyResponse a -> IdfyResponse b
mapIdfyResponse f IdfyResponse {..} = IdfyResponse {result = f <$> result, ..}

type VerificationResponseList = [VerificationResponse]

data IdfyResult
= DLResult (SourceOutput DLVerificationOutput)
| PanResult (SourceOutput PanVerificationOutput)
| GstResult (SourceOutput GstVerificationOutput)
| RCResult (ExtractionOutput RCVerificationOutput)
deriving (Show)

type NameCompareResponse = IdfyResponse NameCompareResponseData

Expand Down Expand Up @@ -88,9 +122,6 @@ instance (ToJSON a) => ToJSON (SourceOutput a)

instance (FromJSON a) => FromJSON (SourceOutput a)

data Output a b = Output {source_output :: Maybe a, extraction_output :: Maybe b}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)

-- RC verification response
data RCVerificationOutput = RCVerificationOutput
{ avg_gross_vehicle_weight :: Maybe Text,
Expand Down Expand Up @@ -193,6 +224,48 @@ data CovDetail = CovDetail
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)

data PanInputDetails = PanInputDetails
{ input_pan_number :: Text,
input_name :: Maybe Text,
input_dob :: Maybe Text
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)

data PanVerificationOutput = PanVerificationOutput
{ aadhaar_seeding_status :: Maybe Bool,
pan_status :: Maybe Text,
name_match :: Maybe Bool,
dob_match :: Maybe Bool,
status :: Maybe Text,
input_details :: Maybe PanInputDetails
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)

data GstVerificationOutput = GstVerificationOutput
{ additional_place_of_business_fields :: Maybe A.Value,
centre_jurisdiction :: Maybe Text,
centre_jurisdiction_code :: Maybe Text,
constitution_of_business :: Maybe Text,
date_of_cancellation :: Maybe Text,
date_of_registration :: Maybe Text,
gstin :: Maybe Text,
gstin_status :: Maybe Text,
last_updated_date :: Maybe Text,
legal_name :: Maybe Text,
nature_of_business_activity :: Maybe A.Value,
principal_place_of_business_fields :: Maybe A.Value,
source :: Maybe Text,
state_jurisdiction_code :: Maybe Text,
status :: Maybe Text,
taxpayer_type :: Maybe Text,
trade_name :: Maybe Text,
einvoice_status :: Maybe Text,
status_details :: Maybe Text,
is_sez :: Maybe Text,
filing_details :: Maybe A.Value
}
deriving (Show, Generic, ToJSON, FromJSON, ToSchema)

-- validate image
data ValidateResponse = ValidateResponse
{ detected_doc_type :: Text,
Expand Down
30 changes: 30 additions & 0 deletions lib/mobility-core/src/Kernel/External/Verification/Interface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
module Kernel.External.Verification.Interface
( module Reexport,
verifyDLAsync,
verifyPanAsync,
verifyGstAsync,
verifyRC,
validateImage,
extractRCImage,
Expand Down Expand Up @@ -64,6 +66,34 @@ verifyDLAsync serviceConfig req = case serviceConfig of
HyperVergeVerificationConfig _ -> throwError $ InternalError "Not Implemented!"
HyperVergeVerificationConfigRCDL cfg -> HyperVerge.verifyDLAsync cfg req

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

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

verifyRC ::
( EncFlow m r,
CoreMetrics m,
Expand Down
Loading