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

feat: added dynamic field rendering for klarna #858

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
57 changes: 18 additions & 39 deletions src/Payments/KlarnaPayment.res
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
open PaymentType
open RecoilAtoms
@react.component
let make = (~paymentType) => {
let (loggerState, _setLoggerState) = Recoil.useRecoilState(loggerAtom)
let {config, themeObj, localeString} = Recoil.useRecoilValueFromAtom(configAtom)
let {fields} = Recoil.useRecoilValueFromAtom(optionAtom)
let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom)
let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom)
let intent = PaymentHelpers.usePaymentIntent(Some(loggerState), KlarnaRedirect)
let isManualRetryEnabled = Recoil.useRecoilValueFromAtom(RecoilAtoms.isManualRetryEnabled)
let setComplete = Recoil.useSetRecoilState(fieldsComplete)
let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue)

let showAddressDetails = getShowAddressDetails(
~billingDetails=fields.billingDetails,
~logger=loggerState,
)
let (fullName, _) = Recoil.useLoggedRecoilState(userFullName, "fullName", loggerState)
let (email, _) = Recoil.useLoggedRecoilState(userEmailAddress, "email", loggerState)

let countryNames =
Utils.getCountryNames(Country.country)->DropdownField.updateArrayOfStringToOptionsTypeArray

let (country, setCountry) = Recoil.useRecoilState(userCountry)
let setCountry = val => {
setCountry(val)
}
let (country, _) = Recoil.useRecoilState(userCountry)
let (_, setRequiredFieldsBody) = React.useState(_ => Dict.make())
RustProfi marked this conversation as resolved.
Show resolved Hide resolved

open Utils
let clientCountryCode =
Expand All @@ -46,16 +35,18 @@ let make = (~paymentType) => {
let confirm = json->Utils.getDictFromJson->ConfirmType.itemToObjMapper
let (connectors, _) =
paymentMethodListValue->PaymentUtils.getConnectors(PayLater(Klarna(Redirect)))
let body = PaymentBody.klarnaRedirectionBody(
~fullName=fullName.value,
~email=email.value,
~country=clientCountryCode.isoAlpha2,
~connectors,
)

if confirm.doSubmit {
if complete {
let bodyArr = PaymentBody.klarnaRedirectionBody(
~fullName=fullName.value,
~email=email.value,
~country=clientCountryCode.isoAlpha2,
~connectors,
)

intent(
~bodyArr=body,
~bodyArr,
~confirmParam=confirm.confirmParams,
~handleUserError=false,
~manualRetry=isManualRetryEnabled,
Expand All @@ -65,25 +56,13 @@ let make = (~paymentType) => {
}
}
}, (email, fullName, country, isManualRetryEnabled))

useSubmitPaymentData(submitCallback)

<div
className="flex flex-col animate-slowShow"
style={
gridGap: config.appearance.innerLayout === Spaced ? themeObj.spacingGridColumn : "",
}>
<EmailPaymentInput paymentType={paymentType} />
<FullNamePaymentInput paymentType={paymentType} />
<RenderIf condition={showAddressDetails.country == Auto}>
<DropdownField
appearance=config.appearance
fieldName=localeString.countryLabel
value=country
setValue=setCountry
disabled=false
options=countryNames
/>
</RenderIf>
<div className="flex flex-col animate-slowShow" style={gridGap: themeObj.spacingTab}>
<DynamicFields
paymentType paymentMethod="pay_later" paymentMethodType="klarna" setRequiredFieldsBody
/>
<Surcharge paymentMethod="pay_later" paymentMethodType="klarna" />
<InfoElement />
</div>
Expand Down
Loading