Skip to content

Commit

Permalink
fix(3ds method iframe): 3ds failing for with no cors and color depth …
Browse files Browse the repository at this point in the history
…for higher resolution error
  • Loading branch information
prafulkoppalkar committed Mar 22, 2024
1 parent 9387515 commit dcb4c77
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 22 deletions.
46 changes: 25 additions & 21 deletions src/BrowserSpec.res
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,28 @@ let checkIsSafari = () => {
}

let date = date()
let broswerInfo = () => [
(
"browser_info",
[
("user_agent", navigator.userAgent->JSON.Encode.string),
(
"accept_header",
"text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8"->JSON.Encode.string,
),
("language", navigator.language->JSON.Encode.string),
("color_depth", screen.colorDepth->Belt.Int.toFloat->JSON.Encode.float),
("screen_height", screen.height->Belt.Int.toFloat->JSON.Encode.float),
("screen_width", screen.width->Belt.Int.toFloat->JSON.Encode.float),
("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,
),
]
let broswerInfo = () => {
let colorDepth =
[1, 4, 8, 15, 16, 24, 32, 48]->Array.includes(screen.colorDepth) ? screen.colorDepth : 24
[
(
"browser_info",
[
("user_agent", navigator.userAgent->JSON.Encode.string),
(
"accept_header",
"text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8"->JSON.Encode.string,
),
("language", navigator.language->JSON.Encode.string),
("color_depth", colorDepth->Belt.Int.toFloat->JSON.Encode.float),
("screen_height", screen.height->Belt.Int.toFloat->JSON.Encode.float),
("screen_width", screen.width->Belt.Int.toFloat->JSON.Encode.float),
("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,
),
]
}
3 changes: 2 additions & 1 deletion src/Utilities/PaymentHelpers.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ let threeDsMethod = (url, threeDsMethodData, ~optLogger) => {
)
let threeDsMethodStr = threeDsMethodData->JSON.Decode.string->Option.getOr("")
let body = `${encodeURIComponent("threeDSMethodData")}=${encodeURIComponent(threeDsMethodStr)}`
fetchApi(url, ~method=#POST, ~bodyStr=body, ())

fetchApiWithNoCors(url, ~method=#POST, ~bodyStr=body, ())
->then(res => {
res->Fetch.Response.text
})
Expand Down
30 changes: 30 additions & 0 deletions src/Utilities/Utils.res
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,42 @@ let fetchApi = (uri, ~bodyStr: string="", ~headers=Dict.make(), ~method: Fetch.m
| #GET => resolve(None)
| _ => resolve(Some(Fetch.Body.string(bodyStr)))
}
body->then(body => {
Fetch.fetch(
uri,
{
method,
?body,
headers: getHeaders(~headers, ~uri, ()),
},
)
->catch(err => {
reject(err)
})
->then(resp => {
resolve(resp)
})
})
}

let fetchApiWithNoCors = (
uri,
~bodyStr: string="",
~headers=Dict.make(),
~method: Fetch.method,
(),
) => {
open Promise
let body = switch method {
| #GET => resolve(None)
| _ => resolve(Some(Fetch.Body.string(bodyStr)))
}
body->then(body => {
Fetch.fetch(
uri,
{
method,
mode: #"no-cors",
?body,
headers: getHeaders(~headers, ~uri, ()),
},
Expand Down

0 comments on commit dcb4c77

Please sign in to comment.