Unable to test In App Subscription

蹲街弑〆低调 提交于 2019-11-26 23:18:04

问题


I couldn't find a way to test InApp Subscription with the test product ID by google i.e. private final String productID = "android.test.purchased"; // Test Product ID by Google

In the docs it is not written anywhere that InAPP subscription couldn't be tested with test product nor it is mentioned anywhere,how to test InApp subscription.

I have implemented my code following docs(InAppV3).

The doc says:

Implementing Subscriptions: Launching a purchase flow for a subscription is similar to launching the purchase flow for a product, with the exception that the product type must be set to "subs". The purchase result is delivered to your Activity's onActivityResult method, exactly as in the case of in-app products.

and I have also implemented that properly.

My app is working if I replace "inapp" with "subs",i.e. it is working perfectly for products and not for subscriptions.

When I change "inapp" to "subs" then the purchase is returning:

09-24 14:01:12.943: I/(16929): isBillingSupported() - success : return 0
09-24 14:01:12.943: D/Finsky(2598): [281] InAppBillingUtils.getPreferredAccount: com.kgandroid.inappsubscriptiondemo: Account from first account - [MOn42QuZgF98vxJi0p3wAN3rfzQ]
09-24 14:01:12.943: I/(16929): getPurchases() - success return Bundle
09-24 14:01:12.943: I/(16929): getPurchases() - "RESPONSE_CODE" return 0
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_PURCHASE_ITEM_LIST" return []
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_PURCHASE_DATA_LIST" return []
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_DATA_SIGNATURE" return null
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_CONTINUATION_TOKEN" return null

As you can see no details for android.test.purchased is returning.The test inapp purchase dialog is also not opening.

The relevant purchase code(Though it is not related to the problem I guess):

void purchase()
{
    if (!blnBind) return;
    if (mService == null) return;

    ArrayList<String> skuList = new ArrayList<String>();
    skuList.add(productID);
    Bundle querySkus = new Bundle();
    querySkus.putStringArrayList("ITEM_ID_LIST", skuList);

    Bundle skuDetails;
    try {
        skuDetails = mService.getSkuDetails(3, getPackageName(), "subs", querySkus);
        System.out.println(skuDetails);
        Toast.makeText(context, "getSkuDetails() - success return Bundle", Toast.LENGTH_SHORT).show();
        Log.i(tag, "getSkuDetails() - success return Bundle");
    } catch (RemoteException e) {
        e.printStackTrace();

        Toast.makeText(context, "getSkuDetails() - fail!", Toast.LENGTH_SHORT).show();
        Log.w(tag, "getSkuDetails() - fail!");
        return;
    }

    int response = skuDetails.getInt("RESPONSE_CODE");
    Toast.makeText(context, "getSkuDetails() - \"RESPONSE_CODE\" return " + String.valueOf(response), Toast.LENGTH_SHORT).show();
    Log.i(tag, "getSkuDetails() - \"RESPONSE_CODE\" return " + String.valueOf(response));

    if (response != 0) return;

    ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
    Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\" return " + responseList.toString());

    if (responseList.size() == 0) return;

    for (String thisResponse : responseList) {
        try {
            JSONObject object = new JSONObject(thisResponse);

            String sku = object.getString("productId");
            String title = object.getString("title");
            String price = object.getString("price");

            Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\":\"productId\" return " + sku);
            Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\":\"title\" return " + title);
            Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\":\"price\" return " + price);

            if (!sku.equals(productID)) continue;

            Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), sku, "subs", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");

            Toast.makeText(context, "getBuyIntent() - success return Bundle", Toast.LENGTH_SHORT).show();
            Log.i(tag, "getBuyIntent() - success return Bundle");

            response = buyIntentBundle.getInt("RESPONSE_CODE");
            //Toast.makeText(context, "getBuyIntent() - \"RESPONSE_CODE\" return " + String.valueOf(response), Toast.LENGTH_SHORT).show();
            Log.i(tag, "getBuyIntent() - \"RESPONSE_CODE\" return " + String.valueOf(response));

            if (response != 0) continue;

            PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
            startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), 0, 0, 0);
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();

            //Toast.makeText(context, "getSkuDetails() - fail!", Toast.LENGTH_SHORT).show();
            Log.w(tag, "getBuyIntent() - fail!");
        } catch (SendIntentException e) {
            e.printStackTrace();
        }
    } 
}

Does subscription supports test purchases?? If not,how to test subscription?? If yes,why google is returning null??

Any related docs or links will be also helpful.


回答1:


I've never tried testing subs using the Test Product ID ("android.test.purchased") and I'm not sure it would work as seems to be a Product ID not a Subscription ID. I use real subscription IDs (that I create on Google Play Developer Console), but I use an account other than my developer account (i.e. the one you use to publish the app).

If you go to https://play.google.com/apps/publish/ then click on Settings, you'll see a field called "Gmail accounts with testing access". You can type one or more gmail addresses for accounts with which you want to test your purchases. Any account added there that purchases a subscription will not be charged and subscriptions will last for 24 hours. (source: http://developer.android.com/google/play/billing/billing_testing.html and my own experience)

That works for me. Although I did seem to have found a bug: Trying to cancel an Android test subscription gives me a 500 response code

Good luck with your app!

Edit:

From Google Docs (http://developer.android.com/google/play/billing/billing_testing.html#billing-testing-test)

You cannot use your developer account to test the complete in-app purchase process because Google payments does not let you buy items from yourself.

Have you tried using another account?



来源:https://stackoverflow.com/questions/32756889/unable-to-test-in-app-subscription

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