Skip to content

Commit

Permalink
Merge branch 'main' into fix/three-ds-method-call
Browse files Browse the repository at this point in the history
  • Loading branch information
prafulkoppalkar authored Apr 18, 2024
2 parents 4a3f2be + 648ea87 commit 7a44e83
Show file tree
Hide file tree
Showing 22 changed files with 888 additions and 654 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
## [0.42.6](https://github.com/juspay/hyperswitch-web/compare/v0.42.5...v0.42.6) (2024-04-17)


### Bug Fixes

* mandate data pass hide checkbox ([#308](https://github.com/juspay/hyperswitch-web/issues/308)) ([51c98ab](https://github.com/juspay/hyperswitch-web/commit/51c98abc4da2438195cfbb7e418bf7f47f800008))

## [0.42.5](https://github.com/juspay/hyperswitch-web/compare/v0.42.4...v0.42.5) (2024-04-17)

## [0.42.4](https://github.com/juspay/hyperswitch-web/compare/v0.42.3...v0.42.4) (2024-04-17)


### Bug Fixes

* promise unresolved type error ([#298](https://github.com/juspay/hyperswitch-web/issues/298)) ([03da575](https://github.com/juspay/hyperswitch-web/commit/03da57557f70ae36dc155392a6ccae2b9cad573e))

## [0.42.3](https://github.com/juspay/hyperswitch-web/compare/v0.42.2...v0.42.3) (2024-04-17)


### Bug Fixes

* (paymenthelpers, paymentelement) promise being unresolved ([#297](https://github.com/juspay/hyperswitch-web/issues/297)) ([6494f51](https://github.com/juspay/hyperswitch-web/commit/6494f517a95321b4cb0911f772866deff055d878))

## [0.42.2](https://github.com/juspay/hyperswitch-web/compare/v0.42.1...v0.42.2) (2024-04-17)


### Bug Fixes

* changes card payment ([#306](https://github.com/juspay/hyperswitch-web/issues/306)) ([d9a5b61](https://github.com/juspay/hyperswitch-web/commit/d9a5b611dbb191f1e3f5a4504f3729249e60d73b))

## [0.42.1](https://github.com/juspay/hyperswitch-web/compare/v0.42.0...v0.42.1) (2024-04-17)


Expand Down
6 changes: 3 additions & 3 deletions aws/hyperswitch_web_aws_production_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ echo $( (aws s3api put-bucket-policy --bucket $MY_AWS_S3_BUCKET_NAME --policy "$

echo "Bucket configuration updated"

echo "Enter the backend endpoint your Hyperswitch Client will hit (hosted Hyperswitch Backend, https://sandbox.hyperswitch.io is taken by default):"
echo "Enter the backend endpoint your Hyperswitch Client will hit (hosted Hyperswitch Backend, https://beta.hyperswitch.io/api is taken by default):"
read AWS_BACKEND_URL </dev/tty

if [ -z $AWS_BACKEND_URL ]; then
echo "Setting backend URL value to https://sandbox.hyperswitch.io by default"
AWS_BACKEND_URL="https://sandbox.hyperswitch.io"
echo "Setting backend URL value to https://beta.hyperswitch.io/api by default"
AWS_BACKEND_URL="https://beta.hyperswitch.io/api"

fi

Expand Down
12 changes: 6 additions & 6 deletions aws/hyperswitch_web_aws_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ command_discovery() {
command_discovery curl
command_discovery aws

echo "Please enter the URL where you have hosted Hyperswitch Backend (https://sandbox.hyperswitch.io) "
echo "Please enter the URL where you have hosted Hyperswitch Backend (https://beta.hyperswitch.io/api) "
read HYPERSWITCH_SERVER_URL < /dev/tty

if [ -z "$HYPERSWITCH_SERVER_URL" ]; then
echo "Using default api url: https://sandbox.hyperswitch.io"
HYPERSWITCH_SERVER_URL="https://sandbox.hyperswitch.io"
echo "Using default api url: https://beta.hyperswitch.io/api"
HYPERSWITCH_SERVER_URL="https://beta.hyperswitch.io/api"
fi

# echo "Please enter the api url (https://sandbox.hyperswitch.io) "
# echo "Please enter the api url (https://beta.hyperswitch.io/api) "
# read apiBaseUrl < /dev/tty

# if [ -z "$apiBaseUrl" ]; then
# echo "Using default api url: https://sandbox.hyperswitch.io"
# apiBaseUrl="https://sandbox.hyperswitch.io"
# echo "Using default api url: https://beta.hyperswitch.io/api"
# apiBaseUrl="https://beta.hyperswitch.io/api"
# fi

echo "Please enter the URL where you have hosted Hyperswitch Client SDK (https://beta.hyperswitch.io/v1) "
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.1",
"version": "0.42.6",
"main": "index.js",
"private": true,
"dependencies": {
Expand Down
4 changes: 1 addition & 3 deletions src/App.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ let make = () => {
let clientSecret = CardUtils.getQueryParamsDictforKey(url.search, "clientSecret")
let sessionId = CardUtils.getQueryParamsDictforKey(url.search, "sessionId")
let publishableKey = CardUtils.getQueryParamsDictforKey(url.search, "publishableKey")
let endpoint =
CardUtils.getQueryParamsDictforKey(url.search, "endpoint")->decodeURIComponent
<PreMountLoader publishableKey sessionId clientSecret endpoint />
<PreMountLoader publishableKey sessionId clientSecret />
}
| "achBankTransfer"
| "bacsBankTransfer"
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
3 changes: 2 additions & 1 deletion src/PaymentElement.res
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ let make = (
React.useEffect(() => {
let evalMethodsList = () =>
switch methodslist {
| SemiLoaded | Loaded(_) => handlePostMessage([("ready", true->JSON.Encode.bool)])
| SemiLoaded | LoadError(_) | Loaded(_) =>
handlePostMessage([("ready", true->JSON.Encode.bool)])
| _ => ()
}
if !displaySavedPaymentMethods {
Expand Down
Loading

0 comments on commit 7a44e83

Please sign in to comment.