I have purchased and cancelled the order. So it got refunded. After the refund the purchaseState is in 0 (UNSPECIFIED_STATE). Hereafter cancellation of the purchaseQuerySkus return the state as 0.
But the for loop returns the value as 1 for getPurchaseState.
But while processing it satisfying the condition. It is weird.
List returns for me [Purchase.Json: {
"orderId": "orderID",
"packageName": "com.android.app",
"productId": "in_app",
"purchaseTime": 29323923232,
"purchaseState": 0,
"purchaseToken": "weorehrhjewrhewirhewiruhewfbewfbweuyfbwehfbweyfbwefbwefweuyfhweyufhwe",
"quantity": 1,
"acknowledged": true
}]
Code:
private List<Purchase> purchaseQuerySkus;
private void queryPurchasesAsync() {
if(mBillingClient.isReady()) {
LogUtils.LOGI(TAG, "queryPurchasesAsync");
billingClient.queryPurchasesAsync(BillingClient.SkuType.INAPP, new PurchasesResponseListener() {
@Override
public void onQueryPurchasesResponse(@NonNull BillingResult billingResult, @NonNull List<Purchase> list) {
LogUtils.LOGI(TAG, "queryPurchasesAsync list" + list);
purchaseQuerySkus = list;
}
});
}
}
Checking the purchase is already made or not after the cancellation. It returning the purchaseState as 0. But the print values shows as 1.
if (billingClient.isReady()) {
queryPurchasesAsync();
LogUtils.LOGI(TAG, "QUE_PUR_LIST_SIZE " + purchaseQuerySkus.size());
//It returns the size of the list as 1
for (Purchase pur : purchaseQuerySkus) {
String thisSku = pur.getSkus().get(0); //my sku value
LogUtils.LOGI(TAG, "pur.getPurchase state " + pur.getPurchaseState()); //It prints the value as 1
But the returned list has the purchaseState as 0 which I have added above.
// So it satisfying the condition and showing the item was purchased
if (pur.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
// Acknowledging the user if purchased
}