From bc60a591c0a13210898f17b9159ef6ed948b07ae Mon Sep 17 00:00:00 2001 From: Saksham Sharma Date: Wed, 10 Sep 2025 12:11:49 +0530 Subject: [PATCH 1/5] feat: added get intent call for v2 --- src/LoaderController.res | 6 ++++ src/Payments/PreMountLoader.res | 12 ++++++++ src/Types/UnifiedPaymentsTypesV2.res | 4 +++ src/Utilities/PaymentHelpersV2.res | 41 ++++++++++++++++++++++++++++ src/Utilities/RecoilAtomsV2.res | 1 + src/Utilities/UnifiedHelpersV2.res | 17 ++++++++++++ src/hyper-loader/Elements.res | 24 +++++++++++++++- 7 files changed, 104 insertions(+), 1 deletion(-) diff --git a/src/LoaderController.res b/src/LoaderController.res index 137495f4d..bac771411 100644 --- a/src/LoaderController.res +++ b/src/LoaderController.res @@ -12,6 +12,7 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime let (optionsPayment, setOptionsPayment) = Recoil.useRecoilState(optionAtom) let setPaymentManagementList = Recoil.useSetRecoilState(paymentManagementList) let setPaymentMethodsListV2 = Recoil.useSetRecoilState(paymentMethodsListV2) + let setIntentList = Recoil.useSetRecoilState(intentList) let setSessionId = Recoil.useSetRecoilState(sessionId) let setBlockConfirm = Recoil.useSetRecoilState(isConfirmBlocked) let setCustomPodUri = Recoil.useSetRecoilState(customPodUri) @@ -443,6 +444,11 @@ let make = (~children, ~paymentMode, ~setIntegrateErrorError, ~logger, ~initTime } } } + if dict->getDictIsSome("getIntent") { + let getIntentDict = dict->getJsonObjectFromDict("getIntent")->getDictFromJson + let intentDetails = getIntentDict->UnifiedHelpersV2.createIntentDetails("response") + setIntentList(_ => intentDetails) + } if dict->getDictIsSome("paymentsListV2") { let paymentsListV2 = dict->getJsonObjectFromDict("paymentsListV2") let listDict = paymentsListV2->getDictFromJson diff --git a/src/Payments/PreMountLoader.res b/src/Payments/PreMountLoader.res index e98921f94..698ca2bbc 100644 --- a/src/Payments/PreMountLoader.res +++ b/src/Payments/PreMountLoader.res @@ -120,6 +120,16 @@ let getMessageHandlerV2Elements = ( ~endpoint, ) + let getIntentPromise = PaymentHelpersV2.fetchIntent( + ~clientSecret, + ~paymentId, + ~profileId, + ~publishableKey, + ~logger, + ~customPodUri, + ~endpoint, + ) + ev => { open Utils let dict = ev.data->safeParse->getDictFromJson @@ -127,6 +137,8 @@ let getMessageHandlerV2Elements = ( paymentMethodsListPromise->sendPromiseData("payment_methods_list_v2") } else if dict->isKeyPresentInDict("sendSessionTokensResponse") { sessionTokensPromise->sendPromiseData("session_tokens") + } else if dict->isKeyPresentInDict("sendGetIntentResponse") { + getIntentPromise->sendPromiseData("get_intent_v2") } } } diff --git a/src/Types/UnifiedPaymentsTypesV2.res b/src/Types/UnifiedPaymentsTypesV2.res index 1e4a7bce8..dcde92b0a 100644 --- a/src/Types/UnifiedPaymentsTypesV2.res +++ b/src/Types/UnifiedPaymentsTypesV2.res @@ -101,3 +101,7 @@ type paymentListLookupNew = { walletsList: array, otherPaymentList: array, } + +type intentCall = {paymentType: PaymentMethodsRecord.payment_type} + +type intentLoadState = LoadingIntent | LoadedIntent(intentCall) | Error(JSON.t) diff --git a/src/Utilities/PaymentHelpersV2.res b/src/Utilities/PaymentHelpersV2.res index 2a6b96e1f..981260bc9 100644 --- a/src/Utilities/PaymentHelpersV2.res +++ b/src/Utilities/PaymentHelpersV2.res @@ -585,3 +585,44 @@ let fetchSessions = ( JSON.Encode.null->resolve }) } + +let fetchIntent = ( + ~clientSecret, + ~publishableKey, + ~paymentId, + ~logger as _, + ~customPodUri, + ~endpoint, + ~profileId, +) => { + open Promise + let baseHeaders = [ + ("Content-Type", "application/json"), + ("x-profile-id", profileId), + ("Authorization", `publishable-key=${publishableKey},client-secret=${clientSecret}`), + ] + + let headers = switch customPodUri { + | value if value != "" => [...baseHeaders, ("x-feature", value)] + | _ => baseHeaders + } + + let uri = `${endpoint}/v2/payments/${paymentId}/get-intent` + fetchApi(uri, ~method=#GET, ~headers=headers->ApiEndpoint.addCustomPodHeader(~customPodUri)) + ->then(resp => { + if !(resp->Fetch.Response.ok) { + resp + ->Fetch.Response.json + ->then(_ => { + JSON.Encode.null->resolve + }) + } else { + Fetch.Response.json(resp) + } + }) + ->catch(err => { + let exceptionMessage = err->formatException + Console.error2("Error ", exceptionMessage) + JSON.Encode.null->resolve + }) +} diff --git a/src/Utilities/RecoilAtomsV2.res b/src/Utilities/RecoilAtomsV2.res index 23a1f6e0e..8fae504f9 100644 --- a/src/Utilities/RecoilAtomsV2.res +++ b/src/Utilities/RecoilAtomsV2.res @@ -4,6 +4,7 @@ let vaultMode = Recoil.atom("vaultMode", VaultHelpers.None) let managePaymentMethod = Recoil.atom("managePaymentMethod", "") let savedMethodsV2 = Recoil.atom("savedMethodsV2", [UnifiedHelpersV2.defaultCustomerMethods]) let paymentMethodsListV2 = Recoil.atom("paymentMethodsListV2", UnifiedPaymentsTypesV2.LoadingV2) +let intentList = Recoil.atom("intentList", UnifiedPaymentsTypesV2.LoadingIntent) let paymentMethodListValueV2 = Recoil.atom( "paymentMethodListValueV2", UnifiedHelpersV2.defaultPaymentsList, diff --git a/src/Utilities/UnifiedHelpersV2.res b/src/Utilities/UnifiedHelpersV2.res index bca227c51..a0a799fe2 100644 --- a/src/Utilities/UnifiedHelpersV2.res +++ b/src/Utilities/UnifiedHelpersV2.res @@ -149,6 +149,23 @@ let itemToPaymentDetails = cust => { } } +let itemToIntentObjMapper = dict => { + { + paymentType: getString(dict, "payment_type", "")->paymentTypeMapper, + } +} + +let createIntentDetails = (dict, key) => { + let intentDict = + dict + ->Dict.get(key) + ->Option.flatMap(JSON.Decode.object) + ->Option.getOr(Dict.make()) + let response = intentDict->itemToIntentObjMapper + + LoadedIntent(response) +} + let defaultAddress = { city: "", country: "", diff --git a/src/hyper-loader/Elements.res b/src/hyper-loader/Elements.res index a36575cf6..880e2cfc1 100644 --- a/src/hyper-loader/Elements.res +++ b/src/hyper-loader/Elements.res @@ -216,6 +216,24 @@ let make = ( }) } + let fetchIntent = (mountedIframeRef, componentType) => { + Promise.make((resolve, _) => { + let handleIntentLoaded = (event: Types.event) => { + let json = event.data->anyTypeToJson + let dict = json->getDictFromJson + let isGetIntentData = dict->getString("data", "") === "get_intent_v2" + if isGetIntentData { + resolve() + let msg = [("getIntent", json)]->Dict.fromArray + mountedIframeRef->Window.iframePostMessage(msg) + } + } + let msg = [("sendGetIntentResponse", true->JSON.Encode.bool)]->Dict.fromArray + addSmartEventListener("message", handleIntentLoaded, `onGetIntentLoaded-${componentType}`) + preMountLoaderIframeDiv->Window.iframePostMessage(msg) + }) + } + let fetchPaymentsListV2 = (mountedIframeRef, componentType) => { Promise.make((resolve, _) => { let handlePaymentMethodsLoaded = (event: Types.event) => { @@ -1389,7 +1407,11 @@ let make = ( ), sessionTokensPromise, ] - | V2 => [fetchPaymentsListV2(mountedIframeRef, componentType), sessionTokensPromise] + | V2 => [ + fetchPaymentsListV2(mountedIframeRef, componentType), + sessionTokensPromise, + fetchIntent(mountedIframeRef, componentType), + ] } Promise.all(promises)->then(_ => { From 63e8c8ef3e67345842674e5b0f3a6baaabc1b801 Mon Sep 17 00:00:00 2001 From: Saksham Sharma Date: Mon, 22 Sep 2025 12:54:52 +0530 Subject: [PATCH 2/5] refactor: addressed comments --- src/Utilities/APIHelpers/APIUtils.res | 6 +- src/Utilities/PaymentHelpers.res | 13 ++++ src/Utilities/PaymentHelpersV2.res | 60 +++++++++--------- src/Utilities/UnifiedHelpersV2.res | 6 +- src/Utilities/Utils.res | 90 +++++++++++++++++---------- src/hyper-loader/Hyper.res | 1 + 6 files changed, 108 insertions(+), 68 deletions(-) diff --git a/src/Utilities/APIHelpers/APIUtils.res b/src/Utilities/APIHelpers/APIUtils.res index 45638a642..e8b7ef4c1 100644 --- a/src/Utilities/APIHelpers/APIUtils.res +++ b/src/Utilities/APIHelpers/APIUtils.res @@ -13,7 +13,7 @@ type apiCallV1 = | RetrieveStatus | ConfirmPayout -type apiCallV2 = FetchSessionsV2 +type apiCallV2 = FetchSessionsV2 | FetchIntent type apiCall = | V1(apiCallV1) @@ -26,6 +26,7 @@ type apiParams = { paymentMethodId: option, forceSync: option, pollId: option, + paymentIdV2: option, } let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => { @@ -36,6 +37,7 @@ let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => { paymentMethodId, forceSync, pollId, + paymentIdV2, } = params let clientSecretVal = clientSecret->Option.getOr("") @@ -43,6 +45,7 @@ let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => { let paymentIntentID = Utils.getPaymentId(clientSecretVal) let paymentMethodIdVal = paymentMethodId->Option.getOr("") let pollIdVal = pollId->Option.getOr("") + let paymentIdVal = paymentIdV2->Option.getOr("") let baseUrl = customBackendBaseUrl->Option.getOr( @@ -115,6 +118,7 @@ let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => { | V2(inner) => switch inner { | FetchSessionsV2 => `v2/payments/${paymentIntentID}/create-external-sdk-tokens` + | FetchIntent => `v2/payments/${paymentIdVal}/get-intent` } } diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 10cb63859..6e0dd1f87 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -36,6 +36,7 @@ let retrievePaymentIntent = async ( paymentMethodId: None, forceSync: isForceSync ? Some("true") : None, pollId: None, + paymentIdV2: None, }, ) @@ -71,6 +72,7 @@ let threeDsAuth = async (~clientSecret, ~logger, ~threeDsMethodComp, ~headers) = paymentMethodId: None, forceSync: None, pollId: None, + paymentIdV2: None, }, ) let broswerInfo = BrowserSpec.broswerInfo @@ -172,6 +174,7 @@ let retrieveStatus = async (~publishableKey, ~customPodUri, pollID, logger) => { paymentMethodId: None, forceSync: None, pollId: Some(pollID), + paymentIdV2: None, }, ) @@ -1368,6 +1371,7 @@ let fetchSessions = async ( paymentMethodId: None, forceSync: None, pollId: None, + paymentIdV2: None, }, ) @@ -1407,6 +1411,7 @@ let confirmPayout = async ( paymentMethodId: None, forceSync: None, pollId: None, + paymentIdV2: None, }, ) @@ -1449,6 +1454,7 @@ let createPaymentMethod = async ( paymentMethodId: None, forceSync: None, pollId: None, + paymentIdV2: None, }, ) @@ -1490,6 +1496,7 @@ let fetchPaymentMethodList = async ( paymentMethodId: None, forceSync: None, pollId: None, + paymentIdV2: None, }, ) @@ -1526,6 +1533,7 @@ let fetchCustomerPaymentMethodList = async ( paymentMethodId: None, forceSync: None, pollId: None, + paymentIdV2: None, }, ) @@ -1632,6 +1640,7 @@ let callAuthLink = async ( paymentMethodId: None, forceSync: None, pollId: None, + paymentIdV2: None, }, ) @@ -1695,6 +1704,7 @@ let callAuthExchange = async ( paymentMethodId: None, forceSync: None, pollId: None, + paymentIdV2: None, }, ) @@ -1767,6 +1777,7 @@ let fetchSavedPaymentMethodList = async ( paymentMethodId: None, forceSync: None, pollId: None, + paymentIdV2: None, }, ) @@ -1797,6 +1808,7 @@ let deletePaymentMethod = async (~ephemeralKey, ~paymentMethodId, ~logger, ~cust paymentMethodId: Some(paymentMethodId), forceSync: None, pollId: None, + paymentIdV2: None, }, ) @@ -1834,6 +1846,7 @@ let calculateTax = async ( paymentMethodId: None, forceSync: None, pollId: None, + paymentIdV2: None, }, ) let onSuccess = data => data diff --git a/src/Utilities/PaymentHelpersV2.res b/src/Utilities/PaymentHelpersV2.res index 981260bc9..6d33d87fc 100644 --- a/src/Utilities/PaymentHelpersV2.res +++ b/src/Utilities/PaymentHelpersV2.res @@ -586,43 +586,43 @@ let fetchSessions = ( }) } -let fetchIntent = ( +let fetchIntent = async ( ~clientSecret, ~publishableKey, ~paymentId, - ~logger as _, + ~logger, ~customPodUri, ~endpoint, ~profileId, ) => { - open Promise - let baseHeaders = [ - ("Content-Type", "application/json"), - ("x-profile-id", profileId), - ("Authorization", `publishable-key=${publishableKey},client-secret=${clientSecret}`), - ] + let uri = APIUtils.generateApiUrl( + V2(FetchIntent), + ~params={ + clientSecret: Some(clientSecret), + customBackendBaseUrl: Some(endpoint), + publishableKey: Some(publishableKey), + paymentMethodId: None, + forceSync: None, + pollId: None, + paymentIdV2: Some(paymentId), + }, + ) - let headers = switch customPodUri { - | value if value != "" => [...baseHeaders, ("x-feature", value)] - | _ => baseHeaders - } + let onSuccess = data => data - let uri = `${endpoint}/v2/payments/${paymentId}/get-intent` - fetchApi(uri, ~method=#GET, ~headers=headers->ApiEndpoint.addCustomPodHeader(~customPodUri)) - ->then(resp => { - if !(resp->Fetch.Response.ok) { - resp - ->Fetch.Response.json - ->then(_ => { - JSON.Encode.null->resolve - }) - } else { - Fetch.Response.json(resp) - } - }) - ->catch(err => { - let exceptionMessage = err->formatException - Console.error2("Error ", exceptionMessage) - JSON.Encode.null->resolve - }) + let onFailure = _ => JSON.Encode.null + + // Todo: Add logger + await fetchApiWithLogging( + uri, + ~eventName=CUSTOMER_PAYMENT_METHODS_CALL, + ~logger, + ~method=#GET, + ~customPodUri=Some(customPodUri), + ~publishableKey=Some(publishableKey), + ~clientSecret=Some(clientSecret), + ~profileId=Some(profileId), + ~onSuccess, + ~onFailure, + ) } diff --git a/src/Utilities/UnifiedHelpersV2.res b/src/Utilities/UnifiedHelpersV2.res index a0a799fe2..bd0373d6f 100644 --- a/src/Utilities/UnifiedHelpersV2.res +++ b/src/Utilities/UnifiedHelpersV2.res @@ -156,11 +156,7 @@ let itemToIntentObjMapper = dict => { } let createIntentDetails = (dict, key) => { - let intentDict = - dict - ->Dict.get(key) - ->Option.flatMap(JSON.Decode.object) - ->Option.getOr(Dict.make()) + let intentDict = dict->Utils.getDictFromDict(key) let response = intentDict->itemToIntentObjMapper LoadedIntent(response) diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index befbc35a8..7e5e29708 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -848,10 +848,15 @@ let getHeaders = ( ~customPodUri=None, ~headers=Dict.make(), ~publishableKey=None, + ~clientSecret=None, + ~profileId=None, ): Fetch.Headers.t => { + let publishableKeyVal = publishableKey->Option.map(key => key)->Option.getOr("invalid_key") + let profileIdVal = profileId->Option.getOr("invalid_key") + let clientSecretVal = clientSecret->Option.getOr("invalid_key") + let defaultHeaders = [ ("Content-Type", "application/json"), - ("api-key", publishableKey->Option.map(key => key)->Option.getOr("invalid_key")), ("X-Client-Version", Window.version), ("X-Payment-Confirm-Source", "sdk"), ("X-Browser-Name", HyperLogger.arrayOfNameAndVersion->Array.get(0)->Option.getOr("Others")), @@ -859,6 +864,14 @@ let getHeaders = ( ("X-Client-Platform", "web"), ] + let authorizationHeaders = switch GlobalVars.sdkVersion { + | V2 => [ + ("x-profile-id", profileIdVal), + ("Authorization", `publishable-key=${publishableKeyVal},client-secret=${clientSecretVal}`), + ] + | V1 => [("api-key", publishableKey->Option.map(key => key)->Option.getOr("invalid_key"))] + } + let authHeader = switch (token, uri) { | (Some(tok), Some(_)) => [("Authorization", tok)] | _ => [] @@ -871,6 +884,7 @@ let getHeaders = ( let finalHeaders = [ ...defaultHeaders, + ...authorizationHeaders, ...authHeader, ...customPodHeader, ...Dict.toArray(headers), @@ -949,16 +963,20 @@ let fetchApiWithLogging = async ( ~publishableKey=None, ~isPaymentSession=false, ~onCatchCallback=None, + ~clientSecret=None, + ~profileId=None, ) => { open LoggerUtils // * Log request initiation - LogAPIResponse.logApiResponse( - ~logger, - ~uri, - ~eventName=apiEventInitMapper(eventName), - ~status=Request, - ) + if GlobalVars.sdkVersion != V2 { + LogAPIResponse.logApiResponse( + ~logger, + ~uri, + ~eventName=apiEventInitMapper(eventName), + ~status=Request, + ) + } try { let body = switch method { @@ -976,6 +994,8 @@ let fetchApiWithLogging = async ( ~uri, ~customPodUri, ~publishableKey, + ~clientSecret, + ~profileId, ), }, ) @@ -984,26 +1004,30 @@ let fetchApiWithLogging = async ( if resp->Fetch.Response.ok { let data = await Fetch.Response.json(resp) - LogAPIResponse.logApiResponse( - ~logger, - ~uri, - ~eventName=Some(eventName), - ~status=Success, - ~statusCode, - ~isPaymentSession, - ) + if GlobalVars.sdkVersion != V2 { + LogAPIResponse.logApiResponse( + ~logger, + ~uri, + ~eventName=Some(eventName), + ~status=Success, + ~statusCode, + ~isPaymentSession, + ) + } onSuccess(data) } else { let data = await resp->Fetch.Response.json - LogAPIResponse.logApiResponse( - ~logger, - ~uri, - ~eventName=Some(eventName), - ~status=Error, - ~statusCode, - ~data, - ~isPaymentSession, - ) + if GlobalVars.sdkVersion != V2 { + LogAPIResponse.logApiResponse( + ~logger, + ~uri, + ~eventName=Some(eventName), + ~status=Error, + ~statusCode, + ~data, + ~isPaymentSession, + ) + } onFailure(data) } } catch { @@ -1017,14 +1041,16 @@ let fetchApiWithLogging = async ( "error": exceptionMessage, }, ) - LogAPIResponse.logApiResponse( - ~logger, - ~uri, - ~eventName=Some(eventName), - ~status=Exception, - ~data=exceptionMessage, - ~isPaymentSession, - ) + if GlobalVars.sdkVersion != V2 { + LogAPIResponse.logApiResponse( + ~logger, + ~uri, + ~eventName=Some(eventName), + ~status=Exception, + ~data=exceptionMessage, + ~isPaymentSession, + ) + } switch onCatchCallback { | Some(fun) => fun(exceptionMessage) | None => onFailure(exceptionMessage) diff --git a/src/hyper-loader/Hyper.res b/src/hyper-loader/Hyper.res index 03667c7f9..6707037c8 100644 --- a/src/hyper-loader/Hyper.res +++ b/src/hyper-loader/Hyper.res @@ -340,6 +340,7 @@ let make = (keys, options: option, analyticsInfo: option) => { paymentMethodId: None, forceSync: None, pollId: None, + paymentIdV2: None, }, ) From d690e893114c95e400f66a8c034042b34a31c8be Mon Sep 17 00:00:00 2001 From: Saksham Sharma Date: Tue, 23 Sep 2025 12:16:47 +0530 Subject: [PATCH 3/5] refactor: api utils for v1 and v2 --- src/Utilities/APIHelpers/APIUtils.res | 131 ++++++++++++++------------ src/Utilities/PaymentHelpers.res | 52 +++++----- src/Utilities/PaymentHelpersV2.res | 8 +- src/hyper-loader/Hyper.res | 4 +- 4 files changed, 102 insertions(+), 93 deletions(-) diff --git a/src/Utilities/APIHelpers/APIUtils.res b/src/Utilities/APIHelpers/APIUtils.res index eba33309f..e01acd522 100644 --- a/src/Utilities/APIHelpers/APIUtils.res +++ b/src/Utilities/APIHelpers/APIUtils.res @@ -15,14 +15,16 @@ type apiCallV1 = type apiCallV2 = FetchSessionsV2 | FetchIntent -type apiCall = - | V1(apiCallV1) - | V2(apiCallV2) - -type apiParams = { - clientSecret: option, +type commonApiParams = { publishableKey: option, customBackendBaseUrl: option, +} + +type apiParamsV2 = {...commonApiParams, paymentIdV2: option} + +type apiParamsV1 = { + ...commonApiParams, + clientSecret: option, paymentMethodId: option, forceSync: option, pollId: option, @@ -30,7 +32,18 @@ type apiParams = { payoutId: option, } -let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => { +module CommonUtils = { + let buildQueryParams = params => + switch params { + | list{} => "" + | _ => + params + ->List.map(((key, value)) => `${key}=${value}`) + ->List.reduce("", (acc, param) => acc === "" ? `?${param}` : `${acc}&${param}`) + } +} + +let generateApiUrlV1 = (~params: apiParamsV1, ~apiCallType: apiCallV1) => { let { clientSecret, publishableKey, @@ -38,7 +51,6 @@ let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => { paymentMethodId, forceSync, pollId, - paymentIdV2, payoutId, } = params @@ -47,7 +59,6 @@ let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => { let paymentIntentID = Utils.getPaymentId(clientSecretVal) let paymentMethodIdVal = paymentMethodId->Option.getOr("") let pollIdVal = pollId->Option.getOr("") - let paymentIdVal = paymentIdV2->Option.getOr("") let payoutIdVal = payoutId->Option.getOr("") let baseUrl = @@ -55,17 +66,8 @@ let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => { ApiEndpoint.getApiEndPoint(~publishableKey=publishableKeyVal), ) - let buildQueryParams = params => - switch params { - | list{} => "" - | _ => - params - ->List.map(((key, value)) => `${key}=${value}`) - ->List.reduce("", (acc, param) => acc === "" ? `?${param}` : `${acc}&${param}`) - } - let isRetrieveIntent = switch apiCallType { - | V1(RetrievePaymentIntent) => true + | RetrievePaymentIntent => true | _ => false } @@ -81,49 +83,60 @@ let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => { }->List.filterMap(x => x) let queryParams = switch apiCallType { - | V1(inner) => - switch inner { - | FetchPaymentMethodList - | FetchCustomerPaymentMethodList - | RetrievePaymentIntent => defaultParams - | FetchSessions - | FetchThreeDsAuth - | FetchSavedPaymentMethodList - | DeletePaymentMethod - | CalculateTax - | CreatePaymentMethod - | CallAuthLink - | CallAuthExchange - | RetrieveStatus - | ConfirmPayout => - list{} - } - | V2(_) => list{} + | FetchPaymentMethodList + | FetchCustomerPaymentMethodList + | RetrievePaymentIntent => defaultParams + | FetchSessions + | FetchThreeDsAuth + | FetchSavedPaymentMethodList + | DeletePaymentMethod + | CalculateTax + | CreatePaymentMethod + | CallAuthLink + | CallAuthExchange + | RetrieveStatus + | ConfirmPayout => + list{} } let path = switch apiCallType { - | V1(inner) => - switch inner { - | FetchPaymentMethodList => "account/payment_methods" - | FetchSessions => "payments/session_tokens" - | FetchThreeDsAuth => `payments/${paymentIntentID}/3ds/authentication` - | FetchCustomerPaymentMethodList - | FetchSavedPaymentMethodList => "customers/payment_methods" - | DeletePaymentMethod => `payment_methods/${paymentMethodIdVal}` - | CalculateTax => `payments/${paymentIntentID}/calculate_tax` - | CreatePaymentMethod => "payment_methods" - | RetrievePaymentIntent => `payments/${paymentIntentID}` - | CallAuthLink => "payment_methods/auth/link" - | CallAuthExchange => "payment_methods/auth/exchange" - | RetrieveStatus => `poll/status/${pollIdVal}` - | ConfirmPayout => `payouts/${payoutIdVal}/confirm` - } - | V2(inner) => - switch inner { - | FetchSessionsV2 => `v2/payments/${paymentIntentID}/create-external-sdk-tokens` - | FetchIntent => `v2/payments/${paymentIdVal}/get-intent` - } + | FetchPaymentMethodList => "account/payment_methods" + | FetchSessions => "payments/session_tokens" + | FetchThreeDsAuth => `payments/${paymentIntentID}/3ds/authentication` + | FetchCustomerPaymentMethodList + | FetchSavedPaymentMethodList => "customers/payment_methods" + | DeletePaymentMethod => `payment_methods/${paymentMethodIdVal}` + | CalculateTax => `payments/${paymentIntentID}/calculate_tax` + | CreatePaymentMethod => "payment_methods" + | RetrievePaymentIntent => `payments/${paymentIntentID}` + | CallAuthLink => "payment_methods/auth/link" + | CallAuthExchange => "payment_methods/auth/exchange" + | RetrieveStatus => `poll/status/${pollIdVal}` + | ConfirmPayout => `payouts/${payoutIdVal}/confirm` + } + + `${baseUrl}/${path}${CommonUtils.buildQueryParams(queryParams)}` +} + +let generateApiUrlV2 = (~params: apiParamsV2, ~apiCallType: apiCallV2) => { + let {publishableKey, customBackendBaseUrl, paymentIdV2} = params + + let publishableKeyVal = publishableKey->Option.getOr("") + let paymentIdVal = paymentIdV2->Option.getOr("") + + let baseUrl = + customBackendBaseUrl->Option.getOr( + ApiEndpoint.getApiEndPoint(~publishableKey=publishableKeyVal), + ) + + let queryParams = switch apiCallType { + | _ => list{} + } + + let path = switch apiCallType { + | FetchSessionsV2 => `v2/payments/${paymentIdVal}/create-external-sdk-tokens` + | FetchIntent => `v2/payments/${paymentIdVal}/get-intent` } - `${baseUrl}/${path}${buildQueryParams(queryParams)}` + `${baseUrl}/${path}${CommonUtils.buildQueryParams(queryParams)}` } diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 3bef47e95..893592098 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -27,8 +27,8 @@ let retrievePaymentIntent = async ( ~customPodUri, ~isForceSync=false, ) => { - let uri = APIUtils.generateApiUrl( - V1(RetrievePaymentIntent), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=RetrievePaymentIntent, ~params={ clientSecret: Some(clientSecret), publishableKey: Some(publishableKey), @@ -64,8 +64,8 @@ let retrievePaymentIntent = async ( } let threeDsAuth = async (~clientSecret, ~logger, ~threeDsMethodComp, ~headers) => { - let url = APIUtils.generateApiUrl( - V1(FetchThreeDsAuth), + let url = APIUtils.generateApiUrlV1( + ~apiCallType=FetchThreeDsAuth, ~params={ clientSecret: Some(clientSecret), publishableKey: None, @@ -167,8 +167,8 @@ let rec pollRetrievePaymentIntent = ( } let retrieveStatus = async (~publishableKey, ~customPodUri, pollID, logger) => { - let uri = APIUtils.generateApiUrl( - V1(RetrieveStatus), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=RetrieveStatus, ~params={ clientSecret: None, publishableKey: Some(publishableKey), @@ -1365,8 +1365,8 @@ let fetchSessions = async ( ("wallets", wallets->JSON.Encode.array), ("delayed_session_token", isDelayedSessionToken->JSON.Encode.bool), ]->getJsonFromArrayOfJson - let uri = APIUtils.generateApiUrl( - V1(FetchSessions), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=FetchSessions, ~params={ customBackendBaseUrl: Some(endpoint), clientSecret: None, @@ -1407,8 +1407,8 @@ let confirmPayout = async ( ~body, ~payoutId, ) => { - let uri = APIUtils.generateApiUrl( - V1(ConfirmPayout), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=ConfirmPayout, ~params={ clientSecret: Some(clientSecret), customBackendBaseUrl: Some(endpoint), @@ -1451,8 +1451,8 @@ let createPaymentMethod = async ( ~endpoint, ~body, ) => { - let uri = APIUtils.generateApiUrl( - V1(CreatePaymentMethod), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=CreatePaymentMethod, ~params={ clientSecret: Some(clientSecret), customBackendBaseUrl: Some(endpoint), @@ -1494,8 +1494,8 @@ let fetchPaymentMethodList = async ( ~customPodUri, ~endpoint, ) => { - let uri = APIUtils.generateApiUrl( - V1(FetchPaymentMethodList), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=FetchPaymentMethodList, ~params={ clientSecret: Some(clientSecret), customBackendBaseUrl: Some(endpoint), @@ -1532,8 +1532,8 @@ let fetchCustomerPaymentMethodList = async ( ~endpoint, ~isPaymentSession=false, ) => { - let uri = APIUtils.generateApiUrl( - V1(FetchCustomerPaymentMethodList), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=FetchCustomerPaymentMethodList, ~params={ clientSecret: Some(clientSecret), customBackendBaseUrl: Some(endpoint), @@ -1640,8 +1640,8 @@ let callAuthLink = async ( ~iframeId, ~logger, ) => { - let uri = APIUtils.generateApiUrl( - V1(CallAuthLink), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=CallAuthLink, ~params={ clientSecret: None, publishableKey: Some(publishableKey), @@ -1705,8 +1705,8 @@ let callAuthExchange = async ( ) => { open Promise open PaymentType - let uri = APIUtils.generateApiUrl( - V1(CallAuthExchange), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=CallAuthExchange, ~params={ clientSecret: None, publishableKey: Some(publishableKey), @@ -1779,8 +1779,8 @@ let fetchSavedPaymentMethodList = async ( ~customPodUri, ~isPaymentSession=false, ) => { - let uri = APIUtils.generateApiUrl( - V1(FetchSavedPaymentMethodList), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=FetchSavedPaymentMethodList, ~params={ customBackendBaseUrl: Some(endpoint), clientSecret: None, @@ -1811,8 +1811,8 @@ let fetchSavedPaymentMethodList = async ( } let deletePaymentMethod = async (~ephemeralKey, ~paymentMethodId, ~logger, ~customPodUri) => { - let uri = APIUtils.generateApiUrl( - V1(DeletePaymentMethod), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=DeletePaymentMethod, ~params={ customBackendBaseUrl: None, clientSecret: None, @@ -1850,8 +1850,8 @@ let calculateTax = async ( ~customPodUri, ~sessionId, ) => { - let uri = APIUtils.generateApiUrl( - V1(CalculateTax), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=CalculateTax, ~params={ customBackendBaseUrl: None, clientSecret: Some(clientSecret), diff --git a/src/Utilities/PaymentHelpersV2.res b/src/Utilities/PaymentHelpersV2.res index 6d33d87fc..74b8b0946 100644 --- a/src/Utilities/PaymentHelpersV2.res +++ b/src/Utilities/PaymentHelpersV2.res @@ -595,15 +595,11 @@ let fetchIntent = async ( ~endpoint, ~profileId, ) => { - let uri = APIUtils.generateApiUrl( - V2(FetchIntent), + let uri = APIUtils.generateApiUrlV2( + ~apiCallType=FetchIntent, ~params={ - clientSecret: Some(clientSecret), customBackendBaseUrl: Some(endpoint), publishableKey: Some(publishableKey), - paymentMethodId: None, - forceSync: None, - pollId: None, paymentIdV2: Some(paymentId), }, ) diff --git a/src/hyper-loader/Hyper.res b/src/hyper-loader/Hyper.res index 508186c53..be8144f6a 100644 --- a/src/hyper-loader/Hyper.res +++ b/src/hyper-loader/Hyper.res @@ -331,8 +331,8 @@ let make = (keys, options: option, analyticsInfo: option) => { } let retrievePaymentIntentFn = async clientSecret => { - let uri = APIUtils.generateApiUrl( - V1(RetrievePaymentIntent), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=RetrievePaymentIntent, ~params={ clientSecret: Some(clientSecret), publishableKey: Some(publishableKey), From 83deb7735c09bd8f682d697328b4add325ba6916 Mon Sep 17 00:00:00 2001 From: Saksham Sharma Date: Tue, 23 Sep 2025 15:57:32 +0530 Subject: [PATCH 4/5] refactor: removed payment id form v1 params --- src/Utilities/APIHelpers/APIUtils.res | 1 - src/Utilities/PaymentHelpers.res | 13 ------------- src/hyper-loader/Hyper.res | 1 - 3 files changed, 15 deletions(-) diff --git a/src/Utilities/APIHelpers/APIUtils.res b/src/Utilities/APIHelpers/APIUtils.res index e01acd522..c0978e599 100644 --- a/src/Utilities/APIHelpers/APIUtils.res +++ b/src/Utilities/APIHelpers/APIUtils.res @@ -28,7 +28,6 @@ type apiParamsV1 = { paymentMethodId: option, forceSync: option, pollId: option, - paymentIdV2: option, payoutId: option, } diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 893592098..89d39fdb8 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -36,7 +36,6 @@ let retrievePaymentIntent = async ( paymentMethodId: None, forceSync: isForceSync ? Some("true") : None, pollId: None, - paymentIdV2: None, payoutId: None, }, ) @@ -73,7 +72,6 @@ let threeDsAuth = async (~clientSecret, ~logger, ~threeDsMethodComp, ~headers) = paymentMethodId: None, forceSync: None, pollId: None, - paymentIdV2: None, payoutId: None, }, ) @@ -176,7 +174,6 @@ let retrieveStatus = async (~publishableKey, ~customPodUri, pollID, logger) => { paymentMethodId: None, forceSync: None, pollId: Some(pollID), - paymentIdV2: None, payoutId: None, }, ) @@ -1374,7 +1371,6 @@ let fetchSessions = async ( paymentMethodId: None, forceSync: None, pollId: None, - paymentIdV2: None, payoutId: None, }, ) @@ -1416,7 +1412,6 @@ let confirmPayout = async ( paymentMethodId: None, forceSync: None, pollId: None, - paymentIdV2: None, payoutId: Some(payoutId), }, ) @@ -1460,7 +1455,6 @@ let createPaymentMethod = async ( paymentMethodId: None, forceSync: None, pollId: None, - paymentIdV2: None, payoutId: None, }, ) @@ -1503,7 +1497,6 @@ let fetchPaymentMethodList = async ( paymentMethodId: None, forceSync: None, pollId: None, - paymentIdV2: None, payoutId: None, }, ) @@ -1541,7 +1534,6 @@ let fetchCustomerPaymentMethodList = async ( paymentMethodId: None, forceSync: None, pollId: None, - paymentIdV2: None, payoutId: None, }, ) @@ -1649,7 +1641,6 @@ let callAuthLink = async ( paymentMethodId: None, forceSync: None, pollId: None, - paymentIdV2: None, payoutId: None, }, ) @@ -1714,7 +1705,6 @@ let callAuthExchange = async ( paymentMethodId: None, forceSync: None, pollId: None, - paymentIdV2: None, payoutId: None, }, ) @@ -1788,7 +1778,6 @@ let fetchSavedPaymentMethodList = async ( paymentMethodId: None, forceSync: None, pollId: None, - paymentIdV2: None, payoutId: None, }, ) @@ -1820,7 +1809,6 @@ let deletePaymentMethod = async (~ephemeralKey, ~paymentMethodId, ~logger, ~cust paymentMethodId: Some(paymentMethodId), forceSync: None, pollId: None, - paymentIdV2: None, payoutId: None, }, ) @@ -1859,7 +1847,6 @@ let calculateTax = async ( paymentMethodId: None, forceSync: None, pollId: None, - paymentIdV2: None, payoutId: None, }, ) diff --git a/src/hyper-loader/Hyper.res b/src/hyper-loader/Hyper.res index be8144f6a..f3a53acc7 100644 --- a/src/hyper-loader/Hyper.res +++ b/src/hyper-loader/Hyper.res @@ -340,7 +340,6 @@ let make = (keys, options: option, analyticsInfo: option) => { paymentMethodId: None, forceSync: None, pollId: None, - paymentIdV2: None, payoutId: None, }, ) From 9fed7d8f6b548bb29fef72328edd7894f06312e6 Mon Sep 17 00:00:00 2001 From: Saksham Sharma Date: Wed, 24 Sep 2025 12:10:09 +0530 Subject: [PATCH 5/5] fix: resolved conflicts --- src/Utilities/PaymentHelpers.res | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 1714fd96e..e7d4fef33 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -69,8 +69,8 @@ let fetchBlockedBins = async ( ~customPodUri, ~endpoint, ) => { - let uri = APIUtils.generateApiUrl( - V1(FetchBlockedBins), + let uri = APIUtils.generateApiUrlV1( + ~apiCallType=FetchBlockedBins, ~params={ clientSecret: Some(clientSecret), publishableKey: None,