这是我第一次在 android 应用程序中实现应用程序内计费,我直接从指南中获取了大部分代码,一切都完全忘记了,直到我想到退款。示例应用程序已经实现了退款,但是以一种奇怪的方式!退款是在应用程序上作为购买收到的,但退款状态是完全可以理解的,但原始来源如下所示:
// 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);
即使它已退款,它也会添加项目,我不知道这是为什么?退款的商品是否有特殊 ID 或我缺少什么?我只用测试产品尝试过这个,所以我不知道。
如果数量为 0,updatePurchasedItem 方法会从表中删除条目,这似乎完全正确,所以我将代码更改为此
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);
但我怀疑示例应用程序中会有错误的代码,所以我完全不确定我是否做对了!
我该如何处理?请帮我!