This is the first time I am implementing in-app billing in android app and I took most of the code straightly from guideline and everything forget perfectly til I thought about refunding. The example app has already refunding implemented, but in a weird way! Refund is received on app as purchase but with state of refund which is totally understandable but the original source looks like this:
// 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 item even if it was refunded and I got no idea why is this? Does refunded item has special id or what am i missing? I've only tried this yet with the testing products so I got no idea.
updatePurchasedItem method removes entry from table if quantity is 0 which seems totally right, so I changed my 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 there would be wrong code in the example app so I am totally unsure if I am doing it right!
How should i handle this? Please help me!