From dcb4c774e6404aa8cb60cce4a01768dbf6c9e801 Mon Sep 17 00:00:00 2001 From: Praful Koppalkar Date: Fri, 22 Mar 2024 19:03:02 +0530 Subject: [PATCH] fix(3ds method iframe): 3ds failing for with no cors and color depth for higher resolution error --- src/BrowserSpec.res | 46 +++++++++++++++++--------------- src/Utilities/PaymentHelpers.res | 3 ++- src/Utilities/Utils.res | 30 +++++++++++++++++++++ 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/BrowserSpec.res b/src/BrowserSpec.res index 342f0d676..02f7f1bfc 100644 --- a/src/BrowserSpec.res +++ b/src/BrowserSpec.res @@ -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, + ), + ] +} diff --git a/src/Utilities/PaymentHelpers.res b/src/Utilities/PaymentHelpers.res index 2f8e3d13c..853e5f33e 100644 --- a/src/Utilities/PaymentHelpers.res +++ b/src/Utilities/PaymentHelpers.res @@ -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 }) diff --git a/src/Utilities/Utils.res b/src/Utilities/Utils.res index f1226ee5e..a0b8684d9 100644 --- a/src/Utilities/Utils.res +++ b/src/Utilities/Utils.res @@ -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, ()), },