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

Get help using Construct 2

Post » Tue May 12, 2015 3:51 am

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! :P
else-> [I left this empty, which I think should mean no ads are loaded or displayed if the variable is 1?]

and:
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:
Trigger
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!
B
8
S
2
Posts: 16
Reputation: 635

Post » Tue May 12, 2015 9:58 pm

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?
B
8
S
2
Posts: 16
Reputation: 635

Post » Tue May 12, 2015 11:29 pm

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 ([email protected])
good luck
B
7
S
1
Posts: 3
Reputation: 383

Post » Tue May 12, 2015 11:57 pm

@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!
B
8
S
2
Posts: 16
Reputation: 635

Post » Wed May 13, 2015 8:28 am

@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 :(
B
7
S
1
Posts: 3
Reputation: 383

Post » Wed May 13, 2015 5:50 pm

@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!
B
8
S
2
Posts: 16
Reputation: 635


Return to How do I....?

Who is online

Users browsing this forum: bluesun66 and 2 guests