【问题标题】:Android In-App Billing V5 subscription with trial period带有试用期的 Android In-App Billing V5 订阅
【发布时间】:2022-06-16 12:54:49
【问题描述】:

Google 已更新其计费系统,但没有完整的信息如何处理。

因此,我们有 ProductDetails 类,而不是 SkyDetails。我们可以在billingClient.queryProductDetailsAsync() 的回调中接收到这个对象。然后我们可以在这个对象上调用getSubscriptionOfferDetails() 并访问ProductDetails.PricingPhases 的列表。例如,如果产品有 2 个报价(基本报价和试用报价),我们会得到 2 个ProductDetails.PricingPhases 的列表。

那么当用户想要购买产品时,我们使用这个(来自官方文档):

val offerToken = productDetails.offerDetails(selectedOfferIndex).offerToken

selectedOfferIndex 是什么?我们应该始终选择第一个项目还是视情况而定?

提前感谢大家。

【问题讨论】:

  • 由于getSubscriptionOfferDetails()返回一个类型List<ProductDetails.SubscriptionOfferDetails>,你需要一个类型为ProductDetails.SubscriptionOfferDetails的单数对象,所以selectedOfferIndex是用户从列表中选择的项目的索引提供的优惠。有关 api 文档的更多信息:developer.android.com/reference/com/android/billingclient/api/…

标签: android in-app-billing


【解决方案1】:

例如,您有 2 个这样的订阅(2 个产品)

[
  ProductDetails{
    parsedJson={
      "productId": "...",
      "subscriptionOfferDetails": [
        {
          "offerIdToken": "...token_1...",
          "pricingPhases": [
            {
              "priceAmountMicros": 631000000000,
              "priceCurrencyCode": "VND",
              "formattedPrice": "₫631,000",
              "billingPeriod": "P6M",
              
            }
          ]
        }
      ]
    }
  },
  ProductDetails{
    parsedJson={
      "productId": "...",
      "subscriptionOfferDetails": [
        {
          "offerIdToken": "...token_2...",
          "pricingPhases": [
            {
              "priceAmountMicros": 0,
              "priceCurrencyCode": "VND",
              "formattedPrice": "Free",
              "billingPeriod": "P1M",
              "recurrenceMode": 2,
              "billingCycleCount": 1
            },
            {
              "priceAmountMicros": 112000000000,
              "priceCurrencyCode": "VND",
              "formattedPrice": "₫112,000",
              "billingPeriod": "P6M",
              
            }
          ],
          {
            "offerIdToken": "...token_3...",
            "pricingPhases": [
              {
                "priceAmountMicros": 631000000000,
                "priceCurrencyCode": "VND",
                "formattedPrice": "₫631,000",
                "billingPeriod": "P6M",
              }
            ]
          }
        }
      ]
    }
  }
]

第二次订阅时购买第一个计划(免费试用 1 个月)的示例(产品详情)

val productDetails2 = ...
val offerToken = "...token_2..."
// val offerToken = productDetails2.subscriptionOfferDetails.get(0).offerToken
// in json response, it name is offerIdToken but after parse it's offerToken

val productDetailsParamsList =
    listOf(
        BillingFlowParams.ProductDetailsParams.newBuilder()
            .setProductDetails(productDetails2)
            .setOfferToken(offerToken)
            .build()
    )
val billingFlowParams = BillingFlowParams.newBuilder()
        .setProductDetailsParamsList(productDetailsParamsList)
        .build()

billingClient.launchBillingFlow(this, billingFlowParams)

【讨论】:

    猜你喜欢
    • 2015-12-03
    • 1970-01-01
    • 2014-06-06
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    • 2023-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多