diff --git a/CHANGELOG.md b/CHANGELOG.md index 837a7fd..bf9f006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Fixed +- Error when sku offer has no payment option. + ## [1.6.2] - 2024-03-20 ### Fixed diff --git a/src/convertSearchDocument.ts b/src/convertSearchDocument.ts index b121067..4c159fa 100644 --- a/src/convertSearchDocument.ts +++ b/src/convertSearchDocument.ts @@ -181,19 +181,19 @@ const skuSpecificationsFromDocuments = ( }) } -const getSpotPrice = (paymentOptions: PaymentOptions, priceWithoutDiscount: number) => { - const installments = paymentOptions.InstallmentOptions.flatMap((option) => option.Installments) - const installment = installments.find( +const getSpotPrice = (paymentOptions: PaymentOptions | null, priceWithoutDiscount: number) => { + const installments = paymentOptions?.InstallmentOptions.flatMap((option) => option.Installments) + const installment = installments?.find( (inst) => inst.Count && inst.ValueAsInt && inst.ValueAsInt / 100 < priceWithoutDiscount ) return installment ? installment.ValueAsInt / 100 : priceWithoutDiscount } -const buildInstallments = (paymentOptions: PaymentOptions, unitMultiplier: number): SearchInstallment[] => { +const buildInstallments = (paymentOptions: PaymentOptions | null, unitMultiplier: number): SearchInstallment[] => { const installments: SearchInstallment[] = [] - paymentOptions.InstallmentOptions.forEach((option) => { + paymentOptions?.InstallmentOptions.forEach((option) => { option.Installments.forEach((installment) => { installments.push({ NumberOfInstallments: installment.Count, diff --git a/src/typings/global.ts b/src/typings/global.ts index 661e15a..8797786 100644 --- a/src/typings/global.ts +++ b/src/typings/global.ts @@ -329,7 +329,7 @@ declare global { IsAvailable: boolean DeliverySlaSamples: any[] RatesAndBenefitsData: RatesAndBenefitsData | null - PaymentOptions: PaymentOptions + PaymentOptions: PaymentOptions | null } interface SkuOfferDetails {