Skip to main content

Fetching Purchases

When you want to get user's purchase history, you can fetch them via getCurrentPurchases and getAllPurchases methods of the SDK. All of the previous purchases made for consumable, non-consumable and subcription product types made by user will be return as a result. Even if the purchases which are made by user before the implementing the appmate SDK will also be return.

Fetching All Purchases#

With calling getAllPurchases method of the SDK you can get all of the purchases list made by user. The list returned by this method might be contains purchases which are already consumed or just purchased but not consumed consumable product's purchases. Also might be contains expired/ongoing subscription product's purchases or entitlement granted non-consumable product's purchases. In summary, you get all the purchases made by the user without any filtering.

Request#

Parameter NameType
completion([PurchaseInfo]?, GenericError?) -> Void

Response#

Parameter NameType
purchases[PurchaseInfo]?
errorGenericError?
PurchaseClient.shared.getAllPurchases { purchases, error in    if let purchases = purchases {        print(purchases)    } else {        print(error)    }}

Fetching Current Purchases#

With calling getCurrentPurchases method of the SDK you can get the list of purchases which comes with specific filtering rules from the user's purchases. These filtering rules are;

  • Purchased but not consumed purchases
  • Ongoing subscription purchases
note

Purchases which are made before or without appmate SDK implementation still will be return if they match these filtering rules.

important

When subsscription purchase is made, there might be a grace period defined for purchased product. If you cancelled this subscription from Google Play or AppGallery or unsubscribe within related sdk method, purchase will be still returning if there is a grace period defined before. Subscription purchase will be active until the time set for the grace period ends.

Request#

Parameter NameType
completion([PurchaseInfo]?, GenericError?) -> Void

Response#

Parameter NameType
purchases[PurchaseInfo]?
errorGenericError?
PurchaseClient.shared.getCurrentPurchases { purchases, error in    if let purchases = purchases {        print(purchases)    } else {        print(error)    }}

Checking If Product is Purchased#

With calling isProductPurchased method of the SDK you can check whether a product is purchased or not. Once you query a product with productId, a boolean response comes back. True means that the product is purchased.

  • Purchased but not consumed purchases
  • Non-consumable purchases
  • Ongoing subscription purchases

Request#

Parameter NameType
productIdString
completion(Bool, GenericError?) -> Void

Response#

Parameter NameType
isPurchasedBool
errorGenericError?
PurchaseClient.shared.isProductPurchased(productId: productId) { isPurchased, error in    if let error = error {        print(message: error.message)    } else {        print(message: isPurchased ? "Purchased" : "Not Purchased")    }}