Friday, July 6, 2012

[android-developers] Re: In App Billing V2: Item not found, but purchase OK

This is a bug in the sample Dungeons application in the onClick method for the purchase button.

I posted a solution here:
http://stackoverflow.com/a/11371927/625030

The supplied method has a bug in the if {} else if {} statement where it causes the mBillingService.requestPurchase to be called twice, when the selected item is not a subscription item (mManagedType != Managed.SUBSCRIPTION). So the same item will be requested twice, once with an item type of "inapp" (which is the valid request) and immediately after that with an item type of "subs" (which is incorrect and it shows "item not found").

Here is the buggy code:

if (mManagedType != Managed.SUBSCRIPTION &&
                   
!mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_INAPP, mPayloadContents)) {
                showDialog
(DIALOG_BILLING_NOT_SUPPORTED_ID);
           
} else if (!mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_SUBSCRIPTION, mPayloadContents)) {
               
// Note: mManagedType == Managed.SUBSCRIPTION
                showDialog
(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
           
}

To fix this, add mManagedType == Managed.SUBSCRIPTION to the else if above.

Here is how the function should look:

@Override
   
public void onClick(View v) {
       
if (v == mBuyButton) {
           
if (Consts.DEBUG) {
               
Log.d(TAG, "buying: " + mItemName + " sku: " + mSku);
           
}

           
if (mManagedType != Managed.SUBSCRIPTION &&
                   
!mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_INAPP, mPayloadContents)) {
                showDialog
(DIALOG_BILLING_NOT_SUPPORTED_ID);
           
} else if (mManagedType == Managed.SUBSCRIPTION && !mBillingService.requestPurchase(mSku, Consts.ITEM_TYPE_SUBSCRIPTION, mPayloadContents)) {
               
// Note: mManagedType == Managed.SUBSCRIPTION
                showDialog
(DIALOG_SUBSCRIPTIONS_NOT_SUPPORTED_ID);
           
}
       
} else if (v == mEditPayloadButton) {
            showPayloadEditDialog
();
       
} else if (v == mEditSubscriptionsButton) {
            editSubscriptions
();
       
}
   
}

On Saturday, 16 June 2012 00:23:02 UTC-4, John wrote:
Have In App Billing V2 incorporated into my code and be able to buy one-time purchase item and yearly subscription item. But when purchasing one-time purchase item, always get the message "Item not found". Is this a Google bug? Any help? Thanks in advance.

-John

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment