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
6 changes: 6 additions & 0 deletions src/LoaderController.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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)
Expand Down Expand Up @@ -444,6 +445,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
Expand Down
12 changes: 12 additions & 0 deletions src/Payments/PreMountLoader.res
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,25 @@ let getMessageHandlerV2Elements = (
~endpoint,
)

let getIntentPromise = PaymentHelpersV2.fetchIntent(
~clientSecret,
~paymentId,
~profileId,
~publishableKey,
~logger,
~customPodUri,
~endpoint,
)

ev => {
open Utils
let dict = ev.data->safeParse->getDictFromJson
if dict->isKeyPresentInDict("sendPaymentMethodsListV2Response") {
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")
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Types/UnifiedPaymentsTypesV2.res
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ type paymentListLookupNew = {
walletsList: array<string>,
otherPaymentList: array<string>,
}

type intentCall = {paymentType: PaymentMethodsRecord.payment_type}

type intentLoadState = LoadingIntent | LoadedIntent(intentCall) | Error(JSON.t)
134 changes: 75 additions & 59 deletions src/Utilities/APIHelpers/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,36 @@ type apiCallV1 =
| ConfirmPayout
| FetchBlockedBins

type apiCallV2 = FetchSessionsV2
type apiCallV2 = FetchSessionsV2 | FetchIntent

type apiCall =
| V1(apiCallV1)
| V2(apiCallV2)

type apiParams = {
clientSecret: option<string>,
type commonApiParams = {
publishableKey: option<string>,
customBackendBaseUrl: option<string>,
}

type apiParamsV2 = {...commonApiParams, paymentIdV2: option<string>}

type apiParamsV1 = {
...commonApiParams,
clientSecret: option<string>,
paymentMethodId: option<string>,
forceSync: option<string>,
pollId: option<string>,
payoutId: option<string>,
}

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,
Expand All @@ -53,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
}

Expand All @@ -79,50 +83,62 @@ let generateApiUrl = (apiCallType: apiCall, ~params: apiParams) => {
}->List.filterMap(x => x)

let queryParams = switch apiCallType {
| V1(inner) =>
switch inner {
| FetchPaymentMethodList
| FetchCustomerPaymentMethodList
| RetrievePaymentIntent => defaultParams
| FetchBlockedBins => list{("data_kind", "card_bin"), ...defaultParams}
| FetchSessions
| FetchThreeDsAuth
| FetchSavedPaymentMethodList
| DeletePaymentMethod
| CalculateTax
| CreatePaymentMethod
| CallAuthLink
| CallAuthExchange
| RetrieveStatus
| ConfirmPayout =>
list{}
}
| V2(_) => list{}
| FetchPaymentMethodList
| FetchCustomerPaymentMethodList
| RetrievePaymentIntent => defaultParams
| FetchBlockedBins => list{("data_kind", "card_bin"), ...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`
| FetchBlockedBins => "blocklist"
}
| V2(inner) =>
switch inner {
| FetchSessionsV2 => `v2/payments/${paymentIntentID}/create-external-sdk-tokens`
}
| 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`
| FetchBlockedBins => "blocklist"
}

`${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)}`
}
56 changes: 28 additions & 28 deletions src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -99,8 +99,8 @@ let fetchBlockedBins = 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,
Expand Down Expand Up @@ -201,8 +201,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),
Expand Down Expand Up @@ -1398,8 +1398,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,
Expand Down Expand Up @@ -1439,8 +1439,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),
Expand Down Expand Up @@ -1482,8 +1482,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),
Expand Down Expand Up @@ -1524,8 +1524,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),
Expand Down Expand Up @@ -1561,8 +1561,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),
Expand Down Expand Up @@ -1668,8 +1668,8 @@ let callAuthLink = async (
~iframeId,
~logger,
) => {
let uri = APIUtils.generateApiUrl(
V1(CallAuthLink),
let uri = APIUtils.generateApiUrlV1(
~apiCallType=CallAuthLink,
~params={
clientSecret: None,
publishableKey: Some(publishableKey),
Expand Down Expand Up @@ -1732,8 +1732,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),
Expand Down Expand Up @@ -1805,8 +1805,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,
Expand Down Expand Up @@ -1836,8 +1836,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,
Expand Down Expand Up @@ -1874,8 +1874,8 @@ let calculateTax = async (
~customPodUri,
~sessionId,
) => {
let uri = APIUtils.generateApiUrl(
V1(CalculateTax),
let uri = APIUtils.generateApiUrlV1(
~apiCallType=CalculateTax,
~params={
customBackendBaseUrl: None,
clientSecret: Some(clientSecret),
Expand Down
Loading
Loading