In-App Billing and Purchases is a native extension to purchase items from stores. Supported on more than one platform, the extension provides access to the Apple “InApp Purchases” and access to the Google Play “InApp Billing”. It’s possible to get a list of products, which will initialize the list of items available, retrieving information about the product such as: price, title, description etc.
The extension also allows a developer to restore purchases that a user may have previously made, dispatching the proper purchase events for the products. A purchase can be made by creating a new Purchase
object and passing it to the extension. The only required information is the product ID, which must be one of the ID’s successfully retrieved through a call to get a list of products.
Sample
InAppBilling.init( DEV_KEY ); InAppBilling.service.setServiceType( InAppBillingServiceTypes.APPLE_INAPP_PURCHASE ); InAppBilling.service.addEventListener( InAppBillingEvent.SETUP_SUCCESS, setup_successHandler, false, 0, true ); InAppBilling.service.addEventListener( InAppBillingEvent.SETUP_FAILURE, setup_failureHandler, false, 0, true ); InAppBilling.service.setup( YOUR_SERVICE_ENCRYPTION_KEY ); InAppBilling.service.addEventListener( InAppBillingEvent.INVALID_PRODUCT, product_invalidHandler, false, 0, true ); InAppBilling.service.addEventListener( InAppBillingEvent.PRODUCTS_LOADED, products_loadedHandler, false, 0, true ); InAppBilling.service.addEventListener( InAppBillingEvent.PRODUCTS_FAILED, products_failedHandler, false, 0, true ); InAppBilling.service.getProducts( [ "com.distriqt.test.exampleProduct" ] ); private function product_invalidHandler( event:InAppBillingEvent ) :void { trace( "invalid product:"+event.errorCode+":"+event.message ); } private function products_loadedHandler( event:InAppBillingEvent ) :void { for each (var product:Product in event.data) { trace( "received:"+product.title+" price="+product.priceString ); } // Retrieve any previously purchased products InAppBilling.service.restorePurchases(); }