How do I Make In-app purchases correctly?

0 favourites
  • 14 posts
From the Asset Store
The internet is bombarded daily with new apps (app is the short term for application)
  • hey guys so i've published my game and when i press the button to buy an item it gives the PURCHASE FAILED message for the first try, on the second button press it works. This happens to all my in-app products!

    First press nothing, second button press works

    here is my code:

    On btn press: fetch product "name"

    is in cocoonJS

    is store available then: purchase product "name" with preview

    Anything wrong with this? I dont want to have the user to press 2 times for 1 purchase!

  • Just to be more clear:

    The problem happens on each purchase i try to make for the first time but disappears on second try

    If you want a visual example go to the play store and download The Game Of Boz and see for yourself, so far i've had no luck in fixing this issue.. if you guys know what i could do then please help

  • If I understand correctly you are trying to fetch and buy in the same event..

    There is a big chance fetch works like .get and it's results will only be available the next tick..

    That sounds like a reason why the second time it is working..

  • So what should i do to fix this, could you please explain more about this "next tick" ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • BUMP would like to solve this as soon as possible so i can finally publish the whole thing (can't wait!!!)

    what i tried to do just now was adding a WAIT after the fetch but nothing changed :/ How do i make this "next tick" work LittleStain

  • LittleStain

    Thats the tutorial i followed in the first place! The only difference is that instead of fetching the product on start of layout im fetching it on button press because there is more than 1 product to fetch!

    So, taking for example the pic you posted its:

    ON TOUCH SPRITE: fetch "firstproduct"

    is in cocoonJS

    is store available : then : purchase product "firstproduct"

    Any workaround to this?

  • From another topic:

    2) Fetching can be done at any point in time before the user could buy. For example: On start of layout, or even "On Purchase button pressed". But in this case, you should also use "is Fetched" then Purchase.

  • is "is fetched" the same as "is store available" or "is in cocoonJS"? Because i dont see any other options such as "Is fetched" There is, however, these two:

    "on product fetch completed"


    "on product fetch started"

    Are these the same as "is fetched"?

    Sorry for all these noob questions LittleStain and thanks for the help so far!

  • I can only guess, not having worked with this before, but "on product fetch completed" sounds right..

  • So how should i set up the code?

    ON sprite(btn) touched: FETCH PRODUCT X



    where do i put the ON product fetch complete? (it cant go under On sprite touched, it has to be separate somehow)

    LittleStain if you've never worked with fetching products do you knwo someone who has so he could help out?

  • ON sprite(btn) touched: FETCH PRODUCT X

    ON product fetch complete


    -----IS STORE AVAILABLE : Purchase X

  • Thanks for the code LittleStain but what im wondering is how do i know which product has been fetched

    for example

    ON sprite(btn1) touched: FETCH PRODUCT 1

    ON sprite(btn2) touched: FETCH PRODUCT 2

    ON product fetch complete


    -----IS STORE AVAILABLE : Purchase PRODUCT 1

    How do i purchase the product based on the fetched product of the button? Since the "on product fetch complete" cant go under BTN touch

    In this example:

    How do i know if i've fetched the product from BTN 1 or BTN 2? (without declaring variables for each button and setting them to true and then doing an IF true then kind of thing, because it would take a lot of space and time for all of the products i've got)

  • bump!

    Really need to solve this guys so i can update the final version of the game!

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