简体   繁体   English

取消通过 google play billing 处理的购买后,购买查询在循环中显示购买 state 为 1

[英]After cancelling the purchase made by google play billing processing the purchase query shows purchase state as 1 in the loop

I have purchased and cancelled the order.我已经购买并取消了订单。 So it got refunded.所以它得到了退款。 After the refund the purchaseState is in 0 (UNSPECIFIED_STATE).退款后 purchaseState 为 0 (UNSPECIFIED_STATE)。 Hereafter cancellation of the purchaseQuerySkus return the state as 0.此后取消购买QuerySkus 将 state 返回为 0。

But the for loop returns the value as 1 for getPurchaseState.但是 for 循环将 getPurchaseState 的值返回为 1。

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
    
                     }
           

   

   

I know I'm a bit late for the party but stil... This also surprised me.我知道我参加派对有点晚了,但还是……这也让我感到惊讶。 It's because list is using toString() to show elements which in turns uses original json and purchaseState from json isn't directly matched with Purchase.PurchaseState enum.这是因为列表使用toString()来显示元素,这些元素又使用原始 json 和来自 json 的purchaseStatePurchase.PurchaseState枚举不直接匹配。 If you checkout Purchase.class file there you'll find this enum:如果你在那里签出Purchase.class文件,你会发现这个枚举:

@Retention(RetentionPolicy.SOURCE)
    public @interface PurchaseState {
        int UNSPECIFIED_STATE = 0;
        int PURCHASED = 1;
        int PENDING = 2;
}

and if you check Purchase.getPurchaseState() you'll see how it's converting purchaseState from json int to Purchase.PurchaseState enum.如果您检查Purchase.getPurchaseState() ,您将看到它如何将 purchaseState 从 json int 转换为Purchase.PurchaseState枚举。 Please note that by default it's picking purchased state and it looks like Purchase.PurchaseState.UNSPECIFIED_STATE from java class is never used.请注意,默认情况下,它正在挑选已购买的 state,看起来从未使用过来自 java class 的Purchase.PurchaseState.UNSPECIFIED_STATE

public int getPurchaseState() {
        switch(this.zzc.optInt("purchaseState", 1)) {
        case 4:
            return 2;
        default:
            return 1;
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM