This is the first time that I am implementing billing in an Android app, and I took most of the code directly from the guideline , and everything forgets perfectly, until I thought about a refund. The sample application is already coming back, but it's weird! The return is received in the application as a purchase, but with the return condition, which is quite understandable, but the original source is as follows:
// Count the number of times the product was purchased while (cursor.moveToNext()) { int stateIndex = cursor.getInt(2); PurchaseState state = PurchaseState.valueOf(stateIndex); // Note that a refunded purchase is treated as a purchase. Such // a friendly refund policy is nice for the user. if (state == PurchaseState.PURCHASED || state == PurchaseState.REFUNDED) { quantity += 1; } } // Update the "purchased items" table updatePurchasedItem(productId, quantity);
its adding goods, even if it was returned, and I had no idea why this is so? Does the returned product have a special identifier or what am I missing? I just tried this with testing products, so I had no idea.
The updatePurchasedItem method removes the record from the table if the number is 0, which seems completely correct, so I changed the code to this
while (cursor.moveToNext()) { int stateIndex = cursor.getInt(2); PurchaseState state = PurchaseState.valueOf(stateIndex); // Note that a refunded purchase is treated as a purchase. Such // a friendly refund policy is nice for the user. if(Consts.DEBUG) Log.v(TAG, state == PurchaseState.PURCHASED ? "purchase" : "refund"); if (state == PurchaseState.PURCHASED) { quantity += 1; } else if(state == PurchaseState.REFUNDED) { quantity = 0; } } // Update the "purchased items" table updatePurchasedItem(productId, quantity);
but I doubt that the sample application will have the wrong code, so Iโm absolutely sure that I am doing it right!
How should I handle this? Please help me!
source share