求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:
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 totrueafter you callBillingClient.acknowledgePurchase()to confirm you've processed the purchasepurchaseToken: Use this value to verify the purchase with Google's Play Developer API on your server
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 periodexpiryTimeMillis: Timestamp marking when the active subscription period endspriceAmountMicros: 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

