Support to round+truncate prices displayed on paywalls for backend-specified countries#1806
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1806 +/- ##
==========================================
- Coverage 82.89% 82.84% -0.06%
==========================================
Files 221 222 +1
Lines 7660 7670 +10
Branches 1074 1077 +3
==========================================
+ Hits 6350 6354 +4
- Misses 891 894 +3
- Partials 419 422 +3 ☔ View full report in Codecov by Sentry. |
tonidero
left a comment
There was a problem hiding this comment.
Mostly some API tests missing and some questions but looking good!
|
|
||
| @SerialName("zero_decimal_place_countries") | ||
| @Serializable(with = GoogleListSerializer::class) | ||
| val zeroDecimalPlaceCountries: List<String> = emptyList(), |
There was a problem hiding this comment.
Also need to add this to API tests
There was a problem hiding this comment.
I don't see any explicit API testers for PaywallData, but the sample paywalls in SamplePaywalls.kt serves this purpose. Is there somewhere else this should be added?
…venuecatui/data/processed/VariableDataProvider.kt Co-authored-by: JayShortway <29483617+JayShortway@users.noreply.github.com>
AFAIK this rounding is only needed for paywall presentation. I see you added the code for |
(Really missing GitLab's comment threads ☝️) Alright! They're not presented to the user, unless the app developer does it in their own UI. They're purely convenience functions (but I do imagine their main purpose is to show in UI). cc @tonidero for verification 🙏 |
Yeah, that's true. It's part of the public API, in case a developer wants to use them. They can also write this logic themselves for sure, so this would be a mostly convenience change. However, note that this is configured from the paywalls, so maybe it makes more sense to restrain this logic to paywalls and just use what comes from the store otherwise? Happy to discuss this more over Slack if needed. |
Yea I think that makes a lot of sense! |
|
I believe I've addressed all concerns raised. |
JayShortway
left a comment
There was a problem hiding this comment.
LGTM!
To fix PurchasesAPI.java:
- final String storefrontCountryCode = purchases.storefrontCountryCode();
+ final String storefrontCountryCode = purchases.getStorefrontCountryCode();Java loves its getters and setters. So a val in Kotlin becomes a getter. A var becomes a pair of getter and setter.
THANK YOU!!! |
**This is an automatic release.** ### New Features * [Paywalls] Add default locale (#1809) via Josh Holtz (@joshdholtz) * [Paywalls] Support to round+truncate prices displayed on paywalls for backend-specified countries (#1806) via James Borthwick (@jamesrb1) ### Other Changes * Publish paywall tester on each release (#1803) via Toni Rico (@tonidero) --------- Co-authored-by: revenuecat-ops <ops@revenuecat.com> Co-authored-by: Josh Holtz <me@joshholtz.com>
Round and truncate prices displayed on paywalls for storefronts specified by the backend
Some countries have cents as part of their currency, but it is rare to see them written in prices. This PR makes it possible to round/hide the cents component.
Prices are only truncated if the price ends in .00.
The steps to do this are:
1. Get list of storefronts for which rounding should occur.
PaywallDataaszeroDecimalPlaceCountries.2. Determine if this user is in a "rounding" country.
VariableProcessor.PackageContext.showZeroDecimalPlacePricestotrue.VariableProcessor.PackageContextis used byVariableProcessorto translate{{ price_variables }}into the correct strings.3. Round prices if needed while processing variables
VariableProcessoris asked for a localized price string (localizedPrice(...),localizedPricePerWeek(...)etc., it returns a rounded price if rounding conditions are met.The server is currently returning "PH", "KZ", "TW", "MX", "TH" as zero decimal countries. If your google account is not in one of these countries, you can turn temporarily turn rounding "on" by going to
PackageConfigurationFactory.ktand replacingpaywallData.zeroDecimalPlaceCountries.contains( Purchases.sharedInstance.storefrontCountryCode, )with
paywallData.zeroDecimalPlaceCountries.contains( "TW", )Note that prices are formatted according to the locale of the RC paywall. For example, if the device's language setting is Canadian English (en_CA), and attached the Canadian Play store (CA), but there is no RC paywall localized to English (Canada), then the paywall that we show falls back to the en_US paywall, and all prices will be formatted according to en_US rules, meaning a price will show as e.g. "CA$7.99". If there is an en_CA paywall, then prices are formatted according to en_CA rules, e.g. "$7.99".
This is the Android version of RevenueCat/purchases-ios#4132