Skip to content

Commit

Permalink
Paywalls: fix empty description when using custom package type and Of…
Browse files Browse the repository at this point in the history
…fer Period (#1519)

Android equivalent of
RevenueCat/purchases-ios#3495

If you select a custom package type and set Offer Period, the paywall
would have an empty entry for that package.


![image](https://github.com/RevenueCat/purchases-android/assets/3922667/3c3461b9-6732-4aaf-8497-5915a72f9c5f)

| Before | After |
| :-: | :-: |
|
![Screenshot_20231206-144952](https://github.com/RevenueCat/purchases-android/assets/3922667/8331b6ae-f87b-487a-a20d-0cbca86a937c)
|
![Screenshot_20231206-151434](https://github.com/RevenueCat/purchases-android/assets/3922667/33fc77a8-e5b8-4457-bc20-f2096238f1c7)
|
  • Loading branch information
aboedo authored Dec 20, 2023
1 parent 9b6c4ca commit 89b7b98
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ internal class VariableDataProvider(
}

fun periodName(rcPackage: Package): String? {
if (rcPackage.packageType == PackageType.CUSTOM ||
rcPackage.packageType == PackageType.UNKNOWN
) {
return rcPackage.identifier
}
val stringId = when (rcPackage.packageType) {
PackageType.LIFETIME -> R.string.lifetime
PackageType.ANNUAL -> R.string.annual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,30 @@ internal object TestData {
period = Period(value = 6, unit = Period.Unit.MONTH, iso8601 = "P6M"),
),
)
val custom = Package(
packageType = PackageType.CUSTOM,
identifier = "Custom",
offering = "offering",
product = TestStoreProduct(
id = "com.revenuecat.semester_product",
title = "6 month",
price = Price(amountMicros = 39_990_000, currencyCode = "USD", formatted = "$39.99"),
description = "6 month",
period = Period(value = 6, unit = Period.Unit.MONTH, iso8601 = "P6M"),
),
)
val unknown = Package(
packageType = PackageType.UNKNOWN,
identifier = "Unknown",
offering = "offering",
product = TestStoreProduct(
id = "com.revenuecat.semester_product",
title = "6 month",
price = Price(amountMicros = 39_990_000, currencyCode = "USD", formatted = "$39.99"),
description = "6 month",
period = Period(value = 6, unit = Period.Unit.MONTH, iso8601 = "P6M"),
),
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,13 @@ class VariableProcessorTest {

@Test
fun `process variables processes sub_period custom period`() {
rcPackage = TestData.Packages.annual.copy(packageType = PackageType.CUSTOM)
expectVariablesResult("{{ sub_period }}", "")
expectVariablesResult("{{ sub_period }}", "Custom", rcPackage = TestData.Packages.custom)
}

@Test
fun `process variables processes sub_period unknown period`() {
expectVariablesResult("{{ sub_period }}", "Unknown", rcPackage = TestData.Packages.unknown)
}
// endregion

// region sub_price_per_week
Expand Down

0 comments on commit 89b7b98

Please sign in to comment.