diff --git a/src/BrowserSpec.res b/src/BrowserSpec.res index 64212c9a4..967bf789d 100644 --- a/src/BrowserSpec.res +++ b/src/BrowserSpec.res @@ -38,9 +38,7 @@ let broswerInfo = () => { ("time_zone", date.getTimezoneOffset()->JSON.Encode.float), ("java_enabled", true->JSON.Encode.bool), ("java_script_enabled", true->JSON.Encode.bool), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] } diff --git a/src/Components/SavedMethods.res b/src/Components/SavedMethods.res index b7a0eda17..811c25063 100644 --- a/src/Components/SavedMethods.res +++ b/src/Components/SavedMethods.res @@ -139,8 +139,7 @@ let make = ( ) { intent( ~bodyArr=savedPaymentMethodBody - ->Dict.fromArray - ->JSON.Encode.object + ->getJsonFromArrayOfJson ->flattenObject(true) ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) ->getArrayOfTupleFromDict, diff --git a/src/Payments/ApplePay.res b/src/Payments/ApplePay.res index ee407552c..83d7e8ef9 100644 --- a/src/Payments/ApplePay.res +++ b/src/Payments/ApplePay.res @@ -81,8 +81,7 @@ let make = ( } else { let requiredFieldsBodyArr = requestBody - ->Dict.fromArray - ->JSON.Encode.object + ->getJsonFromArrayOfJson ->flattenObject(true) ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) ->getArrayOfTupleFromDict diff --git a/src/Payments/CardPayment.res b/src/Payments/CardPayment.res index 1b5c649c3..fa1c03192 100644 --- a/src/Payments/CardPayment.res +++ b/src/Payments/CardPayment.res @@ -157,8 +157,7 @@ let make = ( intent( ~bodyArr={ (isBancontact ? banContactBody : cardBody) - ->Dict.fromArray - ->JSON.Encode.object + ->getJsonFromArrayOfJson ->flattenObject(true) ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) ->getArrayOfTupleFromDict diff --git a/src/Payments/GPay.res b/src/Payments/GPay.res index 08c3493d9..47fca8bc3 100644 --- a/src/Payments/GPay.res +++ b/src/Payments/GPay.res @@ -104,8 +104,7 @@ let make = ( let body = { gPayBody - ->Dict.fromArray - ->JSON.Encode.object + ->getJsonFromArrayOfJson ->flattenObject(true) ->mergeTwoFlattenedJsonDicts(requiredFieldsBody) ->getArrayOfTupleFromDict diff --git a/src/Utilities/PaymentBody.res b/src/Utilities/PaymentBody.res index d3b7ab42d..a7e3ac0ca 100644 --- a/src/Utilities/PaymentBody.res +++ b/src/Utilities/PaymentBody.res @@ -10,30 +10,24 @@ let billingDetailsTuple = ( ~state, ~postalCode, ~country, -) => { - ( - "billing_details", - [ - ("name", fullName->JSON.Encode.string), - ("email", email->JSON.Encode.string), - ( - "address", - [ - ("line1", line1->JSON.Encode.string), - ("line2", line2->JSON.Encode.string), - ("city", city->JSON.Encode.string), - ("state", state->JSON.Encode.string), - ("zip", postalCode->JSON.Encode.string), - ("country", country->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, - ), - ] - ->Dict.fromArray - ->JSON.Encode.object, - ) -} +) => ( + "billing_details", + [ + ("name", fullName->JSON.Encode.string), + ("email", email->JSON.Encode.string), + ( + "address", + [ + ("line1", line1->JSON.Encode.string), + ("line2", line2->JSON.Encode.string), + ("city", city->JSON.Encode.string), + ("state", state->JSON.Encode.string), + ("zip", postalCode->JSON.Encode.string), + ("country", country->JSON.Encode.string), + ]->Utils.getJsonFromArrayOfJson, + ), + ]->Utils.getJsonFromArrayOfJson, +) let cardPaymentBody = ( ~cardNumber, @@ -62,9 +56,9 @@ let cardPaymentBody = ( ("payment_method", "card"->JSON.Encode.string), ( "payment_method_data", - [("card", cardBody->Array.concat(cardBrand)->Dict.fromArray->JSON.Encode.object)] - ->Dict.fromArray - ->JSON.Encode.object, + [ + ("card", cardBody->Array.concat(cardBrand)->Utils.getJsonFromArrayOfJson), + ]->Utils.getJsonFromArrayOfJson, ), ] } @@ -85,17 +79,13 @@ let boletoBody = (~socialSecurityNumber) => [ [ ( "boleto", - [("social_security_number", socialSecurityNumber->JSON.Encode.string)] - ->Dict.fromArray - ->JSON.Encode.object, + [ + ("social_security_number", socialSecurityNumber->JSON.Encode.string), + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -105,13 +95,11 @@ let customerAcceptanceBody = ("accepted_at", Date.now()->Js.Date.fromFloat->Date.toISOString->JSON.Encode.string), ( "online", - [("user_agent", BrowserSpec.navigator.userAgent->JSON.Encode.string)] - ->Dict.fromArray - ->JSON.Encode.object, + [ + ("user_agent", BrowserSpec.navigator.userAgent->JSON.Encode.string), + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object + ]->Utils.getJsonFromArrayOfJson let savedCardBody = ( ~paymentToken, @@ -158,38 +146,30 @@ let savedPaymentMethodBody = ( savedPaymentMethodBody } -let mandateBody = paymentType => { - [ - ( - "mandate_data", - [("customer_acceptance", customerAcceptanceBody)]->Dict.fromArray->JSON.Encode.object, - ), - ("customer_acceptance", customerAcceptanceBody), - ("setup_future_usage", "off_session"->JSON.Encode.string), - ("payment_type", {paymentType === "" ? JSON.Encode.null : paymentType->JSON.Encode.string}), - ] -} +let mandateBody = paymentType => [ + ("mandate_data", [("customer_acceptance", customerAcceptanceBody)]->Utils.getJsonFromArrayOfJson), + ("customer_acceptance", customerAcceptanceBody), + ("setup_future_usage", "off_session"->JSON.Encode.string), + ("payment_type", {paymentType === "" ? JSON.Encode.null : paymentType->JSON.Encode.string}), +] -let paymentTypeBody = paymentType => { +let paymentTypeBody = paymentType => if paymentType != "" { [("payment_type", paymentType->JSON.Encode.string)] } else { [] } -} let confirmPayloadForSDKButton = (sdkHandleConfirmPayment: PaymentType.sdkHandleConfirmPayment) => [ ("redirect", "always"->JSON.Encode.string), ( "confirmParams", - [("return_url", sdkHandleConfirmPayment.confirmParams.return_url->JSON.Encode.string)] - ->Dict.fromArray - ->JSON.Encode.object, + [ + ("return_url", sdkHandleConfirmPayment.confirmParams.return_url->JSON.Encode.string), + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object + ]->Utils.getJsonFromArrayOfJson let achBankDebitBody = ( ~email, @@ -230,17 +210,11 @@ let achBankDebitBody = ( ("bank_account_holder_name", bank.accountHolderName->JSON.Encode.string), ("routing_number", bank.routingNumber->JSON.Encode.string), ("bank_type", bank.accountType->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ]->Array.concat(mandateBody(paymentType->PaymentMethodsRecord.paymentTypeToStringMapper)) @@ -278,17 +252,11 @@ let sepaBankDebitBody = ( ), ("iban", data.iban->JSON.Encode.string), ("bank_account_holder_name", data.accountHolderName->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -328,17 +296,11 @@ let bacsBankDebitBody = ( ("bank_account_holder_name", bankAccountHolderName->JSON.Encode.string), ("sort_code", sortCode->JSON.Encode.string), ("account_number", accNum->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -377,17 +339,11 @@ let becsBankDebitBody = ( ("bsb_number", data.sortCode->JSON.Encode.string), ("account_number", data.accountNumber->JSON.Encode.string), ("bank_account_holder_name", data.accountHolderName->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -408,17 +364,11 @@ let klarnaRedirectionBody = (~fullName, ~email, ~country, ~connectors) => [ [ ("billing_email", email->JSON.Encode.string), ("billing_country", country->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -432,13 +382,11 @@ let klarnaSDKbody = (~token, ~connectors) => [ [ ( "pay_later", - [("klarna_sdk", [("token", token->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object)] - ->Dict.fromArray - ->JSON.Encode.object, + [ + ("klarna_sdk", [("token", token->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson), + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -452,13 +400,9 @@ let paypalRedirectionBody = (~connectors) => [ [ ( "wallet", - [("paypal_redirect", []->Dict.fromArray->JSON.Encode.object)] - ->Dict.fromArray - ->JSON.Encode.object, + [("paypal_redirect", []->Utils.getJsonFromArrayOfJson)]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -472,13 +416,11 @@ let paypalSdkBody = (~token, ~connectors) => [ [ ( "wallet", - [("paypal_sdk", [("token", token->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object)] - ->Dict.fromArray - ->JSON.Encode.object, + [ + ("paypal_sdk", [("token", token->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson), + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -502,17 +444,11 @@ let gpayBody = (~payObj: GooglePayType.paymentData, ~connectors: array) "tokenization_data", payObj.paymentMethodData.tokenizationData->Utils.transformKeys(Utils.SnakeCase), ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -525,9 +461,24 @@ let gpayRedirectBody = (~connectors: array) => [ [ ( "wallet", - [("google_pay_redirect", Dict.make()->JSON.Encode.object)] - ->Dict.fromArray - ->JSON.Encode.object, + [("google_pay_redirect", Dict.make()->JSON.Encode.object)]->Utils.getJsonFromArrayOfJson, + ), + ]->Utils.getJsonFromArrayOfJson, + ), +] + +let gPayThirdPartySdkBody = (~connectors) => [ + ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), + ("payment_method", "wallet"->JSON.Encode.string), + ("payment_method_type", "google_pay"->JSON.Encode.string), + ( + "payment_method_data", + [ + ( + "wallet", + [ + ("google_pay_third_party_sdk", Dict.make()->JSON.Encode.object), + ]->Utils.getJsonFromArrayOfJson, ), ] ->Dict.fromArray @@ -535,27 +486,6 @@ let gpayRedirectBody = (~connectors: array) => [ ), ] -let gPayThirdPartySdkBody = (~connectors) => { - [ - ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), - ("payment_method", "wallet"->JSON.Encode.string), - ("payment_method_type", "google_pay"->JSON.Encode.string), - ( - "payment_method_data", - [ - ( - "wallet", - [("google_pay_third_party_sdk", Dict.make()->JSON.Encode.object)] - ->Dict.fromArray - ->JSON.Encode.object, - ), - ] - ->Dict.fromArray - ->JSON.Encode.object, - ), - ] -} - let applePayBody = (~token, ~connectors) => { let dict = token->JSON.Decode.object->Option.getOr(Dict.make()) let paymentDataString = @@ -574,9 +504,9 @@ let applePayBody = (~token, ~connectors) => { [ ( "wallet", - [("apple_pay", dict->JSON.Encode.object->Utils.transformKeys(SnakeCase))] - ->Dict.fromArray - ->JSON.Encode.object, + [ + ("apple_pay", dict->JSON.Encode.object->Utils.transformKeys(SnakeCase)), + ]->Utils.getJsonFromArrayOfJson, ), ] ->Dict.fromArray @@ -585,47 +515,37 @@ let applePayBody = (~token, ~connectors) => { ] } -let applePayRedirectBody = (~connectors) => { - [ - ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), - ("payment_method", "wallet"->JSON.Encode.string), - ("payment_method_type", "apple_pay"->JSON.Encode.string), - ( - "payment_method_data", - [ - ( - "wallet", - [("apple_pay_redirect", Dict.make()->JSON.Encode.object)] - ->Dict.fromArray - ->JSON.Encode.object, - ), - ] - ->Dict.fromArray - ->JSON.Encode.object, - ), - ] -} +let applePayRedirectBody = (~connectors) => [ + ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), + ("payment_method", "wallet"->JSON.Encode.string), + ("payment_method_type", "apple_pay"->JSON.Encode.string), + ( + "payment_method_data", + [ + ( + "wallet", + [("apple_pay_redirect", Dict.make()->JSON.Encode.object)]->Utils.getJsonFromArrayOfJson, + ), + ]->Utils.getJsonFromArrayOfJson, + ), +] -let applePayThirdPartySdkBody = (~connectors) => { - [ - ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), - ("payment_method", "wallet"->JSON.Encode.string), - ("payment_method_type", "apple_pay"->JSON.Encode.string), - ( - "payment_method_data", - [ - ( - "wallet", - [("apple_pay_third_party_sdk", Dict.make()->JSON.Encode.object)] - ->Dict.fromArray - ->JSON.Encode.object, - ), - ] - ->Dict.fromArray - ->JSON.Encode.object, - ), - ] -} +let applePayThirdPartySdkBody = (~connectors) => [ + ("connector", connectors->Utils.getArrofJsonString->JSON.Encode.array), + ("payment_method", "wallet"->JSON.Encode.string), + ("payment_method_type", "apple_pay"->JSON.Encode.string), + ( + "payment_method_data", + [ + ( + "wallet", + [ + ("apple_pay_third_party_sdk", Dict.make()->JSON.Encode.object), + ]->Utils.getJsonFromArrayOfJson, + ), + ]->Utils.getJsonFromArrayOfJson, + ), +] let cryptoBody = (~currency) => [ ("payment_method", "crypto"->JSON.Encode.string), @@ -634,13 +554,8 @@ let cryptoBody = (~currency) => [ ( "payment_method_data", [ - ( - "crypto", - [("pay_currency", currency->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, - ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ("crypto", [("pay_currency", currency->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson), + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -659,17 +574,11 @@ let afterpayRedirectionBody = (~fullName, ~email) => [ [ ("billing_email", email->JSON.Encode.string), ("billing_name", fullName->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -687,20 +596,14 @@ let giroPayBody = (~name, ~iban="", ()) => [ [ ( "billing_details", - [("billing_name", name->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, + [("billing_name", name->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, ), ("bank_account_iban", iban->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -723,21 +626,13 @@ let sofortBody = (~country, ~name, ~email) => [ [ ("billing_name", name->JSON.Encode.string), ("email", (email == "" ? "test@gmail.com" : email)->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -755,20 +650,14 @@ let iDealBody = (~name, ~bankName) => [ [ ( "billing_details", - [("billing_name", name->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, + [("billing_name", name->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, ), ("bank_name", (bankName == "" ? "american_express" : bankName)->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -786,20 +675,14 @@ let epsBody = (~name, ~bankName) => [ [ ( "billing_details", - [("billing_name", name->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, + [("billing_name", name->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, ), ("bank_name", (bankName === "" ? "american_express" : bankName)->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -818,19 +701,13 @@ let achBankTransferBody = (~email, ~connectors) => [ [ ( "billing_details", - [("email", email->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, + [("email", email->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] let bacsBankTransferBody = (~email, ~name, ~connectors) => [ @@ -848,21 +725,16 @@ let bacsBankTransferBody = (~email, ~name, ~connectors) => [ [ ( "billing_details", - [("email", email->JSON.Encode.string), ("name", name->JSON.Encode.string)] - ->Dict.fromArray - ->JSON.Encode.object, + [ + ("email", email->JSON.Encode.string), + ("name", name->JSON.Encode.string), + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] let sepaBankTransferBody = (~email, ~name, ~country, ~connectors) => [ @@ -880,22 +752,17 @@ let sepaBankTransferBody = (~email, ~name, ~country, ~connectors) => [ [ ( "billing_details", - [("email", email->JSON.Encode.string), ("name", name->JSON.Encode.string)] - ->Dict.fromArray - ->JSON.Encode.object, + [ + ("email", email->JSON.Encode.string), + ("name", name->JSON.Encode.string), + ]->Utils.getJsonFromArrayOfJson, ), ("country", country->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] let blikBody = (~blikCode) => [ @@ -907,17 +774,10 @@ let blikBody = (~blikCode) => [ ( "bank_redirect", [ - ( - "blik", - [("blik_code", blikCode->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, - ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ("blik", [("blik_code", blikCode->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson), + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -935,19 +795,13 @@ let p24Body = (~email) => [ [ ( "billing_details", - [("email", email->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, + [("email", email->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -962,17 +816,14 @@ let interacBody = (~email, ~country) => [ [ ( "interac", - [("email", email->JSON.Encode.string), ("country", country->JSON.Encode.string)] - ->Dict.fromArray - ->JSON.Encode.object, + [ + ("email", email->JSON.Encode.string), + ("country", country->JSON.Encode.string), + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -985,17 +836,10 @@ let trustlyBody = (~country) => [ ( "bank_redirect", [ - ( - "trustly", - [("country", country->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, - ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ("trustly", [("country", country->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson), + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -1010,15 +854,11 @@ let polandOB = (~bank) => [ [ ( "online_banking_poland", - [("issuer", bank->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, + [("issuer", bank->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -1033,15 +873,11 @@ let czechOB = (~bank) => [ [ ( "online_banking_czech_republic", - [("issuer", bank->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, + [("issuer", bank->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -1056,15 +892,11 @@ let slovakiaOB = (~bank) => [ [ ( "online_banking_slovakia", - [("issuer", bank->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, + [("issuer", bank->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -1079,17 +911,11 @@ let mbWayBody = (~phoneNumber) => [ [ ( "mb_way_redirect", - [("telephone_number", phoneNumber->JSON.Encode.string)] - ->Dict.fromArray - ->JSON.Encode.object, + [("telephone_number", phoneNumber->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -1110,15 +936,11 @@ let fpxOBBody = (~bank) => [ [ ( "online_banking_fpx", - [("issuer", bank->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, + [("issuer", bank->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] let thailandOBBody = (~bank) => [ @@ -1132,15 +954,11 @@ let thailandOBBody = (~bank) => [ [ ( "online_banking_thailand", - [("issuer", bank->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, + [("issuer", bank->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] @@ -1158,29 +976,22 @@ let multibancoBody = (~email) => [ [ ( "billing_details", - [("email", email->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, + [("email", email->JSON.Encode.string)]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ] -let getPaymentMethodType = (paymentMethod, paymentMethodType) => { +let getPaymentMethodType = (paymentMethod, paymentMethodType) => switch paymentMethod { | "bank_debit" => paymentMethodType->String.replace("_debit", "") | "bank_transfer" => paymentMethodType->String.replace("_transfer", "") | _ => paymentMethodType } -} let appendRedirectPaymentMethods = [ "touch_n_go", @@ -1199,7 +1010,7 @@ let appendRedirectPaymentMethods = [ "ali_pay", ] -let appendPaymentMethodExperience = (paymentMethodType, isQrPaymentMethod) => { +let appendPaymentMethodExperience = (paymentMethodType, isQrPaymentMethod) => if isQrPaymentMethod { paymentMethodType ++ "_qr" } else if appendRedirectPaymentMethods->Array.includes(paymentMethodType) { @@ -1207,17 +1018,15 @@ let appendPaymentMethodExperience = (paymentMethodType, isQrPaymentMethod) => { } else { paymentMethodType } -} let paymentExperiencePaymentMethods = ["affirm"] -let appendPaymentExperience = (paymentBodyArr, paymentMethodType) => { +let appendPaymentExperience = (paymentBodyArr, paymentMethodType) => if paymentExperiencePaymentMethods->Array.includes(paymentMethodType) { paymentBodyArr->Array.concat([("payment_experience", "redirect_to_url"->JSON.Encode.string)]) } else { paymentBodyArr } -} let dynamicPaymentBody = (paymentMethod, paymentMethodType, ~isQrPaymentMethod=false) => { let paymentMethodType = paymentMethod->getPaymentMethodType(paymentMethodType) @@ -1234,13 +1043,9 @@ let dynamicPaymentBody = (paymentMethod, paymentMethodType, ~isQrPaymentMethod=f paymentMethodType->appendPaymentMethodExperience(isQrPaymentMethod), Dict.make()->JSON.Encode.object, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->Utils.getJsonFromArrayOfJson, ), ]->appendPaymentExperience(paymentMethodType) } @@ -1256,7 +1061,7 @@ let getPaymentBody = ( ~paymentExperience: PaymentMethodsRecord.paymentFlow=RedirectToURL, ~phoneNumber, ~currency, -) => { +) => switch paymentMethodType { | "afterpay_clearpay" => afterpayRedirectionBody(~fullName, ~email) | "crypto_currency" => cryptoBody(~currency) @@ -1294,4 +1099,3 @@ let getPaymentBody = ( rewardBody(~paymentMethodType) | _ => dynamicPaymentBody(paymentMethod, paymentMethodType) } -} diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 5aa53d49e..92698aa1f 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -91,8 +91,7 @@ let threeDsAuth = (~clientSecret, ~optLogger, ~threeDsMethodComp, ~headers) => { ("threeds_method_comp_ind", threeDsMethodComp->JSON.Encode.string), ] ->Array.concat(broswerInfo()) - ->Dict.fromArray - ->JSON.Encode.object + ->getJsonFromArrayOfJson open Promise logApi( @@ -934,8 +933,7 @@ let rec maskPayload = payloadJson => { let (key, value) = entry (key, maskPayload(value)) }) - ->Dict.fromArray - ->JSON.Encode.object + ->Utils.getJsonFromArrayOfJson | Array(arr) => arr->Array.map(maskPayload)->JSON.Encode.array | String(valueStr) => valueStr->maskStr->JSON.Encode.string @@ -995,12 +993,10 @@ let usePaymentIntent = (optLogger, paymentType) => { let (key, value) = header (key, value->JSON.Encode.string) }) - ->Dict.fromArray - ->JSON.Encode.object, + ->Utils.getJsonFromArrayOfJson, ), ] - ->Dict.fromArray - ->JSON.Encode.object + ->Utils.getJsonFromArrayOfJson ->JSON.stringify switch paymentType { | Card => @@ -1059,8 +1055,7 @@ let usePaymentIntent = (optLogger, paymentType) => { bodyArr->Array.concat(broswerInfo()), mandatePaymentType->PaymentBody.paymentTypeBody, ]) - ->Dict.fromArray - ->JSON.Encode.object + ->Utils.getJsonFromArrayOfJson ->JSON.stringify callIntent(bodyStr) } @@ -1071,8 +1066,7 @@ let usePaymentIntent = (optLogger, paymentType) => { ->Array.concat( bodyArr->Array.concatMany([PaymentBody.mandateBody(mandatePaymentType), broswerInfo()]), ) - ->Dict.fromArray - ->JSON.Encode.object + ->Utils.getJsonFromArrayOfJson ->JSON.stringify callIntent(bodyStr) } @@ -1140,9 +1134,7 @@ let fetchSessions = ( ("client_secret", clientSecret->JSON.Encode.string), ("wallets", wallets->JSON.Encode.array), ("delayed_session_token", isDelayedSessionToken->JSON.Encode.bool), - ] - ->Dict.fromArray - ->JSON.Encode.object + ]->getJsonFromArrayOfJson let uri = `${endpoint}/payments/session_tokens` logApi( ~optLogger, diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index a59e79bc0..27d211e8b 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -1244,3 +1244,5 @@ let isWalletElementPaymentType = (paymentType: CardThemeType.mode) => { } let getUniqueArray = arr => arr->Array.map(item => (item, ""))->Dict.fromArray->Dict.keysToArray + +let getJsonFromArrayOfJson = arr => arr->Dict.fromArray->JSON.Encode.object diff --git a/src/orca-loader/Elements.res b/src/orca-loader/Elements.res index 095d1cd29..699eb7df4 100644 --- a/src/orca-loader/Elements.res +++ b/src/orca-loader/Elements.res @@ -92,7 +92,7 @@ let make = ( let preMountLoaderMountedPromise = Promise.make((resolve, _reject) => { let preMountLoaderIframeCallback = (ev: Types.event) => { let json = ev.data->Identity.anyTypeToJson - let dict = json->Utils.getDictFromJson + let dict = json->getDictFromJson if dict->Dict.get("preMountLoaderIframeMountedCallback")->Option.isSome { resolve(true->JSON.Encode.bool) } @@ -108,12 +108,12 @@ let make = ( let handlePaymentMethodsLoaded = (event: Types.event) => { let json = event.data->Identity.anyTypeToJson let dict = json->getDictFromJson - let isPaymentMethodsData = dict->Utils.getString("data", "") === "payment_methods" + let isPaymentMethodsData = dict->getString("data", "") === "payment_methods" if isPaymentMethodsData { - let json = dict->Utils.getJsonFromDict("response", JSON.Encode.null) + let json = dict->getJsonFromDict("response", JSON.Encode.null) let isApplePayPresent = PaymentMethodsRecord.getPaymentMethodTypeFromList( ~paymentMethodListValue=json - ->Utils.getDictFromJson + ->getDictFromJson ->PaymentMethodsRecord.itemToObjMapper, ~paymentMethod="wallet", ~paymentMethodType="apple_pay", @@ -121,7 +121,7 @@ let make = ( let isGooglePayPresent = PaymentMethodsRecord.getPaymentMethodTypeFromList( ~paymentMethodListValue=json - ->Utils.getDictFromJson + ->getDictFromJson ->PaymentMethodsRecord.itemToObjMapper, ~paymentMethod="wallet", ~paymentMethodType="google_pay", @@ -140,7 +140,7 @@ let make = ( logger.setLogInfo(~value="TrustPay Script Loading", ~eventName=TRUSTPAY_SCRIPT, ()) trustPayScript->Window.elementSrc(trustPayScriptURL) trustPayScript->Window.elementOnerror(err => { - Utils.logInfo(Console.log2("ERROR DURING LOADING TRUSTPAY APPLE PAY", err)) + logInfo(Console.log2("ERROR DURING LOADING TRUSTPAY APPLE PAY", err)) }) trustPayScript->Window.elementOnload(_ => { logger.setLogInfo(~value="TrustPay Script Loaded", ~eventName=TRUSTPAY_SCRIPT, ()) @@ -167,9 +167,9 @@ let make = ( let json = event.data->Identity.anyTypeToJson let dict = json->getDictFromJson let isCustomerPaymentMethodsData = - dict->Utils.getString("data", "") === "customer_payment_methods" + dict->getString("data", "") === "customer_payment_methods" if isCustomerPaymentMethodsData { - let json = dict->Utils.getJsonFromDict("response", JSON.Encode.null) + let json = dict->getJsonFromDict("response", JSON.Encode.null) let msg = [("customerPaymentMethods", json)]->Dict.fromArray mountedIframeRef->Window.iframePostMessage(msg) } @@ -265,14 +265,12 @@ let make = ( ("locale", locale), ("loader", loader), ("fonts", fonts), - ] - ->Dict.fromArray - ->JSON.Encode.object + ]->getJsonFromArrayOfJson let message = [ ( "paymentElementCreate", - componentType->Utils.isComponentTypeForPaymentElementCreate->JSON.Encode.bool, + componentType->isComponentTypeForPaymentElementCreate->JSON.Encode.bool, ), ("otherElements", otherElements->JSON.Encode.bool), ("options", newOptions), @@ -401,9 +399,7 @@ let make = ( ) let timeOut = delay(600000)->then(_ => { let errorMsg = - [("error", "Request Timed Out"->JSON.Encode.string)] - ->Dict.fromArray - ->JSON.Encode.object + [("error", "Request Timed Out"->JSON.Encode.string)]->getJsonFromArrayOfJson reject(Exn.anyToExnInternal(errorMsg)) }) @@ -555,7 +551,7 @@ let make = ( resolve() }) ->catch(err => { - let exceptionMessage = err->Utils.formatException->JSON.stringify + let exceptionMessage = err->formatException->JSON.stringify logger.setLogInfo( ~eventName=APPLE_PAY_FLOW, ~paymentMethod="APPLE_PAY", @@ -570,7 +566,7 @@ let make = ( } catch { | exn => { logger.setLogInfo( - ~value=exn->Utils.formatException->JSON.stringify, + ~value=exn->formatException->JSON.stringify, ~eventName=APPLE_PAY_FLOW, ~paymentMethod="APPLE_PAY", (), @@ -654,9 +650,9 @@ let make = ( let handleSessionTokensLoaded = (event: Types.event) => { let json = event.data->Identity.anyTypeToJson let dict = json->getDictFromJson - let sessionTokensData = dict->Utils.getString("data", "") === "session_tokens" + let sessionTokensData = dict->getString("data", "") === "session_tokens" if sessionTokensData { - let json = dict->Utils.getJsonFromDict("response", JSON.Encode.null) + let json = dict->getJsonFromDict("response", JSON.Encode.null) { let sessionsArr = @@ -698,7 +694,7 @@ let make = ( ->then(res => { let (json, applePayPresent, googlePayPresent) = res if ( - componentType->Utils.isComponentTypeForPaymentElementCreate && + componentType->isComponentTypeForPaymentElementCreate && applePayPresent->Belt.Option.isSome ) { //do operations here @@ -735,7 +731,7 @@ let make = ( ->Belt.Option.getWithDefault(Dict.make()) ->Dict.get("payment_request_data") ->Belt.Option.getWithDefault(Dict.make()->JSON.Encode.object) - ->Utils.transformKeys(Utils.CamelCase) + ->transformKeys(CamelCase) let ssn = applePaySession(3, paymentRequest) switch applePaySessionRef.contents->Nullable.toOption { @@ -757,7 +753,7 @@ let make = ( ->Belt.Option.getWithDefault(Dict.make()) ->Dict.get("session_token_data") ->Belt.Option.getWithDefault(Dict.make()->JSON.Encode.object) - ->Utils.transformKeys(Utils.CamelCase) + ->transformKeys(CamelCase) ssn.completeMerchantValidation(merchantSession) } @@ -780,7 +776,7 @@ let make = ( [("showApplePayButton", true->JSON.Encode.bool)]->Dict.fromArray mountedIframeRef->Window.iframePostMessage(msg) applePaySessionRef := Nullable.null - Utils.logInfo(Console.log("Apple Pay Payment Cancelled")) + logInfo(Console.log("Apple Pay Payment Cancelled")) logger.setLogInfo( ~value="Apple Pay Payment Cancelled", ~eventName=APPLE_PAY_FLOW, @@ -800,7 +796,7 @@ let make = ( addSmartEventListener("message", handleApplePayMessages, "onApplePayMessages") } if ( - componentType->Utils.isComponentTypeForPaymentElementCreate && + componentType->isComponentTypeForPaymentElementCreate && googlePayPresent->Belt.Option.isSome && wallets.googlePay === Auto ) { @@ -950,7 +946,7 @@ let make = ( newOptions ->getDictFromJson ->getBool("displaySavedPaymentMethods", true) && - !(Utils.expressCheckoutComponents->Array.includes(componentType)) + !(expressCheckoutComponents->Array.includes(componentType)) ) { fetchCustomerPaymentMethods(mountedIframeRef, false, componentType) } diff --git a/src/orca-loader/Hyper.res b/src/orca-loader/Hyper.res index fb39f0356..ccd57afcb 100644 --- a/src/orca-loader/Hyper.res +++ b/src/orca-loader/Hyper.res @@ -265,7 +265,7 @@ let make = (publishableKey, options: option, analyticsInfo: optionthen(data => { - [("paymentIntent", data)]->Dict.fromArray->JSON.Encode.object->Promise.resolve + [("paymentIntent", data)]->getJsonFromArrayOfJson->Promise.resolve }) } @@ -351,9 +351,7 @@ let make = (publishableKey, options: option, analyticsInfo: optionJSON.Encode.string), ("publishableKey", publishableKey->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->getJsonFromArrayOfJson, ), ]->Dict.fromArray addSmartEventListener("message", handleMessage, "onSubmit") @@ -436,9 +434,7 @@ let make = (publishableKey, options: option, analyticsInfo: optionJSON.Encode.string), ( "confirmParams", - [("publishableKey", publishableKey->JSON.Encode.string)] - ->Dict.fromArray - ->JSON.Encode.object, + [("publishableKey", publishableKey->JSON.Encode.string)]->getJsonFromArrayOfJson, ), ]->Dict.fromArray, ) @@ -478,7 +474,7 @@ let make = (publishableKey, options: option, analyticsInfo: optionDict.get("amount")->Option.getOr(0.0->JSON.Encode.float) dict->Dict.set( "amount", - [("currency", currency), ("value", amount)]->Dict.fromArray->JSON.Encode.object, + [("currency", currency), ("value", amount)]->getJsonFromArrayOfJson, ) Some(dict->JSON.Encode.object) } @@ -507,10 +503,8 @@ let make = (publishableKey, options: option, analyticsInfo: optionJSON.Encode.string), - ("data", [("version", 12.00->JSON.Encode.float)]->Dict.fromArray->JSON.Encode.object), - ] - ->Dict.fromArray - ->JSON.Encode.object + ("data", [("version", 12.00->JSON.Encode.float)]->getJsonFromArrayOfJson), + ]->getJsonFromArrayOfJson let methodData = [applePayPaymentMethodData]->JSON.Encode.array let details = [ @@ -518,9 +512,7 @@ let make = (publishableKey, options: option, analyticsInfo: optionDict.fromArray - ->JSON.Encode.object + ]->getJsonFromArrayOfJson let optionsForPaymentRequest = [ @@ -529,9 +521,7 @@ let make = (publishableKey, options: option, analyticsInfo: optionJSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object + ]->getJsonFromArrayOfJson Window.paymentRequest(methodData, details, optionsForPaymentRequest) } diff --git a/src/orca-loader/PaymentSessionMethods.res b/src/orca-loader/PaymentSessionMethods.res index bdf2693ac..1a8efcd00 100644 --- a/src/orca-loader/PaymentSessionMethods.res +++ b/src/orca-loader/PaymentSessionMethods.res @@ -1,5 +1,3 @@ -open Types - let getCustomerSavedPaymentMethods = ( ~clientSecret, ~publishableKey, @@ -8,6 +6,8 @@ let getCustomerSavedPaymentMethods = ( ~switchToCustomPod, ) => { open Promise + open Types + open Utils PaymentHelpers.fetchCustomerPaymentMethodList( ~clientSecret, ~publishableKey, @@ -40,12 +40,11 @@ let getCustomerSavedPaymentMethods = ( let confirmWithCustomerDefaultPaymentMethod = payload => { let customerPaymentMethod = customerDefaultPaymentMethod->JSON.Decode.object->Option.getOr(Dict.make()) - let paymentToken = - customerPaymentMethod->Utils.getJsonFromDict("payment_token", JSON.Encode.null) + let paymentToken = customerPaymentMethod->getJsonFromDict("payment_token", JSON.Encode.null) let paymentMethod = - customerPaymentMethod->Utils.getJsonFromDict("payment_method", JSON.Encode.null) + customerPaymentMethod->getJsonFromDict("payment_method", JSON.Encode.null) let paymentMethodType = - customerPaymentMethod->Utils.getJsonFromDict("payment_method_type", JSON.Encode.null) + customerPaymentMethod->getJsonFromDict("payment_method_type", JSON.Encode.null) let confirmParams = payload @@ -105,11 +104,10 @@ let getCustomerSavedPaymentMethods = ( ("payment_method_type", paymentMethodType), ] - let bodyStr = - body->Array.concat(broswerInfo)->Dict.fromArray->JSON.Encode.object->JSON.stringify + let bodyStr = body->Array.concat(broswerInfo)->getJsonFromArrayOfJson->JSON.stringify PaymentHelpers.intentCall( - ~fetchApi=Utils.fetchApi, + ~fetchApi, ~uri, ~headers, ~bodyStr, @@ -147,19 +145,15 @@ let getCustomerSavedPaymentMethods = ( "message", "There is no customer default saved payment method data"->JSON.Encode.string, ), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object + ]->getJsonFromArrayOfJson updatedCustomerDetails->resolve } } }) ->catch(err => { - let exceptionMessage = err->Utils.formatException->JSON.stringify + let exceptionMessage = err->formatException->JSON.stringify let updatedCustomerDetails = [ ( @@ -167,13 +161,9 @@ let getCustomerSavedPaymentMethods = ( [ ("type", "server_error"->JSON.Encode.string), ("message", exceptionMessage->JSON.Encode.string), - ] - ->Dict.fromArray - ->JSON.Encode.object, + ]->getJsonFromArrayOfJson, ), - ] - ->Dict.fromArray - ->JSON.Encode.object + ]->getJsonFromArrayOfJson updatedCustomerDetails->resolve }) }