Skip to content

Commit

Permalink
Merge branch 'main' into multi-filters-support
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarnaikjuspay committed Dec 7, 2023
2 parents 72d6afc + d77b875 commit e825959
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 69 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@
"uuid": "^9.0.0"
},
"packageManager": "[email protected]"
}
}
9 changes: 8 additions & 1 deletion src/screens/HyperSwitch/Analytics/AnalyticsTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,19 @@ type paymentsSingleStateSeries = {
payment_processed_amount: float,
payment_avg_ticket_size: float,
}

type error_message_type = {
reason: string,
count: int,
percentage: float,
}

type paymentTableType = {
payment_success_rate: float,
payment_count: float,
payment_success_count: float,
payment_processed_amount: float,
payment_error_message: string,
payment_error_message: array<error_message_type>,
avg_ticket_size: float,
connector: string,
payment_method: string,
Expand Down
84 changes: 34 additions & 50 deletions src/screens/HyperSwitch/Analytics/ErrorReasons.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type errorObject = {
error_reason: string,
count: string,
percentage: string,
count: int,
percentage: float,
}

type cols =
Expand All @@ -23,8 +23,8 @@ let tableItemToObjMapper: 'a => errorObject = dict => {
open LogicUtils
{
error_reason: dict->getString(ErrorReason->colMapper, "NA"),
count: dict->getString(Count->colMapper, "NA"),
percentage: dict->getString(Percentage->colMapper, "NA"),
count: dict->getInt(Count->colMapper, 0),
percentage: dict->getFloat(Percentage->colMapper, 0.0),
}
}

Expand All @@ -51,8 +51,8 @@ let getHeading = colType => {
let getCell = (errorObj, colType): Table.cell => {
switch colType {
| ErrorReason => Text(errorObj.error_reason)
| Count => Text(errorObj.count)
| Percentage => Text(errorObj.percentage)
| Count => Text(errorObj.count->Belt.Int.toString)
| Percentage => Text(errorObj.percentage->Belt.Float.toString)
}
}

Expand All @@ -69,7 +69,7 @@ let tableEntity = EntityType.makeEntity(
)

@react.component
let make = (~errorMessage) => {
let make = (~errors: array<AnalyticsTypes.error_message_type>) => {
let (showModal, setShowModal) = React.useState(_ => false)
let (offset, setOffset) = React.useState(_ => 0)

Expand All @@ -78,43 +78,28 @@ let make = (~errorMessage) => {
order: Table.INC,
}

let errors =
errorMessage
->Js.String2.split("$$")
->Js.Array2.filter(err => err->Js.String2.length > 0)
->Js.Array2.map(Js.String2.trim)
->Js.Array2.reverseInPlace

let getCellText = {
let errorStr =
errors
->Belt.Array.get(0)
->Belt.Option.getWithDefault("Error Reasons")
->Js.String2.slice(~from=0, ~to_=15)
let errorStr = switch errors->Belt.Array.get(0) {
| Some(val) => val.reason->Js.String2.slice(~from=0, ~to_=15)
| _ => "Error Reasons"
}

`${errorStr}...`
}

let getItem = (arr, index) => arr->Belt.Array.get(index)->Belt.Option.getWithDefault("")

let tableData = if errors->Js.Array2.length > 0 {
errors->Js.Array2.map(item => {
let arr = item->Js.String2.split("(")
let error_reason = arr->getItem(0)
let percentage = arr->getItem(1)->Js.String2.split(")")->getItem(0)
let count = arr->getItem(2)->Js.String2.split(")")->getItem(0)

{
error_reason,
percentage,
count,
error_reason: item.reason,
percentage: item.percentage,
count: item.count,
}->Js.Nullable.return
})
} else {
[]
}

let tableBorderClass = "border-collapse border border-jp-gray-940 border-solid border-2 rounded-sm border-opacity-30 dark:border-jp-gray-dark_table_border_color dark:border-opacity-30 -mt-4"
let tableBorderClass = "border-collapse border border-jp-gray-940 border-solid border-2 border-opacity-30 dark:border-jp-gray-dark_table_border_color dark:border-opacity-30"

<>
{if errors->Js.Array2.length > 0 {
Expand All @@ -132,26 +117,25 @@ let make = (~errorMessage) => {
showModal
setShowModal
modalClass="w-full max-w-xl mx-auto md:mt-44 ">
<div className="border-t-1 border-x-1">
<LoadedTable
visibleColumns
title=" "
hideTitle=true
actualData={tableData}
entity=tableEntity
resultsPerPage=10
totalResults={tableData->Js.Array2.length}
offset
setOffset
defaultSort
currrentFetchCount={tableData->Js.Array2.length}
tableLocalFilter=false
tableheadingClass=tableBorderClass
tableBorderClass
tableDataBorderClass=tableBorderClass
isAnalyticsModule=true
/>
</div>
<LoadedTable
visibleColumns
title=" "
hideTitle=true
actualData={tableData}
entity=tableEntity
resultsPerPage=10
totalResults={tableData->Js.Array2.length}
offset
setOffset
defaultSort
currrentFetchCount={tableData->Js.Array2.length}
tableLocalFilter=false
tableheadingClass=tableBorderClass
tableBorderClass
ignoreHeaderBg=true
tableDataBorderClass=tableBorderClass
isAnalyticsModule=true
/>
</Modal>
</>
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,21 @@ let distribution =
->Js.Dict.fromArray
->Js.Json.object_

let tableItemToObjMapper: 'a => paymentTableType = dict => {
let tableItemToObjMapper: Js.Dict.t<Js.Json.t> => paymentTableType = dict => {
let parseErrorReasons = dict => {
dict
->getArrayFromDict(PaymentErrorMessage->colMapper, [])
->Js.Array2.map(errorJson => {
let dict = errorJson->getDictFromJsonObject

{
reason: dict->getString("reason", ""),
count: dict->getInt("count", 0),
percentage: dict->getFloat("percentage", 0.0),
}
})
}

{
payment_success_rate: dict->getFloat(SuccessRate->colMapper, 0.0),
payment_count: dict->getFloat(Count->colMapper, 0.0),
Expand All @@ -90,7 +104,7 @@ let tableItemToObjMapper: 'a => paymentTableType = dict => {
authentication_type: dict->getString(AuthType->colMapper, "OTHER")->Js.String2.toUpperCase,
refund_status: dict->getString(Status->colMapper, "OTHER")->Js.String2.toUpperCase,
weekly_payment_success_rate: dict->getWeeklySR->Js.String2.toUpperCase,
payment_error_message: dict->getString(PaymentErrorMessage->colMapper, ""),
payment_error_message: dict->parseErrorReasons,
}
}

Expand Down Expand Up @@ -195,7 +209,7 @@ let getCell = (paymentTable, colType): Table.cell => {
| Status => Text(paymentTable.refund_status)
| WeeklySuccessRate => Text(paymentTable.weekly_payment_success_rate)
| PaymentErrorMessage =>
Table.CustomCell(<ErrorReasons errorMessage={paymentTable.payment_error_message} />, "NA")
Table.CustomCell(<ErrorReasons errors={paymentTable.payment_error_message} />, "NA")
| NoCol => Text("")
}
}
Expand Down
23 changes: 21 additions & 2 deletions src/screens/HyperSwitch/SDKPayment/SDKPage.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
let h3Leading2Style = HSwitchUtils.getTextClass(~textVariant=H3, ~h3TextVariant=Leading_2, ())
external toJson: 'a => Js.Json.t = "%identity"
external formEventToStr: ReactEvent.Form.t => string = "%identity"
external strToFormEvent: Js.String.t => ReactEvent.Form.t = "%identity"

module SDKConfiguarationFields = {
open HSwitchMerchantAccountUtils
Expand Down Expand Up @@ -60,8 +62,24 @@ module SDKConfiguarationFields = {
let enterAmountField = FormRenderer.makeFieldInfo(
~label="Enter amount",
~name="amount",
~placeholder="Enter amount",
~customInput=InputFields.numericTextInput(~isDisabled=false, ~customStyle="w-full", ()),
~customInput=(~input, ~placeholder as _) =>
InputFields.numericTextInput(
~input={
...input,
value: (initialValues.amount / 100)->string_of_int->Js.Json.string,
onChange: {
ev => {
let eventValueToInt = ev->formEventToStr->LogicUtils.getIntFromString(0)
let valInCents = (eventValueToInt * 100)->string_of_int->strToFormEvent
input.onChange(valInCents)
}
},
},
~isDisabled=false,
~customStyle="w-full",
~placeholder="Enter amount",
(),
),
(),
)

Expand All @@ -70,6 +88,7 @@ module SDKConfiguarationFields = {
<FormRenderer.FieldRenderer field=selectProfileId fieldWrapperClass="!w-full" />
<FormRenderer.FieldRenderer field=selectCurrencyField fieldWrapperClass="!w-full" />
<FormRenderer.FieldRenderer field=enterAmountField fieldWrapperClass="!w-full" />
<FormValuesSpy />
<FormRenderer.SubmitButton
text="Show preview" disabledParamter={!(initialValues.profile_id->Js.String2.length > 0)}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/screens/HyperSwitch/SDKPayment/SDKPaymentTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type orderDetails = {
type metadata = {order_details: orderDetails}

type paymentType = {
mutable amount: int,
amount: int,
mutable currency: string,
profile_id: string,
customer_id: string,
Expand All @@ -47,4 +47,5 @@ type paymentType = {
shipping: shipping,
billing: billing,
metadata: metadata,
return_url: string,
}
14 changes: 6 additions & 8 deletions src/screens/HyperSwitch/SDKPayment/SDKPaymentUtils.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let initialValueForForm: HSwitchSettingTypes.profileEntity => SDKPaymentTypes.paymentType = defaultBusinessProfile => {
{
amount: 100,
amount: 10000,
currency: "United States-USD",
profile_id: defaultBusinessProfile.profile_id,
description: "Default value",
Expand Down Expand Up @@ -53,13 +53,10 @@ let initialValueForForm: HSwitchSettingTypes.profileEntity => SDKPaymentTypes.pa
},
capture_method: "automatic",
amount_to_capture: 100,
return_url: `${Window.Location.origin}${Window.Location.pathName}`,
}
}

let convertAmountToCents = (amount: int) => {
amount * 100
}

let getCurrencyValue = (countryCurrency: string) => {
countryCurrency
->Js.String2.split("-")
Expand All @@ -81,7 +78,7 @@ let getTypedValueForPayment: Js.Json.t => SDKPaymentTypes.paymentType = values =
values->getDictFromJsonObject->getDictfromDict("shipping")->getDictfromDict("phone")
let metaData =
values->getDictFromJsonObject->getDictfromDict("metadata")->getDictfromDict("order_details")
let cents = dictOfValues->getInt("amount", 100)->convertAmountToCents

{
amount: dictOfValues->getInt("amount", 100),
currency: dictOfValues->getString("currency", "United States-USD"),
Expand Down Expand Up @@ -131,10 +128,11 @@ let getTypedValueForPayment: Js.Json.t => SDKPaymentTypes.paymentType = values =
order_details: {
product_name: metaData->getString("product_name", ""),
quantity: 1,
amount: cents,
amount: dictOfValues->getInt("amount", 100),
},
},
capture_method: "automatic",
amount_to_capture: cents,
amount_to_capture: dictOfValues->getInt("amount", 100),
return_url: dictOfValues->getString("return_url", ""),
}
}
5 changes: 2 additions & 3 deletions src/screens/HyperSwitch/SDKPayment/TestPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ let make = (
try {
let url = `${HSwitchGlobalVars.hyperSwitchApiPrefix}/payments`
let paymentData = initialValues->toJson->Js.Json.stringify->safeParse->getTypedValueForPayment
paymentData.amount = paymentData.amount->convertAmountToCents
paymentData.currency = paymentData.currency->getCurrencyValue
let body = paymentData->toJson
let response = await updateDetails(url, body, Post)
Expand Down Expand Up @@ -126,7 +125,7 @@ let make = (
elementOptions
paymentElementOptions
returnUrl
amount={initialValues.amount->SDKPaymentUtils.convertAmountToCents}
amount={initialValues.amount}
setClientSecret
/>
</div>
Expand All @@ -143,7 +142,7 @@ let make = (
elementOptions
paymentElementOptions
returnUrl
amount={initialValues.amount->SDKPaymentUtils.convertAmountToCents}
amount={initialValues.amount}
setClientSecret
/>
}
Expand Down

0 comments on commit e825959

Please sign in to comment.