Skip to content

Commit

Permalink
refactor: added utility for mergeAndFlattenToTuples
Browse files Browse the repository at this point in the history
  • Loading branch information
sakksham7 committed Nov 7, 2024
1 parent 2930ae0 commit f86f7dc
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 67 deletions.
18 changes: 3 additions & 15 deletions src/Components/SavedMethods.res
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -168,23 +164,15 @@ 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,
)
}
| _ =>
intent(
~bodyArr=savedPaymentMethodBody
->getJsonFromArrayOfJson
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict,
~bodyArr=savedPaymentMethodBody->mergeAndFlattenToTuples(requiredFieldsBody),
~confirmParam=confirm.confirmParams,
~handleUserError=false,
~manualRetry=isManualRetryEnabled,
Expand Down
8 changes: 3 additions & 5 deletions src/Payments/ACHBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 1 addition & 5 deletions src/Payments/CardPayment.res
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 1 addition & 5 deletions src/Payments/KlarnaSDK.res
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ let make = (~sessionObj: SessionsType.token) => {
)

let body = {
klarnaSDKBody
->getJsonFromArrayOfJson
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict
klarnaSDKBody->mergeAndFlattenToTuples(requiredFieldsBody)
}

res.approved
Expand Down
7 changes: 1 addition & 6 deletions src/Payments/PaymentMethodsWrapper.res
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions src/Payments/PaypalSDKHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions src/Payments/SepaBankTransfer.res
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 2 additions & 10 deletions src/Utilities/ApplePayHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ let getApplePayFromResponse = (

let bodyDict = PaymentBody.applePayBody(~token, ~connectors)

bodyDict
->getJsonFromArrayOfJson
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict
bodyDict->mergeAndFlattenToTuples(requiredFieldsBody)
}

let startApplePaySession = (
Expand Down Expand Up @@ -261,11 +257,7 @@ let useHandleApplePayResponse = (
let bodyArr = if isWallet {
applePayBody
} else {
applePayBody
->getJsonFromArrayOfJson
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict
applePayBody->mergeAndFlattenToTuples(requiredFieldsBody)
}

processPayment(
Expand Down
12 changes: 2 additions & 10 deletions src/Utilities/GooglePayHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ let getGooglePayBodyFromResponse = (
)
}

gPayBody
->getJsonFromArrayOfJson
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict
gPayBody->mergeAndFlattenToTuples(requiredFieldsBody)
}

let processPayment = (
Expand Down Expand Up @@ -123,11 +119,7 @@ let useHandleGooglePayResponse = (
let googlePayBody = if isWallet {
body
} else {
body
->getJsonFromArrayOfJson
->flattenObject(true)
->mergeTwoFlattenedJsonDicts(requiredFieldsBody)
->getArrayOfTupleFromDict
body->mergeAndFlattenToTuples(requiredFieldsBody)
}

processPayment(
Expand Down
7 changes: 7 additions & 0 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f86f7dc

Please sign in to comment.