diff --git a/src/Components/DynamicFields.res b/src/Components/DynamicFields.res index ee1fe6e3..2c6f9ea3 100644 --- a/src/Components/DynamicFields.res +++ b/src/Components/DynamicFields.res @@ -1,4 +1,3 @@ -open RecoilAtoms @react.component let make = ( ~paymentType, @@ -12,7 +11,9 @@ let make = ( ~cvcProps=None, ~isBancontact=false, ) => { + open DynamicFieldsUtils open Utils + open RecoilAtoms let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue) React.useEffect(() => { @@ -41,10 +42,8 @@ let make = ( paymentMethodTypes.required_fields ->Array.concat(creditRequiredFields) - ->DynamicFieldsUtils.removeRequiredFieldsDuplicates - } else if ( - PaymentMethodsRecord.dynamicFieldsEnabledPaymentMethods->Array.includes(paymentMethodType) - ) { + ->removeRequiredFieldsDuplicates + } else if dynamicFieldsEnabledPaymentMethods->Array.includes(paymentMethodType) { paymentMethodTypes.required_fields } else { [] @@ -52,9 +51,7 @@ let make = ( }, (paymentMethod, paymentMethodTypes.required_fields, paymentMethodType)) let requiredFields = React.useMemo(() => { - requiredFieldsWithBillingDetails->DynamicFieldsUtils.removeBillingDetailsIfUseBillingAddress( - billingAddress, - ) + requiredFieldsWithBillingDetails->removeBillingDetailsIfUseBillingAddress(billingAddress) }, [requiredFieldsWithBillingDetails]) let isAllStoredCardsHaveName = React.useMemo(() => { @@ -69,7 +66,7 @@ let make = ( ~isSavedCardFlow, ~isAllStoredCardsHaveName, ) - ->DynamicFieldsUtils.updateDynamicFields(billingAddress) + ->updateDynamicFields(billingAddress) ->Belt.SortArray.stableSortBy(PaymentMethodsRecord.sortPaymentMethodFields) //<...>// }, (requiredFields, isAllStoredCardsHaveName, isSavedCardFlow)) @@ -255,7 +252,7 @@ let make = ( } } - DynamicFieldsUtils.useRequiredFieldsEmptyAndValid( + useRequiredFieldsEmptyAndValid( ~requiredFields, ~fieldsArr, ~countryNames, @@ -268,14 +265,14 @@ let make = ( ~cvcNumber, ) - DynamicFieldsUtils.useSetInitialRequiredFields( + useSetInitialRequiredFields( ~requiredFields={ billingAddress.usePrefilledValues === Auto ? requiredFieldsWithBillingDetails : requiredFields }, ~paymentMethodType, ) - DynamicFieldsUtils.useRequiredFieldsBody( + useRequiredFieldsBody( ~requiredFields, ~paymentMethodType, ~cardNumber, @@ -286,7 +283,7 @@ let make = ( ~setRequiredFieldsBody, ) - let submitCallback = DynamicFieldsUtils.useSubmitCallback() + let submitCallback = useSubmitCallback() useSubmitPaymentData(submitCallback) let bottomElement = @@ -307,11 +304,11 @@ let make = ( } let dynamicFieldsToRenderOutsideBilling = React.useMemo(() => { - fieldsArr->Array.filter(DynamicFieldsUtils.isFieldTypeToRenderOutsideBilling) + fieldsArr->Array.filter(isFieldTypeToRenderOutsideBilling) }, [fieldsArr]) let dynamicFieldsToRenderInsideBilling = React.useMemo(() => { - fieldsArr->Array.filter(field => !(field->DynamicFieldsUtils.isFieldTypeToRenderOutsideBilling)) + fieldsArr->Array.filter(field => !(field->isFieldTypeToRenderOutsideBilling)) }, [fieldsArr]) let isInfoElementPresent = dynamicFieldsToRenderInsideBilling->Array.includes(InfoElement) diff --git a/src/Components/SavedMethods.res b/src/Components/SavedMethods.res index ae2dbdf1..377deb88 100644 --- a/src/Components/SavedMethods.res +++ b/src/Components/SavedMethods.res @@ -147,11 +147,7 @@ let make = ( | _ => // TODO - To be replaced with proper error message intent( - ~bodyArr=savedPaymentMethodBody - ->getJsonFromArrayOfJson - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict, + ~bodyArr=savedPaymentMethodBody->mergeAndFlattenToTuples(requiredFieldsBody), ~confirmParam=confirm.confirmParams, ~handleUserError=false, ~manualRetry=isManualRetryEnabled, @@ -168,11 +164,7 @@ let make = ( | _ => // TODO - To be replaced with proper error message intent( - ~bodyArr=savedPaymentMethodBody - ->getJsonFromArrayOfJson - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict, + ~bodyArr=savedPaymentMethodBody->mergeAndFlattenToTuples(requiredFieldsBody), ~confirmParam=confirm.confirmParams, ~handleUserError=false, ~manualRetry=isManualRetryEnabled, @@ -180,11 +172,7 @@ let make = ( } | _ => intent( - ~bodyArr=savedPaymentMethodBody - ->getJsonFromArrayOfJson - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict, + ~bodyArr=savedPaymentMethodBody->mergeAndFlattenToTuples(requiredFieldsBody), ~confirmParam=confirm.confirmParams, ~handleUserError=false, ~manualRetry=isManualRetryEnabled, diff --git a/src/Payments/ACHBankTransfer.res b/src/Payments/ACHBankTransfer.res index 98a91da3..c7fc5b91 100644 --- a/src/Payments/ACHBankTransfer.res +++ b/src/Payments/ACHBankTransfer.res @@ -29,11 +29,9 @@ let make = (~paymentType: CardThemeType.mode) => { if confirm.doSubmit { if complete { let bodyArr = - PaymentBody.dynamicPaymentBody("bank_transfer", "ach") - ->getJsonFromArrayOfJson - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict + PaymentBody.dynamicPaymentBody("bank_transfer", "ach")->mergeAndFlattenToTuples( + requiredFieldsBody, + ) intent( ~bodyArr, ~confirmParam=confirm.confirmParams, diff --git a/src/Payments/CardPayment.res b/src/Payments/CardPayment.res index da4da5c9..05c54066 100644 --- a/src/Payments/CardPayment.res +++ b/src/Payments/CardPayment.res @@ -163,11 +163,7 @@ let make = ( if validFormat && (showFields || isBancontact) { intent( ~bodyArr={ - (isBancontact ? banContactBody : cardBody) - ->getJsonFromArrayOfJson - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict + (isBancontact ? banContactBody : cardBody)->mergeAndFlattenToTuples(requiredFieldsBody) }, ~confirmParam=confirm.confirmParams, ~handleUserError=false, diff --git a/src/Payments/KlarnaSDK.res b/src/Payments/KlarnaSDK.res index a53771a7..ea7ab530 100644 --- a/src/Payments/KlarnaSDK.res +++ b/src/Payments/KlarnaSDK.res @@ -100,11 +100,7 @@ let make = (~sessionObj: SessionsType.token) => { ) let body = { - klarnaSDKBody - ->getJsonFromArrayOfJson - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict + klarnaSDKBody->mergeAndFlattenToTuples(requiredFieldsBody) } res.approved diff --git a/src/Payments/PaymentMethodsRecord.res b/src/Payments/PaymentMethodsRecord.res index 939697ea..050542ba 100644 --- a/src/Payments/PaymentMethodsRecord.res +++ b/src/Payments/PaymentMethodsRecord.res @@ -661,29 +661,6 @@ let getFieldType = (dict, isBancontact) => { } } -let dynamicFieldsEnabledPaymentMethods = [ - "crypto_currency", - "debit", - "credit", - "blik", - "google_pay", - "apple_pay", - "bancontact_card", - "open_banking_uk", - "eps", - "ideal", - "sofort", - "pix_transfer", - "giropay", - "local_bank_transfer_transfer", - "afterpay_clearpay", - "mifinity", - "upi_collect", - "sepa", - "affirm", - "ach", -] - let getIsBillingField = requiredFieldType => { switch requiredFieldType { | AddressLine1 diff --git a/src/Payments/PaymentMethodsWrapper.res b/src/Payments/PaymentMethodsWrapper.res index 857a796e..cb4cf062 100644 --- a/src/Payments/PaymentMethodsWrapper.res +++ b/src/Payments/PaymentMethodsWrapper.res @@ -84,12 +84,7 @@ let make = (~paymentType: CardThemeType.mode, ~paymentMethodName: string) => { phoneNumber.countryCode->Option.getOr("") ++ phoneNumber.value, ), ~paymentExperience=paymentFlow, - ) - ->Dict.fromArray - ->JSON.Encode.object - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict + )->mergeAndFlattenToTuples(requiredFieldsBody) intent( ~bodyArr=body, diff --git a/src/Payments/PaypalSDKHelpers.res b/src/Payments/PaypalSDKHelpers.res index 2b22e4cc..d50d0a33 100644 --- a/src/Payments/PaypalSDKHelpers.res +++ b/src/Payments/PaypalSDKHelpers.res @@ -299,12 +299,7 @@ let loadBraintreePaypalSdk = ( ~statesList=stateJson, ) - let paypalBody = - body - ->getJsonFromArrayOfJson - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict + let paypalBody = body->mergeAndFlattenToTuples(requiredFieldsBody) let modifiedPaymentBody = PaymentUtils.appendedCustomerAcceptance( ~isGuestCustomer, diff --git a/src/Payments/SepaBankTransfer.res b/src/Payments/SepaBankTransfer.res index 8f9c4bd2..ca543425 100644 --- a/src/Payments/SepaBankTransfer.res +++ b/src/Payments/SepaBankTransfer.res @@ -29,11 +29,9 @@ let make = (~paymentType) => { if confirm.doSubmit { if complete { let bodyArr = - PaymentBody.dynamicPaymentBody("bank_transfer", "sepa") - ->getJsonFromArrayOfJson - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict + PaymentBody.dynamicPaymentBody("bank_transfer", "sepa")->mergeAndFlattenToTuples( + requiredFieldsBody, + ) intent( ~bodyArr, diff --git a/src/Utilities/ApplePayHelpers.res b/src/Utilities/ApplePayHelpers.res index 71b92d0d..3a342cac 100644 --- a/src/Utilities/ApplePayHelpers.res +++ b/src/Utilities/ApplePayHelpers.res @@ -61,11 +61,7 @@ let getApplePayFromResponse = ( let bodyDict = PaymentBody.applePayBody(~token, ~connectors) - bodyDict - ->getJsonFromArrayOfJson - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict + bodyDict->mergeAndFlattenToTuples(requiredFieldsBody) } let startApplePaySession = ( @@ -261,11 +257,7 @@ let useHandleApplePayResponse = ( let bodyArr = if isWallet { applePayBody } else { - applePayBody - ->getJsonFromArrayOfJson - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict + applePayBody->mergeAndFlattenToTuples(requiredFieldsBody) } processPayment( diff --git a/src/Utilities/DynamicFieldsUtils.res b/src/Utilities/DynamicFieldsUtils.res index 380d087e..4861d6f4 100644 --- a/src/Utilities/DynamicFieldsUtils.res +++ b/src/Utilities/DynamicFieldsUtils.res @@ -1,5 +1,28 @@ open RecoilAtoms +let dynamicFieldsEnabledPaymentMethods = [ + "crypto_currency", + "debit", + "credit", + "blik", + "google_pay", + "apple_pay", + "bancontact_card", + "open_banking_uk", + "eps", + "ideal", + "sofort", + "pix_transfer", + "giropay", + "local_bank_transfer_transfer", + "afterpay_clearpay", + "mifinity", + "upi_collect", + "sepa", + "affirm", + "ach", +] + let getName = (item: PaymentMethodsRecord.required_fields, field: RecoilAtomTypes.field) => { let fieldNameArr = field.value->String.split(" ") let requiredFieldsArr = item.required_field->String.split(".") diff --git a/src/Utilities/GooglePayHelpers.res b/src/Utilities/GooglePayHelpers.res index 4f4e961e..8552941d 100644 --- a/src/Utilities/GooglePayHelpers.res +++ b/src/Utilities/GooglePayHelpers.res @@ -53,11 +53,7 @@ let getGooglePayBodyFromResponse = ( ) } - gPayBody - ->getJsonFromArrayOfJson - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict + gPayBody->mergeAndFlattenToTuples(requiredFieldsBody) } let processPayment = ( @@ -123,11 +119,7 @@ let useHandleGooglePayResponse = ( let googlePayBody = if isWallet { body } else { - body - ->getJsonFromArrayOfJson - ->flattenObject(true) - ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) - ->getArrayOfTupleFromDict + body->mergeAndFlattenToTuples(requiredFieldsBody) } processPayment( diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index 49b177a6..45c43cc0 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -1423,3 +1423,10 @@ let isKeyPresentInDict = (dict, key) => dict->Dict.get(key)->Option.isSome let checkIsTestCardWildcard = val => ["1111222233334444"]->Array.includes(val) let minorUnitToString = val => (val->Int.toFloat /. 100.)->Float.toString + +let mergeAndFlattenToTuples = (body, requiredFieldsBody) => + body + ->getJsonFromArrayOfJson + ->flattenObject(true) + ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) + ->getArrayOfTupleFromDict