Restoring purchases is a critical functionality for mobile apps, allowing users to recover access to in-app purchases (IAPs) they've previously made, especially when transitioning to a new device, reinstalling an app, or after updates. This process ensures that users maintain access to features, content, or subscriptions they've paid for, without any additional cost or complications.
Let's explore how to ensure your users can easily recover their purchases and continue enjoying everything your app has to offer.
For app managers and developers, facilitating smooth purchase restoration is key to enhancing the user experience and maintaining customer loyalty. When users know their purchases are secure and easily recoverable, they feel more confident investing in your app. This assurance is vital for preventing user churn; frustrated users who can't easily access their purchases might abandon the app and switch to competitors.
Ensuring seamless purchase restoration can lead to better reviews, increased user retention, and, ultimately, higher lifetime value (LTV) of users. It also reduces customer support queries, saving time and resources. By prioritizing this functionality, app developers can create a reliable and positive user experience, fostering trust and encouraging more in-app purchases.
Restoring purchases involves a series of steps where the app communicates with the respective app store to verify the user's purchase history and reinstate access to their paid features. Understanding the intricacies of in-app purchases (IAPs) and how they are stored and verified is crucial for implementing effective purchase restoration.
In-app purchases and subscriptions are stored in the app store's servers and linked to the user's account.
When a purchase is made, a receipt is generated, which serves as proof of the transaction. For app developers, verification entails checking these receipts against the app store's records to confirm their validity before restoring any purchases.
The primary task of the app is to retrieve the receipt, which contains a list of transactions (purchases).
One of the key changes introduced with StoreKit 2 is how purchase data is accessed and validated. In StoreKit 1, apps rely on a single receipt file (appStoreReceiptURL
) that's stored on the user's device. This file includes a list of all in-app purchases made by the user and must be manually retrieved and sent to your server for validation, typically via Apple’s /verifyReceipt
endpoint. Parsing this file requires base64-encoding, server-side validation, and dealing with ASN.1 decoding - a process that’s often considered cumbersome and error-prone.
StoreKit 2, on the other hand, introduces a modern Swift-based API that offers direct access to transaction and subscription data without needing to fetch or validate the receipt manually. Instead of relying on a single receipt file, StoreKit 2 exposes a structured list of transactions through methods like Transaction.currentEntitlements
and Transaction.all
, giving developers a much more readable and convenient way to access purchase history right on the device.
Another major difference is that StoreKit 2 transactions are cryptographically signed using JSON Web Signature (JWS). These signed transactions can optionally be sent to your backend for verification, but it's no longer mandatory to rely solely on server-side decoding. This allows for more flexibility in implementation, especially useful for apps that want to offer offline functionality or real-time entitlement checks without relying on a network call.
While StoreKit 2 dramatically simplifies receipt handling, developers working with legacy code or older iOS versions may still need to support StoreKit 1 receipts. Understanding the differences - and knowing when to use each - is essential for maintaining a robust and future-proof subscription system.
There are two primary categories of in-app purchases:
Subscriptions give users access to content or services for a set period of time. Apple supports two main types of subscriptions:
Apple also provides several marketing and pricing tools to increase conversion and retention:
1. Pay As You Go: Discounted rate for the first few billing periods (e.g., $0.99/month for 3 months).
2. Pay Up Front: A single upfront payment for a longer initial period (e.g., $9.99 for 6 months).
3. Free Trial: Users can try a subscription for free for a limited period. Trials can convert automatically into a paid plan unless canceled before the end of the trial.
All of these options can be combined strategically to build a subscription funnel that aligns with your app's business goals while giving users flexible, transparent pricing options.
Implementing a Restore Purchases feature is essential for providing a seamless user experience. Here’s a step-by-step guide for both iOS and Android platforms.
import StoreKit class PurchaseManager: NSObject, SKPaymentTransactionObserver { func restorePurchases() { SKPaymentQueue.default().add(self) SKPaymentQueue.default().restoreCompletedTransactions() } func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { for transaction in transactions { switch transaction.transactionState { case .restored: // Unlock the non-consumable purchase or subscription // Finish the restored transaction SKPaymentQueue.default().finishTransaction(transaction) default: break } } } }
3. Handle Restored Transactions: Implement logic to unlock features related to restored purchases. Ensure transactions are properly finished to prevent duplicates.
Simplifying In-App Purchases with Apphud
One of the key advantages is automatic purchase restoration. Apphud handles restoring purchases automatically in the background, with no extra effort required from your side. The only case where manual restoration is recommended is on paywalls, where you may want to explicitly offer a "Restore" button for better UX transparency.
When switching to Apphud from another platform or your own in-house solution, there's no need for complex migration logic. The default integration is usually enough to recognize and carry over existing purchases seamlessly. Apphud retrieves the receipt, processes it on the server, and updates entitlements accordingly.
Import ApphudSDK class PurchaseManager: NSObject { func restorePurchases() { Apphud.restorePurchases() } }
build.gradle
file:implementation 'com.android.billingclient:billing:5.0.0'
2. Configure In-App Products in Google Play Console: Define your in-app products, such as non-consumables and subscriptions.
1. Connect to Google Play Billing: Set up the billing client in your activity or service
BillingClient billingClient = BillingClient.newBuilder(context) .setListener(purchasesUpdatedListener) .enablePendingPurchases() .build();
2. Query Purchases: Use the billing client to query purchases, which allows users to restore their purchases.
billingClient.startConnection(new BillingClientStateListener() { @Override public void onBillingSetupFinished(BillingResult billingResult) { if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) { Purchase.PurchasesResult purchasesResult = billingClient.queryPurchases(BillingClient.SkuType.INAPP); handlePurchases(purchasesResult.getPurchasesList()); } } @Override public void onBillingServiceDisconnected() { // Try reconnecting } });
3. Handle Purchases: Implement logic to check and restore the user's previous purchases
void handlePurchases(List<Purchase> purchases) { for (Purchase purchase : purchases) { // Verify purchase and grant entitlement to the user } }
Restoring purchases is a vital aspect of app development that ensures a seamless and user-friendly experience, safeguarding your users' investments and enhancing app loyalty. By implementing effective restoration mechanisms for both iOS and Android apps, you can reduce churn and improve user satisfaction. This approach not only retains your existing customers but also builds trust, encouraging further in-app purchases.
Apphud is an invaluable tool for app developers looking to optimize their subscription-based revenue strategies. It provides a comprehensive solution for managing in-app purchases and subscriptions. With features like automated receipt validation, user-friendly dashboards, and advanced analytics, Apphud streamlines the monetization process, ensuring that you maximize revenue while maintaining a high-quality user experience.
By integrating Apphud, developers can easily handle complex tasks like purchase restoration, subscription management, and data analysis, allowing them to focus on delivering great app features and customer service. Whether you're just starting or looking to enhance your app's monetization strategy, leveraging Apphud's capabilities can give you a competitive edge in today's dynamic app market. Sign up for free today!