Skip to content

Commit

Permalink
Merge branch 'main' into enhancement/cdn_route
Browse files Browse the repository at this point in the history
  • Loading branch information
vsrivatsa-edinburgh authored Apr 16, 2024
2 parents 0772ed4 + e42000a commit 5bcdb50
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 53 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# [0.41.0](https://github.com/juspay/hyperswitch-web/compare/v0.40.0...v0.41.0) (2024-04-16)


### Bug Fixes

* **hyper.res:** prefetch assets instead of preload ([#291](https://github.com/juspay/hyperswitch-web/issues/291)) ([703fd50](https://github.com/juspay/hyperswitch-web/commit/703fd505e686d9c897e82bb0109a280484fc1d6b))


### Features

* mandate Changes for the Saved card screen & SDK Button Loader changes ([#289](https://github.com/juspay/hyperswitch-web/issues/289)) ([0e5b5ab](https://github.com/juspay/hyperswitch-web/commit/0e5b5abd588732481bfbafb84080b3297bf993c5))

# [0.40.0](https://github.com/juspay/hyperswitch-web/compare/v0.39.4...v0.40.0) (2024-04-15)


Expand Down
2 changes: 1 addition & 1 deletion Hyperswitch-React-Demo-App/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let devServer = {
},
},
headers: {
"Cache-Control": "max-age=31536000,must-revalidate",
"Cache-Control": "must-revalidate",
},
};

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.40.0",
"version": "0.41.0",
"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 make = (~isChecked, ~setIsChecked, ~list: PaymentMethodsRecord.list) => {
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 @@ -46,13 +48,21 @@ let make = (~isChecked, ~setIsChecked) => {
? ("Checkbox--checked", "CheckboxInput--checked", "CheckboxLabel--checked")
: ("", "", "")

let valueToBeRendered = if showFields {
localeString.saveCardDetails
} else if business.name !== "" {
localeString.cardTerms(business.name)
} else {
localeString.cardTerms(list.merchant_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 ${checkBoxLabelSate} ml-2 w-11/12`}>
{React.string(valueToBeRendered)}
</div>
</label>
</div>
Expand Down
40 changes: 35 additions & 5 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 @@ -8,8 +6,12 @@ let make = (
~loadSavedCards: PaymentType.savedCardsLoadState,
~cvcProps,
~paymentType,
~list,
~list: PaymentMethodsRecord.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 +21,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 +38,13 @@ let make = (
}
}

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

let bottomElement = {
savedMethods
->Array.mapWithIndex((obj, i) => {
Expand Down Expand Up @@ -90,7 +102,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 +115,7 @@ let make = (
~customerId,
~cvcNumber,
~requiresCvv=customerMethod.requiresCvv,
~isCustomerAcceptanceRequired,
)
| _ => {
let paymentMethodType = switch customerMethod.paymentMethodType {
Expand All @@ -115,6 +128,7 @@ let make = (
~customerId,
~paymentMethod=customerMethod.paymentMethod,
~paymentMethodType,
~isCustomerAcceptanceRequired,
)
}
}
Expand Down Expand Up @@ -153,9 +167,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 +204,11 @@ 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 list />
</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))
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 @@ -276,7 +273,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 list
/>
</div>
</RenderIf>
<RenderIf condition={isCustomerAcceptanceRequired}>
Expand Down
3 changes: 3 additions & 0 deletions src/Payments/PaymentMethodsRecord.res
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ type list = {
payment_methods: array<methods>,
mandate_payment: option<mandate>,
payment_type: payment_type,
merchant_name: string,
}

open Utils
Expand All @@ -745,6 +746,7 @@ let defaultList = {
payment_methods: [],
mandate_payment: None,
payment_type: NONE,
merchant_name: "",
}
let getMethod = str => {
switch str {
Expand Down Expand Up @@ -963,6 +965,7 @@ let itemToObjMapper = dict => {
payment_methods: getMethodsArr(dict, "payment_methods"),
mandate_payment: getMandate(dict, "mandate_payment"),
payment_type: getString(dict, "payment_type", "")->paymentTypeMapper,
merchant_name: getString(dict, "merchant_name", ""),
}
}

Expand Down
65 changes: 45 additions & 20 deletions src/Utilities/PaymentBody.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,6 @@ let boletoBody = (~socialSecurityNumber) => [
),
]

let savedCardBody = (~paymentToken, ~customerId, ~cvcNumber, ~requiresCvv) => {
let savedCardBody = [
("payment_method", "card"->JSON.Encode.string),
("payment_token", paymentToken->JSON.Encode.string),
("customer_id", customerId->JSON.Encode.string),
]

if requiresCvv {
savedCardBody->Array.push(("card_cvc", cvcNumber->JSON.Encode.string))->ignore
}

savedCardBody
}

let customerAcceptanceBody =
[
("acceptance_type", "online"->JSON.Encode.string),
Expand All @@ -92,12 +78,51 @@ let customerAcceptanceBody =
->Dict.fromArray
->JSON.Encode.object

let savedPaymentMethodBody = (~paymentToken, ~customerId, ~paymentMethod, ~paymentMethodType) => [
("payment_method", paymentMethod->JSON.Encode.string),
("payment_token", paymentToken->JSON.Encode.string),
("customer_id", customerId->JSON.Encode.string),
("payment_method_type", paymentMethodType),
]
let savedPaymentMethodBody = (
~paymentToken,
~customerId,
~paymentMethod,
~paymentMethodType,
~isCustomerAcceptanceRequired,
) => {
let savedPaymentMethodBody = [
("payment_method", paymentMethod->JSON.Encode.string),
("payment_token", paymentToken->JSON.Encode.string),
("customer_id", customerId->JSON.Encode.string),
("payment_method_type", paymentMethodType),
]

if isCustomerAcceptanceRequired {
savedPaymentMethodBody->Array.push(("customer_acceptance", customerAcceptanceBody))->ignore
}

savedPaymentMethodBody
}

let savedCardBody = (
~paymentToken,
~customerId,
~cvcNumber,
~requiresCvv,
~isCustomerAcceptanceRequired,
) => {
let savedCardBody = [
("payment_method", "card"->JSON.Encode.string),
("payment_token", paymentToken->JSON.Encode.string),
("customer_id", customerId->JSON.Encode.string),
("customer_acceptance", customerAcceptanceBody),
]

if requiresCvv {
savedCardBody->Array.push(("card_cvc", cvcNumber->JSON.Encode.string))->ignore
}

if isCustomerAcceptanceRequired {
savedCardBody->Array.push(("customer_acceptance", customerAcceptanceBody))->ignore
}

savedCardBody
}

let mandateBody = paymentType => {
[
Expand Down
4 changes: 2 additions & 2 deletions src/orca-loader/Hyper.res
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let preloadFile = (~type_, ~href=``, ()) => {
let link = CommonHooks.createElement("link")
link.href = href
link.\"as" = type_
link.rel = "preload"
link.rel = "prefetch"
link.crossorigin = "anonymous"
checkAndAppend(`link[href="${href}"]`, link)
}
Expand Down Expand Up @@ -319,7 +319,7 @@ let make = (publishableKey, options: option<JSON.t>, analyticsInfo: option<JSON.
},
)
}

postSubmitMessage(dict)
if val->JSON.Decode.bool->Option.getOr(false) && redirect === "always" {
Window.replace(returnUrl)
} else if !(val->JSON.Decode.bool->Option.getOr(false)) {
Expand Down
Loading

0 comments on commit 5bcdb50

Please sign in to comment.