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: hideExpiredPaymentMethods prop added #350

Merged
merged 3 commits into from
May 6, 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
245 changes: 124 additions & 121 deletions src/Components/SavedCardItem.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let make = (
~setRequiredFieldsBody,
) => {
let {themeObj, config, localeString} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom)
let {hideExpiredPaymentMethods} = Recoil.useRecoilValueFromAtom(RecoilAtoms.optionAtom)
let (cardBrand, setCardBrand) = Recoil.useRecoilState(RecoilAtoms.cardBrand)
let (
isCVCValid,
Expand Down Expand Up @@ -48,8 +49,10 @@ let make = (

let isCard = paymentItem.paymentMethod === "card"
let isRenderCvv = isCard && paymentItem.requiresCvv
let expiryMonth = paymentItem.card.expiryMonth
let expiryYear = paymentItem.card.expiryYear

let expiryDate = Date.fromString(`${paymentItem.card.expiryYear}-${paymentItem.card.expiryMonth}`)
let expiryDate = Date.fromString(`${expiryYear}-${expiryMonth}`)
expiryDate->Date.setMonth(expiryDate->Date.getMonth + 1)
let currentDate = Date.make()
let isCardExpired = isCard && expiryDate < currentDate
Expand All @@ -59,135 +62,135 @@ let make = (
| None => "debit"
}

<button
className={`PickerItem ${pickerItemClass} flex flex-row items-stretch`}
type_="button"
style={ReactDOMStyle.make(
~minWidth="150px",
~width="100%",
~padding="1rem 0 1rem 0",
~cursor="pointer",
~borderBottom=index == savedCardlength - 1 ? "0px" : `1px solid ${themeObj.borderColor}`,
~borderTop="none",
~borderLeft="none",
~borderRight="none",
~borderRadius="0px",
~background="transparent",
~color=themeObj.colorTextSecondary,
~boxShadow="none",
~opacity={isCardExpired ? "0.7" : "1"},
(),
)}
onClick={_ => setPaymentToken(_ => (paymentItem.paymentToken, paymentItem.customerId))}>
<div className="w-full">
<div>
<div className="flex flex-row justify-between items-center">
<div
className={`flex flex-row justify-center items-center`}
style={ReactDOMStyle.make(~columnGap=themeObj.spacingUnit, ())}>
<div style={ReactDOMStyle.make(~color=isActive ? themeObj.colorPrimary : "", ())}>
<Radio
checked=isActive
height="18px"
className="savedcard"
marginTop="-2px"
opacity="20%"
padding="46%"
border="1px solid currentColor"
/>
</div>
<div className={`PickerItemIcon mx-3 flex items-center `}> brandIcon </div>
<div className="flex flex-col">
<div className="flex items-center gap-4">
{isCard
? <div className="flex flex-col items-start">
<div> {React.string(paymentItem.card.nickname)} </div>
<div className={`PickerItemLabel flex flex-row gap-3 items-center`}>
<div className="tracking-widest"> {React.string(`****`)} </div>
<div> {React.string(paymentItem.card.last4Digits)} </div>
</div>
</div>
: <div> {React.string(paymentMethodType->Utils.snakeToTitleCase)} </div>}
<RenderIf condition={paymentItem.defaultPaymentMethodSet}>
<Icon
size=18
name="checkmark"
style={ReactDOMStyle.make(~color=themeObj.colorPrimary, ())}
/>
</RenderIf>
</div>
</div>
</div>
<RenderIf condition={isCard}>
<RenderIf condition={!hideExpiredPaymentMethods || !isCardExpired}>
<button
className={`PickerItem ${pickerItemClass} flex flex-row items-stretch`}
type_="button"
style={ReactDOMStyle.make(
~minWidth="150px",
~width="100%",
~padding="1rem 0 1rem 0",
~cursor="pointer",
~borderBottom=index == savedCardlength - 1 ? "0px" : `1px solid ${themeObj.borderColor}`,
~borderTop="none",
~borderLeft="none",
~borderRight="none",
~borderRadius="0px",
~background="transparent",
~color=themeObj.colorTextSecondary,
~boxShadow="none",
~opacity={isCardExpired ? "0.7" : "1"},
(),
)}
onClick={_ => setPaymentToken(_ => (paymentItem.paymentToken, paymentItem.customerId))}>
<div className="w-full">
<div>
<div className="flex flex-row justify-between items-center">
<div
className={`flex flex-row items-center justify-end gap-3 -mt-1`}
style={ReactDOMStyle.make(~fontSize="14px", ~opacity="0.5", ())}>
<div className="flex">
{React.string(
`${paymentItem.card.expiryMonth} / ${paymentItem.card.expiryYear->CardUtils.formatExpiryToTwoDigit}`,
)}
className={`flex flex-row justify-center items-center`}
style={ReactDOMStyle.make(~columnGap=themeObj.spacingUnit, ())}>
<div style={ReactDOMStyle.make(~color=isActive ? themeObj.colorPrimary : "", ())}>
<Radio
checked=isActive
height="18px"
className="savedcard"
marginTop="-2px"
opacity="20%"
padding="46%"
border="1px solid currentColor"
/>
</div>
<div className={`PickerItemIcon mx-3 flex items-center `}> brandIcon </div>
<div className="flex flex-col">
<div className="flex items-center gap-4">
{isCard
? <div className="flex flex-col items-start">
<div> {React.string(paymentItem.card.nickname)} </div>
<div className={`PickerItemLabel flex flex-row gap-3 items-center`}>
<div className="tracking-widest"> {React.string(`****`)} </div>
<div> {React.string(paymentItem.card.last4Digits)} </div>
</div>
</div>
: <div> {React.string(paymentMethodType->Utils.snakeToTitleCase)} </div>}
<RenderIf condition={paymentItem.defaultPaymentMethodSet}>
<Icon
size=18
name="checkmark"
style={ReactDOMStyle.make(~color=themeObj.colorPrimary, ())}
/>
</RenderIf>
</div>
</div>
</div>
</RenderIf>
</div>
<div className="w-full ">
<div className="flex flex-col items-start mx-8">
<RenderIf condition={isActive && isRenderCvv}>
<RenderIf condition={isCard}>
<div
className={`flex flex-row items-start justify-start gap-2`}
className={`flex flex-row items-center justify-end gap-3 -mt-1`}
style={ReactDOMStyle.make(~fontSize="14px", ~opacity="0.5", ())}>
<div className="w-12 mt-6"> {React.string("CVC: ")} </div>
<div
className={`flex h mx-4 justify-start w-16 ${isActive
? "opacity-1 mt-4"
: "opacity-0"}`}>
<PaymentInputField
isValid=isCVCValid
setIsValid=setIsCVCValid
value=cvcNumber
onChange=changeCVCNumber
onBlur=handleCVCBlur
errorString=cvcError
inputFieldClassName="flex justify-start"
paymentType
appearance=config.appearance
type_="tel"
className={`tracking-widest justify-start w-full`}
maxLength=4
inputRef=cvcRef
placeholder="123"
height="2.2rem"
/>
<div className="flex">
{React.string(`${expiryMonth} / ${expiryYear->CardUtils.formatExpiryToTwoDigit}`)}
</div>
</div>
</RenderIf>
<RenderIf condition={isCardExpired}>
<div
className="italic mt-3 ml-1"
style={ReactDOMStyle.make(~fontSize="14px", ~opacity="0.7", ())}>
{`*${localeString.cardExpiredText}`->React.string}
</div>
</RenderIf>
<RenderIf condition={isActive}>
<DynamicFields
paymentType
list
paymentMethod=paymentItem.paymentMethod
paymentMethodType
setRequiredFieldsBody
isSavedCardFlow=true
savedMethod=paymentItem
/>
<Surcharge
list
paymentMethod=paymentItem.paymentMethod
paymentMethodType
cardBrand={cardBrand->CardUtils.getCardType}
/>
</RenderIf>
</div>
<div className="w-full">
<div className="flex flex-col items-start mx-8">
<RenderIf condition={isActive && isRenderCvv}>
<div
className={`flex flex-row items-start justify-start gap-2`}
style={ReactDOMStyle.make(~fontSize="14px", ~opacity="0.5", ())}>
<div className="w-12 mt-6"> {React.string("CVC: ")} </div>
<div
className={`flex h mx-4 justify-start w-16 ${isActive
? "opacity-1 mt-4"
: "opacity-0"}`}>
<PaymentInputField
isValid=isCVCValid
setIsValid=setIsCVCValid
value=cvcNumber
onChange=changeCVCNumber
onBlur=handleCVCBlur
errorString=cvcError
inputFieldClassName="flex justify-start"
paymentType
appearance=config.appearance
type_="tel"
className={`tracking-widest justify-start w-full`}
maxLength=4
inputRef=cvcRef
placeholder="123"
height="2.2rem"
/>
</div>
</div>
</RenderIf>
<RenderIf condition={isCardExpired}>
<div
className="italic mt-3 ml-1"
style={ReactDOMStyle.make(~fontSize="14px", ~opacity="0.7", ())}>
{`*${localeString.cardExpiredText}`->React.string}
</div>
</RenderIf>
<RenderIf condition={isActive}>
<DynamicFields
paymentType
list
paymentMethod=paymentItem.paymentMethod
paymentMethodType
setRequiredFieldsBody
isSavedCardFlow=true
savedMethod=paymentItem
/>
<Surcharge
list
paymentMethod=paymentItem.paymentMethod
paymentMethodType
cardBrand={cardBrand->CardUtils.getCardType}
/>
</RenderIf>
</div>
</div>
</div>
</div>
</div>
</button>
</button>
</RenderIf>
}
4 changes: 4 additions & 0 deletions src/Types/PaymentType.res
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ type options = {
sdkHandleConfirmPayment: sdkHandleConfirmPayment,
paymentMethodsHeaderText?: string,
savedPaymentMethodsHeaderText?: string,
hideExpiredPaymentMethods: bool,
}
let defaultCardDetails = {
scheme: None,
Expand Down Expand Up @@ -289,6 +290,7 @@ let defaultOptions = {
showCardFormByDefault: true,
billingAddress: defaultBillingAddress,
sdkHandleConfirmPayment: defaultSdkHandleConfirmPayment,
hideExpiredPaymentMethods: false,
}
let getLayout = (str, logger) => {
switch str {
Expand Down Expand Up @@ -935,6 +937,7 @@ let itemToObjMapper = (dict, logger) => {
"sdkHandleConfirmPayment",
"paymentMethodsHeaderText",
"savedPaymentMethodsHeaderText",
"hideExpiredPaymentMethods",
],
dict,
"options",
Expand Down Expand Up @@ -975,6 +978,7 @@ let itemToObjMapper = (dict, logger) => {
->getSdkHandleConfirmPaymentProps,
paymentMethodsHeaderText: ?getOptionString(dict, "paymentMethodsHeaderText"),
savedPaymentMethodsHeaderText: ?getOptionString(dict, "savedPaymentMethodsHeaderText"),
hideExpiredPaymentMethods: getBool(dict, "hideExpiredPaymentMethods", false),
}
}

Expand Down
Loading