IAP Android - identify product purchased

Hi,

I’m sure (hope!) this is an easy one…

I have the IAP sample code used in my game. I can purchase an item fine. I have 5 items for sale but when a purchase occurs, how can i determine which item has been purchased?

For each item purchased i need to update a .data file. Is there a way i can get the productID of the item purchased so that i can perform a save command based on this id?

Thank you [import]uid: 125592 topic_id: 30256 reply_id: 330256[/import]

Hi, I’m still struggling with this.

I have 5 products that i want to be able to sell in my App. For now i am testing on android using the test product - android.test.purchased

When user completes a transaction, what do i use to identify and perform an action based on the specific product purchased?

[code]
if event.transaction.state == “purchased” then

– i want to find the specific product purchased here and then write to a data file based on the product

end

@neil6, when a user picks a product to buy, how does your app know which item (out of 5 available items) the user had picked to buy? Could it be possible that your app doesn’t know which item? If it does know, then I really don’t understand why you’re having trouble sorting this out.

Just to make sure your app knows which item the user is paying for, you may want to temporarily set different prices for the 5 items you sell. If a user can pay for each of the items at its right price, the rest should be fairly straight forward to work out…

By the way, what does your product table looks like? I man, the one that lists the items you have for sale.

Naomi [import]uid: 67217 topic_id: 30256 reply_id: 121446[/import]

Hi Naomi,

Thanks for the reply. I’ve taken the demo code provided by Ansca and have simply replaced the items used in the demo with my own (for google play). my items are retrieved from the store without issue and listed perfectly.

The problem I have is that after a successful purchase how can I callback the details of the item purchased from google play store so I can unlock the item purchased?

Is there a way to identify which hit item was successfully purchased? Can I call back the product ID from google? So I can perform ‘if’ statement on this?

Thank you! [import]uid: 125592 topic_id: 30256 reply_id: 121489[/import]

@neil6, I don’t specifically remember the details (because I haven’t really looked closely at IAP routines quite a while), but if you are using the sample code, it might help if you do number of print statements inside the transactionCallback function under transaction.state == “purchased” to figure out what you need to know, such as…

print("event.transaction.productIdentifier = ", event.transaction.productIdentifier)  
-- you mentioned you have 5 products, so maybe try this too  
for i=1,5 do  
 print("googleProductList[" .. i .."] = ", googleProductList[i])  
end  

Also, have you kept all of the print statements that come with the sample code? If you have, look very closely at what it’s printing. You should be able to figure out which product is being purchased fairly quickly and should be able to write up a savePurchase function with a parameter (to be called like savePurchase(1) for the purchase of a product listed first, and savePurchase(2) for the second product).

Good luck.

Naomi
[import]uid: 67217 topic_id: 30256 reply_id: 121514[/import]

Hi, I’m still struggling with this.

I have 5 products that i want to be able to sell in my App. For now i am testing on android using the test product - android.test.purchased

When user completes a transaction, what do i use to identify and perform an action based on the specific product purchased?

[code]
if event.transaction.state == “purchased” then

– i want to find the specific product purchased here and then write to a data file based on the product

end

@neil6, when a user picks a product to buy, how does your app know which item (out of 5 available items) the user had picked to buy? Could it be possible that your app doesn’t know which item? If it does know, then I really don’t understand why you’re having trouble sorting this out.

Just to make sure your app knows which item the user is paying for, you may want to temporarily set different prices for the 5 items you sell. If a user can pay for each of the items at its right price, the rest should be fairly straight forward to work out…

By the way, what does your product table looks like? I man, the one that lists the items you have for sale.

Naomi [import]uid: 67217 topic_id: 30256 reply_id: 121446[/import]

Hi Naomi,

Thanks for the reply. I’ve taken the demo code provided by Ansca and have simply replaced the items used in the demo with my own (for google play). my items are retrieved from the store without issue and listed perfectly.

The problem I have is that after a successful purchase how can I callback the details of the item purchased from google play store so I can unlock the item purchased?

Is there a way to identify which hit item was successfully purchased? Can I call back the product ID from google? So I can perform ‘if’ statement on this?

Thank you! [import]uid: 125592 topic_id: 30256 reply_id: 121489[/import]

@neil6, I don’t specifically remember the details (because I haven’t really looked closely at IAP routines quite a while), but if you are using the sample code, it might help if you do number of print statements inside the transactionCallback function under transaction.state == “purchased” to figure out what you need to know, such as…

print("event.transaction.productIdentifier = ", event.transaction.productIdentifier)  
-- you mentioned you have 5 products, so maybe try this too  
for i=1,5 do  
 print("googleProductList[" .. i .."] = ", googleProductList[i])  
end  

Also, have you kept all of the print statements that come with the sample code? If you have, look very closely at what it’s printing. You should be able to figure out which product is being purchased fairly quickly and should be able to write up a savePurchase function with a parameter (to be called like savePurchase(1) for the purchase of a product listed first, and savePurchase(2) for the second product).

Good luck.

Naomi
[import]uid: 67217 topic_id: 30256 reply_id: 121514[/import]