Beginner with In-apps

Hello.

I am creating an application in which some parts are blocked. To unlock all parts you will have to make a single purchase (It would be like having a ‘lite’ and ‘full’ version).

I want that when you click on a locked content the app open the content if you have bought it. If not, the app open a screer when you can purchase the ‘full’ content.

I try to store in an external file (txt) a variable which indicates if the app has been purchased or not (like the choice of language or sound activated). I have doubts whether this would be a correct method or insurance.

Thanks

It’s not wrong to track that on your own, but it’s certainly not insurance.  If someone removes your app then re-installs it, your data files get deleted.   The store.* API has a call:  store.restore() that will instruct the store to provide you a list of items that person has purchased.  If you see your item in the list, then unlock your content.  If you do this at app start up time, you will always know the state of your app, assuming you have network connectivity.

Thank you Darth Rob.   :wink:

I will use the method that you show me, but it brings me a question:

I can keep an internal variable, but if the user closes the application, that variable is lost. So if I do not keep an external variable to indicate whether the app has been purchased, how do I do to unlock the content if there is no connection?

I have a quick question Rob.

You say that “store.restore() will instruct the store to provide you a list of items that person has purchased”

I read in the docs somewhere that iOS returns a “restored” state, but Google doesn’t - it returns “purchased” again.

How would this work in regards to consumable items (e.g. in game currency)?

If the user bought a set of levels, and 100 coins - I would only expect the levels to be restored, not the consumable coins. Since I’m still at the beginning of setting up IAP, I’d be interested to know how this is handled. Are consumables not returned in the restore function? If they are, then that makes restoring on Google Play very difficult, since we’d need to differentiate between a real purchase event and a “purchased” event triggered by store.restore().

Also (while we’re on the subject) I’ve posted before that there are no full IAP tutorials, though there are some that cover a lot of the info, and we have the sample app. However none of these explain what to actually do once the purchase has all gone through successfully.

I presume that it would be something like

function transactionCallback( event )     if event.transaction.state == "purchased" then                  if event.transaction.productIdentifier == "mycompany.mygame.consumableOne" then                          coinTotal = coinTotal + 100 --then save coins locally / on server         end     end end  

Is that correct? I find it a bit odd that no one has mentioned it in any of the tutorials, maybe it’s super obvious but when you’re dealing with something as complicated (and potentially costly if you do it wrong) as this there should probably be a full on tutorial covering this somewhere. If there is one and I’ve missed it then please ignore my ramblings  :stuck_out_tongue:

@juan-imaxina, this is probably why you want to save the information to a local database or text file too.

@AlanPlantPot, I’m working on an app for a client that is using IAP and well I cursed Google multiple times trying to figure out how to determine if a purchase is a purchase or a restore.  I ended up parsing the time coming back from the server and determining how old the transaction is.  I forget what I used but if a purchase is over 5 minutes old (I think thats what I used) then I assume it’s a restore.   Ugly hack.

There isn’t much we can do.  It’s what Google hands us.

Rob,   you say the store provides you with a list of the items purchased.  The example of the call back function shows just event.transaction.productIdentifier as though there is just one item.  Does it provide an array if there is more than one, or do you get multiple callback events triggered?  I’m working through this right now since my users may have multiple products to restore. 

Also, is it the same whether apple or google?

-jerry

p.s.  I just saw on another thread that it fires multiple events, so if that is correct for both apple and google I’ll be set…

It’s not wrong to track that on your own, but it’s certainly not insurance.  If someone removes your app then re-installs it, your data files get deleted.   The store.* API has a call:  store.restore() that will instruct the store to provide you a list of items that person has purchased.  If you see your item in the list, then unlock your content.  If you do this at app start up time, you will always know the state of your app, assuming you have network connectivity.

Thank you Darth Rob.   :wink:

I will use the method that you show me, but it brings me a question:

I can keep an internal variable, but if the user closes the application, that variable is lost. So if I do not keep an external variable to indicate whether the app has been purchased, how do I do to unlock the content if there is no connection?

I have a quick question Rob.

You say that “store.restore() will instruct the store to provide you a list of items that person has purchased”

I read in the docs somewhere that iOS returns a “restored” state, but Google doesn’t - it returns “purchased” again.

How would this work in regards to consumable items (e.g. in game currency)?

If the user bought a set of levels, and 100 coins - I would only expect the levels to be restored, not the consumable coins. Since I’m still at the beginning of setting up IAP, I’d be interested to know how this is handled. Are consumables not returned in the restore function? If they are, then that makes restoring on Google Play very difficult, since we’d need to differentiate between a real purchase event and a “purchased” event triggered by store.restore().

Also (while we’re on the subject) I’ve posted before that there are no full IAP tutorials, though there are some that cover a lot of the info, and we have the sample app. However none of these explain what to actually do once the purchase has all gone through successfully.

I presume that it would be something like

function transactionCallback( event )     if event.transaction.state == "purchased" then                  if event.transaction.productIdentifier == "mycompany.mygame.consumableOne" then                          coinTotal = coinTotal + 100 --then save coins locally / on server         end     end end  

Is that correct? I find it a bit odd that no one has mentioned it in any of the tutorials, maybe it’s super obvious but when you’re dealing with something as complicated (and potentially costly if you do it wrong) as this there should probably be a full on tutorial covering this somewhere. If there is one and I’ve missed it then please ignore my ramblings  :stuck_out_tongue:

@juan-imaxina, this is probably why you want to save the information to a local database or text file too.

@AlanPlantPot, I’m working on an app for a client that is using IAP and well I cursed Google multiple times trying to figure out how to determine if a purchase is a purchase or a restore.  I ended up parsing the time coming back from the server and determining how old the transaction is.  I forget what I used but if a purchase is over 5 minutes old (I think thats what I used) then I assume it’s a restore.   Ugly hack.

There isn’t much we can do.  It’s what Google hands us.

Rob,   you say the store provides you with a list of the items purchased.  The example of the call back function shows just event.transaction.productIdentifier as though there is just one item.  Does it provide an array if there is more than one, or do you get multiple callback events triggered?  I’m working through this right now since my users may have multiple products to restore. 

Also, is it the same whether apple or google?

-jerry

p.s.  I just saw on another thread that it fires multiple events, so if that is correct for both apple and google I’ll be set…