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: SDK Refresh issue #42

Merged
merged 3 commits into from
Dec 1, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ let make = (~connectProcessorValue: connectProcessor) => {
onClick={_ => updateTestPaymentEnum(~paymentId="pay_default")->ignore}
/>}>
<TestPayment
initialValues={activeBusinessProfile.profile_id->SDKPaymentUtils.initialValueForForm}
initialValues={activeBusinessProfile->SDKPaymentUtils.initialValueForForm}
returnUrl={`${HSwitchGlobalVars.hyperSwitchFEPrefix}/quick-start`}
onProceed={updateTestPaymentEnum}
keyValue=key
Expand Down
17 changes: 12 additions & 5 deletions src/screens/HyperSwitch/SDKPayment/SDKPage.res
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
let h3Leading2Style = HSwitchUtils.getTextClass(~textVariant=H3, ~h3TextVariant=Leading_2, ())
external toJson: 'a => Js.Json.t = "%identity"

module SDKConfifiguarationFields = {
module SDKConfiguarationFields = {
open HSwitchMerchantAccountUtils
@react.component
let make = () => {
let make = (~initialValues: SDKPaymentTypes.paymentType) => {
let businessProfiles = Recoil.useRecoilValueFromAtom(HyperswitchAtom.businessProfilesAtom)
let arrayOfBusinessProfile = businessProfiles->getArrayOfBusinessProfile
let disableSelectionForProfile = arrayOfBusinessProfile->HomeUtils.isDefaultBusinessProfile
Expand Down Expand Up @@ -70,7 +70,9 @@ module SDKConfifiguarationFields = {
<FormRenderer.FieldRenderer field=selectProfileId fieldWrapperClass="!w-full" />
<FormRenderer.FieldRenderer field=selectCurrencyField fieldWrapperClass="!w-full" />
<FormRenderer.FieldRenderer field=enterAmountField fieldWrapperClass="!w-full" />
<FormRenderer.SubmitButton text="Show preview" />
<FormRenderer.SubmitButton
text="Show preview" disabledParamter={!(initialValues.profile_id->Js.String2.length > 0)}
/>
</>
}
}
Expand All @@ -86,7 +88,7 @@ let make = () => {
let businessProfiles = Recoil.useRecoilValueFromAtom(HyperswitchAtom.businessProfilesAtom)
let defaultBusinessProfile = businessProfiles->getValueFromBusinessProfile
let (initialValues, setInitialValues) = React.useState(_ =>
defaultBusinessProfile.profile_id->SDKPaymentUtils.initialValueForForm
defaultBusinessProfile->SDKPaymentUtils.initialValueForForm
)
React.useEffect1(() => {
let paymentIntentOptional = filtersFromUrl->Js.Dict.get("payment_intent_client_secret")
Expand All @@ -96,6 +98,11 @@ let make = () => {
None
}, [filtersFromUrl])

React.useEffect1(() => {
setInitialValues(_ => defaultBusinessProfile->SDKPaymentUtils.initialValueForForm)
None
}, [defaultBusinessProfile.profile_id->Js.String2.length])

let onProceed = async (~paymentId as _) => {
let paymentId =
filtersFromUrl
Expand Down Expand Up @@ -138,7 +145,7 @@ let make = () => {
initialValues={initialValues->toJson}
formClass="grid grid-cols-2 gap-x-8 gap-y-4"
onSubmit>
<SDKConfifiguarationFields />
<SDKConfiguarationFields initialValues />
</Form>
<TestCredentials />
</div>
Expand Down
1 change: 1 addition & 0 deletions src/screens/HyperSwitch/SDKPayment/SDKPaymentTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ type paymentType = {
currency: string,
profile_id: string,
customer_id: string,
description: string,
}
14 changes: 9 additions & 5 deletions src/screens/HyperSwitch/SDKPayment/SDKPaymentUtils.res
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
let initialValueForForm: string => SDKPaymentTypes.paymentType = profileId => {
amount: 100,
currency: "United States-USD",
profile_id: profileId,
customer_id: "hyperswitch_sdk_demo_id",
let initialValueForForm: HSwitchSettingTypes.profileEntity => SDKPaymentTypes.paymentType = defaultBusinessProfile => {
{
amount: 100,
currency: "United States-USD",
profile_id: defaultBusinessProfile.profile_id,
description: "Default value",
customer_id: "hyperswitch_sdk_demo_id",
}
}

let getTypedValueForPayment: Js.Json.t => SDKPaymentTypes.paymentType = values => {
Expand All @@ -13,6 +16,7 @@ let getTypedValueForPayment: Js.Json.t => SDKPaymentTypes.paymentType = values =
currency: dictOfValues->getString("currency", "United States-USD"),
profile_id: dictOfValues->getString("profile_id", ""),
customer_id: dictOfValues->getString("customer_id", ""),
description: dictOfValues->getString("description", "Default value"),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/screens/HyperSwitch/SDKPayment/TestPayment.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
external toJson: 'a => Js.Json.t = "%identity"
let headerTextStyle = "text-xl font-semibold text-grey-700"
let subTextStyle = "text-base font-normal text-grey-700 opacity-50"
let dividerColor = "bg-grey-700 bg-opacity-20 h-px w-full"
Expand Down Expand Up @@ -46,6 +47,7 @@ let make = (
),
("profile_id", initialValues.profile_id->Js.Json.string),
("customer_id", "hyperswitch_sdk_demo_id"->Js.Json.string),
("description", initialValues.description->Js.Json.string),
])->Js.Json.object_
let response = await updateDetails(url, body, Post)
let clientSecret = response->getDictFromJsonObject->getOptionString("client_secret")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ module TestPayment = {
}}
/>}>
<TestPayment
initialValues={defaultBusinessProfile.profile_id->SDKPaymentUtils.initialValueForForm}
initialValues={defaultBusinessProfile->SDKPaymentUtils.initialValueForForm}
returnUrl={`${HSwitchGlobalVars.hyperSwitchFEPrefix}/stripe-plus-paypal`}
onProceed={sptestPaymentProceed}
keyValue={key}
Expand Down
Loading