Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sdk pay now button enable prop added #543

Merged
merged 14 commits into from
Aug 7, 2024
5 changes: 5 additions & 0 deletions src/Components/PayNowButton.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ let make = () => {
let confirmPayload = sdkHandleConfirmPayment->PaymentBody.confirmPayloadForSDKButton
let buttonText = sdkHandleConfirmPayment.buttonText->Option.getOr(localeString.payNowButton)

React.useEffect1(() => {
setIsPayNowButtonDisable(_ => !sdkHandleConfirmPayment.allowButtonBeforeValidation)
None
}, [sdkHandleConfirmPayment.allowButtonBeforeValidation])

let handleMessage = (event: Types.event) => {
let json = event.data->Identity.anyTypeToJson->getStringFromJson("")->safeParse
let dict = json->getDictFromJson
Expand Down
9 changes: 7 additions & 2 deletions src/Hooks/UtilityHooks.res
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ let useIsGuestCustomer = () => {
}

let useHandlePostMessages = (~complete, ~empty, ~paymentType, ~savedMethod=false) => {
open RecoilAtoms

let loggerState = Recoil.useRecoilValueFromAtom(RecoilAtoms.loggerAtom)
let setIsPayNowButtonDisable = RecoilAtoms.payNowButtonDisable->Recoil.useSetRecoilState
sakksham7 marked this conversation as resolved.
Show resolved Hide resolved
let {sdkHandleConfirmPayment} = optionAtom->Recoil.useRecoilValueFromAtom

React.useEffect(() => {
let isCompletelyFilled = complete && paymentType !== ""
setIsPayNowButtonDisable(_ => !isCompletelyFilled)
if !sdkHandleConfirmPayment.allowButtonBeforeValidation {
let isCompletelyFilled = complete && paymentType !== ""
setIsPayNowButtonDisable(_ => !isCompletelyFilled)
}
Utils.handlePostMessageEvents(~complete, ~empty, ~paymentType, ~loggerState, ~savedMethod)
None
}, (complete, empty, paymentType))
Expand Down
3 changes: 2 additions & 1 deletion src/TabCard.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let make = (~paymentOption: PaymentMethodsRecord.paymentFieldsInfo, ~isActive: b
let {themeObj, localeString} = Recoil.useRecoilValueFromAtom(configAtom)
let {readOnly, customMethodNames} = Recoil.useRecoilValueFromAtom(optionAtom)
let setSelectedOption = Recoil.useSetRecoilState(selectedOptionAtom)
let {sdkHandleConfirmPayment} = optionAtom->Recoil.useRecoilValueFromAtom
let setIsPayNowButtonDisable = Recoil.useSetRecoilState(payNowButtonDisable)
let (tabClass, tabLabelClass, tabIconClass) = React.useMemo(
() => isActive ? ("Tab--selected", "TabLabel--selected", "TabIcon--selected") : ("", "", ""),
Expand All @@ -16,7 +17,7 @@ let make = (~paymentOption: PaymentMethodsRecord.paymentFieldsInfo, ~isActive: b
paymentOption.icon,
)
let onClick = _ => {
setIsPayNowButtonDisable(_ => true)
setIsPayNowButtonDisable(_ => !sdkHandleConfirmPayment.allowButtonBeforeValidation)
setSelectedOption(_ => paymentOption.paymentMethodName)
}
<button
Expand Down
3 changes: 3 additions & 0 deletions src/Types/PaymentType.res
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ type sdkHandleConfirmPayment = {
handleConfirm: bool,
buttonText?: string,
confirmParams: ConfirmType.confirmParams,
allowButtonBeforeValidation: bool,
}

type options = {
Expand Down Expand Up @@ -286,6 +287,7 @@ let defaultBillingAddress = {
let defaultSdkHandleConfirmPayment = {
handleConfirm: false,
confirmParams: ConfirmType.defaultConfirm,
allowButtonBeforeValidation: false,
}

let defaultOptions = {
Expand Down Expand Up @@ -983,6 +985,7 @@ let getSdkHandleConfirmPaymentProps = dict => {
handleConfirm: dict->getBool("handleConfirm", false),
buttonText: ?dict->getOptionString("buttonText"),
confirmParams: dict->getDictFromDict("confirmParams")->getConfirmParams,
allowButtonBeforeValidation: dict->getBool("allowButtonBeforeValidation", false),
}

let itemToObjMapper = (dict, logger) => {
Expand Down
12 changes: 8 additions & 4 deletions src/orca-loader/Hyper.res
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,14 @@ let make = (publishableKey, options: option<JSON.t>, analyticsInfo: option<JSON.
}
postSubmitMessage(dict)

if (
isSdkButton ||
(val->JSON.Decode.bool->Option.getOr(false) && redirect === "always")
) {
if isSdkButton {
if !(val->JSON.Decode.bool->Option.getOr(false)) {
resolve1(json)
} else {
resolve1(data)
sakksham7 marked this conversation as resolved.
Show resolved Hide resolved
Window.replace(returnUrl)
}
} else if val->JSON.Decode.bool->Option.getOr(false) && redirect === "always" {
Window.replace(returnUrl)
} else if !(val->JSON.Decode.bool->Option.getOr(false)) {
sakksham7 marked this conversation as resolved.
Show resolved Hide resolved
resolve1(json)
Expand Down
Loading