Skip to content

Commit

Permalink
backend/feat/split_settlement
Browse files Browse the repository at this point in the history
  • Loading branch information
0utkarsh committed Sep 11, 2024
1 parent b9c6cf1 commit 6ab20d6
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 6 deletions.
36 changes: 34 additions & 2 deletions lib/mobility-core/src/Kernel/External/Payment/Interface/Juspay.hs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,22 @@ mkCreateOrderReq returnUrl clientId CreateOrderReq {..} =
mandate_end_date = mandateEndDate,
options_get_upi_deep_links = optionsGetUpiDeepLinks,
metadata_expiry_in_mins = metadataExpiryInMins,
metadata_gateway_reference_id = metadataGatewayReferenceId
metadata_gateway_reference_id = metadataGatewayReferenceId,
split_settlement_details = mkSplitSettlementDetails <$> splitSettlementDetails
}

mkSplitSettlementDetails :: SplitSettlementDetails -> Juspay.SplitSettlementDetails
mkSplitSettlementDetails splitDetails =
Juspay.SplitSettlementDetails
{ marketplace = mkMarketplace splitDetails.marketplace,
mdr_borne_by = show splitDetails.mdrBorneBy,
vendor = mkVendor splitDetails.vendor
}
where
mkMarketplace Marketplace {..} = Juspay.Marketplace {..}
mkVendor vendor = Juspay.Vendor {split = mkSplit <$> vendor.split}
mkSplit split = Juspay.Split {amount = split.amount, merchant_commission = split.merchantCommission, sub_mid = split.subMid}

orderStatus ::
( HasCallStack,
Metrics.CoreMetrics m,
Expand Down Expand Up @@ -265,6 +278,7 @@ mkOrderStatusResp Juspay.OrderData {..} =
amountRefunded = realToFrac <$> amount_refunded,
payerVpa = payer_vpa,
upi = castUpi <$> upi,
splitSettlementResponse = mkSplitSettlementResponse <$> split_settlement_response,
..
}

Expand Down Expand Up @@ -384,7 +398,7 @@ mkWebhookOrderStatusResp now (eventName, Juspay.OrderAndNotificationStatusConten
payerVpa = justOrder.payer_vpa,
upi = castUpi <$> justOrder.upi,
refunds = maybe [] mkRefundsData justOrder.refunds,
amountRefunded = realToFrac <$> justOrder.amount_refunded
amountRefunded = realToFrac <$> justOrder.amount_refunded -- not adding split
}
Nothing -> do
let (isRetriedOrder, retargetPaymentLink, retargetPaymentLinkExpiry, isRetargetedOrder) = parseRetargetAndRetryData justOrder.metadata justOrder.links justOrder.additional_info
Expand All @@ -409,6 +423,7 @@ mkWebhookOrderStatusResp now (eventName, Juspay.OrderAndNotificationStatusConten
amountRefunded = realToFrac <$> justOrder.amount_refunded,
payerVpa = justOrder.payer_vpa,
upi = castUpi <$> justOrder.upi,
splitSettlementResponse = mkSplitSettlementResponse <$> justOrder.split_settlement_response,
..
}
(Nothing, Just justMandate, _, _) ->
Expand Down Expand Up @@ -458,10 +473,27 @@ mkWebhookOrderStatusResp now (eventName, Juspay.OrderAndNotificationStatusConten
amountRefunded = Nothing,
payerVpa = justTransaction.payer_vpa,
upi = castUpi <$> justTransaction.upi,
splitSettlementResponse = Nothing,
..
}
(_, _, Nothing, _) -> BadStatusResp

mkSplitSettlementResponse :: Juspay.SplitSettlementResponse -> SplitSettlementResponse
mkSplitSettlementResponse Juspay.SplitSettlementResponse {..} =
SplitSettlementResponse
{ splitDetails = map mkSplitDetailsResponse split_details,
splitApplied = split_applied
}
where
mkSplitDetailsResponse Juspay.SplitDetailsResponse {..} =
SplitDetailsResponse
{ subVendorId = sub_vendor_id,
merchantCommission = merchant_commission,
amount = amount,
gatewaySubAccountId = gateway_sub_account_id,
epgTxnId = epg_txn_id
}

castSourceInfo :: Juspay.SourceInfo -> SourceInfo
castSourceInfo source_info =
SourceInfo
Expand Down
49 changes: 47 additions & 2 deletions lib/mobility-core/src/Kernel/External/Payment/Interface/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,36 @@ data CreateOrderReq = CreateOrderReq
mandateEndDate :: Maybe Text,
metadataGatewayReferenceId :: Maybe Text,
optionsGetUpiDeepLinks :: Maybe Bool,
metadataExpiryInMins :: Maybe Int
metadataExpiryInMins :: Maybe Int,
splitSettlementDetails :: Maybe SplitSettlementDetails
}

data Split = Split
{ amount :: HighPrecMoney,
merchantCommission :: HighPrecMoney,
subMid :: Text
}
deriving stock (Show, Eq, Generic)

newtype Vendor = Vendor
{ split :: [Split]
}
deriving stock (Show, Eq, Generic)

data SplitSettlementDetails = SplitSettlementDetails
{ marketplace :: Marketplace,
mdrBorneBy :: MBY,
vendor :: Vendor
}
deriving stock (Show, Eq, Generic)

data MBY = MARKETPLACE | VENDOR | ALL deriving stock (Show, Eq, Generic)

newtype Marketplace = Marketplace
{ amount :: HighPrecMoney
}
deriving stock (Show, Eq, Generic)

newtype OrderStatusReq = OrderStatusReq
{ orderShortId :: Text
}
Expand Down Expand Up @@ -103,7 +130,8 @@ data OrderStatusResp
amountRefunded :: Maybe HighPrecMoney,
refunds :: [RefundsData],
payerVpa :: Maybe Text,
upi :: Maybe Upi
upi :: Maybe Upi,
splitSettlementResponse :: Maybe SplitSettlementResponse
}
| MandateOrderStatusResp
{ eventName :: Maybe PaymentStatus,
Expand Down Expand Up @@ -159,6 +187,23 @@ data OrderStatusResp
deriving stock (Show, Read, Eq, Generic)
deriving anyclass (FromJSON, ToJSON, ToSchema)

data SplitSettlementResponse = SplitSettlementResponse
{ splitDetails :: [SplitDetailsResponse],
splitApplied :: Bool
}
deriving stock (Show, Read, Eq, Generic)
deriving anyclass (FromJSON, ToJSON, ToSchema)

data SplitDetailsResponse = SplitDetailsResponse
{ subVendorId :: Maybe Text,
amount :: Maybe HighPrecMoney,
merchantCommission :: Maybe HighPrecMoney,
gatewaySubAccountId :: Maybe Text,
epgTxnId :: Maybe Text
}
deriving stock (Show, Read, Eq, Generic)
deriving anyclass (FromJSON, ToJSON, ToSchema)

data Upi = Upi
{ payerApp :: Maybe Text,
payerVpa :: Maybe Text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,25 @@ data OrderData = OrderData
additional_info :: Maybe AdditionalInfo,
links :: Maybe LinkData,
amount_refunded :: Maybe Double,
refunds :: Maybe [RefundsData]
refunds :: Maybe [RefundsData],
split_settlement_response :: Maybe SplitSettlementResponse
}
deriving stock (Show, Generic)
deriving anyclass (FromJSON, ToJSON, ToSchema)

data SplitSettlementResponse = SplitSettlementResponse
{ split_details :: [SplitDetailsResponse],
split_applied :: Bool
}
deriving stock (Show, Generic)
deriving anyclass (FromJSON, ToJSON, ToSchema)

data SplitDetailsResponse = SplitDetailsResponse
{ sub_vendor_id :: Maybe Text,
amount :: Maybe HighPrecMoney,
merchant_commission :: Maybe HighPrecMoney,
gateway_sub_account_id :: Maybe Text,
epg_txn_id :: Maybe Text
}
deriving stock (Show, Generic)
deriving anyclass (FromJSON, ToJSON, ToSchema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,43 @@ data CreateOrderReq = CreateOrderReq
mandate_end_date :: Maybe Text,
metadata_gateway_reference_id :: Maybe Text,
options_get_upi_deep_links :: Maybe Bool,
metadata_expiry_in_mins :: Maybe Int
metadata_expiry_in_mins :: Maybe Int,
split_settlement_details :: Maybe SplitSettlementDetails
}
deriving stock (Show, Eq, Generic)

data Split = Split
{ amount :: HighPrecMoney,
merchant_commission :: HighPrecMoney,
sub_mid :: Text
}
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)

newtype Vendor = Vendor
{ split :: [Split]
}
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)

data SplitSettlementDetails = SplitSettlementDetails
{ marketplace :: Marketplace,
mdr_borne_by :: Text,
vendor :: Vendor
}
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)

data MBY = MARKETPLACE | VENDOR | ALL
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)

newtype Marketplace = Marketplace
{ amount :: HighPrecMoney
}
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)

jsonReqOptions :: Options
jsonReqOptions =
defaultOptions
Expand All @@ -58,6 +91,7 @@ jsonReqOptions =
"metadata_remarks" -> "metadata.AXIS_BIZ:remarks"
"metadata_gateway_reference_id" -> "metadata.JUSPAY:gateway_reference_id"
"metadata_expiry_in_mins" -> "metadata.expiryInMins"
"split_settlement_details" -> "metadata.split_settlement_details"
other -> other
}

Expand Down

0 comments on commit 6ab20d6

Please sign in to comment.