how to cancel an in-app test purchase on android?

孤街浪徒 提交于 2019-11-29 02:10:42

问题


Until june 20th 2016 i was able to cancel test purchases done in my app. Doing multiple in-app purchases (not consumable) from the same test account made it easy to develop and test the code without too much hazzle.

After 20th june 2016, the purchases did not show in my merchant account and i was unable to do more than 1 purchase from my test account. All i got was the: "you already own this item" message.

I logged a request to the google developer support group and the answer was:

Beginning June 20, 2016, we changed test purchases for one-time in-app purchases (IAPs). Previously, test purchases for one-time IAPs generated order IDs. Starting June 20, 2016, one-time IAPs do not generate official order IDs (if at all) and will not appear in the Merchant Center. This behavior already applies to subscription IAPs. You can learn more about testing in-app billing in the Android Developers Help Center: https://developer.android.com/google/play/billing/billing_testing.html#testing-purchases

allright.. so i go to the mentioned link and theres a section there: Canceling completed test purchases which states:

Google Play accumulates completed test purchases for each user but does not pass them on to financial processing. In some cases, you might want to manually cancel a test purchase to continue testing. To do so, open the app page in the Play Store. If the test purchase that you want to cancel is a subscription, you can also use the cancel() method of the Purchases.subscriptions API. Important: The refund() and revoke() methods of the Purchases.subscriptions API don't support test purchases.

So I go to the app page in play store...and do what exactly? the webpage does not state what i am supposed to do there. anyone know?

it does say: you can also use the cancel() method of the Purchases.subscriptions API.

which indicates that using the cancel() method is not the only method.

How to solve this without adding additional code in my app?


回答1:


I went into the main Google Play Console page and clicked on Order Management. Under that I was able to select all test purchases and Refund them. I'm the primary developer of the app so I have access. If you are a tester you'd probably have to contact the support team and request that they refund your order.




回答2:


All managed in-app products are consumable.

as stated in the docs.

That means that you can consume an owned item instead of cancelling the purchase and buy it all over again. I suggest querying the inventory at the app launch time:

mIabHelper.queryInventoryAsync(this);

You can then consume the owned item in the callback:

@Override
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
    Purchase purchase = inventory.getPurchase(MY_SKU);
    boolean isBought = (purchase != null && verifyDeveloperPayload(purchase));
    if (isBought) {
        mIabHelper.consumeAsync(purchase, new OnConsumeFinishedListener() {
            @Override
            public void onConsumeFinished(Purchase purchase, IabResult result) {
                //Clear the purchase info from persistent storage
            }
        });
    }
}

This is OK for testing the IAB flow but make sure to remove this code from the release version.




回答3:


  • On Play Console, go to Developer Account -> Account Details, set the license testers (you are one by default)

  • Purchase items

  • Go to Order Management, choose those test orders, select: refund, but DON'T FORGET to check REVOKE when you are refunding. (I forgot to revoke, and now can't find a way to take them back)

Anyway, another test account will do.




回答4:


I found a solution which isn't very convenient, but works. It seems like you can consume uncomsumable products and that way you can buy them again. I'm working with phonegap so I only have example code for the cordova-plugin-purchase plugin:

store.when("your.product.id").updated(product => {
    if(product.owned) {
        var transaction = product.transaction;
        product.transaction = null;
        store.inappbilling.consumePurchase(
            function() { // success
                alert("consume success");
            },
            function(err, code) { // error
                alert("consume error " + err)
            },
            product.id,
            transaction.id
        );
    }
});

The updated callback gets called when you call store.refresh() or buy the product. So depending on your use case you'd want to implement an additional method of checking when to consume the product.

I have no experience with the native Android in-app payments, but obviously you will be able to consume the products there as well.

Edit: Sorry, I just read that you didn't want to include additional code in your project. I don't think that's possible at the moment, but would like to keep my answer here because it might help other people trying to test in-app payments.




回答5:


From https://stackoverflow.com/a/30178861/326904 @mttmllns

No need to write any special consumption code. Just use the adb command for clearing the Google Play Store data:

adb shell pm clear com.android.vending



回答6:


Didn't find a solution for this. My workaround is simply remove the current test user from the test users list, make a real purchase, then cancel it using the merchant console.



来源:https://stackoverflow.com/questions/38835452/how-to-cancel-an-in-app-test-purchase-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!