Skip to content

Commit

Permalink
feat: analytics payment processed currency conversion (#1691)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarnaikjuspay authored Nov 7, 2024
1 parent aef8c0f commit 19d2c70
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type chart = {
type dataObj = {
showInLegend: showInLegend,
name: name,
data: array<int>,
data: array<float>,
color: color,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,27 @@ let getColor = index => {
["#1059C1B2", "#0EB025B2"]->Array.get(index)->Option.getOr("#1059C1B2")
}

let getAmountValue = (data, ~id) => {
switch data->getOptionFloat(id) {
| Some(value) => value /. 100.0
| _ => 0.0
}
}

let getLineGraphObj = (
~array: array<JSON.t>,
~key: string,
~name: string,
~color,
~isAmount=false,
): LineGraphTypes.dataObj => {
let data = array->Array.map(item => {
item->getDictFromJsonObject->getInt(key, 0)
let dict = item->getDictFromJsonObject
if isAmount {
dict->getAmountValue(~id=key)
} else {
dict->getFloat(key, 0.0)
}
})
let dataObj: LineGraphTypes.dataObj = {
showInLegend: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ type overviewColumns =
| Total_Dispute

type dataObj = {
total_smart_retried_amount: float,
total_smart_retried_amount_without_smart_retries: float,
total_smart_retried_amount_usd: float,
total_smart_retried_amount_without_smart_retries_usd: float,
total_success_rate: float,
total_success_rate_without_smart_retries: float,
total_payment_processed_amount: float,
total_payment_processed_amount_usd: float,
total_payment_processed_count: int,
total_payment_processed_amount_without_smart_retries: float,
total_payment_processed_amount_without_smart_retries_usd: float,
total_payment_processed_count_without_smart_retries: int,
refund_processed_amount: float,
total_dispute: int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ open NewPaymentsOverviewSectionTypes

let getStringFromVariant = value => {
switch value {
| Total_Smart_Retried_Amount => "total_smart_retried_amount"
| Total_Smart_Retried_Amount_Without_Smart_Retries => "total_smart_retried_amount_without_smart_retries"
| Total_Smart_Retried_Amount => "total_smart_retried_amount_usd"
| Total_Smart_Retried_Amount_Without_Smart_Retries => "total_smart_retried_amount_without_smart_retries_usd"
| Total_Success_Rate => "total_success_rate"
| Total_Success_Rate_Without_Smart_Retries => "total_success_rate_without_smart_retries"
| Total_Payment_Processed_Amount => "total_payment_processed_amount"
| Total_Payment_Processed_Amount_Without_Smart_Retries => "total_payment_processed_amount_without_smart_retries"
| Total_Payment_Processed_Amount => "total_payment_processed_amount_usd"
| Total_Payment_Processed_Amount_Without_Smart_Retries => "total_payment_processed_amount_without_smart_retries_usd"
| Refund_Processed_Amount => "refund_processed_amount"
| Total_Dispute => "total_dispute"
}
}

let defaultValue =
{
total_smart_retried_amount: 0.0,
total_smart_retried_amount_without_smart_retries: 0.0,
total_smart_retried_amount_usd: 0.0,
total_smart_retried_amount_without_smart_retries_usd: 0.0,
total_success_rate: 0.0,
total_success_rate_without_smart_retries: 0.0,
total_payment_processed_amount: 0.0,
total_payment_processed_amount_usd: 0.0,
total_payment_processed_count: 0,
total_payment_processed_amount_without_smart_retries: 0.0,
total_payment_processed_amount_without_smart_retries_usd: 0.0,
total_payment_processed_count_without_smart_retries: 0,
refund_processed_amount: 0.0,
total_dispute: 0,
Expand Down Expand Up @@ -54,15 +54,24 @@ let parseResponse = (response, key) => {

open NewAnalyticsTypes
let setValue = (dict, ~data, ~ids: array<overviewColumns>) => {
open NewPaymentAnalyticsUtils
open LogicUtils

ids->Array.forEach(id => {
dict->Dict.set(
id->getStringFromVariant,
let key = id->getStringFromVariant
let value = switch id {
| Total_Smart_Retried_Amount
| Total_Smart_Retried_Amount_Without_Smart_Retries
| Total_Payment_Processed_Amount
| Total_Payment_Processed_Amount_Without_Smart_Retries =>
data->getAmountValue(~id=id->getStringFromVariant)->JSON.Encode.float
| _ =>
data
->getFloat(id->getStringFromVariant, 0.0)
->JSON.Encode.float,
)
->JSON.Encode.float
}

dict->Dict.set(key, value)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ module PaymentsProcessedHeader = {
~key=selectedMetric.value->getMetaDataMapper(~isSmartRetryEnabled),
)

let (primaryValue, secondaryValue) = if (
selectedMetric.value->getMetaDataMapper(~isSmartRetryEnabled)->isAmountMetric
) {
(primaryValue /. 100.0, secondaryValue /. 100.0)
} else {
(primaryValue, secondaryValue)
}

let (value, direction) = calculatePercentageChange(~primaryValue, ~secondaryValue)

let setViewType = value => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ type paymentsProcessedCols =
| Time_Bucket

type paymentsProcessedObject = {
payment_processed_amount: float,
payment_processed_amount_usd: float,
payment_processed_count: int,
payment_processed_amount_without_smart_retries: float,
payment_processed_amount_without_smart_retries_usd: float,
payment_processed_count_without_smart_retries: int,
total_payment_processed_amount: float,
total_payment_processed_amount_usd: float,
total_payment_processed_count: int,
total_payment_processed_amount_without_smart_retries: float,
total_payment_processed_amount_without_smart_retries_usd: float,
total_payment_processed_count_without_smart_retries: int,
time_bucket: string,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,45 @@ open LogicUtils

let getStringFromVariant = value => {
switch value {
| Payment_Processed_Amount => "payment_processed_amount"
| Payment_Processed_Amount => "payment_processed_amount_usd"
| Payment_Processed_Count => "payment_processed_count"
| Payment_Processed_Amount_Without_Smart_Retries => "payment_processed_amount_without_smart_retries"
| Payment_Processed_Amount_Without_Smart_Retries => "payment_processed_amount_without_smart_retries_usd"
| Payment_Processed_Count_Without_Smart_Retries => "payment_processed_count_without_smart_retries"
| Total_Payment_Processed_Amount => "total_payment_processed_amount"
| Total_Payment_Processed_Amount => "total_payment_processed_amount_usd"
| Total_Payment_Processed_Count => "total_payment_processed_count"
| Total_Payment_Processed_Amount_Without_Smart_Retries => "total_payment_processed_amount_without_smart_retries"
| Total_Payment_Processed_Amount_Without_Smart_Retries => "total_payment_processed_amount_without_smart_retries_usd"
| Total_Payment_Processed_Count_Without_Smart_Retriess => "total_payment_processed_count_without_smart_retries"
| Time_Bucket => "time_bucket"
}
}

let getVariantValueFromString = value => {
switch value {
| "payment_processed_amount" => Payment_Processed_Amount
| "payment_processed_amount_usd" => Payment_Processed_Amount
| "payment_processed_count" => Payment_Processed_Count
| "payment_processed_amount_without_smart_retries" =>
| "payment_processed_amount_without_smart_retries_usd" =>
Payment_Processed_Amount_Without_Smart_Retries
| "payment_processed_count_without_smart_retries" => Payment_Processed_Count_Without_Smart_Retries
| "total_payment_processed_amount" => Total_Payment_Processed_Amount
| "total_payment_processed_amount_usd" => Total_Payment_Processed_Amount
| "total_payment_processed_count" => Total_Payment_Processed_Count
| "total_payment_processed_amount_without_smart_retries" =>
| "total_payment_processed_amount_without_smart_retries_usd" =>
Total_Payment_Processed_Amount_Without_Smart_Retries
| "total_payment_processed_count_without_smart_retries" =>
Total_Payment_Processed_Count_Without_Smart_Retriess
| "time_bucket" | _ => Time_Bucket
}
}

let isAmountMetric = key => {
switch key->getVariantValueFromString {
| Payment_Processed_Amount
| Payment_Processed_Amount_Without_Smart_Retries
| Total_Payment_Processed_Amount
| Total_Payment_Processed_Amount_Without_Smart_Retries => true
| _ => false
}
}

let paymentsProcessedMapper = (
~params: NewAnalyticsTypes.getObjects<JSON.t>,
): LineGraphTypes.lineGraphPayload => {
Expand All @@ -51,7 +61,13 @@ let paymentsProcessedMapper = (
->Array.mapWithIndex((item, index) => {
let name = NewAnalyticsUtils.getLabelName(~key=yKey, ~index, ~points=item)
let color = index->getColor
getLineGraphObj(~array=item->getArrayFromJson([]), ~key=xKey, ~name, ~color)
getLineGraphObj(
~array=item->getArrayFromJson([]),
~key=xKey,
~name,
~color,
~isAmount=xKey->isAmountMetric,
)
})
let title = {
text: "Payments Processed",
Expand Down Expand Up @@ -82,27 +98,26 @@ let visibleColumns = [Time_Bucket]

let tableItemToObjMapper: Dict.t<JSON.t> => paymentsProcessedObject = dict => {
{
payment_processed_amount: dict->getFloat(Payment_Processed_Amount->getStringFromVariant, 0.0),
payment_processed_amount_usd: dict->getAmountValue(
~id=Payment_Processed_Amount->getStringFromVariant,
),
payment_processed_count: dict->getInt(Payment_Processed_Count->getStringFromVariant, 0),
payment_processed_amount_without_smart_retries: dict->getFloat(
Payment_Processed_Amount_Without_Smart_Retries->getStringFromVariant,
0.0,
payment_processed_amount_without_smart_retries_usd: dict->getAmountValue(
~id=Payment_Processed_Amount_Without_Smart_Retries->getStringFromVariant,
),
payment_processed_count_without_smart_retries: dict->getInt(
Payment_Processed_Count_Without_Smart_Retries->getStringFromVariant,
0,
),
total_payment_processed_amount: dict->getFloat(
Total_Payment_Processed_Amount->getStringFromVariant,
0.0,
total_payment_processed_amount_usd: dict->getAmountValue(
~id=Total_Payment_Processed_Amount->getStringFromVariant,
),
total_payment_processed_count: dict->getInt(
Total_Payment_Processed_Count->getStringFromVariant,
0,
),
total_payment_processed_amount_without_smart_retries: dict->getFloat(
Total_Payment_Processed_Amount_Without_Smart_Retries->getStringFromVariant,
0.0,
total_payment_processed_amount_without_smart_retries_usd: dict->getAmountValue(
~id=Total_Payment_Processed_Amount_Without_Smart_Retries->getStringFromVariant,
),
total_payment_processed_count_without_smart_retries: dict->getInt(
Total_Payment_Processed_Count_Without_Smart_Retriess->getStringFromVariant,
Expand Down Expand Up @@ -160,9 +175,9 @@ let getHeading = colType => {
let getCell = (obj, colType): Table.cell => {
open NewAnalyticsUtils
switch colType {
| Payment_Processed_Amount => Text(obj.payment_processed_amount->valueFormatter(Amount))
| Payment_Processed_Amount => Text(obj.payment_processed_amount_usd->valueFormatter(Amount))
| Payment_Processed_Amount_Without_Smart_Retries =>
Text(obj.payment_processed_amount_without_smart_retries->valueFormatter(Amount))
Text(obj.payment_processed_amount_without_smart_retries_usd->valueFormatter(Amount))
| Payment_Processed_Count => Text(obj.payment_processed_count->Int.toString)
| Payment_Processed_Count_Without_Smart_Retries =>
Text(obj.payment_processed_count_without_smart_retries->Int.toString)
Expand Down

0 comments on commit 19d2c70

Please sign in to comment.