diff --git a/src/screens/SDKPayment/SDKPaymentUtils.res b/src/screens/SDKPayment/SDKPaymentUtils.res index b69af1555..68459b9bc 100644 --- a/src/screens/SDKPayment/SDKPaymentUtils.res +++ b/src/screens/SDKPayment/SDKPaymentUtils.res @@ -49,11 +49,11 @@ let initialValueForForm: HSwitchSettingTypes.profileEntity => SDKPaymentTypes.pa order_details: { product_name: "Apple iphone 15", quantity: 1, - amount: 100.00, + amount: 10000.00, }, }, capture_method: "automatic", - amount_to_capture: Nullable.make(100.00), + amount_to_capture: Nullable.make(10000.00), return_url: `${Window.Location.origin}${Window.Location.pathName}`, } } @@ -94,7 +94,7 @@ let getTypedValueForPayment: JSON.t => SDKPaymentTypes.paymentType = values => { }, }, } - let amount = dictOfValues->getFloat("amount", 100.00) + let amount = dictOfValues->getFloat("amount", 10000.00) { amount, diff --git a/src/screens/SDKPayment/WebSDK.res b/src/screens/SDKPayment/WebSDK.res index b238ffdc0..73222a8af 100644 --- a/src/screens/SDKPayment/WebSDK.res +++ b/src/screens/SDKPayment/WebSDK.res @@ -158,50 +158,49 @@ module CheckoutForm = { None }, (layout, elements, methodsOrder)) - let handleSubmit = () => { - let confirmParams = - [ - ( - "confirmParams", - [("return_url", returnUrl->JSON.Encode.string)]->Dict.fromArray->JSON.Encode.object, - ), - ("redirect", "always"->JSON.Encode.string), - ]->LogicUtils.getJsonFromArrayOfJson - hyper.confirmPayment(confirmParams) - ->then(val => { - let resDict = val->JSON.Decode.object->Option.getOr(Dict.make()) - let errorDict = - resDict->Dict.get("error")->Option.flatMap(JSON.Decode.object)->Option.getOr(Dict.make()) - - let errorMsg = errorDict->Dict.get("message") - - switch errorMsg { - | Some(val) => { - let str = - val - ->LogicUtils.getStringFromJson("") - ->String.replace("\"", "") - ->String.replace("\"", "") - if str == "Something went wrong" { - setPaymentStatus(_ => CUSTOMSTATE) - setError(_ => None) - } else { - setPaymentStatus(_ => FAILED(val->LogicUtils.getStringFromJson(""))) - setError(_ => errorMsg) - } + let handleSubmit = async () => { + open LogicUtils + try { + let confirmParams = + [ + ( + "confirmParams", + [ + ("return_url", returnUrl->JSON.Encode.string), + ("redirect", "always"->JSON.Encode.string), + ] + ->Dict.fromArray + ->JSON.Encode.object, + ), + ]->getJsonFromArrayOfJson + let res = await hyper.confirmPayment(confirmParams) + let status = res->getDictFromJsonObject->getOptionString("status") + switch status { + | Some(str) => + switch str { + | "failed" => setPaymentStatus(_ => FAILED("Failed")) + | "succeeded" => setPaymentStatus(_ => SUCCESS) + | _ => setPaymentStatus(_ => CUSTOMSTATE) } - - | _ => () + | None => setPaymentStatus(_ => CUSTOMSTATE) } - setClientSecret(_ => None) - - setError(_ => errorMsg) - setBtnState(_ => Button.Normal) - - resolve() - }) - ->ignore + } catch { + | Exn.Error(e) => { + let err = Exn.message(e)->Option.getOr("Failed to Fetch!") + let str = err->String.replace("\"", "")->String.replace("\"", "") + if str == "Something went wrong" { + setPaymentStatus(_ => CUSTOMSTATE) + setError(_ => None) + } else { + setPaymentStatus(_ => FAILED(err)) + setError(_ => Some(err)) + } + } + } + setClientSecret(_ => None) + setBtnState(_ => Button.Normal) } + React.useEffect1(() => { hyper.retrievePaymentIntent(clientSecret) ->then(_ => { @@ -230,7 +229,7 @@ module CheckoutForm = { customButtonStyle={`p-1 mt-2 w-full rounded-md ${primaryColor}`} onClick={_ => { setBtnState(_ => Button.Loading) - handleSubmit() + handleSubmit()->ignore }} />