我在我的应用中使用基于订阅的结算,用户可以按月付款订阅高级会员资格。我正在编写代码,我每隔30天检查高级用户的付款状态,并在未支付每月付款的情况下取消他的高级会员资格。我的问题是,如果付款失败,“inventory.getPurchase(my_prod_id)会返回什么?”对于已取消的订单也是如此。
我检查付款状态的代码在
之下/**
* query for the product for premium membership from inventory,
*/
public void queryInventory(){
IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory)
{
if (result.isFailure()) {
// handle error
Toast.makeText(getApplicationContext(), "Error : "+result.toString(), Toast.LENGTH_LONG).show();
}
else{
try{
//check if user has existing subscription purchase
Purchase membershipPurchase = inventory.getPurchase
if (membershipPurchase !=null){
if (Integer.parseInt(membershipPurchase.getOrderId())>Integer.parseInt(jsonPurchase.getString("OrderId"))){
//means membership has been renewed, hence update the backend database with new purchase data
updateUserTable();
}
}
else{
//subscription has not been renewed or has expired. Alert user and update user status back to free member.
Toast.makeText(ctx.getApplicationContext(), "Your Premium User membership has expired or not renewed. Please go to 'MyApps' in Google Play and verify", Toast.LENGTH_LONG).show();
//update backend database with status change to free member
updatetoFree();
}
}
catch(Exception e){
Toast.makeText(ctx.getApplicationContext(), "Error in membership verification: "+e.toString(), Toast.LENGTH_LONG).show();
}
}
}
};
List<String> additionalSkuList = new ArrayList<String>();
additionalSkuList.add(sku_premium_membership);
mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener);
}