Skip to content
Open
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
2 changes: 1 addition & 1 deletion ios
3 changes: 2 additions & 1 deletion src/components/common/CustomAccordionView.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module SectionHeader = {
{section.title === "loading"
? <CustomLoader height="18" width="18" />
: <Icon
name=section.title width=18. height=18. fill={isExpanded ? primaryColor : iconColor}
name={section.icon->Option.getOr(section.title)} width=18. height=18. fill={isExpanded ? primaryColor : iconColor}
/>}
<Space height=5. />
{section.title === "loading"
Expand Down Expand Up @@ -90,6 +90,7 @@ let make = (
let allSections = hocComponentArr->Array.mapWithIndex((hoc, index) => {
AccordionView.key: index,
title: hoc.name,
icon: hoc.iconName,
isExpanded: expandedSections->Array.includes(index),
componentHoc: hoc.componentHoc,
})
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/CustomTabView.res
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let make = (
isLoading
? <CustomLoader height="18" width="18" />
: <Icon
name=hoc.name
name=hoc.iconName
width=18.
height=18.
fill={indexInFocus === index ? primaryColor : iconColor}
Expand Down Expand Up @@ -68,7 +68,7 @@ let make = (
let isScrollBarOnlyCards =
hocComponentArr->Array.length == 1 &&
switch hocComponentArr->Array.get(0) {
| Some({name}) => name == "Card"
| Some({iconName}) => iconName == "credit"
| None => true
}

Expand Down
31 changes: 26 additions & 5 deletions src/hooks/AllApiDataModifier.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type componentHoc = (

type hoc = {
name: string,
iconName: string,
componentHoc: componentHoc,
}

Expand All @@ -20,7 +21,17 @@ let useAccountPaymentMethodModifier = () => {
)
let samsungPayStatus = SamsungPay.useSamsungPayValidityHook()

React.useMemo3(() => {
React.useMemo4(() => {
let customMethodNames = nativeProp.configuration.customMethodNames

// Returns the merchant-defined alias name for a payment method, or the default display name.
let resolveDisplayName = (paymentMethodType, defaultName) => {
customMethodNames
->Array.find((alias: SdkTypes.alias) => alias.paymentMethodName->String.toLowerCase === paymentMethodType->String.toLowerCase)
->Option.map((alias: SdkTypes.alias) => alias.aliasName)
->Option.getOr(defaultName)
}

let (initialTabArr, initialElementArr) = if nativeProp.configuration.displayMergedSavedMethods {
customerPaymentMethodData
->Option.map(customerPaymentMethods => {
Expand All @@ -35,7 +46,8 @@ let useAccountPaymentMethodModifier = () => {
customerPaymentMethods->Array.length > 0
? [
{
name: "Saved",
name: resolveDisplayName("saved", "Saved"),
iconName: "saved",
componentHoc: (~isScreenFocus, ~setConfirmButtonData) =>
<SavedPaymentSheet
isScreenFocus
Expand Down Expand Up @@ -150,14 +162,22 @@ let useAccountPaymentMethodModifier = () => {
/>,
)
: tabArr->Array.push({
name: paymentMethodData.payment_method_type->CommonUtils.getDisplayName,
name: resolveDisplayName(
paymentMethodData.payment_method_type,
paymentMethodData.payment_method_type->CommonUtils.getDisplayName,
),
iconName: paymentMethodData.payment_method_type,
componentHoc: (~isScreenFocus, ~setConfirmButtonData) =>
<PaymentMethod isScreenFocus paymentMethodData setConfirmButtonData />,
})

| TabSheet | WidgetTabSheet =>
tabArr->Array.push({
name: paymentMethodData.payment_method_type->CommonUtils.getDisplayName,
name: resolveDisplayName(
paymentMethodData.payment_method_type,
paymentMethodData.payment_method_type->CommonUtils.getDisplayName,
),
iconName: paymentMethodData.payment_method_type,
componentHoc: (~isScreenFocus, ~setConfirmButtonData) =>
<PaymentMethod isScreenFocus paymentMethodData setConfirmButtonData />,
})
Expand All @@ -179,6 +199,7 @@ let useAccountPaymentMethodModifier = () => {
| None =>
let loadingTabElement = {
name: "loading",
iconName: "loading", /* sentinel — short-circuited before Icon render */
componentHoc: (~isScreenFocus as _, ~setConfirmButtonData as _) => <>
<Space height=20. />
<CustomLoader />
Expand Down Expand Up @@ -216,7 +237,7 @@ let useAccountPaymentMethodModifier = () => {
| _ => ([], [], [])
}
}
}, (accountPaymentMethodData, customerPaymentMethodData, sessionTokenData))
}, (accountPaymentMethodData, customerPaymentMethodData, sessionTokenData, nativeProp))
}

let useAddWebPaymentButton = () => {
Expand Down
43 changes: 43 additions & 0 deletions src/types/SdkTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ type placeholder = {
cvv: string,
}

type alias = {
paymentMethodName: string,
aliasName: string,
}
type customMethodNames = array<alias>

type configurationType = {
allowsDelayedPaymentMethods: bool,
appearance: appearance,
Expand All @@ -234,6 +240,7 @@ type configurationType = {
enablePartialLoading: bool,
displayMergedSavedMethods: bool,
disableBranding: bool,
customMethodNames: customMethodNames,
}

type sdkState =
Expand Down Expand Up @@ -836,6 +843,42 @@ let parseConfigurationDict = (configObj, from) => {
},
displayMergedSavedMethods: getBool(configObj, "displayMergedSavedMethods", false),
disableBranding: getBool(configObj, "disableBranding", false),
customMethodNames: {
// Android passes customMethodNames as a JSON string; iOS passes it as a native array.
// Handle both cases gracefully.
let rawValue = configObj->Dict.get("customMethodNames")
let jsonArr = switch rawValue {
| Some(v) =>
switch JSON.Decode.array(v) {
| Some(arr) => arr
| None =>
// Try to parse as a JSON string (Android bundle path)
switch JSON.Decode.string(v) {
| Some(str) =>
let parsedValue = switch try {
Some(JSON.parseExn(str))
} catch {
| _ => None
} {
| value => value
}
switch parsedValue->Option.flatMap(JSON.Decode.array) {
| Some(arr) => arr
| _ => []
}
| None => []
}
}
| None => []
}
jsonArr
->Array.filterMap(JSON.Decode.object)
->Array.map(json => {
paymentMethodName: getString(json, "paymentMethodName", ""),
aliasName: getString(json, "aliasName", ""),
})
->Array.filter(alias => alias.paymentMethodName !== "" && alias.aliasName !== "")
},
}
configuration
}
Expand Down
Loading