Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changes for supporting form data type in api #257

Merged
merged 13 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/HSwitchFeedBackModal.res
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let make = (
[
("Feedback", values->HSwitchUtils.getBodyForFeedBack(~modalType, ())->Js.Json.object_),
]->LogicUtils.getJsonFromArrayOfJson
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
let successMessage = switch modalType {
| FeedBackModal => "Thanks for feedback"
| RequestConnectorModal => "Request submitted succesfully"
Expand Down
2 changes: 1 addition & 1 deletion src/entryPoints/hyperswitch/HyperSwitchEntry.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module HyperSwitchEntryComponent = {
let url = `${HSwitchGlobalVars.hyperSwitchFEPrefix}/config/merchant-access`
let typedResponse =
(
await postDetails(url, Dict.make()->Js.Json.object_, Post)
await postDetails(url, Dict.make()->Js.Json.object_, Post, ())
)->FeatureFlagUtils.featureFlagType
setFeatureFlag(._ => typedResponse)
setScreenState(_ => PageLoaderWrapper.Success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module SelectPaymentMethods = {
let body = ConnectorUtils.constructConnectorRequestBody(obj, initialValues)
let connectorUrl = APIUtils.getURL(~entityName=CONNECTOR, ~methodType=Post, ~id=None, ())

let response = await updateAPIHook(connectorUrl, body, Post)
let response = await updateAPIHook(connectorUrl, body, Post, ())
setInitialValues(_ => response)
response->LogicUtils.getDictFromJsonObject->updateEnumForConnector->ignore
setConnectorConfigureState(_ => Summary)
Expand Down
17 changes: 14 additions & 3 deletions src/hooks/AuthHooks.res
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type sessionStorage = {
external dictToObj: Js.Dict.t<'a> => {..} = "%identity"
@val external atob: string => string = "atob"

let getHeaders = (~uri, ~headers, ()) => {
let getHeaders = (~uri, ~headers, ~isFromFormData, ()) => {
let hyperSwitchToken = LocalStorage.getItem("login")->Js.Nullable.toOption
let isMixpanel = uri->String.includes("mixpanel")

Expand All @@ -20,6 +20,12 @@ let getHeaders = (~uri, ~headers, ()) => {
"accept": "application/json",
}
Fetch.HeadersInit.make(headerObj)
} else if isFromFormData {
let headerObj = {
"Authorization": `Bearer ${hyperSwitchToken->Belt.Option.getWithDefault("")}`,
"api-key": headers->Dict.get("api-key")->Belt.Option.getWithDefault("hyperswitch"),
}
Fetch.HeadersInit.make(headerObj)
jainlokesh318 marked this conversation as resolved.
Show resolved Hide resolved
} else {
let headerObj = headers->Dict.get("api-key")->Belt.Option.getWithDefault("")->String.length > 0

Expand Down Expand Up @@ -81,6 +87,7 @@ let useApiFetcher = () => {
(
uri,
~bodyStr: string="",
~bodyFormData=None,
~headers=Dict.make(),
~bodyHeader as _=?,
~method_: Fetch.requestMethod,
Expand All @@ -98,7 +105,11 @@ let useApiFetcher = () => {

let body = switch method_ {
| Get => resolve(None)
| _ => resolve(Some(Fetch.BodyInit.make(bodyStr)))
| _ =>
switch bodyFormData {
| Some(formDataVal) => resolve(Some(Fetch.BodyInit.makeWithFormData(formDataVal)))
| None => resolve(Some(Fetch.BodyInit.make(bodyStr)))
}
}

body->then(body => {
Expand All @@ -109,7 +120,7 @@ let useApiFetcher = () => {
~method_,
~body?,
~credentials=SameOrigin,
~headers=getHeaders(~headers, ~uri, ()),
~headers=getHeaders(~headers, ~uri, ~isFromFormData=bodyFormData->Option.isSome, ()),
(),
),
)
Expand Down
11 changes: 9 additions & 2 deletions src/screens/HyperSwitch/APIUtils/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ let handleLogout = async (
~fetchApi as _: (
Js.String2.t,
~bodyStr: string=?,
~bodyFormData: option<Fetch.formData>=?,
~headers: Js.Dict.t<Js.String2.t>=?,
~bodyHeader: Js.Dict.t<Js.Json.t>=?,
~method_: Fetch.requestMethod,
Expand Down Expand Up @@ -386,9 +387,15 @@ let useUpdateMethod = (~showErrorToast=true, ()) => {
},
})

async (url, body, method) => {
async (url, body, method, ~bodyFormData=?, ()) => {
try {
let res = await fetchApi(url, ~method_=method, ~bodyStr=body->Js.Json.stringify, ())
let res = await fetchApi(
url,
~method_=method,
~bodyStr=body->Js.Json.stringify,
~bodyFormData,
(),
)
await responseHandler(
~res,
~showErrorToast,
Expand Down
6 changes: 3 additions & 3 deletions src/screens/HyperSwitch/Analytics/Analytics.res
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ module TableWrapper = {
(),
)

fetchDetails(tableEntity.uri, weeklyTableReqBody, Post)
fetchDetails(tableEntity.uri, weeklyTableReqBody, Post, ())
->thenResolve(json => {
setTableData(_ => getUpdatedData(data, json, cols))
setTableDataLoading(_ => false)
Expand Down Expand Up @@ -285,7 +285,7 @@ module TableWrapper = {
(),
)

fetchDetails(tableEntity.uri, tableReqBody, Post)
fetchDetails(tableEntity.uri, tableReqBody, Post, ())
->thenResolve(json => {
switch weeklyTableMetricsCols {
| Some(cols) => getWeeklyData(json, cols)->ignore
Expand Down Expand Up @@ -612,7 +612,7 @@ let make = (
setFilterDataJson(_ => None)
if startTimeVal->isStringNonEmpty && endTimeVal->isStringNonEmpty {
try {
updateDetails(filterUri, filterBody->Js.Json.object_, Post)
updateDetails(filterUri, filterBody->Js.Json.object_, Post, ())
->thenResolve(json => setFilterDataJson(_ => json->Some))
->catch(_ => resolve())
->ignore
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/Analytics/DownloadReportModal.res
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let make = (~reportModal, ~setReportModal, ~entityName) => {
let downloadReport = async body => {
try {
let url = getURL(~entityName, ~methodType=Post, ())
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
setReportModal(_ => false)
showToast(~message="Email Sent", ~toastType=ToastSuccess, ())
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ module OverviewInfo = {
generateSampleDataUrl,
[("record", 50.0->Js.Json.number)]->Dict.fromArray->Js.Json.object_,
Post,
(),
)
showToast(~message="Sample data generated successfully.", ~toastType=ToastSuccess, ())
Window.Location.reload()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let make = () => {
let refundUrl = getURL(~entityName=REFUNDS, ~methodType=Post, ~id=Some("refund-post"), ())
let body = Dict.make()
body->Dict.set("limit", 100->Belt.Int.toFloat->Js.Json.number)
let refundDetails = await updateDetails(refundUrl, body->Js.Json.object_, Post)
let refundDetails = await updateDetails(refundUrl, body->Js.Json.object_, Post, ())
let data = refundDetails->getDictFromJsonObject->getArrayFromDict("data", [])

if data->Array.length < 1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ module HSiwtchPaymentConfirmLatency = {
}

let getOverallLatency = async () => {
updateDetails(url, singleStatBodyEntity->singleStatBodyMake("Payment"), Fetch.Post)
updateDetails(url, singleStatBodyEntity->singleStatBodyMake("Payment"), Fetch.Post, ())
->thenResolve(json => {
setOverallrLatency(_ => json->parseJson)
})
Expand All @@ -146,7 +146,7 @@ module HSiwtchPaymentConfirmLatency = {
}

let getConnectorLatency = () => {
updateDetails(url, singleStatBodyEntity->singleStatBodyMake("OutgoingEvent"), Fetch.Post)
updateDetails(url, singleStatBodyEntity->singleStatBodyMake("OutgoingEvent"), Fetch.Post, ())
->thenResolve(json => {
setConnectorLatency(_ => json->parseJson)
setIsLoading(_ => false)
Expand Down Expand Up @@ -275,7 +275,7 @@ module SystemMetricsAnalytics = {
setFilterDataJson(_ => None)
if startTimeVal->isStringNonEmpty && endTimeVal->isStringNonEmpty {
try {
updateDetails(filterUri, filterBody->Js.Json.object_, Post)
updateDetails(filterUri, filterBody->Js.Json.object_, Post, ())
->thenResolve(json => setFilterDataJson(_ => json->Some))
->catch(_ => resolve())
->ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ let make = (~setCurrentStep, ~setInitialValues, ~initialValues, ~isUpdateFlow, ~
~connector=Some(connector),
(),
)
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
setShowVerifyModal(_ => false)
onSubmitMain(values)->ignore
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let make = (
ConnectorUtils.connectorIgnoredField,
)
let connectorUrl = getURL(~entityName=CONNECTOR, ~methodType=Post, ~id=connectorID, ())
let response = await updateAPIHook(connectorUrl, body, Post)
let response = await updateAPIHook(connectorUrl, body, Post, ())
setInitialValues(_ => response)
setScreenState(_ => Success)
setCurrentStep(_ => ConnectorTypes.SummaryAndTest)
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/Connectors/ConnectorPreview.res
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ let make = (
isConnectorDisabled,
)
let url = getURL(~entityName=CONNECTOR, ~methodType=Post, ~id=Some(connectorID), ())
let _ = await updateDetails(url, disableConnectorPayload->Js.Json.object_, Post)
let _ = await updateDetails(url, disableConnectorPayload->Js.Json.object_, Post, ())
showToast(~message=`Successfully Saved the Changes`, ~toastType=ToastSuccess, ())
RescriptReactRouter.push("/connectors")
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module Simplified = {
try {
let (body, domainName) = values->constructVerifyApplePayReq(connectorID)
let verifyAppleUrl = getURL(~entityName=VERIFY_APPLE_PAY, ~methodType=Post, ())
let _ = await updateAPIHook(`${verifyAppleUrl}/${merchantId}`, body, Post)
let _ = await updateAPIHook(`${verifyAppleUrl}/${merchantId}`, body, Post, ())

let updatedValue = values->constructApplePayMetadata(metadataInputs, #simplified)
update(updatedValue)
Expand Down
4 changes: 2 additions & 2 deletions src/screens/HyperSwitch/Developer/APIKeys/KeyManagement.res
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module ApiEditModal = {
| _ => APIUtils.getURL(~entityName=API_KEYS, ~methodType=Post, ())
}

let json = await updateDetails(url, body->Js.Json.object_, Post)
let json = await updateDetails(url, body->Js.Json.object_, Post, ())
let keyDict = json->LogicUtils.getDictFromJsonObject

setApiKey(_ => keyDict->LogicUtils.getString("api_key", ""))
Expand Down Expand Up @@ -222,7 +222,7 @@ module TableActionsCell = {
~id=Some(keyId),
(),
)
(await deleteDetails(deleteUrl, body->Js.Json.object_, Delete))->ignore
(await deleteDetails(deleteUrl, body->Js.Json.object_, Delete, ()))->ignore
getAPIKeyDetails()->ignore
} catch {
| Js.Exn.Error(e) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let make = (~webhookOnly=false, ~showFormOnly=false, ~profileId="") => {
setScreenState(_ => PageLoaderWrapper.Loading)
let url = getURL(~entityName=BUSINESS_PROFILE, ~methodType=Post, ~id=Some(id), ())
let body = values->getBusinessProfilePayload->Js.Json.object_
let res = await updateDetails(url, body, Post)
let res = await updateDetails(url, body, Post, ())
let profileTypeInfo = res->businessProfileTypeMapper
setProfileInfo(_ => profileTypeInfo)
showToast(~message=`Details updated`, ~toastType=ToastState.ToastSuccess, ())
Expand Down
4 changes: 2 additions & 2 deletions src/screens/HyperSwitch/FraudAndRisk/FRMIntegrationFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ let make = (
->Js.Json.object_
let url = getURL(~entityName=MERCHANT_ACCOUNT, ~methodType=Post, ())
try {
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
} catch {
| _ => ()
}
Js.Nullable.null
}

let setFRMValues = async body => {
fetchApi(frmUrl, body, Fetch.Post)
fetchApi(frmUrl, body, Fetch.Post, ())
->thenResolve(res => {
setCurrentStep(prev => prev->getNextStep)
let _ = updateMerchantDetails()
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/FraudAndRisk/FRMSummary.res
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ let make = (~initialValues, ~currentStep, ~setCurrentStep) => {
let frmID = initialValues->getDictFromJsonObject->getString("merchant_connector_id", "")
let disableFRMPayload = initialValues->FRMTypes.getDisableConnectorPayload(isFRMDisabled)
let url = getURL(~entityName=FRAUD_RISK_MANAGEMENT, ~methodType=Post, ~id=Some(frmID), ())
let _ = await updateDetails(url, disableFRMPayload->Js.Json.object_, Post)
let _ = await updateDetails(url, disableFRMPayload->Js.Json.object_, Post, ())
showToast(~message=`Successfully Saved the Changes`, ~toastType=ToastSuccess, ())
RescriptReactRouter.push("/fraud-risk-management")
} catch {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/HSwitchRemoteFilter.res
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ module RemoteTableFilters = {
setFilterDataJson(_ => None)
if startTimeVal->isStringNonEmpty && endTimeVal->isStringNonEmpty {
try {
updateDetails(filterUrl, filterBody->Js.Json.object_, Post)
updateDetails(filterUrl, filterBody->Js.Json.object_, Post, ())
->thenResolve(json => setFilterDataJson(_ => json->Some))
->catch(_ => resolve())
->ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ let make = (~connectProcessorValue: connectProcessor) => {
firstProcessorRoutingPayload,
secondProcessorRoutingPayload,
)
let routingResponse = await updateDetails(routingUrl, body, Post)
let routingResponse = await updateDetails(routingUrl, body, Post, ())
let activatingId = routingResponse->getDictFromJsonObject->getString("id", "")
let activateRuleURL = getURL(
~entityName=ROUTING,
~methodType=Post,
~id=Some(activatingId),
(),
)
let _ = await updateDetails(activateRuleURL, Dict.make()->Js.Json.object_, Post)
let _ = await updateDetails(activateRuleURL, Dict.make()->Js.Json.object_, Post, ())
let _ = await updateEnumForRouting(activatingId)
setButtonState(_ => Normal)
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ let make = (
~json=connectorName->Window.getConnectorConfig,
~profileId=activeBusinessProfile.profile_id,
)
let res = await updateDetails(url, testConnectorBody, Post)
let res = await updateDetails(url, testConnectorBody, Post, ())
connectorArray->Array.push(connectorName)
setConnectorArray(_ => connectorArray)
setInitialValues(_ => res)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ module SelectPaymentMethods = {
let body = ConnectorUtils.constructConnectorRequestBody(obj, initialValues)
let connectorUrl = APIUtils.getURL(~entityName=CONNECTOR, ~methodType=Post, ~id=None, ())

let response = await updateAPIHook(connectorUrl, body, Post)
let response = await updateAPIHook(connectorUrl, body, Post, ())

setInitialValues(_ => response)
connectorArray->Array.push(connectorName)
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/Home/DelayedVerificationBanner.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let make = React.memo((~merchantId="", ~verificationDays) => {
let body = email->HyperSwitchAuthUtils.getEmailBody()
try {
let url = getURL(~entityName=USERS, ~userType=#VERIFY_EMAIL_REQUEST, ~methodType=Post, ())
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
showToast(~message=`Email Send Successfully!`, ~toastType=ToastSuccess, ())
} catch {
| _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let make = (~showModal, ~setShowModal, ~initialValues=Dict.make(), ~getProdVerif
let url = getURL(~entityName=USERS, ~userType=#USER_DATA, ~methodType=Post, ())
let bodyValues = values->getBody->Js.Json.object_
let body = [("ProdIntent", bodyValues)]->LogicUtils.getJsonFromArrayOfJson
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
showToast(
~toastType=ToastSuccess,
~message="Successfully sent for verification!",
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/Home/QuickStart/GoLive.res
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let make = (~goLive) => {
let url = getURL(~entityName=USERS, ~userType=#USER_DATA, ~methodType=Post, ())
let bodyValues = values->getBody->Js.Json.object_
let body = [("ProdIntent", bodyValues)]->LogicUtils.getJsonFromArrayOfJson
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())

getProdVerifyDetails()->ignore
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module RequestPage = {
->Js.Json.object_

let body = [("Feedback", requestedBody)]->LogicUtils.getJsonFromArrayOfJson
let _ = await updateDetails(url, body, Post)
let _ = await updateDetails(url, body, Post, ())
showToast(
~toastType=ToastSuccess,
~message="Request submitted successfully!",
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/Hooks/EnumVariantHook.res
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ let usePostEnumDetails = () => {
try {
let url = getURL(~entityName=USERS, ~userType=#MERCHANT_DATA, ~methodType=Post, ())
let bodyValForApi = enumVariant->QuickStartUtils.generateBodyBasedOnType(body)
let _ = await updateDetails(url, bodyValForApi, Post)
let _ = await updateDetails(url, bodyValForApi, Post, ())

let updatedRecoilValueDict = updateEnumInRecoil([(body, enumVariant)])
Js.Nullable.return(updatedRecoilValueDict)
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/Order/OrderRefundForm.res
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let make = (
let updateRefundDetails = async body => {
try {
let refundsUrl = getURL(~entityName=REFUNDS, ~methodType=Post, ())
let res = await updateDetails(refundsUrl, body, Post)
let res = await updateDetails(refundsUrl, body, Post, ())
let refundStatus = res->LogicUtils.getDictFromJsonObject->LogicUtils.getString("status", "")
refetch()
switch refundStatus->statusVariantMapper {
Expand Down
Loading
Loading