WISHY
WISHY

Reputation: 11999

BILLING_RESPONSE_RESULT_ERROR android in app purchase AIDL?

My app has in-app products to purchase. Till yesterday consumers were able to purchase the products but from today morning only I keep BILLING_RESPONSE_RESULT_ERROR. Can someone walk me through for the fix

Below is my code for the purchase flow

Bundle activeSubs = null;
                try {
                    activeSubs = inAppBillingService.getPurchases(3,
                            currentActivity.getPackageName(),
                            "subs",
                            null);
                } catch (RemoteException e) {
                    //Log.e(TAG, "Failed to retrieve current active subscriptions: " + e.getMessage());
                }

                ArrayList<String> subscribedSkus = null;

                if (activeSubs != null) {
                    subscribedSkus = activeSubs.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
                }

                Bundle buyIntentBundle;
                if (subscribedSkus != null && !subscribedSkus.isEmpty()) {
                    //Log.d(TAG, "Initiating upgrade purchase");
                } else {
                    //Log.d(TAG, "Initiating new item purchase");
                }

                buyIntentBundle = inAppBillingService.getBuyIntentToReplaceSkus(5,
                        currentActivity.getPackageName(),
                        subscribedSkus,
                        skuToPurchase,
                        "subs",
                        null);

                if (buyIntentBundle != null) {
                    int resultCode = buyIntentBundle.getInt("RESPONSE_CODE");
                    if (resultCode == 0) {
                        PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
                        if (pendingIntent != null) {
                            //Log.d(TAG, "Launching intent to initiate item purchase");
                            currentActivity.startIntentSenderForResult(pendingIntent.getIntentSender(),
                                    RC_PURCHASE_PLAY_STORE_ITEM,
                                    new Intent(),
                                    0,
                                    0,
                                    0);
                        } else {
                            showToast(getLanguageResourcesFile().getUIresource(currentActivity.getString(R.string.app_cms_cancel_subscription_subscription_not_valid_message)),
                                    Toast.LENGTH_LONG);
                        }
                    } else {
                        if (resultCode == IabHelper.BILLING_RESPONSE_RESULT_USER_CANCELED) {
                            showDialog(DialogType.SUBSCRIBE, getLanguageResourcesFile().getUIresource(currentActivity.getString(R.string.subscription_billing_response_result_user_canceled)), false, null, null);
                        } else if (resultCode == IabHelper.BILLING_RESPONSE_RESULT_SERVICE_UNAVAILABLE) {
                            showDialog(DialogType.SUBSCRIBE, getLanguageResourcesFile().getUIresource(currentActivity.getString(R.string.subscription_billing_response_result_service_unavailable)), false, null, null);
                        } else if (resultCode == IabHelper.BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE) {
                            addGoogleAccountToDevice();
                        } else if (resultCode == IabHelper.BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE) {
                            showDialog(DialogType.SUBSCRIBE, getLanguageResourcesFile().getUIresource(currentActivity.getString(R.string.subscription_billing_response_result_item_unavailable)), false, null, null);
                        } else if (resultCode == IabHelper.BILLING_RESPONSE_RESULT_DEVELOPER_ERROR) {
                            showDialog(DialogType.SUBSCRIBE, getLanguageResourcesFile().getUIresource(currentActivity.getString(R.string.subscription_billing_response_result_developer_error)), false, null, null);
                        } else if (resultCode == IabHelper.BILLING_RESPONSE_RESULT_ERROR) {
                            showDialog(DialogType.SUBSCRIBE, getLanguageResourcesFile().getUIresource(currentActivity.getString(R.string.subscription_billing_response_result_error)), false, null, null);
                        } else if (resultCode == IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                            showDialog(DialogType.SUBSCRIBE, getLanguageResourcesFile().getUIresource(currentActivity.getString(R.string.subscription_billing_response_item_already_purchased)), false, null, null);
                        } else if (resultCode == IabHelper.BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED) {
                            showDialog(DialogType.SUBSCRIBE, getLanguageResourcesFile().getUIresource(currentActivity.getString(R.string.subscription_billing_response_item_not_owned)), false, null, null);
                        }
                    }
                }

Upvotes: 1

Views: 832

Answers (2)

WISHY
WISHY

Reputation: 11999

Don't know what was causing the issue. Had to change bit of code

 Bundle activeSubs = null;
                try {
                    activeSubs = inAppBillingService.getPurchases(3,
                            currentActivity.getPackageName(),
                            "subs",
                            null);
                } catch (RemoteException e) {
                    //Log.e(TAG, "Failed to retrieve current active subscriptions: " + e.getMessage());
                }

                ArrayList<String> subscribedSkus = null;

                if (activeSubs != null) {
                    subscribedSkus = activeSubs.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
                }

                Bundle buyIntentBundle;
                if (subscribedSkus != null && !subscribedSkus.isEmpty()) {
                    //Log.d(TAG, "Initiating upgrade purchase");
                } else {
                    //Log.d(TAG, "Initiating new item purchase");
                }
                String purchasePayload = "subs" + ":" + skuToPurchase;
                /*buyIntentBundle = inAppBillingService.getBuyIntentToReplaceSkus(5,
                        currentActivity.getPackageName(),
                        subscribedSkus,
                        skuToPurchase,
                        "subs",
                        purchasePayload);*/
                buyIntentBundle = inAppBillingService.getBuyIntent(3,
                        currentActivity.getPackageName(),
                        skuToPurchase,
                        "subs",
                        purchasePayload);

Upvotes: 1

Andrea De Gaetano
Andrea De Gaetano

Reputation: 335

We found a solution (maybe). Something changed in google play services.. we had a working app until some days ago.. btw In our case , we used billingService.getBuyIntentExtraParams

method.. and we added

extraParams.putStringArrayList("skusToReplace",actualSkus);

with actualSkus, rappresenting the list of skus/subscription the user had. For new user this call generated the Error code 6 (it worked until some days ago)... so we added this check:

if ( ! actualSkus.isEmpty() ) extraParams.putStringArrayList("skusToReplace",actualSkus)

Upvotes: 0

Related Questions