iOS - Making Purchases

Learn how to make and restore mobile purchases using Adapty iOS SDK. Adapty handles server-side validation, including renewals and grace periods

To make the purchase, you have to call .makePurchase() method:

Adapty.makePurchase(product: <product>, offerId: <offerId>) { (purchaserInfo, receipt, appleValidationResult, product, error) in
    if error == nil {
        // successful purchase
    }
}

Request parameters:

  • Product (required): a ProductModel object retrieved from the paywall.
  • Offer Id (optional): a string identifier of promotional offer from App Store Connect. Adapty signs the request according to Apple guidelines, please make sure you've uploaded Subscription Key in Adapty Dashboard when using promotional offers.

Response parameters:

  • Purchaser info: a PurchaserInfoModel object. This model contains info about access levels, subscriptions, and non-subscription purchases. Generally, you have to check only access level status to determine whether the user has premium access to the app.
  • Receipt: a string representation of Apple's receipt.
  • Apple validation result: a dictionary containing raw validation result from Apple.
  • Product: a ProductModel object you've passed to this method.

🚧

Make sure you've added App Store Shared Secret in Adapty Dashboard, without it, we can't validate purchases.

Below is a complete example of making the purchase and checking the user's access level.

Adapty.makePurchase(product: <product>, offerId: <offerId>) { (purchaserInfo, receipt, appleValidationResult, product, error) in
    if error == nil {
        // "premium" is an identifier of default access level
        if purchaserInfo?.accessLevels["premium"]?.isActive == true {
            // grant access to premium features
        }
    }
}

🚧

Make sure to set up App Store Server Notifications to receive subscription updates without significant delays.

Restoring purchases

To restore purchases, you have to call .restorePurchases() method:

Adapty.restorePurchases { (purchaserInfo, receipt, appleValidationResult, error) in
    if error == nil {
        // successful restore
    }
}

Response parameters:

  • Purchaser info: a PurchaserInfoModel object. This model contains info about access levels, subscriptions, and non-subscription purchases. Generally, you have to check only access level status to determine whether the user has premium access to the app.
  • Receipt: a string representation of Apple's receipt.
  • Apple validation result: a dictionary containing raw validation result from Apple.

Deferred purchases

For deferred purchases, Adapty SDK has an optional delegate method, which is called when the user starts the purchase in the App Store, and the transaction continues in your app. Just store makeDeferredPurchase and call it later if you want to hold your purchase for now. Then show the paywall to your user. To continue purchase, call makeDeferredPurchase.

extension AppDelegate: AdaptyDelegate {

    func paymentQueue(shouldAddStorePaymentFor product: ProductModel, defermentCompletion makeDeferredPurchase: @escaping DeferredPurchaseCompletion) {
        // you can store makeDeferredPurchase callback and call it later
        
        // or you can call it right away
        makeDeferredPurchase { (purchaserInfo, receipt, appleValidationResult, product, error) in
            // check the purchase
        }
    }
    
}

Redeeming an Offer Code

Since iOS 14.0 your users can redeem Offer Codes. To allow them to do so, you can present the Offer Code redemption sheet by calling the related SDK method.

Adapty.presentCodeRedemptionSheet()

Did this page help you?