Skip to content
Draft
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
7 changes: 7 additions & 0 deletions lib/mobility-core/mobility-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,20 @@ library
Kernel.External.Payment.Types
Kernel.External.Payout.Interface
Kernel.External.Payout.Interface.Juspay
Kernel.External.Payout.Interface.Stripe
Kernel.External.Payout.Interface.Types
Kernel.External.Payout.Juspay.Config
Kernel.External.Payout.Juspay.Flow
Kernel.External.Payout.Juspay.Types
Kernel.External.Payout.Juspay.Types.Payout
Kernel.External.Payout.Juspay.Types.Webhook
Kernel.External.Payout.Juspay.Webhook
Kernel.External.Payout.Stripe.Config
Kernel.External.Payout.Stripe.Flow
Kernel.External.Payout.Stripe.Types
Kernel.External.Payout.Stripe.Types.Common
Kernel.External.Payout.Stripe.Types.ExternalAccount
Kernel.External.Payout.Stripe.Types.Payout
Kernel.External.Payout.Types
Kernel.External.Plasma
Kernel.External.Plasma.Interface
Expand Down
79 changes: 73 additions & 6 deletions lib/mobility-core/src/Kernel/External/Payout/Interface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ module Kernel.External.Payout.Interface
where

import qualified Kernel.External.Payout.Interface.Juspay as Juspay
import qualified Kernel.External.Payout.Interface.Stripe as Stripe
import Kernel.External.Payout.Interface.Types as Reexport
import Kernel.External.Payout.Types as Reexport
import Kernel.Prelude
import Kernel.Tools.Metrics.CoreMetrics (CoreMetrics)
import Kernel.Types.Error (GenericError (InvalidRequest))
import Kernel.Utils.Common

createPayoutOrder ::
Expand All @@ -32,11 +34,11 @@ createPayoutOrder ::
HasFlowEnv m r '["selfBaseUrl" ::: BaseUrl]
) =>
PayoutServiceConfig ->
Maybe Text ->
CreatePayoutOrderReq ->
m CreatePayoutOrderResp
createPayoutOrder serviceConfig mRoutingId req = case serviceConfig of
JuspayConfig cfg -> Juspay.createPayoutOrder cfg mRoutingId req
createPayoutOrder serviceConfig req = case serviceConfig of
JuspayConfig cfg -> Juspay.createPayoutOrder cfg req
StripeConfig cfg -> Stripe.createPayoutOrder cfg req

payoutOrderStatus ::
( EncFlow m r,
Expand All @@ -45,8 +47,73 @@ payoutOrderStatus ::
MonadReader r m
) =>
PayoutServiceConfig ->
Maybe Text ->
PayoutOrderStatusReq ->
m PayoutOrderStatusResp
payoutOrderStatus serviceConfig mRoutingId req = case serviceConfig of
JuspayConfig cfg -> Juspay.payoutOrderStatus cfg req.orderId mRoutingId req.mbExpand
payoutOrderStatus serviceConfig req = case serviceConfig of
JuspayConfig cfg -> Juspay.payoutOrderStatus cfg req
StripeConfig cfg -> Stripe.payoutOrderStatus cfg req

listExternalAccounts ::
( EncFlow m r,
CoreMetrics m,
HasRequestId r,
MonadReader r m
) =>
PayoutServiceConfig ->
ListExternalAccountsReq ->
m ListExternalAccountsResp
listExternalAccounts serviceConfig req = case serviceConfig of
JuspayConfig _ -> throwError $ InvalidRequest "Juspay List External Accounts not supported."
StripeConfig cfg -> Stripe.listExternalAccounts cfg req

createExternalAccount ::
( EncFlow m r,
CoreMetrics m,
HasRequestId r,
MonadReader r m
) =>
PayoutServiceConfig ->
CreateExternalAccountReq ->
m CreateExternalAccountResp
createExternalAccount serviceConfig req = case serviceConfig of
JuspayConfig _ -> throwError $ InvalidRequest "Juspay Create External Account not supported."
StripeConfig cfg -> Stripe.createExternalAccount cfg req

getExternalAccount ::
( EncFlow m r,
CoreMetrics m,
HasRequestId r,
MonadReader r m
) =>
PayoutServiceConfig ->
GetExternalAccountReq ->
m GetExternalAccountResp
getExternalAccount serviceConfig req = case serviceConfig of
JuspayConfig _ -> throwError $ InvalidRequest "Juspay Get External Account not supported."
StripeConfig cfg -> Stripe.getExternalAccount cfg req

updateExternalAccount ::
( EncFlow m r,
CoreMetrics m,
HasRequestId r,
MonadReader r m
) =>
PayoutServiceConfig ->
UpdateExternalAccountReq ->
m UpdateExternalAccountResp
updateExternalAccount serviceConfig req = case serviceConfig of
JuspayConfig _ -> throwError $ InvalidRequest "Juspay Update External Account not supported"
StripeConfig cfg -> Stripe.updateExternalAccount cfg req

deleteExternalAccount ::
( EncFlow m r,
CoreMetrics m,
HasRequestId r,
MonadReader r m
) =>
PayoutServiceConfig ->
DeleteExternalAccountReq ->
m DeleteExternalAccountResp
deleteExternalAccount serviceConfig req = case serviceConfig of
JuspayConfig _ -> throwError $ InvalidRequest "Juspay Delete External Account not supported."
StripeConfig cfg -> Stripe.deleteExternalAccount cfg req
16 changes: 8 additions & 8 deletions lib/mobility-core/src/Kernel/External/Payout/Interface/Juspay.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ createPayoutOrder ::
HasFlowEnv m r '["selfBaseUrl" ::: BaseUrl]
) =>
JuspayConfig ->
Maybe Text ->
CreatePayoutOrderReq ->
m CreatePayoutOrderResp
createPayoutOrder config mRoutingId req = do
createPayoutOrder config req = do
let url = config.url
merchantId = config.merchantId
apiKey <- decrypt config.apiKey
orderReq <- mkCreatePayoutOrderReq req
mkCreatePayoutOrderResp <$> Juspay.createPayoutOrder url apiKey merchantId mRoutingId orderReq
mkCreatePayoutOrderResp <$> Juspay.createPayoutOrder url apiKey merchantId req.mRoutingId orderReq
where
mkCreatePayoutOrderReq CreatePayoutOrderReq {..} = do
webhookDetails <- case isDynamicWebhookRequired of
Expand Down Expand Up @@ -113,6 +112,7 @@ createPayoutOrder config mRoutingId req = do
mkCreatePayoutOrderResp Payout.PayoutOrderResp {..} = do
CreatePayoutOrderResp
{ amount = realToFrac amount,
idAssignedByServiceProvider = Nothing,
..
}

Expand All @@ -134,19 +134,18 @@ payoutOrderStatus ::
MonadReader r m
) =>
JuspayConfig ->
Text ->
Maybe Text ->
Maybe Expand ->
PayoutOrderStatusReq ->
m PayoutOrderStatusResp
payoutOrderStatus config orderId' mRoutingId mbExpand = do
payoutOrderStatus config req = do
let url = config.url
merchantId = config.merchantId
apiKey <- decrypt config.apiKey
mkPayoutOrderStatusResp <$> Juspay.payoutOrderStatus url apiKey merchantId mRoutingId orderId' mbExpand
mkPayoutOrderStatusResp <$> Juspay.payoutOrderStatus url apiKey merchantId req.mRoutingId req.orderId req.mbExpand
where
mkPayoutOrderStatusResp Payout.PayoutOrderResp {..} = do
CreatePayoutOrderResp
{ amount = realToFrac amount,
idAssignedByServiceProvider = Nothing,
..
}

Expand All @@ -170,6 +169,7 @@ mkWebhookOrderStatusPayoutResp payoutReq = case payoutReq.label of
| not (T.null (T.strip orderId)) ->
OrderStatusPayoutResp
{ payoutOrderId = orderId,
idAssignedByServiceProvider = Nothing,
payoutStatus = payoutReq.info.status,
orderType = payoutReq.info._type,
merchantCustomerId = payoutReq.info.merchantCustomerId,
Expand Down
Loading
Loading