Skip to content
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
3 changes: 3 additions & 0 deletions src/Widgets/EligibilityModal/ModalContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Props = {
configPlans?: ConfigPlan[]
customerBillingCountry?: string
customerShippingCountry?: string
merchantCoversAllFees?: boolean
onClose: (event: React.MouseEvent | React.KeyboardEvent) => void
cards?: Card[]
}
Expand All @@ -23,6 +24,7 @@ const ModalContainer: React.FC<Props> = ({
configPlans,
customerBillingCountry,
customerShippingCountry,
merchantCoversAllFees,
onClose,
cards,
}) => {
Expand All @@ -32,6 +34,7 @@ const ModalContainer: React.FC<Props> = ({
configPlans,
customerBillingCountry,
customerShippingCountry,
merchantCoversAllFees,
)

return (
Expand Down
3 changes: 3 additions & 0 deletions src/Widgets/PaymentPlans/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Props = {
transitionDelay?: number
customerBillingCountry?: string
customerShippingCountry?: string
merchantCoversAllFees?: boolean
hideIfNotEligible?: boolean
monochrome?: boolean
suggestedPaymentPlan?: number | number[]
Expand Down Expand Up @@ -56,6 +57,7 @@ const PaymentPlanWidget: FunctionComponent<Props> = ({
cards,
customerBillingCountry,
customerShippingCountry,
merchantCoversAllFees,
transitionDelay,
hideBorder = false,
onModalClose,
Expand All @@ -69,6 +71,7 @@ const PaymentPlanWidget: FunctionComponent<Props> = ({
configPlans,
customerBillingCountry,
customerShippingCountry,
merchantCoversAllFees,
)

// Memoized array of only eligible plans to avoid unnecessary re-renders
Expand Down
15 changes: 15 additions & 0 deletions src/hooks/useFetchEligibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,28 @@ describe('useFetchEligibility', () => {
undefined,
'FR',
'FR',
true,
),
)
// First the API response is pending
expect(result.current[1]).toBe(statusResponse.PENDING)

// The API is called
expect(fetchFromApi).toHaveBeenCalledTimes(1)
expect(fetchFromApi).toHaveBeenCalledWith(
{
purchase_amount: 45000,
queries: undefined,
billing_address: { country: 'FR' },
shipping_address: { country: 'FR' },
merchant_covers_all_fees: true,
},
{
Authorization: 'Alma-Merchant-Auth test_id',
'X-Alma-Agent': 'Alma Widget/undefined',
},
`${ApiMode.TEST}/v2/payments/eligibility`,
)
// The hooks returns the filtered result of the API response
await waitFor(() => {
expect(result.current[0]).toEqual(filterEligibility(mockPlansAllEligible))
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useFetchEligibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const useFetchEligibility = (
plans?: ConfigPlan[],
customerBillingCountry?: string,
customerShippingCountry?: string,
merchantCoversAllFees?: boolean,
): [EligibilityPlan[], statusResponse] => {
const [eligibility, setEligibility] = useState([] as EligibilityPlan[])
const [status, setStatus] = useState(statusResponse.PENDING)
Expand All @@ -23,6 +24,7 @@ const useFetchEligibility = (
plans,
customerBillingCountry,
customerShippingCountry,
merchantCoversAllFees,
domain,
merchantId,
})
Expand Down Expand Up @@ -67,6 +69,7 @@ const useFetchEligibility = (
queries: configInstallments,
billing_address: billingAddress,
shipping_address: shippingAddress,
merchant_covers_all_fees: merchantCoversAllFees,
},
{
Authorization: `Alma-Merchant-Auth ${merchantId}`,
Expand Down Expand Up @@ -102,6 +105,7 @@ const useFetchEligibility = (
configInstallments,
merchantId,
domain,
merchantCoversAllFees,
setCache,
clearCache,
])
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useSessionStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type CreateKeyType = {
plans?: ConfigPlan[]
customerBillingCountry?: string
customerShippingCountry?: string
merchantCoversAllFees?: boolean
domain?: string
merchantId?: string
}
Expand Down Expand Up @@ -53,6 +54,7 @@ export const useSessionStorage: () => UseSessionStorageType = () => {
plans,
customerBillingCountry,
customerShippingCountry,
merchantCoversAllFees,
domain,
merchantId,
} = params
Expand All @@ -62,7 +64,7 @@ export const useSessionStorage: () => UseSessionStorageType = () => {
// Using build version into the key to invalidate cache when the widget is updated
const buildVersion = process.env.BUILD_VERSION ?? 'local-build'
return hashStringForStorage(
`${domain}${merchantId}${stringAmount}${stringPlans}${customerBillingCountry}${customerShippingCountry}${buildVersion}`,
`${domain}${merchantId}${stringAmount}${stringPlans}${customerBillingCountry}${customerShippingCountry}${merchantCoversAllFees}${buildVersion}`,
)
}

Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type PaymentPlanWidgetOptions = {
hideBorder?: boolean
customerBillingCountry?: string
customerShippingCountry?: string
merchantCoversAllFees?: boolean
onModalClose?: (event: React.MouseEvent | React.KeyboardEvent) => void
}

Expand All @@ -97,6 +98,7 @@ export type ModalOptions = {
purchaseAmount: number
customerBillingCountry?: string
customerShippingCountry?: string
merchantCoversAllFees?: boolean
plans?: ConfigPlan[]
locale?: Locale
cards?: Card[]
Expand Down
4 changes: 4 additions & 0 deletions src/widgets_controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const addWidget = (
suggestedPaymentPlan,
customerBillingCountry,
customerShippingCountry,
merchantCoversAllFees,
locale = Locale.en,
cards,
onModalClose,
Expand All @@ -71,6 +72,7 @@ const addWidget = (
cards={cards}
customerBillingCountry={customerBillingCountry}
customerShippingCountry={customerShippingCountry}
merchantCoversAllFees={merchantCoversAllFees}
transitionDelay={transitionDelay}
hideBorder={hideBorder}
onModalClose={onModalClose}
Expand All @@ -89,6 +91,7 @@ const addWidget = (
locale = Locale.en,
customerBillingCountry,
customerShippingCountry,
merchantCoversAllFees,
cards,
onClose,
} = options as ModalOptions
Expand All @@ -114,6 +117,7 @@ const addWidget = (
configPlans={plans}
customerBillingCountry={customerBillingCountry}
customerShippingCountry={customerShippingCountry}
merchantCoversAllFees={merchantCoversAllFees}
onClose={close}
cards={cards}
/>
Expand Down