Skip to content

Commit

Permalink
Merge branch 'main' of github.com:juspay/hyperswitch-web into feat/un…
Browse files Browse the repository at this point in the history
…supported_card_networks
  • Loading branch information
vsrivatsa-juspay committed May 22, 2024
2 parents a095c8b + 9bc1355 commit c59aa41
Show file tree
Hide file tree
Showing 20 changed files with 239 additions and 112 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
## [0.53.3](https://github.com/juspay/hyperswitch-web/compare/v0.53.2...v0.53.3) (2024-05-22)


### Bug Fixes

* added patch for revert to generate tag ([#385](https://github.com/juspay/hyperswitch-web/issues/385)) ([4a0d92f](https://github.com/juspay/hyperswitch-web/commit/4a0d92f775fafd21e892e58a12151cbd58f7a170))
* reverse core lib issue ([#386](https://github.com/juspay/hyperswitch-web/issues/386)) ([28f9067](https://github.com/juspay/hyperswitch-web/commit/28f90670d61c18828f7e24007f9c898bf3ad2acc))

## [0.53.2](https://github.com/juspay/hyperswitch-web/compare/v0.53.1...v0.53.2) (2024-05-22)


### Bug Fixes

* updated headers ([#381](https://github.com/juspay/hyperswitch-web/issues/381)) ([bd9d7e4](https://github.com/juspay/hyperswitch-web/commit/bd9d7e4f31b8c88e34c675c87655f2a51fe475f7))


### Reverts

* do not unmount preMountLoader iframe ([#382](https://github.com/juspay/hyperswitch-web/issues/382)) ([9d259c2](https://github.com/juspay/hyperswitch-web/commit/9d259c25ac88d142f910bff81895d10dabbd0dc1))

## [0.53.1](https://github.com/juspay/hyperswitch-web/compare/v0.53.0...v0.53.1) (2024-05-17)


### Bug Fixes

* openurl_if_required enhancement ([#371](https://github.com/juspay/hyperswitch-web/issues/371)) ([77fcdcf](https://github.com/juspay/hyperswitch-web/commit/77fcdcf09f2352b72908ffca770be6bdfd57932a))

# [0.53.0](https://github.com/juspay/hyperswitch-web/compare/v0.52.3...v0.53.0) (2024-05-17)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orca-payment-page",
"version": "0.53.0",
"version": "0.53.3",
"main": "index.js",
"private": true,
"dependencies": {
Expand Down Expand Up @@ -145,6 +145,10 @@
{
"type": "chore",
"release": "patch"
},
{
"type": "revert",
"release": "patch"
}
]
}
Expand Down
58 changes: 34 additions & 24 deletions src/CardTheme.res
Original file line number Diff line number Diff line change
Expand Up @@ -67,35 +67,45 @@ type recoilConfig = {
localeString: LocaleStringTypes.localeStrings,
showLoader: bool,
}
let getLocaleObject = string => {
let locale = if string == "auto" {
navigator["language"]
} else {
string
}
switch locale->LocaleStringHelper.mapLocalStringToTypeLocale {
| EN => EnglishLocale.localeStrings
| HE => HebrewLocale.localeStrings
| FR => FrenchLocale.localeStrings
| EN_GB => EnglishGBLocale.localeStrings
| AR => ArabicLocale.localeStrings
| JA => JapaneseLocale.localeStrings
| DE => DeutschLocale.localeStrings
| FR_BE => FrenchBelgiumLocale.localeStrings
| ES => SpanishLocale.localeStrings
| CA => CatalanLocale.localeStrings
| PT => PortugueseLocale.localeStrings
| IT => ItalianLocale.localeStrings
| PL => PolishLocale.localeStrings
| NL => DutchLocale.localeStrings
| SV => SwedishLocale.localeStrings
| RU => RussianLocale.localeStrings

let getLocaleObject = async string => {
try {
let locale = if string == "auto" {
navigator["language"]
} else {
string
}

let promiseLocale = switch locale->LocaleStringHelper.mapLocalStringToTypeLocale {
| EN => Js.import(EnglishLocale.localeStrings)
| HE => Js.import(HebrewLocale.localeStrings)
| FR => Js.import(FrenchLocale.localeStrings)
| EN_GB => Js.import(EnglishGBLocale.localeStrings)
| AR => Js.import(ArabicLocale.localeStrings)
| JA => Js.import(JapaneseLocale.localeStrings)
| DE => Js.import(DeutschLocale.localeStrings)
| FR_BE => Js.import(FrenchBelgiumLocale.localeStrings)
| ES => Js.import(SpanishLocale.localeStrings)
| CA => Js.import(CatalanLocale.localeStrings)
| PT => Js.import(PortugueseLocale.localeStrings)
| IT => Js.import(ItalianLocale.localeStrings)
| PL => Js.import(PolishLocale.localeStrings)
| NL => Js.import(DutchLocale.localeStrings)
| SV => Js.import(SwedishLocale.localeStrings)
| RU => Js.import(RussianLocale.localeStrings)
}

let awaitedLocaleValue = await promiseLocale
awaitedLocaleValue
} catch {
| _ => EnglishLocale.localeStrings
}
}

let defaultRecoilConfig: recoilConfig = {
config: defaultConfig,
themeObj: defaultConfig.appearance.variables,
localeString: getLocaleObject(defaultConfig.locale),
localeString: EnglishLocale.localeStrings,
showLoader: false,
}

Expand Down
4 changes: 2 additions & 2 deletions src/CardUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ let getCardBrand = cardNumber => {

let calculateLuhn = value => {
let card = value->clearSpaces

let splitArr = card->String.split("")->Array.toReversed
let splitArr = card->String.split("")
splitArr->Array.reverse
let unCheckArr = splitArr->Array.filterWithIndex((_, i) => {
mod(i, 2) == 0
})
Expand Down
8 changes: 7 additions & 1 deletion src/Components/SavedCardItem.res
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ let make = (
boxShadow: "none",
opacity: {isCardExpired ? "0.7" : "1"},
}
onClick={_ => setPaymentToken(_ => (paymentItem.paymentToken, paymentItem.customerId))}>
onClick={_ => {
open RecoilAtomTypes
setPaymentToken(_ => {
paymentToken: paymentItem.paymentToken,
customerId: paymentItem.customerId,
})
}}>
<div className="w-full">
<div>
<div className="flex flex-row justify-between items-center">
Expand Down
16 changes: 8 additions & 8 deletions src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@react.component
let make = (
~paymentToken,
~paymentToken: RecoilAtomTypes.paymentToken,
~setPaymentToken,
~savedMethods: array<PaymentType.customerMethods>,
~loadSavedCards: PaymentType.savedCardsLoadState,
Expand All @@ -24,10 +24,11 @@ let make = (
let isGuestCustomer = useIsGuestCustomer()

let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Card)
let (token, _) = paymentToken
let savedCardlength = savedMethods->Array.length
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)

let {paymentToken: paymentTokenVal, customerId} = paymentToken

let getWalletBrandIcon = (obj: PaymentType.customerMethods) => {
switch obj.paymentMethodType {
| Some("apple_pay") => <Icon size=brandIconSize name="apple_pay_saved" />
Expand Down Expand Up @@ -57,7 +58,7 @@ let make = (
""->CardThemeType.getPaymentMode,
)
}
let isActive = token == obj.paymentToken
let isActive = paymentTokenVal == obj.paymentToken
<SavedCardItem
key={i->Belt.Int.toString}
setPaymentToken
Expand All @@ -76,15 +77,14 @@ let make = (

let (isCVCValid, _, cvcNumber, _, _, _, _, _, _, setCvcError) = cvcProps
let complete = switch isCVCValid {
| Some(val) => token !== "" && val
| Some(val) => paymentTokenVal !== "" && val
| _ => false
}
let empty = cvcNumber == ""
let (token, customerId) = paymentToken
let customerMethod =
savedMethods
->Array.filter(savedMethod => {
savedMethod.paymentToken === token
savedMethod.paymentToken === paymentTokenVal
})
->Array.get(0)
->Option.getOr(PaymentType.defaultCustomerMethods)
Expand All @@ -108,7 +108,7 @@ let make = (
let savedPaymentMethodBody = switch customerMethod.paymentMethod {
| "card" =>
PaymentBody.savedCardBody(
~paymentToken=token,
~paymentToken=paymentTokenVal,
~customerId,
~cvcNumber,
~requiresCvv=customerMethod.requiresCvv,
Expand All @@ -121,7 +121,7 @@ let make = (
| Some(paymentMethodType) => paymentMethodType->JSON.Encode.string
}
PaymentBody.savedPaymentMethodBody(
~paymentToken=token,
~paymentToken=paymentTokenVal,
~customerId,
~paymentMethod=customerMethod.paymentMethod,
~paymentMethodType,
Expand Down
89 changes: 42 additions & 47 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,40 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
}
}

let setConfigs = (dict, themeValues: ThemeImporter.themeDataModule) => {
let paymentOptions = dict->getDictFromObj("paymentOptions")
let optionsDict = dict->getDictFromObj("options")
let (default, defaultRules) = (themeValues.default, themeValues.defaultRules)
let config = CardTheme.itemToObjMapper(paymentOptions, default, defaultRules, logger)

let optionsLocaleString = getWarningString(optionsDict, "locale", "", ~logger)

let optionsAppearance = CardTheme.getAppearance(
"appearance",
optionsDict,
default,
defaultRules,
logger,
)
let appearance =
optionsAppearance == CardTheme.defaultAppearance ? config.appearance : optionsAppearance
let localeString = CardTheme.getLocaleObject(
optionsLocaleString == "" ? config.locale : optionsLocaleString,
)
setConfig(_ => {
config: {
appearance,
locale: config.locale,
fonts: config.fonts,
clientSecret: config.clientSecret,
loader: config.loader,
},
themeObj: appearance.variables,
localeString,
showLoader: config.loader == Auto || config.loader == Always,
})
let setConfigs = async (dict, themeValues: ThemeImporter.themeDataModule) => {
try {
let paymentOptions = dict->getDictFromObj("paymentOptions")
let optionsDict = dict->getDictFromObj("options")
let (default, defaultRules) = (themeValues.default, themeValues.defaultRules)
let config = CardTheme.itemToObjMapper(paymentOptions, default, defaultRules, logger)
let optionsLocaleString = getWarningString(optionsDict, "locale", "", ~logger)
let optionsAppearance = CardTheme.getAppearance(
"appearance",
optionsDict,
default,
defaultRules,
logger,
)
let appearance =
optionsAppearance == CardTheme.defaultAppearance ? config.appearance : optionsAppearance
let localeString = await CardTheme.getLocaleObject(
optionsLocaleString == "" ? config.locale : optionsLocaleString,
)
setConfig(_ => {
config: {
appearance,
locale: config.locale,
fonts: config.fonts,
clientSecret: config.clientSecret,
loader: config.loader,
},
themeObj: appearance.variables,
localeString,
showLoader: config.loader == Auto || config.loader == Always,
})
} catch {
| _ => ()
}
}

React.useEffect0(() => {
Expand Down Expand Up @@ -253,18 +255,15 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime

switch getThemePromise(paymentOptions) {
| Some(promise) =>
promise
->then(res => {
promise->then(res => {
dict->setConfigs(res)
resolve()
})
->ignore
| None =>
dict->setConfigs({
default: DefaultTheme.default,
defaultRules: DefaultTheme.defaultRules,
})
}
}->ignore
}
let newLaunchTime = dict->getFloat("launchTime", 0.0)
setLaunchTime(_ => newLaunchTime)
Expand Down Expand Up @@ -303,18 +302,16 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime

switch getThemePromise(paymentOptions) {
| Some(promise) =>
promise
->then(res => {
promise->then(res => {
dict->setConfigs(res)
resolve()
})
->ignore

| None =>
dict->setConfigs({
default: DefaultTheme.default,
defaultRules: DefaultTheme.defaultRules,
})
}
}->ignore
}
} else if dict->getDictIsSome("paymentElementsUpdate") {
updateOptions(dict)
Expand All @@ -338,18 +335,16 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
}
switch getThemePromise(optionsDict) {
| Some(promise) =>
promise
->then(res => {
promise->then(res => {
dict->setConfigs(res)
resolve()
})
->ignore

| None =>
dict->setConfigs({
default: DefaultTheme.default,
defaultRules: DefaultTheme.defaultRules,
})
}
}->ignore
}
if dict->getDictIsSome("sessions") {
setSessions(_ => Loaded(dict->getJsonObjectFromDict("sessions")))
Expand Down
3 changes: 1 addition & 2 deletions src/Payment.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
let selectedOption = Recoil.useRecoilValueFromAtom(selectedOptionAtom)
let paymentToken = Recoil.useRecoilValueFromAtom(paymentTokenAtom)
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)
let (token, _) = paymentToken

let {iframeId} = keys

Expand Down Expand Up @@ -256,7 +255,7 @@ let make = (~paymentMode, ~integrateError, ~logger) => {
setCardError(_ => "")
setExpiryError(_ => "")
None
}, (token, showFields))
}, (paymentToken.paymentToken, showFields))

let submitValue = (_ev, confirmParam) => {
let validFormat = switch paymentMode->getPaymentMode {
Expand Down
6 changes: 5 additions & 1 deletion src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod
}

switch tokenObj {
| Some(obj) => setPaymentToken(_ => (obj.paymentToken, obj.customerId))
| Some(obj) =>
setPaymentToken(_ => {
paymentToken: obj.paymentToken,
customerId: obj.customerId,
})
| None => ()
}
None
Expand Down
Loading

0 comments on commit c59aa41

Please sign in to comment.