[TUT] Simple InApp Billing / Payment

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

Re: [TUT] Simple InApp Billing / Payment

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

Exactly what I am researching now :)

My developer account was setup via a Hotmail account.

When I look at my phone, Settings, About, Phone Identity, Current username - It lists a sprintpcs.com address.

Also on my phone Android Market account is a gmail.com address.

And finally on my phone my default email account is also my Hotmail account.

So now I am a little confused, do I need to add any of the above (except my Hotmail developer) account to my developer "Edit Profile | Test Accounts" or?
DKDiveDude
Junior Developer
Junior Developer
 
Posts: 18
Joined: Mon Dec 13, 2010 2:40 pm

Top

Re: [TUT] Simple InApp Billing / Payment

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

You need to do the opposite. Create a new account with a new credit card that is not related.

You cannot purchase your own in app products just like you can't purchase your own applications!
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 4:39 pm

Just want you to know that I really, really appreciate your help! Thank you VERY much!

1) Create a new account where?

2) Actually I am able to purchase my own Apps via Android Market, through my phone with no problems what so ever. Actually when I goto my Merchant account, Google Checkout, Inbox I see my test purchases I made on my own Apps. Must be because on my phone the Android Market account email address is a gmail address, and I created my Android Developer account with a Hotmail account. This leads me to believe my problem lies elsewhere, as if I can buy my own Apps I should be able to buy the In-App products.
Last edited by DKDiveDude on Tue Aug 16, 2011 5:04 pm, edited 3 times in total.
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 4:43 pm

On this Android Developers page http://developer.android.com/guide/mark ... sting-real, they write:

Make one of your test accounts the primary account on your device.

To perform end-to-end testing of in-app billing, the primary account on your device must be one of the test accounts that you registered on the Android Market site. If the primary account on your device is not a test account, you must do a factory reset of the device and then sign in with one of your test accounts. To perform a factory reset, do the following:
Open Settings on your device.
Touch Privacy.
Touch Factory data reset.
Touch Reset phone.
After the phone resets, be sure to sign in with one of your test accounts during the device setup process.

Well first of all I don't have the "Privacy" section they talk about above, anyways I am sure if I look around I'll find where to do a Factory Reset, my question however is; What is my primary account they write about above?
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 4:54 pm

Just to be sure I was still able to purchase one of my own Apps, as it's been about 5 months since I last tested, I just purchased another one, a different App of mine. Worked like a charm!
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 7:10 pm

I've never done 'test' purchasing, I just purchase for real (which is naughty) :-) so I can't help too much.

You should have privacy, it's under Menu > Settings >
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 » Tue Aug 16, 2011 8:17 pm

Actually what I meant by a "test" purchase, was to test it live and then immediately get a refund. Anyways like I said this problem must be caused by something else, as my primary account on my phone is a gmail, same as MArket, and my developer account is a Hotmail account. So as I can buy my own Apps I should be able to by my own in-app products.
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 10:28 pm

Yes you should, as long as the APK is a signed for release APK? So you would have to put it on the phones SD then install it (or install it from the live market)
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 varun android » Wed Aug 17, 2011 9:24 am

blundell wrote:Yeah exactly :-) this is in BillingSecurity.java


first thanks for wonderfull post....
now when i am trying to run your sample application then i am getting exception.
I'm getting NullPointerException on the 2nd of these two lines (line 251 of BillingHelper.java):
Code: Select all

    ArrayList<VerifiedPurchase> purchases = BillingSecurity.verifyPurchase(signedData, signature);
    latestPurchase = purchases.get(0);


i have already set my public key but appication is crashing.
Another thing i want ask is that why application is not asked for login.
please help me i am the beginner in the android.
varun android
Freshman
Freshman
 
Posts: 5
Joined: Wed Aug 17, 2011 9:05 am

Re: [TUT] Simple InApp Billing / Payment

Postby blundell » Thu Aug 18, 2011 1:14 pm

It's crashing because you have removed the null check:

Code: Select all
ArrayList<VerifiedPurchase> purchases = BillingSecurity.verifyPurchase(signedData, signature);
                if(purchases != null && !purchases.isEmpty()){
                        latestPurchase = purchases.get(0);
                       
                        confirmTransaction(new String[]{latestPurchase.notificationId});
                } else {
                       Log.d(TAG, "BillingHelper.verifyPurchase error. purchases was null");
                }


And it is null because something has gone wrong with verifying the purchase, this all depends on your android market setup and what test product you are using. The best solution is to run your application in debug mode and step through each line to see where the error occurs.
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 varun android » Fri Aug 19, 2011 11:19 am

here you provide source code which does not contain this line
if(purchases != null && !purchases.isEmpty())
any way i have added it as you described but build is crashing.
i am running sample application which you provide on my tablet i have change public key but build is crashing.

logcat :
08-19 15:29:03.338: ERROR/BillingService(19389): Signature verification failed.
08-19 15:29:03.338: WARN/BillingService(19389): signature does not match data.
08-19 15:29:03.338: DEBUG/BillingService(19389): BillingHelper.verifyPurchase error. purchases was null
08-19 15:29:03.338: INFO/BillingService(19389): Transaction complete
08-19 15:29:03.338: DEBUG/AndroidRuntime(19389): Shutting down VM
08-19 15:29:03.338: WARN/dalvikvm(19389): threadid=1: thread exiting with uncaught exception (group=0x40148760)
08-19 15:29:03.338: ERROR/AndroidRuntime(19389): FATAL EXCEPTION: main
08-19 15:29:03.338: ERROR/AndroidRuntime(19389): java.lang.NullPointerException
08-19 15:29:03.338: ERROR/AndroidRuntime(19389): at com.blundell.test.AppMainTest$1.handleMessage(AppMainTest.java:42)
08-19 15:29:03.338: ERROR/AndroidRuntime(19389): at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 15:29:03.338: ERROR/AndroidRuntime(19389): at android.os.Looper.loop(Looper.java:132)
08-19 15:29:03.338: ERROR/AndroidRuntime(19389): at android.app.ActivityThread.main(ActivityThread.java:4025)
08-19 15:29:03.338: ERROR/AndroidRuntime(19389): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 15:29:03.338: ERROR/AndroidRuntime(19389): at java.lang.reflect.Method.invoke(Method.java:491)
08-19 15:29:03.338: ERROR/AndroidRuntime(19389): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-19 15:29:03.338: ERROR/AndroidRuntime(19389): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-19 15:29:03.338: ERROR/AndroidRuntime(19389): at dalvik.system.NativeStart.main(Native Method)
08-19 15:29:03.338: WARN/ActivityManager(128): Force finishing activity com.blundell.test/.AppMainTest
08-19 15:29:03.348: INFO/PowerManagerService(128): WakeLock: ActivityManager-Launch(PARTIAL_WAKE_LOCK ) is acquired by pid(128), uid(1000)
08-19 15:29:03.848: WARN/ActivityManager(128): Activity pause timeout for ActivityRecord{409acaa8 com.blundell.test/.AppMainTest}
varun android
Freshman
Freshman
 
Posts: 5
Joined: Wed Aug 17, 2011 9:05 am

Re: [TUT] Simple InApp Billing / Payment

Postby Hammy » Wed Aug 24, 2011 8:17 pm

I'm actually having the exact same problem as Tyshcr, crahses right after the toast message appears. I even tried the sample apk you uploaded, and that crashes as well with the same error.

I have been messing around the last little bit with the code, but have not been able to come up with a fix yet.. Any suggestions would be of help.
Last edited by Hammy on Wed Aug 24, 2011 10:52 pm, edited 1 time in total.
Hammy
Freshman
Freshman
 
Posts: 3
Joined: Sat Feb 12, 2011 5:56 pm

Re: [TUT] Simple InApp Billing / Payment

Postby blundell » Wed Aug 24, 2011 9:12 pm

It tell's you there error:

08-19 15:29:03.338: DEBUG/BillingService(19389): BillingHelper.verifyPurchase error. purchases was null

the purchases returned from verifyPurchase() was null. Therefore if you look at the source code there are multiple possible reasons.

But reading the logcat is shows the exact reason:

08-19 15:29:03.338: ERROR/BillingService(19389): Signature verification failed.
08-19 15:29:03.338: WARN/BillingService(19389): signature does not match data.

Look at BillingSecurity line 136 , you need to make sure you've set your signature correctly.

At the moment because the signature does not match the data that method is returning null.

So your signature (from your android market account) doesn't match the signature of your product (from your android market account). Ensure these are the same!
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 Hammy » Wed Aug 24, 2011 10:40 pm

I found out exactly where it is crashing, so I did some work-around so if It does do this in the real world, it cancels the transaction.
In BillingHelper.verifyPurchase() the first line: BillingSecurity.verifyPurchase returns null. So it crashes on latestPurchase = purchases.get(0);

It is returning null because the signature does not match the data.. Now I did copy my public key into the code exactly how it should be. My current setup is I'm debugging the project (com.blundell.test) straight to my device and using android.test.purchased as the product

Any suggestions for what I am doing wrong?
Hammy
Freshman
Freshman
 
Posts: 3
Joined: Sat Feb 12, 2011 5:56 pm

Re: [TUT] Simple InApp Billing / Payment

Postby xdebugx » Fri Aug 26, 2011 7:06 am

Hi Blundell, thanks for the tutorial. I am getting ready to add in-app purchases to my app, and this will be very helpful. Do you still intend to create an advanced tutorial for how to restore managed purchases?
xdebugx
Junior Developer
Junior Developer
 
Posts: 24
Joined: Fri Apr 02, 2010 4:06 am

Top
PreviousNext

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests