You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求Google Billing Library返回的Android应用内购买收据响应示例

Hey there, I've put together sample responses you can expect from the Google Billing Library for Android in-app purchases, covering common use cases. These are based on typical JSON representations of the Purchase and SubscriptionPurchase objects you'll work with in your code:

1. 成功的一次性应用内购买响应

This is what you'd receive when a user completes a one-time purchase (like a consumable or non-consumable item):

{
  "orderId": "GPA.1234-5678-9012-34567",
  "packageName": "com.yourcompany.yourapp",
  "productId": "premium_upgrade",
  "purchaseTime": 1690000000000,
  "purchaseState": 0,
  "developerPayload": "custom_user_id_123",
  "purchaseToken": "apabpnljmndejmocppdmlkjh.AO-J1Oz...",
  "quantity": 1,
  "isAutoRenewing": false,
  "acknowledged": false
}

Key field breakdown:

  • purchaseState: 0 means the purchase is successful (1 = pending, 2 = canceled)
  • acknowledged: Set to true after you call BillingClient.acknowledgePurchase() to confirm you've processed the purchase
  • purchaseToken: Use this value to verify the purchase with Google's Play Developer API on your server
2. 订阅购买/状态查询响应

For subscriptions, the response includes extra fields related to renewal cycles and pricing details:

{
  "orderId": "GPA.1234-5678-9012-34567",
  "packageName": "com.yourcompany.yourapp",
  "productId": "monthly_pro_sub",
  "purchaseTime": 1690000000000,
  "purchaseState": 0,
  "developerPayload": "custom_user_id_123",
  "purchaseToken": "apabpnljmndejmocppdmlkjh.AO-J1Oz...",
  "quantity": 1,
  "isAutoRenewing": true,
  "acknowledged": true,
  "priceAmountMicros": 9990000,
  "priceCurrencyCode": "USD",
  "expiryTimeMillis": 1692678000000,
  "autoResumeTimeMillis": 0,
  "cancelReason": 0,
  "userCancellationTimeMillis": 0
}

Key subscription-specific fields:

  • isAutoRenewing: Indicates if the subscription will renew automatically at the end of the current period
  • expiryTimeMillis: Timestamp marking when the active subscription period ends
  • priceAmountMicros: The subscription price in micros (divide by 1,000,000 to get the actual currency value)
  • cancelReason: 0 = no cancellation, 1 = user initiated cancellation, 2 = billing error, etc.

Note: The exact fields might vary slightly depending on your Billing Library version (e.g., v5 vs v6) and the type of purchase, but these samples cover the core data points you'll need.

内容的提问来源于stack exchange,提问作者Kishan Vaishnav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:15:00