Apphud – integrate, analyze and improve in-app purchases and subscriptions in your iOS/Android apps

Development

Testing purchases using Local StoreKit Configuration File

Great news! 🎉 Apphud now supports receipts made using Local StoreKit, a new great feature in Xcode 12. That means you can test your In-App Purchases in Simulator using Apphud SDK just like in Sandbox. These kind of receipts are not being validated through the Apple verification server and are being validated locally.

Note: we don’t validate local receipts with StoreKit certificate at the moment (you can test without them, everything works fine). The certificate is required for testing automation scenarios, this will be added later.

Features:

  • Easily test in-app purchases in Simulator, including introductory or promotional offers.
  • Test interruptions, like ask to buy. In this case a transaction will fail, but in the transaction manager developer is able to resolve it. When the payment issue is resolved, a new transaction is created.
  • Cancel renewals, refund transactions, etc.
  • Manage transactions, change accelerated time rate, change storefront, etc.

Let’s discuss more closely.

StoreKit Configuration File

In Xcode 12 you can create a StoreKit Configuration File in order to create and test in-app purchases without having to create them in App Store Connect.

This is basically a JSON-encoded file that describes a struct of your test in-app purchases. Product Identifiers doesn’t have to be the same as in App Store Connect, however, we recommend creating exactly the same to avoid possible bugs in your logic.

Adding in-app purchases is pretty straightforward. You can easily create and update introductory offers or promotional offers.

Once product identifiers set up, you will need to include the given configuration file to the build scheme.

Go to Product > Scheme > Edit Scheme and in Run/Debug tab under Options choose your StoreKit configuration file.

Make Purchases in Simulator

With the StoreKit Configuration file set up, you can make purchases in Simulator as usual by calling Apphud.purchase(product){..} method.

After the purchase is completed, a receipt is sent to Apphud servers and decoded locally. No HTTP request is sent to Apple, a receipt is being decoded as PKCS#7 container.

Validating local receipts in Apphud

Apphud now finally supports receipts made using Local StoreKit. No need to update SDK, everything is done on our backend.

However, there are some limitations mentioned below.

Limitations

  • The receipt generated by Local StoreKit is limited and doesn’t contain many fields that are available when verifying receipts through Apple. For example, missing trial period field. That means after purchasing a subscription with a trial period enabled, you will get ApphudSubscripton model with regular status in response. But don’t worry, that is only LocalStoreKit’s receipt issue, everything will work fine in production!
  • No access pending_renewal_info, a special sub-JSON, which contains important fields about the state of subscriptions, like autorenewal state, in billing retry state, etc. Subscriptions generated from local receipts will always have isInRetryBilling = false and isAutorenewEnabled = true.
  • A local receipt is just a snapshot and we are unable to detect renewals of such receipts until a fresh local receipt is sent to our backend. This means that the subscription will move to an expired state after the first transaction is expired. When launching the app again in Simulator, a new receipt will be automatically sent to Apphud, and subscription data will be updated. No actions required on the developer side. Again, everything will work just fine in production.
  • Apphud doesn’t create transactions and events of local receipts. On Apphud User page, the subscription will have just status and expiration date:
  • Testing promotional offers using Local StoreKit will be supported soon.

To summarize, in this article we covered how you can easily test your In-App Purchases in Simulator using Apphud SDK thanks to Local StoreKit from Apple. Hope you will like this feature and debugging process become simpler. Have a great day!

Leave a Reply

Your email address will not be published. Required fields are marked *