Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion src/Utilities/APIHelpers/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ type apiCallV1 =
| RetrieveStatus
| ConfirmPayout

type apiCallV2 = FetchSessionsV2
type apiCallV2 =
| FetchSessionsV2
| DeletePaymentMethodV2

type apiCall =
| V1(apiCallV1)
Expand All @@ -27,6 +29,7 @@ type apiParams = {
forceSync: option<string>,
pollId: option<string>,
payoutId: option<string>,
pmSessionId: option<string>,
}

let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => {
Expand All @@ -38,6 +41,7 @@ let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => {
forceSync,
pollId,
payoutId,
pmSessionId,
} = params

let clientSecretVal = clientSecret->Option.getOr("")
Expand All @@ -46,6 +50,7 @@ let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => {
let paymentMethodIdVal = paymentMethodId->Option.getOr("")
let pollIdVal = pollId->Option.getOr("")
let payoutIdVal = payoutId->Option.getOr("")
let pmSessionIdVal = pmSessionId->Option.getOr("")

let baseUrl =
customBackendBaseUrl->Option.getOr(
Expand Down Expand Up @@ -118,6 +123,7 @@ let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => {
| V2(inner) =>
switch inner {
| FetchSessionsV2 => `v2/payments/${paymentIntentID}/create-external-sdk-tokens`
| DeletePaymentMethodV2 => `v2/payment-method-sessions/${pmSessionIdVal}`
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ let retrievePaymentIntent = async (
forceSync: isForceSync ? Some("true") : None,
pollId: None,
payoutId: None,
pmSessionId: None,
},
)

Expand Down Expand Up @@ -73,6 +74,7 @@ let threeDsAuth = async (~clientSecret, ~logger, ~threeDsMethodComp, ~headers) =
forceSync: None,
pollId: None,
payoutId: None,
pmSessionId: None,
},
)
let broswerInfo = BrowserSpec.broswerInfo
Expand Down Expand Up @@ -175,6 +177,7 @@ let retrieveStatus = async (~publishableKey, ~customPodUri, pollID, logger) => {
forceSync: None,
pollId: Some(pollID),
payoutId: None,
pmSessionId: None,
},
)

Expand Down Expand Up @@ -1372,6 +1375,7 @@ let fetchSessions = async (
forceSync: None,
pollId: None,
payoutId: None,
pmSessionId: None,
},
)

Expand Down Expand Up @@ -1413,6 +1417,7 @@ let confirmPayout = async (
forceSync: None,
pollId: None,
payoutId: Some(payoutId),
pmSessionId: None,
},
)

Expand Down Expand Up @@ -1456,6 +1461,7 @@ let createPaymentMethod = async (
forceSync: None,
pollId: None,
payoutId: None,
pmSessionId: None,
},
)

Expand Down Expand Up @@ -1498,6 +1504,7 @@ let fetchPaymentMethodList = async (
forceSync: None,
pollId: None,
payoutId: None,
pmSessionId: None,
},
)

Expand Down Expand Up @@ -1535,6 +1542,7 @@ let fetchCustomerPaymentMethodList = async (
forceSync: None,
pollId: None,
payoutId: None,
pmSessionId: None,
},
)

Expand Down Expand Up @@ -1642,6 +1650,7 @@ let callAuthLink = async (
forceSync: None,
pollId: None,
payoutId: None,
pmSessionId: None,
},
)

Expand Down Expand Up @@ -1706,6 +1715,7 @@ let callAuthExchange = async (
forceSync: None,
pollId: None,
payoutId: None,
pmSessionId: None,
},
)

Expand Down Expand Up @@ -1779,6 +1789,7 @@ let fetchSavedPaymentMethodList = async (
forceSync: None,
pollId: None,
payoutId: None,
pmSessionId: None,
},
)

Expand Down Expand Up @@ -1810,6 +1821,7 @@ let deletePaymentMethod = async (~ephemeralKey, ~paymentMethodId, ~logger, ~cust
forceSync: None,
pollId: None,
payoutId: None,
pmSessionId: None,
},
)

Expand Down Expand Up @@ -1848,6 +1860,7 @@ let calculateTax = async (
forceSync: None,
pollId: None,
payoutId: None,
pmSessionId: None,
},
)
let onSuccess = data => data
Expand Down
58 changes: 33 additions & 25 deletions src/Utilities/PaymentHelpersV2.res
Original file line number Diff line number Diff line change
Expand Up @@ -299,46 +299,54 @@ let fetchPaymentManagementList = (
})
}

let deletePaymentMethodV2 = (
let deletePaymentMethodV2 = async(
~pmClientSecret,
~publishableKey,
~profileId,
~paymentMethodId,
~pmSessionId,
~logger as _,
~logger,
~customPodUri,
) => {
open Promise
let endpoint = ApiEndpoint.getApiEndPoint()
let headers = [
("x-profile-id", `${profileId}`),
("Authorization", `publishable-key=${publishableKey},client-secret=${pmClientSecret}`),
]
let uri = `${endpoint}/v2/payment-method-sessions/${pmSessionId}`
fetchApi(

let uri = APIUtils.generateApiUrl(
V2(DeletePaymentMethodV2),
~params={
customBackendBaseUrl: None,
clientSecret: None,
publishableKey: Some(publishableKey),
paymentMethodId: None,
forceSync: None,
pollId: None,
payoutId: None,
pmSessionId: Some(pmSessionId),
},
)

let bodyStr = [("payment_method_id", paymentMethodId->JSON.Encode.string)]
->getJsonFromArrayOfJson
->JSON.stringify

let onSuccess = data => data

let onFailure = _ => JSON.Encode.null

await fetchApiWithLogging(
uri,
~eventName=DELETE_PAYMENT_METHODS_CALL,
~logger,
~method=#DELETE,
~bodyStr,
~headers=headers->ApiEndpoint.addCustomPodHeader(~customPodUri),
~bodyStr=[("payment_method_id", paymentMethodId->JSON.Encode.string)]
->getJsonFromArrayOfJson
->JSON.stringify,
~customPodUri=Some(customPodUri),
~publishableKey=Some(publishableKey),
~onSuccess,
~onFailure,
)
->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 updatePaymentMethod = (
Expand Down
1 change: 1 addition & 0 deletions src/hyper-loader/Hyper.res
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ let make = (keys, options: option<JSON.t>, analyticsInfo: option<JSON.t>) => {
forceSync: None,
pollId: None,
payoutId: None,
pmSessionId: None,
},
)

Expand Down