From 2e3b4169af98f6cd2b2076b3d3c96fefd2adf03c Mon Sep 17 00:00:00 2001 From: Mark Villacampa Date: Tue, 27 Jun 2023 20:29:06 +0200 Subject: [PATCH] Android: retrieve free trial period from the free phase (#446) Fixes https://github.com/RevenueCat/purchases-flutter/issues/743 --- .../mappers/StoreProductMapper.kt | 2 +- .../StoreProductIntroPriceMapperTests.kt | 27 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/revenuecat/purchases/hybridcommon/mappers/StoreProductMapper.kt b/android/src/main/java/com/revenuecat/purchases/hybridcommon/mappers/StoreProductMapper.kt index 348293e5..8b3ff164 100644 --- a/android/src/main/java/com/revenuecat/purchases/hybridcommon/mappers/StoreProductMapper.kt +++ b/android/src/main/java/com/revenuecat/purchases/hybridcommon/mappers/StoreProductMapper.kt @@ -15,7 +15,7 @@ val StoreProduct.priceString: String val StoreProduct.priceCurrencyCode: String get() = this.price.currencyCode val StoreProduct.freeTrialPeriod: Period? - get() = this.subscriptionOptions?.freeTrial?.billingPeriod + get() = this.subscriptionOptions?.freeTrial?.freePhase?.billingPeriod val StoreProduct.freeTrialCycles: Int? get() = this.subscriptionOptions?.freeTrial?.freePhase?.billingCycleCount diff --git a/android/src/test/java/com/revenuecat/purchases/hybridcommon/mappers/StoreProductIntroPriceMapperTests.kt b/android/src/test/java/com/revenuecat/purchases/hybridcommon/mappers/StoreProductIntroPriceMapperTests.kt index 5c84d2b8..515af74b 100644 --- a/android/src/test/java/com/revenuecat/purchases/hybridcommon/mappers/StoreProductIntroPriceMapperTests.kt +++ b/android/src/test/java/com/revenuecat/purchases/hybridcommon/mappers/StoreProductIntroPriceMapperTests.kt @@ -1,6 +1,9 @@ package com.revenuecat.purchases.hybridcommon.mappers import com.revenuecat.purchases.models.Period +import com.revenuecat.purchases.models.Price +import com.revenuecat.purchases.models.PricingPhase +import com.revenuecat.purchases.models.RecurrenceMode import com.revenuecat.purchases.models.StoreProduct import io.mockk.every import io.mockk.mockk @@ -25,8 +28,12 @@ internal class StoreProductIntroPriceMapperTests { inner class MappingFreeTrial { @Test fun `of 7 days, the map has the correct intro price values`() { - every { mockStoreProduct.freeTrialPeriod } returns Period(7, Period.Unit.DAY, "P7D") - every { mockStoreProduct.freeTrialCycles } returns 1 + every { mockStoreProduct.subscriptionOptions?.freeTrial?.freePhase } returns PricingPhase( + price = Price("$0.00", 0, "USD"), + billingCycleCount = 1, + billingPeriod = Period(7, Period.Unit.DAY, "P7D"), + recurrenceMode = RecurrenceMode.NON_RECURRING, + ) received = mockStoreProduct.mapIntroPrice() val expected = mapOf( "price" to 0, @@ -41,8 +48,12 @@ internal class StoreProductIntroPriceMapperTests { @Test fun `of 1 month, the map has the correct intro price values`() { - every { mockStoreProduct.freeTrialPeriod } returns Period(1, Period.Unit.MONTH, "P1M") - every { mockStoreProduct.freeTrialCycles } returns 1 + every { mockStoreProduct.subscriptionOptions?.freeTrial?.freePhase } returns PricingPhase( + price = Price("$0.00", 0, "USD"), + billingCycleCount = 1, + billingPeriod = Period(1, Period.Unit.MONTH, "P1M"), + recurrenceMode = RecurrenceMode.NON_RECURRING, + ) received = mockStoreProduct.mapIntroPrice() val expected = mapOf( "price" to 0, @@ -57,8 +68,12 @@ internal class StoreProductIntroPriceMapperTests { @Test fun `of 0 days, the map has the correct intro price values`() { - every { mockStoreProduct.freeTrialPeriod } returns Period(0, Period.Unit.DAY, "P0D") - every { mockStoreProduct.freeTrialCycles } returns 1 + every { mockStoreProduct.subscriptionOptions?.freeTrial?.freePhase } returns PricingPhase( + price = Price("$0.00", 0, "USD"), + billingCycleCount = 1, + billingPeriod = Period(0, Period.Unit.DAY, "P0D"), + recurrenceMode = RecurrenceMode.NON_RECURRING, + ) received = mockStoreProduct.mapIntroPrice() val expected = mapOf(