[TUT] Simple InApp Billing / Payment

Tutorials with advanced 'difficulty' and more Lines of Code.

Re: [TUT] Simple InApp Billing / Payment

Postby blundell » Tue Aug 09, 2011 8:08 am

Ah good job!

You may want.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. if (notifyIds[0] != null) {
  2.  
  3. } else {
  4.      // Do nothing - http://developer.android.com/guide/mark ... ion-notify
  5.      Log.d(TAG, "Received confirmTransaction, not sending as not needed.");
  6. }
  7.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Re: [TUT] Simple InApp Billing / Payment

Postby DKDiveDude » Fri Aug 12, 2011 3:42 pm

Thank you VERY much for this example.

I put in my Public key and your example purchases codes/items works fine in your test app and mine, example.
In BillingHelper.requestPurchase(mContext, "android.test.purchased") use one below;
android.test.purchased or android.test.canceled or android.test.refunded

However when I replace ItemID in your test app with "com.blundell.item.passport" or in my app the one I created in Android market for my test app, after I have created, uploaded to Android Market and installed APK on my phone a signed copy, and click my purchase button I get message "the item you requested is not available for purchase".

Any idea why?
DKDiveDude
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Dec 13, 2010 2:40 pm

Re: [TUT] Simple InApp Billing / Payment

Postby blundell » Fri Aug 12, 2011 4:02 pm

You need to create the item on your market.android.com/publish/Home application page.

Go to 'In-App Products' then 'Add in-app product'
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: [TUT] Simple InApp Billing / Payment

Postby DKDiveDude » Fri Aug 12, 2011 6:04 pm

Ok I apologize if I was not clear about that, but I already did add an item for that App and it's published
DKDiveDude
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Dec 13, 2010 2:40 pm

Re: [TUT] Simple InApp Billing / Payment

Postby Tyshcr » Fri Aug 12, 2011 8:40 pm

Thank you for posting this, it has been a great help.

I don't know if other people are having this problem. It is happening in the Sample App that you posted and in my personal application that I am creating - I am able to see the Android Market screen, select my payment method, and tap the "Accept & Buy" button. I then get a toast message that says "Thank You. Your item will appear shortly", but then the app crashes.

Any ideas would be very helpful.
Tyshcr
Freshman
Freshman
 
Posts: 2
Joined: Fri Aug 12, 2011 8:34 pm

Re: [TUT] Simple InApp Billing / Payment

Postby ajwest » Sat Aug 13, 2011 4:47 pm

This tutorial is awesome!

Ok, I was able to get everything to work, but like many I'm having problems restoring my managed purchases. I'm not worried about piracy at all, so after my purchase is successful I'm just storing with preferences.

However, after reinstalling, when I try to repurchase my item, I get a dialog from the market that says, "Item already purchased, You have already purchased this item, or the purchase is still pending."

I guess the idea is to a) check to see if the user prefs is there and b) if it's not there, before calling
Code: Select all
BillingHelper.requestPurchase(mContext, "my.item");

do something with?
Code: Select all
protected static void restoreTransactionInformation(Long nonce)


But how exactly do I do that? All I want to do is check to see if the person has already bought "my.item".

I wish this all worked like this:
Code: Select all
if (myItemPurchased == true){
//do stuff
}
ajwest
Freshman
Freshman
 
Posts: 2
Joined: Mon Apr 25, 2011 2:58 am

Top

Re: [TUT] Simple InApp Billing / Payment

Postby NickAVV » Sun Aug 14, 2011 8:41 pm

Hello, I'd like to know the same as the poster above me. I have something like this:

Code: Select all
purchased = (int) myPrefs.getInt("PURCHASED_STATE",0);
      if(purchased==0){
         BillingHelper.restoreTransactionInformation(BillingSecurity.generateNonce());
      }


I know that restoreTransactionInformation sends some sort of broadcast of its results, I'm not sure how to access that broadcast though.
Image
NickAVV
Freshman
Freshman
 
Posts: 7
Joined: Sun Oct 10, 2010 6:07 am
Location: Massachusetts

Re: [TUT] Simple InApp Billing / Payment

Postby Tyshcr » Mon Aug 15, 2011 8:25 pm

Okay I found that my apps are crashing with "Signature verification failed.", in the 'verify' method in BillingSecurity.java

I have put my public key as the base64EncodedPublicKey. I am not sure how all this verification works, so any ideas about why this is failing would be a great help.
Tyshcr
Freshman
Freshman
 
Posts: 2
Joined: Fri Aug 12, 2011 8:34 pm

Re: [TUT] Simple InApp Billing / Payment

Postby DKDiveDude » Tue Aug 16, 2011 2:57 pm

I am desperately trying to get in-app billing live in my app but still get the message "the item you requested is not available for purchase", after I created and published a test item in my app, and after having created, uploaded and installed signed APK.

Can somebody please verify the below syntax when requesting a purchase using code from this example, thanks!

BillingHelper.requestPurchase(mContext, "mycom.item.my_test_item");
Last edited by DKDiveDude on Tue Aug 16, 2011 3:26 pm, edited 1 time in total.
DKDiveDude
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Dec 13, 2010 2:40 pm

Re: [TUT] Simple InApp Billing / Payment

Postby blundell » Tue Aug 16, 2011 3:06 pm

@DKDiveDude You don't need the "android." unless you have actually added this to your in app item.

@NickAVV, @ajwest As for the restorePurchase call, I'm hoping to do a separate tutorial on this coming soon. It's a bit complex to squash on the end of this tutorial. And this tut is a good beginners introduction.

@Tyshcr Is your sig still failing? You need to make sure it corresponds to your market sig. Also the app shouldn't crash so I'd look you have correctly imported librarys etc
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: [TUT] Simple InApp Billing / Payment

Postby DKDiveDude » Tue Aug 16, 2011 3:25 pm

Oh actually that was a typo in the post which I now corrected. To make it clear, I did NOT add "Android" when I created, uploaded and installed the signed app.

This is really driving me insane, App been ready for two weeks but I still can't get to test purchase the item I created.
DKDiveDude
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Dec 13, 2010 2:40 pm

Re: [TUT] Simple InApp Billing / Payment

Postby NickAVV » Tue Aug 16, 2011 3:28 pm

Okay, thank you, please do make a tutorial on that. That would be wonderful haha
Image
NickAVV
Freshman
Freshman
 
Posts: 7
Joined: Sun Oct 10, 2010 6:07 am
Location: Massachusetts

Re: [TUT] Simple InApp Billing / Payment

Postby DKDiveDude » Tue Aug 16, 2011 3:34 pm

Is it because I need to add "com." to the item string?
I see in your remark below the call you have: "com.blundell.item.passport"
DKDiveDude
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Dec 13, 2010 2:40 pm

Re: [TUT] Simple InApp Billing / Payment

Postby DKDiveDude » Tue Aug 16, 2011 3:47 pm

Nope created, uploaded and installed new APK and it produced same error. This is what I got now straight off your example;

if(BillingHelper.isBillingSupported()){
BillingHelper.requestPurchase(mContext, "com.mycom.item.my_test_item");
// android.test.purchased or android.test.canceled or android.test.refunded or com.blundell.item.passport
} else {
Log.i(TAG,"Can't purchase on this device");
buyBtn.setEnabled(false); // XXX press button before service started will disable when it shouldnt
}

One thing I was puzzled about, does the item string not need to tell Android Market which App the available item resides in, or does it figure that out automatically when calling from the App?
DKDiveDude
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Dec 13, 2010 2:40 pm

Re: [TUT] Simple InApp Billing / Payment

Postby blundell » Tue Aug 16, 2011 4:11 pm

It knows from the android implementation.

Your not trying to purchase your own item from the same gmail address are you? :-)
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top
PreviousNext

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 6 guests