Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: smart retry changes #189

Closed
wants to merge 11 commits into from
11 changes: 8 additions & 3 deletions src/entryPoints/hyperswitch/HyperSwitchApp.res
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,14 @@ let make = () => {
renderShow={_ => <UserRoleShowData />}
/>
| list{"analytics-payments"} =>
<FilterContext key="PaymentsAnalytics" index="PaymentsAnalytics">
<PaymentAnalytics />
</FilterContext>
<>
<FilterContext key="PaymentsAnalytics" index="PaymentsAnalytics">
<PaymentAnalytics />
</FilterContext>
<FilterContext key="SmartRetriesAnalytics" index="SmartRetriesAnalytics">
<SmartRetriesAnalytics />
</FilterContext>
</>
| list{"analytics-refunds"} =>
<FilterContext key="PaymentsRefunds" index="PaymentsRefunds">
<RefundsAnalytics />
Expand Down
16 changes: 12 additions & 4 deletions src/screens/HyperSwitch/Analytics/AnalyticsTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,22 @@ let allPaymentColumns = [
PaymentErrorMessage,
AvgTicketSize,
]

type smartRetrySingleState = {
retries_count: int,
retries_amount_processe: float,
}

type smartRetrySingleStateSeries = {
retries_count: int,
retries_amount_processe: float,
time_series: string,
}

type paymentsSingleState = {
payment_success_rate: float,
payment_count: int,
payment_success_count: int,
retries_count: int,
retries_amount_processe: float,
connector_success_rate: float,
payment_processed_amount: float,
payment_avg_ticket_size: float,
Expand All @@ -165,8 +175,6 @@ type paymentsSingleState = {
type paymentsSingleStateSeries = {
payment_success_rate: float,
payment_count: int,
retries_count: int,
retries_amount_processe: float,
connector_success_rate: float,
payment_success_count: int,
time_series: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ let make = () => {
try {
let infoUrl = getURL(~entityName=ANALYTICS_PAYMENTS, ~methodType=Get, ~id=Some(domain), ())
let infoDetails = await fetchDetails(infoUrl)
setMetrics(_ => infoDetails->getDictFromJsonObject->getArrayFromDict("metrics", []))
let metrics =
infoDetails
->getDictFromJsonObject
->getArrayFromDict("metrics", [])
->Array.filter(item => {
let dict = item->getDictFromJsonObject
dict->Dict.get("name")->Belt.Option.getWithDefault(""->Js.Json.string) !==
sagarnaikjuspay marked this conversation as resolved.
Show resolved Hide resolved
"retries_count"->Js.Json.string
})
setMetrics(_ => metrics)
setDimensions(_ => infoDetails->getDictFromJsonObject->getArrayFromDict("dimensions", []))
setScreenState(_ => PageLoaderWrapper.Success)
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ let paymentTableEntity = EntityType.makeEntity(
let singleStateInitialValue = {
payment_success_rate: 0.0,
payment_count: 0,
retries_count: 0,
retries_amount_processe: 0.0,
payment_success_count: 0,
connector_success_rate: 0.0,
payment_processed_amount: 0.0,
Expand All @@ -250,8 +248,6 @@ let singleStateInitialValue = {
let singleStateSeriesInitialValue = {
payment_success_rate: 0.0,
payment_count: 0,
retries_count: 0,
retries_amount_processe: 0.0,
payment_success_count: 0,
time_series: "",
payment_processed_amount: 0.0,
Expand All @@ -269,8 +265,6 @@ let singleStateItemToObjMapper = json => {
payment_success_count: dict->getInt("payment_success_count", 0),
payment_processed_amount: dict->getFloat("payment_processed_amount", 0.0),
payment_avg_ticket_size: dict->getFloat("avg_ticket_size", 0.0),
retries_count: dict->getInt("retries_count", 0),
retries_amount_processe: dict->getFloat("retries_amount_processed", 0.0),
connector_success_rate: dict->getFloat("connector_success_rate", 0.0),
})
->Belt.Option.getWithDefault({
Expand All @@ -289,8 +283,6 @@ let singleStateSeriesItemToObjMapper = json => {
time_series: dict->getString("time_bucket", ""),
payment_processed_amount: dict->getFloat("payment_processed_amount", 0.0)->setPrecision(),
payment_avg_ticket_size: dict->getFloat("avg_ticket_size", 0.0)->setPrecision(),
retries_count: dict->getInt("retries_count", 0),
retries_amount_processe: dict->getFloat("retries_amount_processed", 0.0),
connector_success_rate: dict->getFloat("connector_success_rate", 0.0),
})
->getWithDefault({
Expand Down Expand Up @@ -323,25 +315,8 @@ let getColumns: bool => array<DynamicSingleStat.columns<colT>> = connector_succe
{
sectionName: "",
columns: connector_success_rate
? [
SuccessRate,
Count,
SuccessCount,
ProcessedAmount,
AvgTicketSize,
RetriesCount,
RetriesAmountProcessed,
ConnectorSuccessRate,
]
: [
SuccessRate,
Count,
SuccessCount,
ProcessedAmount,
AvgTicketSize,
RetriesCount,
RetriesAmountProcessed,
],
? [SuccessRate, Count, SuccessCount, ProcessedAmount, AvgTicketSize, ConnectorSuccessRate]
: [SuccessRate, Count, SuccessCount, ProcessedAmount, AvgTicketSize],
},
]

Expand Down Expand Up @@ -394,17 +369,6 @@ let constructData = (
ob.payment_avg_ticket_size /. 100.00,
))
->Js.Array2.sortInPlaceWith(compareLogic)
| "retries_count" =>
singlestatTimeseriesData->Array.map(ob => (
ob.time_series->DateTimeUtils.parseAsFloat,
ob.retries_count->Belt.Int.toFloat,
))
| "retries_amount_processed" =>
singlestatTimeseriesData
->Array.map(ob => (
ob.time_series->DateTimeUtils.parseAsFloat,
ob.retries_amount_processe /. 100.00,
))
->Js.Array2.sortInPlaceWith(compareLogic)
| "connector_success_rate" =>
singlestatTimeseriesData
Expand Down Expand Up @@ -512,42 +476,8 @@ let getStatData = (
statType: "Volume",
showDelta: false,
}
| RetriesCount => {
title: "Smart Retries made",
tooltipText: "Total number of retries that were attempted after a failed payment attempt (Note: Only date range filters are supoorted currently)",
deltaTooltipComponent: AnalyticsUtils.singlestatDeltaTooltipFormat(
singleStatData.retries_count->Belt.Int.toFloat,
deltaTimestampData.currentSr,
),
value: singleStatData.retries_count->Belt.Int.toFloat,
delta: {
singleStatData.retries_count->Belt.Int.toFloat
},
data: constructData("retries_count", timeSeriesData),
statType: "Volume",
showDelta: false,
}
| RetriesAmountProcessed => {
title: `Smart Retries Savings`,
tooltipText: "Total savings in amount terms from retrying failed payments again through a second processor (Note: Only date range filters are supoorted currently)",
deltaTooltipComponent: AnalyticsUtils.singlestatDeltaTooltipFormat(
singleStatData.retries_amount_processe /. 100.00,
deltaTimestampData.currentSr,
),
value: singleStatData.retries_amount_processe /. 100.00,
delta: {
Js.Float.fromString(
Js.Float.toFixedWithPrecision(
singleStatData.retries_amount_processe /. 100.00,
~digits=2,
),
)
},
data: constructData("retries_amount_processe", timeSeriesData),
statType: "Amount",
showDelta: false,
}
| ConnectorSuccessRate => {

| ConnectorSuccessRate | _ => {
title: "Payment Success Rate",
tooltipText: "Total successful payments processed out of all user confirmed payments",
deltaTooltipComponent: AnalyticsUtils.singlestatDeltaTooltipFormat(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
module SmartRetries = {
@react.component
let make = (
~pageTitle="",
~startTimeFilterKey: string,
~endTimeFilterKey: string,
~tabKeys: array<string>,
~initialFixedFilters: Js.Json.t => array<EntityType.initialFilters<'t>>,
~singleStatEntity: DynamicSingleStat.entityType<'singleStatColType, 'b, 'b2>,
~moduleName: string,
) => {
let {updateExistingKeys, filterValueJson} = React.useContext(FilterContext.filterContext)
let (_totalVolume, setTotalVolume) = React.useState(_ => 0)
sagarnaikjuspay marked this conversation as resolved.
Show resolved Hide resolved
let defaultFilters = [startTimeFilterKey, endTimeFilterKey]

let setInitialFilters = HSwitchRemoteFilter.useSetInitialFilters(
~updateExistingKeys,
~startTimeFilterKey,
~endTimeFilterKey,
)

React.useEffect0(() => {
setInitialFilters()
None
})

let headerTextStyle = HSwitchUtils.getTextClass(~textVariant=H1, ())

<UIUtils.RenderIf condition={filterValueJson->Js.Dict.entries->Array.length > 0}>
<div className="flex flex-col gap-0 mb-10">
<div className={`${headerTextStyle} pt-2`}> {pageTitle->React.string} </div>
<div className="mt-2 -ml-1">
<DynamicFilter
initialFilters=[]
options=[]
popupFilterFields=[]
initialFixedFilters={initialFixedFilters(Js.Json.object_(Dict.make()))}
defaultFilterKeys=defaultFilters
tabNames=tabKeys
updateUrlWith=updateExistingKeys //
key="1"
sagarnaikjuspay marked this conversation as resolved.
Show resolved Hide resolved
filtersDisplayOption=false
filterFieldsPortalName={HSAnalyticsUtils.filterFieldsPortalName}
showCustomFilter=false
refreshFilters=false
/>
</div>
<DynamicSingleStat
entity=singleStatEntity
startTimeFilterKey
endTimeFilterKey
filterKeys=[]
moduleName
setTotalVolume
showPercentage=false
statSentiment={singleStatEntity.statSentiment->Belt.Option.getWithDefault(Dict.make())}
/>
</div>
</UIUtils.RenderIf>
}
}

@react.component
let make = () => {
open SmartRetriesAnalyticsEntity

let metrics = [[("name", "retries_count"->Js.Json.string)]->Dict.fromArray->Js.Json.object_]
sagarnaikjuspay marked this conversation as resolved.
Show resolved Hide resolved

<SmartRetries
pageTitle="Smart Retries"
key="PaymentsAnalytics"
moduleName="Payments"
tabKeys=[]
singleStatEntity={getSingleStatEntity(metrics)}
startTimeFilterKey
endTimeFilterKey
initialFixedFilters=HSAnalyticsUtils.initialFixedFilterFields
/>
}
Loading
Loading