Corona's store module

Applying In-App Purchases in your application can be a little mind-boggling and tedious process. Integrating it with Corona requires calling the store module:

store = require("store")

The store module is already incorporated to the Corona API, similar to Facebook and Game Network. You can find more information on Corona's store module at http://docs.coronalabs.com/daily/guide/monetization/IAP/index.html.

The store.init() function must be called when handling store transactions to your app. It activates In-App Purchases and allows you to receive callbacks with the listener function you specify:

The only parameter here is listener. It's a function that handles transaction callback events.

The following blocks determine the transaction states that can occur during an In-App Purchase. The four different states are purchased, restored, cancelled, and failed:

The store.loadProducts() function retrieves information about items available for sale. This includes the price of each item, a name, and a description:

Its parameters are as follows:

The following block displays the list of products that are available in the app. Information about the product can be retrieved from the loadProductsCallback() function and determines whether it is valid or invalid:

The store.canMakePurchases function returns true if purchases are allowed, and false otherwise. Corona's API can check whether purchasing is possible. iOS devices provide a setting that disables purchasing. This can be used to avoid purchasing apps accidentally.

The store.purchase() function initiates a purchase transaction on a provided list of products.

This function will send purchase requests to the store. The listener specified in store.init() will be invoked when the store finishes processing the transaction:

Its only parameter is arrayOfProducts, an array specifying the products you want to buy:

This function notifies the App Store that a transaction is complete.

After you finish handling a transaction, you must call store.finishTransaction() on the transaction object. If you don't do this, the App Store will think your transaction was interrupted and will attempt to resume it on the next application launch.

Syntax:

Parameters:

Transaction: The transaction object belonging to the transaction you want to mark as finished.

Example:

Any previously purchased items that have been wiped clean from a device or upgraded to a new device can be restored on the user's account without paying for the product again. The store.restore() API initiates this process. Transactions can be restored by the transactionCallback listener, which is registered with store.init(). The transaction state will be "restored" and your app may then make use of the "originalReceipt", "originalIdentifier", and "originalDate" fields of the transaction object:

The block will run through the transactionCallback() function and determine whether a product has been previously purchased from the application. If the result is true, store.restore() will initiate the process of retrieving the product without asking the user to pay for it again: