Skip to content

Commit

Permalink
fix: stable-release
Browse files Browse the repository at this point in the history
  • Loading branch information
JeevaRamu0104 committed May 29, 2024
1 parent 31adb41 commit 620c73f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
6 changes: 3 additions & 3 deletions src/screens/SDKPayment/SDKPaymentUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
}
}
Expand Down Expand Up @@ -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,
Expand Down
83 changes: 41 additions & 42 deletions src/screens/SDKPayment/WebSDK.res
Original file line number Diff line number Diff line change
Expand Up @@ -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(_ => {
Expand Down Expand Up @@ -230,7 +229,7 @@ module CheckoutForm = {
customButtonStyle={`p-1 mt-2 w-full rounded-md ${primaryColor}`}
onClick={_ => {
setBtnState(_ => Button.Loading)
handleSubmit()
handleSubmit()->ignore
}}
/>
</div>
Expand Down

0 comments on commit 620c73f

Please sign in to comment.