What is the structure of the Android ProductDetails object (JSON format) if I add a 7-day free trial offer?

Summary

The Android ProductDetails object is a JSON object that represents a product’s details, including its pricing and subscription offers. When adding a 7-day free trial offer to a base plan, the object’s structure changes to include an additional pricing phase with a free trial period.

Root Cause

The root cause of the change in the object’s structure is the addition of a free trial offer to the base plan. This requires an additional pricing phase to be added to the object, which includes the free trial period and its corresponding pricing details.

Why This Happens in Real Systems

This happens in real systems because the Google Play Billing Library requires a specific structure for the ProductDetails object to handle different types of pricing and subscription offers. When a free trial offer is added to a base plan, the library needs to be able to parse the object and extract the relevant pricing information.

Real-World Impact

The real-world impact of this change is that developers need to update their code to handle the new structure of the ProductDetails object. This includes:

  • Parsing the object to extract the free trial period and its corresponding pricing details
  • Updating the user interface to display the free trial offer and its terms
  • Handling the free trial period and its expiration date in the application’s logic

Example or Code

{
  "productId": "product_id_example",
  "type": "subs",
  "title": "title",
  "name": "name",
  "description": "product description",
  "localizedIn": [
    "en-US"
  ],
  "skuDetailsToken": "sku_details_token_example",
  "subscriptionOfferDetails": [
    {
      "offerIdToken": "offer_id_token_example",
      "basePlanId": "yearly",
      "pricingPhases": [
        {
          "priceAmountMicros": 0,
          "priceCurrencyCode": "",
          "formattedPrice": "",
          "billingPeriod": "P7D",
          "recurrenceMode": 2
        },
        {
          "priceAmountMicros": 49990000,
          "priceCurrencyCode": "EUR",
          "formattedPrice": "€49.99",
          "billingPeriod": "P1Y",
          "recurrenceMode": 1
        }
      ],
      "offerTags": []
    }
  ]
}

How Senior Engineers Fix It

Senior engineers fix this issue by:

  • Carefully reading the Google Play Billing Library documentation to understand the required structure of the ProductDetails object
  • Updating their code to parse the object and extract the relevant pricing information
  • Testing their code to ensure that it handles the free trial offer and its expiration date correctly
  • Using debugging tools to identify and fix any issues that arise during testing

Why Juniors Miss It

Juniors may miss this issue because:

  • They may not have a thorough understanding of the Google Play Billing Library documentation and the required structure of the ProductDetails object
  • They may not have experience with handling free trial offers and their expiration dates in their code
  • They may not test their code thoroughly enough to catch any issues that arise during testing
  • They may not use debugging tools effectively to identify and fix any issues that arise during testing