NEW TO IN APP PURCHASE

So I am a fairly new at developing apps with Corona SDK and I am a little confused on how the In app purchase works and need some guidance. 

I have an app with admob ads, and basically the aim is once the remove ads IAP has been purchased the ads will disappear. What i have done is created a text file that reads: iapBought = “locked”. So the code reads the file and if iapBought = “locked”, ads show.

e.g.

if iapBought == "locked then

    ad.show(etc…)

end

The app is all working and I appear to have everything working just want to know if the way I am calling the store functions is correct. 

This is how my store transaction function looks:

function storeTransaction( event )

    local transaction = event.transaction

    if ( transaction.state == “purchased” ) then

        --handle a successful transaction here

        print( “productIdentifier”, transaction.productIdentifier )

        print( “receipt”, transaction.receipt )

        print( “signature:”, transaction.signature )

        print( “transactionIdentifier”, transaction.identifier )

        print( “date”, transaction.date )

    

        iapBought = "unlocked"

        saveSettings()

        ads.hide()

        composer.gotoScene(“splash”)

        

    elseif ( transaction.state == “cancelled” ) then

        handle a cancelled transaction here

    elseif ( transaction.state == “failed” ) then

        --handle a failed transaction here

    end

    --tell the store that the transaction is complete!

    --if you’re providing downloadable content, do not call this until the download has completed

    store.finishTransaction( event.transaction )

end

store.init( “google”, storeTransaction )

The text in bold is how i have changed the file to unlocked so the ads don’t show. Is this the normal or correct way to give the buyer the IAP goods? Is it right what i have done in the transaction.state == purchase code? Also what am I supposed to do with the receipts and signatures?

Would really appreciate the guidance.

Thank You

In its basic form, what you’ve done is correct. You’ve detected the purchase. You save the setting so next the the app starts up it will remember it and  you disable the ads. As long as your other ad calls are wrapped in the if statement testing if it’s the paid version or not you’re good to do.

Things to consider to improve your handling:

  1. Do you plan to offer other IAP items? If so you need to test in your call back which IAP items was purchased and only turn off the ads if the right item was purchased.

  2. People can delete the app and re-install it. At some point you need to give them the option to restore purchases. For Google, they seem to be okay with doing this at app startup after you have initialized the store. Apple on the other hand requires there be a button in the user interface that allows the user to choose to restore items.

  3. Google will let someone request a refund. You will get an event when this happens you need to test for it in your storeTransaction function and relock the app.

  4. Apps get hacked and it’s more problematic on Android. It’s possible for someone with a rooted device to figure out where your sandbox files are and go edit your save file and mark the app too show no ads. What is the chance of this? Well its likely to up as your app gets more popular. This is where receipts come in. You can store them off line somewhere and check for their presence at app startup time and use that to manage your unlocking functions. Signatures are additional means to verify the authenticity of the app.

Rob

In its basic form, what you’ve done is correct. You’ve detected the purchase. You save the setting so next the the app starts up it will remember it and  you disable the ads. As long as your other ad calls are wrapped in the if statement testing if it’s the paid version or not you’re good to do.

Things to consider to improve your handling:

  1. Do you plan to offer other IAP items? If so you need to test in your call back which IAP items was purchased and only turn off the ads if the right item was purchased.

  2. People can delete the app and re-install it. At some point you need to give them the option to restore purchases. For Google, they seem to be okay with doing this at app startup after you have initialized the store. Apple on the other hand requires there be a button in the user interface that allows the user to choose to restore items.

  3. Google will let someone request a refund. You will get an event when this happens you need to test for it in your storeTransaction function and relock the app.

  4. Apps get hacked and it’s more problematic on Android. It’s possible for someone with a rooted device to figure out where your sandbox files are and go edit your save file and mark the app too show no ads. What is the chance of this? Well its likely to up as your app gets more popular. This is where receipts come in. You can store them off line somewhere and check for their presence at app startup time and use that to manage your unlocking functions. Signatures are additional means to verify the authenticity of the app.

Rob