Skip to main content

Restore Purchases

Restoring purchases is a process that you should allow for user's who have either changed devices or reinstalled your application and hence need to gain access to their purchases again. It should not be an automatic process but one done through user interaction.

App Store Review

This process must be available to your users and must initiated by user interaction in order to pass App Store review.

To satisfy this requirement, you must provide a button somewhere in your application to initiate this restore process. Generally somewhere like your application settings is an appropriate place to have a restore purchases functionality.

For more information on the concepts you can read the Apple documentation here.

For retrieving purchases without user interaction see the Get Purchases functionality.

The restoring purchases process starts by calling the restorePurchases function and concludes with either a success (InAppBillingEvent.RESTORE_PURCHASES_SUCCESS) or failure (InAppBillingEvent.RESTORE_PURCHASES_FAILED) event.

After calling restorePurchases you will a receive PurchaseEvent.PURCHASES_UPDATED dispatched which will contained Purchase objects in the restored state having the original purchase variable representing the original purchase transaction.

// The service must be setup and a list of products retrieved.

// Make sure you have added your purchases handler
InAppBilling.service.addEventListener( PurchaseEvent.PURCHASES_UPDATED, purchases_updatedHandler );

InAppBilling.service.addEventListener( InAppBillingEvent.RESTORE_PURCHASES_SUCCESS, restorePurchases_successHandler );
InAppBilling.service.addEventListener( InAppBillingEvent.RESTORE_PURCHASES_FAILED, restorePurchases_failedHandler );

// Start the restore process
InAppBilling.service.restorePurchases();


//
//
//

function purchases_updatedHandler( event:PurchaseEvent ):void
{
for each (var purchase:Purchase in event.data)
{
switch (purchase.transactionState)
{

// Other states...


case Purchase.STATE_RESTORED:
// The originalPurchase property will contain all the
// information on the original transaction allowing
// you to restore the user's product

addPurchaseToInventory( purchase.originalPurchase );
InAppBilling.service.finishPurchase( purchase );

// Again you could hold on to this purchase and check it against
// your application server before calling finishPurchase
break;


}
}
}


//
// RESTORE PURCHASE EVENTS
//

function restorePurchases_successHandler( event:InAppBillingEvent ):void
{
// Called when all purchases have been restored
// This event contains no data
}

function restorePurchases_failedHandler( event:InAppBillingEvent ):void
{
// Called if there was an error restoring purchases
}