@@ -206,7 +206,7 @@ private void convertSubscriptionProductToInformation(Information.Builder builder
206206 ProductDetails .PricingPhase freeTrialSubscriptionPhase = getFreeTrialSubscriptionPhase (details .getPricingPhases ());
207207
208208 if (freeTrialSubscriptionPhase != null ) {
209- builder .freeTrialPeriod (convertToFreeTrialPeriod (freeTrialSubscriptionPhase .getBillingPeriod ()));
209+ builder .freeTrialPeriod (convertToFreeTrialPeriod (freeTrialSubscriptionPhase .getBillingPeriod (), freeTrialSubscriptionPhase . getBillingCycleCount () ));
210210 }
211211 }
212212
@@ -241,11 +241,14 @@ private static ProductDetails.PricingPhase getFreeTrialSubscriptionPhase(Product
241241
242242
243243 /**
244- * TODO test that we can find free trial phase actually like this. Normally is non-recurring and free.
244+ * Free trial periods come in two ways:
245+ * RecurrenceMode.NON_RECURRING (detected before 2023, android 10)
246+ * RecurrenceMode.FINITE_RECURRING with billingCycleCount of 1 (detected in january 2023)
247+ *
245248 */
246249 private static boolean isFreeTrialSubscriptionPhase (ProductDetails .PricingPhase phase ) {
247- return phase .getRecurrenceMode () == ProductDetails . RecurrenceMode . NON_RECURRING && phase . getPriceAmountMicros () == 0L ;
248-
250+ return phase .getPriceAmountMicros () == 0L &&
251+ ( phase . getRecurrenceMode () == ProductDetails . RecurrenceMode . NON_RECURRING || phase . getRecurrenceMode () == ProductDetails . RecurrenceMode . FINITE_RECURRING );
249252 }
250253
251254 private static void convertOneTimeProductToInformation (Information .Builder builder , ProductDetails .OneTimePurchaseOfferDetails oneTimePurchaseDetails ) {
@@ -259,15 +262,20 @@ private static void convertOneTimeProductToInformation(Information.Builder build
259262
260263 /**
261264 * @param iso8601Duration in ISO 8601 format.
265+ * @param billingCycleCount the number of billing cycles. When testing it, we found value 1 for FINITE_RECURRING cycles
262266 */
263267 @ Nullable
264- private FreeTrialPeriod convertToFreeTrialPeriod (@ Nullable String iso8601Duration ) {
268+ private FreeTrialPeriod convertToFreeTrialPeriod (@ Nullable String iso8601Duration , int billingCycleCount ) {
265269 if (iso8601Duration == null || iso8601Duration .isEmpty ()) {
266270 return null ;
267271 }
268272
269273 try {
270- return Iso8601DurationStringToFreeTrialPeriodConverter .convertToFreeTrialPeriod (iso8601Duration );
274+ FreeTrialPeriod freeTrialPeriod = Iso8601DurationStringToFreeTrialPeriodConverter .convertToFreeTrialPeriod (iso8601Duration );
275+ if (billingCycleCount > 1 ) {
276+ freeTrialPeriod = new FreeTrialPeriod (freeTrialPeriod .getNumberOfUnits () * billingCycleCount , freeTrialPeriod .getUnit ());
277+ }
278+ return freeTrialPeriod ;
271279 } catch (RuntimeException e ) {
272280 Gdx .app .error (TAG , "Failed to parse iso8601Duration: " + iso8601Duration , e );
273281 return null ;
0 commit comments