Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In app billing API v3 INAPP_PURCHASE_DATA is null in bundle when onActivityResult is called

I am implementing subscription billing using the Version 3 Billing API. After the payment dialog has closed (payment succeeded), control is returned back to my activity

Calling method

        String payload = UUID.randomUUID().toString();
        bundle = mService.getBuyIntent(3, getPackageName(), mProduct, "subs", payload);

        int responseCode = bundle.getInt("RESPONSE_CODE");
        if (responseCode == 0) {
             PendingIntent pendingIntent = bundle.getParcelable("BUY_INTENT");
             startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
        } else if (responseCode == 1) {
                mErrorMessage.setText(getResources().getString(R.string.purchase_cancelled));
                mErrorMessage.setVisibility(View.VISIBLE);
        } else if (responseCode == 7) {
                mErrorMessage.setText(getResources().getString(R.string.payment_twice));
                mErrorMessage.setVisibility(View.VISIBLE);
        } else {
                mErrorMessage.setText(getResources().getString(R.string.payment_general_error));
                mErrorMessage.setVisibility(View.VISIBLE);
        }

My activity

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            // Null
            String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA"
        }
    }

The problem is that the purchaseData string is null. This might be because I have already purchased this subscription ( a million times when testing ) - and that I should have checked with getPurchases() first.

Is it known for purchases to "go through - apparently with success", if the user tries to pay when he or she is 1) a current subscriber, or 2) in the period after cancelleation but before the service expires?

like image 533
Glenn Bech Avatar asked Aug 25 '13 08:08

Glenn Bech


1 Answers

I had the same problem and I found out that I was using ITEM_TYPE_SUBS = "subs" instead of ITEM_TYPE_INAPP = "inapp".

When I put the right parameter in, it worked as expected.

like image 162
Repminister Avatar answered Nov 15 '22 13:11

Repminister