Skip to content

Commit

Permalink
Backend/feat/added-verify-vpa-api
Browse files Browse the repository at this point in the history
  • Loading branch information
prashant601 authored and hkmangla committed Nov 29, 2024
1 parent 0b24247 commit 9cc2912
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/mobility-core/src/Kernel/External/Payment/Interface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,14 @@ cancelPaymentIntent ::
cancelPaymentIntent config paymentIntentId = case config of
JuspayConfig _ -> throwError $ InternalError "Juspay Cancel Payment Intent not supported."
StripeConfig cfg -> Stripe.cancelPaymentIntent cfg paymentIntentId

verifyVPA ::
( CoreMetrics m,
EncFlow m r
) =>
PaymentServiceConfig ->
VerifyVPAReq ->
m VerifyVPAResp
verifyVPA config req = case config of
JuspayConfig cfg -> Juspay.verifyVPA cfg req
StripeConfig _ -> throwError $ InternalError "Stripe Verify VPA not supported."
30 changes: 30 additions & 0 deletions lib/mobility-core/src/Kernel/External/Payment/Interface/Juspay.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Kernel.External.Payment.Interface.Juspay
mandateResume,
autoRefund,
mandateNotificationStatus,
verifyVPA,
)
where

Expand Down Expand Up @@ -737,3 +738,32 @@ parseRetargetAndRetryData metaData linkData additionalInfo = do
getFieldData retargetInfoFromMetaData retargetInfoFromLinkData retargetInfoFromAdditionalInfo func = do
listToMaybe $ mapMaybe (>>= func) [retargetInfoFromMetaData, retargetInfoFromLinkData, retargetInfoFromAdditionalInfo]
getBoolValue = (\val -> readMaybe val :: Maybe Bool) . T.unpack

verifyVPA ::
( Metrics.CoreMetrics m,
EncFlow m r
) =>
JuspayCfg ->
VerifyVPAReq ->
m VerifyVPAResp
verifyVPA config req = do
let url = config.url
merchantId = config.merchantId
apiKey <- decrypt config.apiKey
mkVerifyVpaResp <$> Juspay.verifyVPA url apiKey (mkVerifyVpaRequest req merchantId)
where
mkVerifyVpaRequest request merchantId =
Juspay.VerifyVPAReq
{ vpa = request.vpa,
order_id = request.orderId,
merchant_id = merchantId,
customer_id = request.customerId
}

mkVerifyVpaResp :: Juspay.VerifyVPAResp -> VerifyVPAResp
mkVerifyVpaResp Juspay.VerifyVPAResp {..} = do
VerifyVPAResp
{ vpa,
status = show status,
customerName = customer_name
}
16 changes: 16 additions & 0 deletions lib/mobility-core/src/Kernel/External/Payment/Interface/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,19 @@ data CustomerCard = CustomerCard
deriving anyclass (FromJSON, ToJSON, ToSchema)

type CustomerCardListResp = [CustomerCard]

data VerifyVPAReq = VerifyVPAReq
{ vpa :: Text,
customerId :: Maybe Text,
orderId :: Maybe Text
}
deriving stock (Show, Generic, Read, Eq)
deriving anyclass (FromJSON, ToJSON, ToSchema)

data VerifyVPAResp = VerifyVPAResp
{ vpa :: Text,
status :: Text,
customerName :: Maybe Text
}
deriving stock (Show, Generic, Read, Eq)
deriving anyclass (FromJSON, ToJSON, ToSchema)
19 changes: 19 additions & 0 deletions lib/mobility-core/src/Kernel/External/Payment/Juspay/Flow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,22 @@ autoRefund url apiKey orderId req = do
}
callAPI url (eulerClient orderId basicAuthData req) "order-refund" (Proxy @AutoRefundAPI)
>>= fromEitherM (\err -> InternalError $ "Failed to call order refund API: " <> show err)

type VerifyVPAAPI =
"v2"
:> "upi"
:> "verify-vpa"
:> BasicAuth "username-password" BasicAuthData
:> ReqBody '[JSON] VerifyVPAReq
:> Post '[JSON] VerifyVPAResp

verifyVPA ::
(Metrics.CoreMetrics m, MonadFlow m) =>
BaseUrl ->
Text ->
VerifyVPAReq ->
m VerifyVPAResp
verifyVPA url apiKey req = do
let eulerClient = Euler.client (Proxy @VerifyVPAAPI) (mkBasicAuthData apiKey) req
callAPI url eulerClient "verify-vpa" (Proxy @VerifyVPAAPI)
>>= fromEitherM (\err -> InternalError $ "Failed to call verify VPA API: " <> show err)
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,34 @@ data RefundsData = RefundsData
}
deriving stock (Show, Generic, Read, Eq)
deriving anyclass (FromJSON, ToJSON, ToSchema)

data VerifyVPAReq = VerifyVPAReq
{ vpa :: Text,
merchant_id :: Text,
customer_id :: Maybe Text,
order_id :: Maybe Text
}
deriving stock (Show, Generic)
deriving anyclass (FromJSON, ToJSON, ToSchema)

newtype MandateDetails = MandateDetails
{ is_handle_supported :: Bool
}
deriving stock (Show, Generic)
deriving anyclass (FromJSON, ToJSON)

data VPAStatus = VALID | INVALID
deriving (Eq, Show, Read, Generic, ToJSON, FromJSON, ToSchema)

derivePersistField "VPAStatus"

$(mkBeamInstancesForEnum ''VPAStatus)

data VerifyVPAResp = VerifyVPAResp
{ vpa :: Text,
status :: VPAStatus,
mandate_details :: Maybe MandateDetails,
customer_name :: Maybe Text
}
deriving stock (Show, Generic)
deriving anyclass (FromJSON, ToJSON)
18 changes: 18 additions & 0 deletions lib/mobility-core/src/Kernel/Types/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,3 +1243,21 @@ instance IsHTTPError MerchantPNError where
MerchantPNNotFound _ _ -> E500

instance IsAPIError MerchantPNError

data PayoutConfigError
= PayoutConfigNotFound Text Text
deriving (Eq, Show, IsBecknAPIError)

instanceExceptionWithParent 'HTTPException ''PayoutConfigError

instance IsBaseError PayoutConfigError where
toMessage = \case
PayoutConfigNotFound merchantOperatingCityId vehicleCategory -> Just $ "Payout for merchantOperatingCityId \"" <> show merchantOperatingCityId <> " and Vehicle category " <> show vehicleCategory <> "\" not found. "

instance IsHTTPError PayoutConfigError where
toErrorCode = \case
PayoutConfigNotFound _ _ -> "PAYOUT_CONFIG_NOT_FOUND"
toHttpCode = \case
PayoutConfigNotFound _ _ -> E500

instance IsAPIError PayoutConfigError

0 comments on commit 9cc2912

Please sign in to comment.