android in-app billing Trivial Drive - android

I am making in-app purchases like TrivialDrive. Call queryInventoryAsync:
mHelper.queryInventoryAsync(mGotInventoryListener);
mGotInventoryListener:
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
String price = inventory.getSkuDetails(SKU_ALL_INCLUSILE).getPrice();
Log.d("SKU", "price " + price);
}
};
OnClick work perfectly and I can make purchase. But getPrice() method produces NPE. Help me please! I want to show SKU information in ListView.
SOLVED! Just use:
mHelper.queryInventoryAsync(true, skuList, mGotInventoryListener);

Related

How to get a SKU price and display it in a TextView

I need to retrieve the price of my InApp Purchase and display it as a Title in my Card Layout.
This is how the card looks like, instead of "sku price", I need to have the actual price.
I have only this IAP so I shouldn't need an array or a list.
For implementing in App Billing I followed Android Developers - In App Billing Guide
So far I tried to write this inside my onQueryInventoryFinished() method, without any luck.
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
#Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
//have we been disposed of in the meantime? if so, quit
if (mHelper == null) return;
//is it a failure?
if(result.isFailure()) {
alert("Failed to query Inventory: " + result);
return;
}
String skuPrice = inv.getSkuDetails(SKU_PREMIUM).getPrice();
((TextView)findViewById(R.id.card_buy_title)).setText(skuPrice);
//do we have the premium upgrade?
Purchase premiumPurchase = inv.getPurchase(SKU_PREMIUM);
isPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
}
};
As far as I was able to understand this thing I did should get the price of already purchased items. So maybe that is why it does not work.
Can anyone of you point me in the right direction?
In your mHelper setup you have to query all inventory by calling
mHelper.queryInventoryAsync(true, allSkus, null, mGotInventoryListener);
where allSkus is a list of all skues.
Check IabHelper.

Google In-app billing: Can't query subscription details

I have a really strange problem with Google In-app billing API.
I want to get the details of my available subscriptions to show their localised price on the UI. I'm using the IabHelper to query the details of the SKUs I specify, but the result contains no products, but after I purchase the subscription it's working, even if I cancel the subscription then and reinstall the app.
Here is my code:
List<String> additionalSkus = new ArrayList<>();
for (Subscription subscription : subscriptions) {
additionalSkus.add(subscription.getSku());
}
iabHelper.queryInventoryAsync(true, additionalSkus, new IabHelper.QueryInventoryFinishedListener() {
#Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
if (iabHelper == null || result.isFailure()) {
Log.i("subs", result.getMessage());
}
for (Subscription subscription : subscriptions) {
SkuDetails skuDetails = inv.getSkuDetails(subscription.getSku());
if (skuDetails != null) {
subscription.setLocalizedPrice(skuDetails.getPrice());
Log.i("subs", subscription.getLocalizedPrice());
}
}
}
});
I have everything set up right about the In-app billing process. My products are active, I have a published beta APK, I can even get the details of my managed products, and purchase managed products and subscriptions, but this isn't working.
If you're using the latest version of IabHelper class, you should note that the function arguments relevant to additional skus to query are split to moreItemSkus (PRODUCT skus) and moreSubsSkus (SUBSCRIPTIONS skus).
public void queryInventoryAsync(final boolean querySkuDetails, final List<String> moreItemSkus,
final List<String> moreSubsSkus, final QueryInventoryFinishedListener listener)
In your case, your call should be
iabHelper.queryInventoryAsync(true, null, additionalSkus, new IabHelper.QueryInventoryFinishedListener() ...

working in app billing android application,change package name

I have working android project integrated with in app purchase.
now I created new application with different package name, added in app product with same sku in console.
now in android studio updated licence key with new app from console. Changed package name.
from all I understand it should work.
But I am not able to get sku detail on listner.
But the tab-listener is not giving detail of any sku.
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
// Handle failure
}
else {
// now here inventory does not skus information
}
}
Publish your apk (alpha/ beta group) to make it work.

Android iapV3: consuming an ond item

I am trying to implement both consumable & non consumable items.
My problem : I would like to consume an item bought sometime ago (as I purchased and didn't consume it immediately (what an error...)).
I've tried calling the consumeItem(); method when receiving "already bought" message in my purchase handler, but every time I call this method on this product (works for the new ones), I get a NullPointerException.
Here are my methods :
public void consumeItem() {
mHelper.queryInventoryAsync(mReceivedInventoryListener);
}
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
// Handle failure
} else {
mHelper.consumeAsync(inventory.getPurchase(SKU),
mConsumeFinishedListener);
}
}
};
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
if (result.isSuccess()) {
// clickButton.setEnabled(true);
} else {
// handle error
}
}
};
Any help would be welcome :)
Apparently, you can only consume an item when the puchase is made.
Well, to solve the problem, I implemented the concerned product consumption, and canceled my test order on my merchant account. All worked fine when Google cache updated.

Lost purchaseToken for In-App Billing Api

I was integrating Android In-App Billing api. but I lost the purchaseToken as there was a exception thrown somewhere. Now in API 3 I can't re-buy it without consuming the bought product. I can't consume it now as I don't have the purchaseToken? How to retrive it?
Or can I reset the purchase somehow??
You could get it by querying purchases.
Here is an example from Google: http://developer.android.com/google/play/billing/billing_integrate.html#billing-download
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
// Is it a failure?
if (result.isFailure()) {
complain("Failed to query inventory: " + result);
return;
}
Log.d(TAG, "Query inventory was successful.");
/*
* Check for items we own. Notice that for each purchase, we check
* the developer payload to see if it's correct! See
* verifyDeveloperPayload().
*/
// Do we have the premium upgrade?
Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
....
//<- here you can consume your purchase
}

Categories

Resources