Multiply in-app purchases per click

Guzzz

  • Posts: 556
I can't really wrap my head around Google's in-app purchases. With Apple everything seems to work fine but here...
First, every time I buy my product id Google sends me several purchases, so instead of buying product just once per click it's buying several products per click. Sometimes 2, sometimes 5, sometimes 1. I used booleans to make sure that the code is read once per click, or at least I thought it worked (see attached image). Since I'm also receiving emails with the confirmation I can see that he is spending the money only once per click.
Second problem. My other product id (I have 3 in total) is always sending me Purchase failed message even though both products are almost identical. And sometimes I can see this popup message "Purchase failed " several times as well. So he is sending me both negative and positive results several times. In the Log view I can see that my print block went several times as well, so code under When a purchase succeeds - product ID has been read several times which should have been impossible! Boolean is turning back only after 0.6 seconds according to my code.

Do you guys have somewhere an example of the code for Consumables and Regular purchases that 100% work?

« Last Edit: October 17, 2019, 10:35:14 am by Guzzz »
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

Guzzz

  • Posts: 556
Here is the code for actual pressing the button. Also with booleans preventing multiply executions.
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

Guzzz

  • Posts: 556
I've just found a bizarre feature of my problem. I have 2 products: 100 coins and 1000 coins. When I first pressed to buy 1000 coins it gave me 1000 coins without any problems. I've just tried and bought 8 times 1000 coins and I received 8000 coins in total. But, when I tried to buy 100 coins and received "Purchase failed" popup, and after that I pressed buy 1000 coins I've received 2000 coins instead of 1000. And since then I could buy only 2000 coins at a time. I tried 5 more times and every time I pressed buy 1000 coins I received 2000 coins. The email confirmation haven't mentioned any multipliers. 
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

merrak

  • *
  • Posts: 2738
Is this same code working fine on iOS?

Guzzz

  • Posts: 556
Yes. It's almost the same. It's a bit simpler. Without free unmanaged android purchases with ID and spend product ID blocks.
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

merrak

  • *
  • Posts: 2738
I don't think this is the root problem, but unless there's more code, I think you have a logic error when purchases fail. When the player clicks a buy button you set all these booleans, but then their state doesn't change if the purchase fails. So on the next purchase all of the boolean values are already set.

So here's an example of what could happen. Player tries to purchase 100 coins and the purchase fails, but pressed_once and bying_gold are still true because the code that resets them is only triggered when the purchase succeeds. When the player purchases 1000 coins, the boolean values that were set in the 100 coin purchase are still true.

In your latest issue, do you also see the print statement multiple times?

Also try printing the actor name along with the actor... just put the Actor block from Scenes > Actors palette in a print statement. I noticed these are actor behaviors... maybe you somehow ended up with multiple actors that are reacting to the purchase succeeds wrapper.

Guzzz

  • Posts: 556
Thanks for the reply!
I do have events "a purchase fails" and "purchase is canceled". Everything works fine on iOs and everything worked fine with google testing product IDs (android.test.purchased and android.test.canceled). The boolean becomes true at the very beginning therefore this code cannot be read until it rolls back to false. It becomes false always 0.6 seconds after the success, fail or cancel events. I don't think there is a problem in logic of the button, I think there is a problem with requesting information from google play and using this information.
Im really puzzled by whats happening with in-apps in my game right now. For example.
When I press Buy 100 Coins (at some point it broke somehow and started to show me only Purchase failed popup) I receive Purchase failed popup, I press ok. Then I press  Buy 100 Coins again and I receive Purchase failed popup, I press ok and immediately receive another Purchase failed popup. I press ok. Then I press Buy 100 Coins again and this time I receive 3 Purchase failed popups in a row. So there is a pattern. If I've already pressed button 9 times and I press it again I am going to see 10  Purchase failed popups in a row.
If I delete the game from the device and install it again it doesn't change anything. If I delete however product ID on Google Play Console and make a brand new everything works great for a while and then it goes crazy again.
I deleted other google accounts from my device in case if this somehow interfere with purchasing. I also going to look into Google Play Console, maybe I should leave only one build active, because right now I have 2 alpha and one internal.
I will appreciate any help!

« Last Edit: October 19, 2019, 03:52:12 am by Guzzz »
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

Guzzz

  • Posts: 556
I also have this block in the first scene, see attachment. When running on my device it prints me "can make the purchases" which goes after "if product ID =" blocks. These blocks themselves are not printing. Does it mean there is an error with product ID? At this moment none of my product ID is working.
Is there any way to check if my device can see product ID on Google Play? Because "purchase failed" is not saying a lot.
p.s. I've checked payment method on my tester's account and deactivated old builds on Google Play.
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

Guzzz

  • Posts: 556
I created a brand new Google account and created a new product ID for my 1000 coins in the game. So when I tested on my device when I pressed the button I bought 1000 coins, when I pressed second time I went through the buying process but received not 1000 but 2000 coins. When I pressed button 3rd time I received 3000 coins even though I have blocks with "spent product ID" and I'm using print "quantity of product ID " blocks and it always shows 0 after the purchase and spending blocks.

Has someone even tried to make in-app purchases for Android with Stencyl?

« Last Edit: October 20, 2019, 11:05:19 am by Guzzz »
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

merrak

  • *
  • Posts: 2738
That's weird... almost like it's sending both the latest and all purchases at once. I don't suppose each purchase has a unique purchase ID of some kind?

Guzzz

  • Posts: 556
I don't know about any purchase ID but I think there should be one. BTW email confirmation I get from Google Play on my testing account says about purchasing only one product per click.
I know Google Play is a complex system and there are a lot of steps where one can make a mistake, but I just don't know where else I can check and what I can fix...
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

merrak

  • *
  • Posts: 2738
I'm curious why you're getting the "Purchased" print output multiple times... it's like that event (when a purchase succeeds) is being triggered multiple times.

Unfortunately I don't have any working examples of Google Play consumables. I haven't made a mobile game in a long time.

Did you try printing the actor name along with the "Purchased" output? I think the scenario I outlined is still worth eliminating. It's possible there's a logic error but something the way iOS handles purchases prevents it from triggering.

Guzzz

  • Posts: 556
I'm not very sure what you mean by printing Actor. Actor that has been created?
I printed out how many buttons I have on the screen and how many times this button has been pressed. In both cases 1.
Here is the log of what happened when I pressed 1 time button and purchased 3000 instead of 1000 coins. Where "quantity 1000gold" with the following number is amount of product ID player has (thats what called "unmanaged" or "not used"). "1000gold triggered" is a custom event that runs the code for adding in-game currency, save game attributes etc. "Using" is the moment when the block "use product ID" is running.

Quote

10-20 22:51:44.971 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:425: 1000gold triggered
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:192: 0
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:191: quantity 1000gold
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:185: using
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:184: 0
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:183: quantity 1000gold
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:181: adding 1000 gold
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:416: purchased
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:425: 1000gold triggered
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:192: 0
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:191: quantity 1000gold
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:185: using
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:184: 0
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:183: quantity 1000gold
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:181: adding 1000 gold
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:416: purchased
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:425: 1000gold triggered
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:192: 0
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:191: quantity 1000gold
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:185: using
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:184: 0
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:183: quantity 1000gold
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:181: adding 1000 gold
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:416: purchased
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:425: 1000gold triggered
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:192: 0
10-20 22:51:44.961 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:191: quantity 1000gold
10-20 22:51:44.951 13848 14599 I trace   : Purchases.hx:302: Saved Purchases
10-20 22:51:44.951 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:185: using
10-20 22:51:44.951 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:184: 1
10-20 22:51:44.951 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:183: quantity 1000gold
10-20 22:51:44.951 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:181: adding 1000 gold
10-20 22:51:44.951 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:416: purchased
10-20 22:51:44.921 13848 13848 I trace   : Purchases.hx:302: Saved Purchases
10-20 22:51:44.921 13848 13848 I trace   : Purchases.hx:45: Purchases: Successful Purchase
10-20 22:51:37.381 13848 14599 I trace   : Source/scripts/ActorEvents_720.hx:405: pressed btn to buy 1000 coins

As you can see the custom event ("1000gold triggered") is running when purchase succeeds several times despite booleans preventing that.  Also you can see that the actual amount of product IDs been bought is only 1, the rest is just repeating of the code inside of costume event ("1000gold triggered") that has been triggered by "purchase succeeds" event. The actual command to buy is inside of the code when pressed button event, so I guess its why only 1 product has been bought. 

« Last Edit: October 20, 2019, 02:44:09 pm by Guzzz »
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

merrak

  • *
  • Posts: 2738
This is what I meant, although with "Self" instead of "Actor" selected.

Guzzz

  • Posts: 556
I see! I did what you suggested  and noticed in Log Viewer several times (in my case its a popup actor) actor has been mentioned. So I decided to run an experiment and moved all the purchasing events into the scene and so far it works! I actually have the button "buy remove ads" already in the scene and it didn't work as well, so I thought this experiment will fail. I guess "buy remove ads" didn't work for some other reason... Anyway... I created brand new product ID on Google Play Console and now it works. Im gonna try more in the next couple of days, but so far it's good... and conclusion: never put purchasing event into actors,  only into scenes! Especially if these actors are going to be killed like popups, because in this case purchasing events are accumulating somewhere in a weird way.

« Last Edit: October 20, 2019, 03:33:21 pm by Guzzz »
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/