From fcae637d89f867ca2a8a4b9d2f1860b36eaaaf08 Mon Sep 17 00:00:00 2001 From: Arush Date: Thu, 19 Dec 2024 04:36:15 +0530 Subject: [PATCH] feat: added support for ClickToPay --- public/icons/orca.svg | 8 + src/App.res | 1 + src/Components/ClickToPayDetails.res | 179 ++++ src/Components/ClickToPayLearnMore.res | 59 ++ src/Components/ClickToPayNotYou.res | 245 ++++++ src/Components/DynamicFields.res | 11 +- src/Components/SaveDetailsCheckbox.res | 22 +- src/Components/SavedMethods.res | 240 +++++- src/Hooks/CommonHooks.res | 48 +- src/PaymentElement.res | 73 +- src/Payments/CardPayment.res | 129 ++- src/Types/ClickToPayHelpers.res | 961 ++++++++++++++++++++++ src/Types/PaymentType.res | 43 + src/Types/SessionsType.res | 15 +- src/Utilities/DynamicFieldsUtils.res | 33 + src/Utilities/PaymentBody.res | 14 + src/Utilities/RecoilAtoms.res | 20 + src/Window.res | 6 + src/hyper-loader/Elements.res | 2 +- src/hyper-loader/LoaderPaymentElement.res | 1 + src/hyper-log-catcher/HyperLogger.res | 2 + 21 files changed, 2080 insertions(+), 32 deletions(-) create mode 100644 src/Components/ClickToPayDetails.res create mode 100644 src/Components/ClickToPayLearnMore.res create mode 100644 src/Components/ClickToPayNotYou.res create mode 100644 src/Types/ClickToPayHelpers.res diff --git a/public/icons/orca.svg b/public/icons/orca.svg index 17a7c7aaa..989db5f7e 100644 --- a/public/icons/orca.svg +++ b/public/icons/orca.svg @@ -169,6 +169,14 @@ License) d="M70.94 285.81c-16.17 16.24-42.46 16.32-58.71.15-16.24-16.16-16.32-42.46-.15-58.7L226.57 12.23c16.16-16.24 42.46-16.32 58.7-.15l214.65 215.18c16.17 16.24 16.09 42.54-.15 58.7-16.25 16.17-42.54 16.09-58.71-.15L256 100.29 70.94 285.81z" /> + + + + + + + + diff --git a/src/App.res b/src/App.res index aab35134e..28f9def64 100644 --- a/src/App.res +++ b/src/App.res @@ -56,6 +56,7 @@ let make = () => { | _ => switch fullscreenMode { | "paymentloader" => + | "clickToPayLearnMore" => | "plaidSDK" => | "pazeWallet" => | "fullscreen" => diff --git a/src/Components/ClickToPayDetails.res b/src/Components/ClickToPayDetails.res new file mode 100644 index 000000000..37179748c --- /dev/null +++ b/src/Components/ClickToPayDetails.res @@ -0,0 +1,179 @@ +@react.component +let make = ( + ~isSaveDetailsWithClickToPay, + ~setIsSaveDetailsWithClickToPay, + ~clickToPayCardBrand, + ~clickToPayRememberMe, + ~setClickToPayRememberMe, +) => { + let clickToPayConfig = Recoil.useRecoilValueFromAtom(RecoilAtoms.clickToPayConfig) + let {themeObj} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom) + let {iframeId} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys) + let isUnrecognizedUser = clickToPayConfig.clickToPayCards->Option.getOr([])->Array.length == 0 + + let css = SaveDetailsCheckbox.saveDetailsCssStyle(themeObj) + + let getPrivacyNoticeUrl = () => { + switch Js.String.toLowerCase(clickToPayCardBrand) { + | "mastercard" => "https://www.mastercard.com/global/click-to-pay/en-us/privacy-notice.html" + | "visa" => "https://www.visa.com.hk/en_HK/legal/global-privacy-notice.html" + | _ => "https://www.mastercard.com/global/click-to-pay/en-us/privacy-notice.html" + } + } + + let getTermsUrl = () => { + switch Js.String.toLowerCase(clickToPayCardBrand) { + | "mastercard" => "https://www.mastercard.com/global/click-to-pay/en-us/terms-of-use.html" + | "visa" => "https://www.visa.com.hk/en_HK/legal/visa-checkout/terms-of-service.html" + | _ => "https://www.mastercard.com/global/click-to-pay/en-us/terms-of-use.html" + } + } + + let handleOpenUrl = (event: ReactEvent.Mouse.t, url: string) => { + ReactEvent.Mouse.preventDefault(event) + let _ = ClickToPayHelpers.windowOpen(url, "_blank", "") + } + + let capitalizeCardBrand = (brand: string) => { + String.toUpperCase(String.substring(brand, ~start=0, ~end=1)) ++ + String.substring(brand, ~start=1, ~end=String.length(brand)) + } + + let formattedCardBrand = capitalizeCardBrand(clickToPayCardBrand) + + let getIsChecked = ev => { + let target = ev->ReactEvent.Form.target + target["checked"] + } + + let ( + isSaveDetailsCheckboxState, + isSaveDetailsCheckedState, + isSaveDetailsCheckBoxLabelState, + ) = isSaveDetailsWithClickToPay + ? ("Checkbox--checked", "CheckboxInput--checked", "CheckboxLabel--checked") + : ("", "", "") + + let ( + isRememberMeCheckboxState, + isRememberMeCheckedState, + isRememberMeCheckBoxLabelState, + ) = clickToPayRememberMe + ? ("Checkbox--checked", "CheckboxInput--checked", "CheckboxLabel--checked") + : ("", "", "") + + let handleLearnMore = _ => { + let cardBrands = + clickToPayConfig.availableCardBrands->Array.map(brand => brand->JSON.Encode.string) + Utils.messageParentWindow([ + ("fullscreen", true->JSON.Encode.bool), + ("param", `clickToPayLearnMore`->JSON.Encode.string), + ("iframeId", iframeId->JSON.Encode.string), + ("metadata", [("cardBrands", cardBrands->JSON.Encode.array)]->Utils.getJsonFromArrayOfJson), + ]) + } + + + + {!isUnrecognizedUser + ?
+ {React.string( + `By continuing, ${clickToPayConfig.dpaName} will share your card details, billing address, + and email with ${formattedCardBrand} to allow you to securely enroll in Click to + Pay for faster checkouts.`, + )} + {React.string(" ")} + + {React.string("Learn more")} + +
+ : <> + +
+