Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert changes for hyper.res #548

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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
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
Loading