Skip to content

Commit

Permalink
Merge branch 'main' of github.com:juspay/hyperswitch-web into refacto…
Browse files Browse the repository at this point in the history
…r-country-props
  • Loading branch information
Pritish Budhiraja committed Apr 18, 2024
2 parents edc3161 + e4d2243 commit 40bc510
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 217 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## [0.43.2](https://github.com/juspay/hyperswitch-web/compare/v0.43.1...v0.43.2) (2024-04-18)


### Bug Fixes

* Added envLoggingUrl in webpack ([#294](https://github.com/juspay/hyperswitch-web/issues/294)) ([88587ac](https://github.com/juspay/hyperswitch-web/commit/88587ac725c03fa1362e3ad79222a290f4d86cdb))

## [0.43.1](https://github.com/juspay/hyperswitch-web/compare/v0.43.0...v0.43.1) (2024-04-18)


### Bug Fixes

* **threedsmethod:** changed Three DS method API call to hidden Form Post ([#302](https://github.com/juspay/hyperswitch-web/issues/302)) ([e42a5a3](https://github.com/juspay/hyperswitch-web/commit/e42a5a3b0f68ba3264ffbe6d7afde41b1cc01d9d))

# [0.43.0](https://github.com/juspay/hyperswitch-web/compare/v0.42.6...v0.43.0) (2024-04-18)


### Features

* mandate changes for Saved Card flow ([#309](https://github.com/juspay/hyperswitch-web/issues/309)) ([648ea87](https://github.com/juspay/hyperswitch-web/commit/648ea87d8e2b0c989edbe7949b43a2c1e70e70cc))

## [0.42.6](https://github.com/juspay/hyperswitch-web/compare/v0.42.5...v0.42.6) (2024-04-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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orca-payment-page",
"version": "0.42.6",
"version": "0.43.2",
"main": "index.js",
"private": true,
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
@react.component
let make = (~isChecked, ~setIsChecked) => {
let {themeObj} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let showFields = Recoil.useRecoilValueFromAtom(RecoilAtoms.showCardFieldsAtom)
let {business} = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom)

let css = `.container {
display: flex;
cursor: pointer;
position: relative;
justify-content: center;
align-items: center;
}
.container input {
Expand Down Expand Up @@ -42,17 +44,23 @@ let make = (~isChecked, ~setIsChecked) => {
setIsChecked(_ => value)
}
let {localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let (checkboxState, checkedState, checkBoxLabelSate) = isChecked
let (checkboxState, checkedState, checkBoxLabelState) = isChecked
? ("Checkbox--checked", "CheckboxInput--checked", "CheckboxLabel--checked")
: ("", "", "")

let saveCardCheckboxLabel = if showFields {
localeString.saveCardDetails
} else {
localeString.cardTerms(business.name)
}

<div className={`Checkbox ${checkboxState} flex flex-row gap-2 items-center`}>
<style> {React.string(css)} </style>
<label className={`container CheckboxInput ${checkedState}`}>
<input type_={`checkbox`} onChange />
<div className={`checkmark CheckboxInput ${checkedState}`} />
<div className={`CheckboxLabel ${checkBoxLabelSate} ml-2`}>
{React.string(localeString.saveCardDetails)}
<div className={`checkmark CheckboxInput ${checkedState} mt-1`} />
<div className={`CheckboxLabel ${checkBoxLabelState} ml-2 w-11/12`}>
{React.string(saveCardCheckboxLabel)}
</div>
</label>
</div>
Expand Down
48 changes: 44 additions & 4 deletions src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open CardUtils
open Utils
@react.component
let make = (
~paymentToken,
Expand All @@ -10,6 +8,9 @@ let make = (
~paymentType,
~list,
) => {
open CardUtils
open Utils
open UtilityHooks
let {themeObj, localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let (showFields, setShowFields) = Recoil.useRecoilState(RecoilAtoms.showCardFieldsAtom)
let areRequiredFieldsValid = Recoil.useRecoilValueFromAtom(RecoilAtoms.areRequiredFieldsValid)
Expand All @@ -19,6 +20,9 @@ let make = (
postFailedSubmitResponse(~errortype="validation_error", ~message)
loggerState.setLogError(~value=message, ~eventName=INVALID_FORMAT, ())
}
let (isSaveCardsChecked, setIsSaveCardsChecked) = React.useState(_ => false)
let {displaySavedPaymentMethodsCheckbox} = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom)
let isGuestCustomer = useIsGuestCustomer()

let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), Card)
let (token, _) = paymentToken
Expand All @@ -33,6 +37,13 @@ let make = (
}
}

let isCustomerAcceptanceRequired = useIsCustomerAcceptanceRequired(
~displaySavedPaymentMethodsCheckbox,
~isSaveCardsChecked,
~list,
~isGuestCustomer,
)

let bottomElement = {
savedMethods
->Array.mapWithIndex((obj, i) => {
Expand Down Expand Up @@ -90,7 +101,7 @@ let make = (

let paymentType = customerMethod.paymentMethodType->Option.getOr(customerMethod.paymentMethod)

UtilityHooks.useHandlePostMessages(~complete, ~empty, ~paymentType, ~savedMethod=true)
useHandlePostMessages(~complete, ~empty, ~paymentType, ~savedMethod=true)

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
Expand All @@ -103,6 +114,7 @@ let make = (
~customerId,
~cvcNumber,
~requiresCvv=customerMethod.requiresCvv,
~isCustomerAcceptanceRequired,
)
| _ => {
let paymentMethodType = switch customerMethod.paymentMethodType {
Expand All @@ -115,6 +127,7 @@ let make = (
~customerId,
~paymentMethod=customerMethod.paymentMethod,
~paymentMethodType,
~isCustomerAcceptanceRequired,
)
}
}
Expand Down Expand Up @@ -153,9 +166,20 @@ let make = (
}
}
}
}, (areRequiredFieldsValid, requiredFieldsBody, empty, complete, customerMethod))
}, (
areRequiredFieldsValid,
requiredFieldsBody,
empty,
complete,
customerMethod,
isCustomerAcceptanceRequired,
))
useSubmitPaymentData(submitCallback)

let conditionsForShowingSaveCardCheckbox = React.useMemo(() => {
!isGuestCustomer && list.payment_type !== SETUP_MANDATE && displaySavedPaymentMethodsCheckbox
}, (isGuestCustomer, list.payment_type, displaySavedPaymentMethodsCheckbox))

<div className="flex flex-col overflow-auto h-auto no-scrollbar animate-slowShow">
{if savedCardlength === 0 && (loadSavedCards === PaymentType.LoadingSavedCards || !showFields) {
<div
Expand All @@ -179,6 +203,22 @@ let make = (
} else {
<RenderIf condition={!showFields}> {bottomElement} </RenderIf>
}}
<RenderIf condition={conditionsForShowingSaveCardCheckbox}>
<div className="pt-4 pb-2 flex items-center justify-start">
<SaveDetailsCheckbox isChecked=isSaveCardsChecked setIsChecked=setIsSaveCardsChecked />
</div>
</RenderIf>
<RenderIf condition={list.payment_type === SETUP_MANDATE}>
<div
className="opacity-50 text-xs mb-2 text-left"
style={ReactDOMStyle.make(
~color=themeObj.colorText,
~marginTop=themeObj.spacingGridColumn,
(),
)}>
<Terms mode={Card} />
</div>
</RenderIf>
<RenderIf condition={!showFields}>
<div
className="Label flex flex-row gap-3 items-end cursor-pointer"
Expand Down
13 changes: 13 additions & 0 deletions src/Hooks/UtilityHooks.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ let useHandlePostMessages = (~complete, ~empty, ~paymentType, ~savedMethod=false
None
}, (complete, empty, paymentType))
}

let useIsCustomerAcceptanceRequired = (
~displaySavedPaymentMethodsCheckbox,
~isSaveCardsChecked,
~list: PaymentMethodsRecord.list,
~isGuestCustomer,
) => React.useMemo(() => {
if displaySavedPaymentMethodsCheckbox {
isSaveCardsChecked || list.payment_type === SETUP_MANDATE
} else {
!(isGuestCustomer || list.payment_type === NORMAL)
}
}, (isSaveCardsChecked, list.payment_type, isGuestCustomer, displaySavedPaymentMethodsCheckbox))
15 changes: 12 additions & 3 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,15 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
}
if dict->getDictIsSome("paymentMethodList") {
let list = dict->getJsonObjectFromDict("paymentMethodList")
let listDict = list->getDictFromJson
if optionsPayment.business.name === "" {
setOptionsPayment(prev => {
...prev,
business: {
name: listDict->getString("merchant_name", ""),
},
})
}
let finalLoadLatency = if launchTime <= 0.0 {
-1.0
} else {
Expand All @@ -370,11 +379,11 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
let updatedState: PaymentType.loadType =
list == Dict.make()->JSON.Encode.object
? LoadError(list)
: switch list->getDictFromJson->Dict.get("error") {
: switch listDict->Dict.get("error") {
| Some(_) => LoadError(list)
| None =>
let isNonEmptyPaymentMethodList =
list->getDictFromJson->getArray("payment_methods")->Array.length > 0
listDict->getArray("payment_methods")->Array.length > 0
isNonEmptyPaymentMethodList ? Loaded(list) : LoadError(list)
}

Expand Down Expand Up @@ -474,7 +483,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime
}
}
handleMessage(handleFun, "Error in parsing sent Data")
}, (showCardFormByDefault, paymentMethodOrder))
}, (showCardFormByDefault, paymentMethodOrder, optionsPayment))

let observer = ResizeObserver.newResizerObserver(entries => {
entries
Expand Down
31 changes: 15 additions & 16 deletions src/Payments/CardPayment.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
type target = {checked: bool}
type event = {target: target}
open PaymentType
open PaymentModeType

@react.component
let make = (
Expand All @@ -12,7 +10,11 @@ let make = (
~paymentType: CardThemeType.mode,
~list: PaymentMethodsRecord.list,
) => {
open PaymentType
open PaymentModeType
open Utils
open UtilityHooks

let {config, themeObj, localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let options = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom)
let loggerState = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom)
Expand Down Expand Up @@ -81,27 +83,22 @@ let make = (
None
}, [complete])

UtilityHooks.useHandlePostMessages(
~complete=complete && areRequiredFieldsValid,
~empty,
~paymentType="card",
)
useHandlePostMessages(~complete=complete && areRequiredFieldsValid, ~empty, ~paymentType="card")

let isGuestCustomer = UtilityHooks.useIsGuestCustomer()
let isGuestCustomer = useIsGuestCustomer()
let isCvcValidValue = CardUtils.getBoolOptionVal(isCVCValid)
let (cardEmpty, cardComplete, cardInvalid) = CardUtils.useCardDetails(
~cvcNumber,
~isCVCValid,
~isCvcValidValue,
)

let isCustomerAcceptanceRequired = React.useMemo(() => {
if displaySavedPaymentMethodsCheckbox {
isSaveCardsChecked || list.payment_type === SETUP_MANDATE
} else {
!(isGuestCustomer || list.payment_type === NORMAL)
}
}, (isSaveCardsChecked, list.payment_type))
let isCustomerAcceptanceRequired = useIsCustomerAcceptanceRequired(
~displaySavedPaymentMethodsCheckbox,
~isSaveCardsChecked,
~list,
~isGuestCustomer,
)

let submitCallback = React.useCallback((ev: Window.event) => {
let json = ev.data->JSON.parseExn
Expand Down Expand Up @@ -277,7 +274,9 @@ let make = (
/>
<RenderIf condition={conditionsForShowingSaveCardCheckbox}>
<div className="pt-4 pb-2 flex items-center justify-start">
<AnimatedCheckbox isChecked=isSaveCardsChecked setIsChecked=setIsSaveCardsChecked />
<SaveDetailsCheckbox
isChecked=isSaveCardsChecked setIsChecked=setIsSaveCardsChecked
/>
</div>
</RenderIf>
<RenderIf condition={isCustomerAcceptanceRequired}>
Expand Down
Loading

0 comments on commit 40bc510

Please sign in to comment.