Purchases succeeds several times with in-app purchases on Android

70 Views Asked by At

I've developed a game with in-game currency. When I test the game (currently it's on Alpha and closed internal on Google Play) and trying to buy my coins by pressing button only once, I receive Purchase succeeds several times. As result instead of purchasing 100 coins I get sometimes 200, sometimes 500 coins, sometime 300 etc. In the confirmation email that I receive from Google Play only one transaction happened. Here is the code fro Purchase succeeds event:

public function _customEvent_100gold():Void
 {
  if((_adding100gold == false))
  {
   _adding100gold = true;
   _byinggold = true;
   _secondsbeforeclose = 0;
   Engine.engine.setGameAttribute("gold", ((Engine.engine.getGameAttribute("gold") : Float) + 100));
   trace("adding 100 gold");
   _coinicon.setX((actor.getX() + (((((actor.getWidth()) - getFont(660).font.getTextWidth(("" + (Engine.engine.getGameAttribute("gold") : Float)), getFont(660).letterSpacing)/Engine.SCALE) / 2) + 20) - 45)));
   purchasesUse("100gold");
   purchasesGoogleConsume("100gold");
   playSound(getSound(795));
   saveGame("mySave", function(success:Bool):Void
   {
    runLater(1000 * 0.6, function(timeTask:TimedTask):Void
    {
     _pressedonce = false;
     _adding100gold = false;
    }, actor);
    _coinicon.growTo(145/100, 145/100, 0.3, Easing.elasticOut);
    runLater(1000 * 0.3, function(timeTask:TimedTask):Void
    {
     _secondsbeforeclose = 0;
     _100gold.growTo(100/100, 100/100, 0.3, Easing.elasticOut);
     _coinicon.growTo(100/100, 100/100, 0.6, Easing.elasticOut);
     runLater(1000 * 0.3, function(timeTask:TimedTask):Void
     {
      _byinggold = false;
     }, actor);
    }, actor);
   });
  }
 }

So from my understanding my boolean "adding100gold" should prevent from running this code more than once, only after 0.6 seconds after a successful purchase. From my debug log I can see this code is running several times almost simultaneously. The strange thing is I have other in-app product that's always sending me message "purchase failed" and I also receive it on my test device several times in a row. Which shows as well that it runs failed events also several times instead of just once as it should. So how to fix it?

update: 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. It seems that the problem is not in the code but somewhere between my device and Google Play. Is there anything I can check? Like I've already checked my payment method and Public Key. What else?

0

There are 0 best solutions below