Skip to content

Commit

Permalink
revert: revert changes for hyper.res
Browse files Browse the repository at this point in the history
  • Loading branch information
Saksham Sharma authored and Saksham Sharma committed Aug 7, 2024
1 parent 6633c2d commit 6d534a1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 49 deletions.
4 changes: 2 additions & 2 deletions Hyperswitch-React-Demo-App/src/CheckoutForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ export default function CheckoutForm() {
return;
}
hyper.retrievePaymentIntent(clientSecret).then(({ paymentIntent }) => {
console.log("-retrieve called", paymentIntent.status);
handlePaymentStatus(paymentIntent.status);
console.log("-retrieve called", paymentIntent?.status);
handlePaymentStatus(paymentIntent?.status);
});
}, [hyper, navigate]);

Expand Down
98 changes: 51 additions & 47 deletions src/orca-loader/Hyper.res
Original file line number Diff line number Diff line change
Expand Up @@ -291,43 +291,45 @@ let make = (publishableKey, options: option<JSON.t>, analyticsInfo: option<JSON.
let handleMessage = (event: Types.event) => {
let json = event.data->anyTypeToJson
let dict = json->getDictFromJson
let submitSuccessful =
dict->Dict.get("submitSuccessful")->getBoolFromOptionalJson(false)

logApi(
~apiLogType=Method,
~optLogger=Some(logger),
~result=JSON.Encode.bool(submitSuccessful),
~paymentMethod="confirmPayment",
~eventName=CONFIRM_PAYMENT,
)
let data = dict->getDictFromDict("data")->JSON.Encode.object
let returnUrl = dict->getString("url", url)

if isOneClick {
iframeRef.contents->Array.forEach(
ifR => {
// to unset one click button loader
ifR->Window.iframePostMessage(
[("oneClickDoSubmit", false->JSON.Encode.bool)]->Dict.fromArray,
)
},
switch dict->Dict.get("submitSuccessful") {
| Some(val) =>
logApi(
~apiLogType=Method,
~optLogger=Some(logger),
~result=val,
~paymentMethod="confirmPayment",
~eventName=CONFIRM_PAYMENT,
)
}
postSubmitMessage(dict)

if isSdkButton {
if !submitSuccessful {
let data = dict->Dict.get("data")->Option.getOr(Dict.make()->JSON.Encode.object)
let returnUrl =
dict->Dict.get("url")->Option.flatMap(JSON.Decode.string)->Option.getOr(url)

if isOneClick {
iframeRef.contents->Array.forEach(
ifR => {
// to unset one click button loader
ifR->Window.iframePostMessage(
[("oneClickDoSubmit", false->JSON.Encode.bool)]->Dict.fromArray,
)
},
)
}
postSubmitMessage(dict)

if isSdkButton {
if !(val->JSON.Decode.bool->Option.getOr(false)) {
resolve1(json)
} else {
Window.replace(returnUrl)
}
} else if val->JSON.Decode.bool->Option.getOr(false) && redirect === "always" {
Window.replace(returnUrl)
} else if !(val->JSON.Decode.bool->Option.getOr(false)) {
resolve1(json)
} else {
Window.replace(returnUrl)
resolve1(data)
}
} else if submitSuccessful && redirect === "always" {
Window.replace(returnUrl)
} else if !submitSuccessful {
resolve1(json)
} else {
resolve1(data)
| None => ()
}
}
let message = isOneClick
Expand Down Expand Up @@ -487,20 +489,22 @@ let make = (publishableKey, options: option<JSON.t>, analyticsInfo: option<JSON.
let handleMessage = (event: Types.event) => {
let json = event.data->anyTypeToJson
let dict = json->getDictFromJson
let submitSuccessful =
dict->Dict.get("submitSuccessful")->getBoolFromOptionalJson(false)
logApi(
~apiLogType=Method,
~optLogger=Some(logger),
~result=JSON.Encode.bool(submitSuccessful),
~paymentMethod="confirmCardPayment",
~eventName=CONFIRM_CARD_PAYMENT,
)
let url = decodedData->getString("return_url", "/")
if submitSuccessful && url !== "/" {
Window.replace(url)
} else {
resolve(json)
switch dict->Dict.get("submitSuccessful") {
| Some(val) =>
logApi(
~apiLogType=Method,
~optLogger=Some(logger),
~result=val,
~paymentMethod="confirmCardPayment",
~eventName=CONFIRM_CARD_PAYMENT,
)
let url = decodedData->getString("return_url", "/")
if val->JSON.Decode.bool->Option.getOr(false) && url !== "/" {
Window.replace(url)
} else {
resolve(json)
}
| None => resolve(json)
}
}
addSmartEventListener("message", handleMessage, "")
Expand Down

0 comments on commit 6d534a1

Please sign in to comment.