Restoring Purchases
Restoring purchases is a mechanism by which your user can restore their in-app purchases, reactivating any content that had previously been purchased from the same store account (Apple, Google, or Amazon).
It is recommended that all apps have some way for users to trigger the restorePurchases
method, even if you require all customers to create accounts.
- Swift
- Code
- Kotlin
- Kotlin Multiplatform
- Java
- Flutter
- React Native
- Cordova
- Capacitor
- Unity
Purchases.shared.restorePurchases { customerInfo, error in
// ... check customerInfo to see if entitlement is now active
}
[[RCPurchases sharedPurchases] restorePurchasesWithCompletion:^(RCCustomerInfo *customerInfo, NSError *error) {
//... check customerInfo to see if entitlement is now active
}];
Purchases.sharedInstance.restorePurchasesWith() { customerInfo ->
//... check customerInfo to see if entitlement is now active
}
Purchases.sharedInstance.restorePurchases(
onError = { error ->
// An error occurred.
},
onSuccess = { customerInfo ->
//... check customerInfo to see if entitlement is now active
}
)
Purchases.getSharedInstance().restorePurchases(new ReceiveCustomerInfoCallback() {
@Override
public void onError(@NonNull PurchasesError error) {
}
@Override
public void onReceived(@NonNull CustomerInfo customerInfo) {
}
});
try {
CustomerInfo customerInfo = await Purchases.restorePurchases();
// ... check restored purchaserInfo to see if entitlement is now active
} on PlatformException catch (e) {
// Error restoring purchases
}
try {
const restore = await Purchases.restorePurchases();
// ... check restored purchaserInfo to see if entitlement is now active
} catch (e) {
}
Purchases.restorePurchases(
info => {
//... check customerInfo to see if entitlement is now active
},
error => {
// Error restoring purchases
}
);
try {
const customerInfo = await Purchases.restorePurchases();
//... check customerInfo to see if entitlement is now active
} catch (error) {
// Error restoring purchases
}
var purchases = GetComponent<Purchases>();
purchases.RestorePurchases((info, error) =>
{
//... check purchaserInfo to see if entitlement is now active
});
The restorePurchases
method should not be triggered programmatically, since it may cause OS level sign-in prompts to appear, and should only be called from some user interaction (e.g. tapping a "Restore" button.)
If you are trying to restore a purchase programmatically, use syncPurchases
instead. This will not cause OS level sign-in prompts to appear.
Restore behaviorโ
When a user restores purchases that are already attached to another user, RevenueCat will decide whether to transfer the purchase to the new user based on the transfer behavior setting.
Syncing purchases without user interactionโ
syncPurchases
is a method we provide in our SDK which allows you to programmatically trigger a restore. This method, much like restorePurchases, reactivates any content that had previously been purchased from the same store account (Apple, Google, or Amazon).
Considerationsโ
syncPurchases
is typically used for migrating subscriptions- Since this method simulates restoring a purchase, there is a risk of transferring or aliasing an anonymous user
Restoring Purchases for Consumables and Non-renewing Subscriptionsโ
Consumables and non-renewing subscriptions can only be restored by using an acount system with custom App User IDs. This is due to these types of in-app purchases not showing up on the underlying store receipt after the transaction is finished.
By logging in your users with a custom App User ID, RevenueCat can continue to provide transaction details in a user's CustomerInfo for their previous consumable and non-renewing subscription purchases.
Next Stepsโ
- Make sure all purchases are being linked to the correct App User ID
- If you're ready to test, start with our guides on sandbox testing