How do I trigger event/variable on purchase success (IAP)?

0 favourites
  • 6 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • So, I'd like to have the option to pay .99 and remove ads on my app (android, crosswalk, official IAP plugin).

    I've gotten everything to work, except...when you buy the product (ad_remove) the ads are not removed. It is a managed product, not consumable, so as I understand it you should be able to use "restore purchases" and always remember that you've bought it--is that right?

    My app is connected to Google just fine, I think--my test order goes through, no error messages, so I must have something set up wrong in Construct 2.

    To remove the ads, I have the following code:

    On start of layout:

    ->add product IDs "ad_remove"

    ->request store listing

    ->restore purchases

    then as sub-events:

    System global variable noAds=0 ->preload/show banner, etc--this all works--too well!

    else-> [I left this empty, which I think should mean no ads are loaded or displayed if the variable is 1?]


    IAP has product "ad_remove" -> set noAds to 1

    My "buy" button looks like this:

    On tap "remove ads" sprite

    sub event IAP is store available ->request store listing [do I need this?]

    ->purchase product "ad_remove"

    Below that:

    IAP on product "ad_remove" purchase success

    ->restore purchases [do I need that there?]

    ->"buy ad" sprite destroy [which doesn't work--it hasn't been destroyed, though it has become unclickable now that I've purchased the product]

    ->system set variable noAds to 1

    ->hide banner ad [which would be showing at the time of the purchase]

    On the actions that potentially trigger an interstitial I have things set up like so:


    sub events:

    System global variable noAds=0 ->trigger ad, ad plus perform action, etc [this all works as it should]

    else-> blank, or just the action with no ads

    I manually changed the noAds variable to 1 to make sure I'd caught all the possible ad triggers, and I had--so somehow the variable and IAP "has product" information is just not getting changed.

    Do I have events out of order? Am I missing something in how to set up in app purchases or call previous purchases? Or is it something that doesn't work in alpha/beta testing but would work once the app is actually published? (Which is a chance I don't want to take unless someone assures me that's the case!)

    I'll continue testing things and trying to work out the problem, but if any more experienced people have suggestions or could point out where I've gone wrong, I'd greatly appreciate it!

  • I changed my code to match the code by zorida in the thread, "How do I get IAP working properly on Android?" (with a few omissions since I'm only targeting android at the moment.)

    The ads are still visible, the "remove ads" button is still visible, but unclickable now that I purchased the product once (yesterday).

    Is this just the way alpha testing/"fake" iap purchases will work with managed products (ie, not really giving me the product, thus not changing my variable/webstorage), or do I still have something wrong?

  • i have exactly the same problem, i temporally fixed by using a local storage (webstorage plugin) ,where you save if a product has been bought, then you load or hide the ads using webstorage conditions , not iap -> "has product(ID)" .

    And i think thats the part where crashes, all works fine, less the has product option, at least in my code.

    i hope i have been usefull, if you need some help with this or something with your app you can contact me by mail ()

    good luck

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • darkfree13 I just implemented the webstorage idea, so I'll see if that fixes anything. I have the local key set the global variable I already had integrated into my code, so hopefully that's ok and not too roundabout...? Thanks for the suggestion--it's good to hear that it worked for you!

  • mkea but with this solution, never clear all the webstorage data, if you do it you will lose everything and you will have the same problem you had before, just happened to me

  • darkfree13 good to know. I had to create a new product to buy and set the local key since I'd already test bought the first product, but now it seems like it's working!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)