@@ -303,7 +303,6 @@ let rec intentCall = (
303
303
) => {
304
304
open Promise
305
305
let isConfirm = uri -> String .includes ("/confirm" )
306
-
307
306
let isCompleteAuthorize = uri -> String .includes ("/complete_authorize" )
308
307
let isPostSessionTokens = uri -> String .includes ("/post_session_tokens" )
309
308
let (eventName : HyperLogger .eventName , initEventName : HyperLogger .eventName ) = switch (
@@ -332,6 +331,8 @@ let rec intentCall = (
332
331
openUrl (url )
333
332
}
334
333
}
334
+ Console .log ("inside intent Call" )
335
+
335
336
fetchApi (
336
337
uri ,
337
338
~method = fetchMethod ,
@@ -344,9 +345,13 @@ let rec intentCall = (
344
345
url .searchParams .set ("payment_intent_client_secret" , clientSecret )
345
346
url .searchParams .set ("status" , "failed" )
346
347
url .searchParams .set ("payment_id" , clientSecret -> getPaymentId )
348
+ Console .log ("Message parent window" )
349
+
347
350
messageParentWindow ([("confirmParams" , confirmParam -> anyTypeToJson )])
348
351
349
352
if statusCode -> String .charAt (0 ) !== "2" {
353
+ Console .log2 ("statusCode !==2" , statusCode )
354
+
350
355
res
351
356
-> Fetch .Response .json
352
357
-> then (data => {
@@ -469,9 +474,11 @@ let rec intentCall = (
469
474
)-> then (resolve )
470
475
})
471
476
} else {
477
+ Console .log ("status code ===2" )
472
478
res
473
479
-> Fetch .Response .json
474
480
-> then (data => {
481
+ Console .log2 ("statusCode" , statusCode )
475
482
Promise .make (
476
483
(resolve , _ ) => {
477
484
logApi (
@@ -527,7 +534,10 @@ let rec intentCall = (
527
534
}
528
535
529
536
if intent .status == "requires_customer_action" {
537
+ Console .log ("redirect to url" )
530
538
if intent .nextAction .type_ == "redirect_to_url" {
539
+ Console .log2 ("redirect to url inside" , intent .nextAction .redirectToUrl )
540
+
531
541
handleLogging (
532
542
~optLogger ,
533
543
~value = "" ,
@@ -654,6 +664,36 @@ let rec intentCall = (
654
664
("metadata" , metaData -> JSON .Encode .object ),
655
665
])
656
666
}
667
+ } else if intent .nextAction .type_ === "invoke_hidden_iframe" {
668
+ Console .log ("Invoke hidden iframe" )
669
+ let iframeData =
670
+ intent .nextAction .iframe_data
671
+ -> Option .flatMap (JSON .Decode .object )
672
+ -> Option .getOr (Dict .make ())
673
+
674
+ let headerObj = Dict .make ()
675
+ headers -> Array .forEach (
676
+ entries => {
677
+ let (x , val ) = entries
678
+ Dict .set (headerObj , x , val -> JSON .Encode .string )
679
+ },
680
+ )
681
+ let metaData =
682
+ [
683
+ ("iframeData" , iframeData -> JSON .Encode .object ),
684
+ ("paymentIntentId" , clientSecret -> JSON .Encode .string ),
685
+ ("publishableKey" , confirmParam .publishableKey -> JSON .Encode .string ),
686
+ ("headers" , headerObj -> JSON .Encode .object ),
687
+ ("url" , url .href -> JSON .Encode .string ),
688
+ ("iframeId" , iframeId -> JSON .Encode .string ),
689
+ ]-> Dict .fromArray
690
+
691
+ messageParentWindow ([
692
+ ("fullscreen" , true -> JSON .Encode .bool ),
693
+ ("param" , ` redsys3ds`-> JSON .Encode .string ),
694
+ ("iframeId" , iframeId -> JSON .Encode .string ),
695
+ ("metadata" , metaData -> JSON .Encode .object ),
696
+ ])
657
697
} else if intent .nextAction .type_ === "display_voucher_information" {
658
698
let voucherData = intent .nextAction .voucher_details -> Option .getOr ({
659
699
download_url : "" ,
@@ -834,6 +874,8 @@ let rec intentCall = (
834
874
}
835
875
})
836
876
-> catch (err => {
877
+ Console .log ("fetch api fail" )
878
+
837
879
Promise .make ((resolve , _ ) => {
838
880
try {
839
881
let url = makeUrl (confirmParam .return_url )
@@ -916,6 +958,26 @@ let rec intentCall = (
916
958
})
917
959
}
918
960
961
+ // let redsys3dsAuth = (~clientSecret, ~threeDsMethodComp, ~headers) => {
962
+ // let endpoint = ApiEndpoint.getApiEndPoint()
963
+ // let paymentIntentID = String.split(clientSecret, "_secret_")[0]->Option.getOr("")
964
+ // let url = `${endpoint}/payments/${paymentIntentID}/complete_authorize`
965
+ // let body =
966
+ // [
967
+ // ("client_secret", clientSecret->JSON.Encode.string),
968
+ // ("threeds_method_comp_ind", threeDsMethodComp->JSON.Encode.string),
969
+ // ]->getJsonFromArrayOfJson
970
+ // // open Promise
971
+ // // fetchApi(url, ~method=#POST, ~bodyStr=body->JSON.stringify, ~headers=headers->Dict.fromArray)
972
+ // // ->then(res => {
973
+ // // Console.log2("completeAuthorize", res)
974
+ // // resolve(res)
975
+ // // })
976
+ // // ->catch(err => reject(err))
977
+
978
+ // intentCall(~fetchApi, ~uri=url, ~headers, ~bodyStr=body->JSON.stringify)
979
+ // }
980
+
919
981
let usePaymentSync = (optLogger : option <HyperLogger .loggerMake >, paymentType : payment ) => {
920
982
open RecoilAtoms
921
983
let paymentMethodList = Recoil .useRecoilValueFromAtom (paymentMethodList )
@@ -1177,6 +1239,67 @@ let usePaymentIntent = (optLogger, paymentType) => {
1177
1239
}
1178
1240
}
1179
1241
1242
+ let useRedsysCompleteAuthorize = (optLogger : option <HyperLogger .loggerMake >) => {
1243
+ open RecoilAtoms
1244
+ let customPodUri = Recoil .useRecoilValueFromAtom (customPodUri )
1245
+ let setIsManualRetryEnabled = Recoil .useSetRecoilState (isManualRetryEnabled )
1246
+ let isCallbackUsedVal = Recoil .useRecoilValueFromAtom (RecoilAtoms .isCompleteCallbackUsed )
1247
+ let redirectionFlags = Recoil .useRecoilValueFromAtom (redirectionFlagsAtom )
1248
+
1249
+ (
1250
+ ~handleUserError = false ,
1251
+ ~bodyArr : array <(string , JSON .t )>,
1252
+ ~confirmParam : ConfirmType .confirmParams ,
1253
+ ~iframeId = "redsys3ds" ,
1254
+ ~clientSecret ,
1255
+ ~headers ,
1256
+ ) => {
1257
+ Console .log ("intentCall" )
1258
+ switch clientSecret {
1259
+ | Some (clientSecret ) =>
1260
+ let paymentIntentID = clientSecret -> getPaymentId
1261
+ Console .log ("some clientSecret" )
1262
+ let endpoint = ApiEndpoint .getApiEndPoint (~publishableKey = confirmParam .publishableKey )
1263
+ let uri = ` ${endpoint}/payments/${paymentIntentID}/complete_authorize`
1264
+
1265
+ let bodyStr =
1266
+ [("client_secret" , clientSecret -> JSON .Encode .string )]
1267
+ -> Array .concatMany ([bodyArr ])
1268
+ -> getJsonFromArrayOfJson
1269
+ -> JSON .stringify
1270
+
1271
+ let completeAuthorize = () => {
1272
+ intentCall (
1273
+ ~fetchApi ,
1274
+ ~uri ,
1275
+ ~headers ,
1276
+ ~bodyStr ,
1277
+ ~confirmParam : ConfirmType .confirmParams ,
1278
+ ~clientSecret ,
1279
+ ~optLogger ,
1280
+ ~handleUserError ,
1281
+ ~paymentType = Redsys3ds ,
1282
+ ~iframeId ,
1283
+ ~fetchMethod = #POST ,
1284
+ ~setIsManualRetryEnabled ,
1285
+ ~customPodUri ,
1286
+ ~sdkHandleOneClickConfirmPayment = false ,
1287
+ ~counter = 0 ,
1288
+ ~isCallbackUsedVal ,
1289
+ ~redirectionFlags ,
1290
+ )-> ignore
1291
+ }
1292
+
1293
+ completeAuthorize ()
1294
+
1295
+ | None =>
1296
+ postFailedSubmitResponse (
1297
+ ~errortype = "complete_authorize_failed" ,
1298
+ ~message = "Complete Authorize Failed. Try Again!" ,
1299
+ )
1300
+ }
1301
+ }
1302
+ }
1180
1303
let useCompleteAuthorize = (optLogger : option <HyperLogger .loggerMake >, paymentType : payment ) => {
1181
1304
open RecoilAtoms
1182
1305
let paymentMethodList = Recoil .useRecoilValueFromAtom (paymentMethodList )
0 commit comments