StoreKit 2
brand new set of modern and flexible Swift APIs for working with In-App Purchase across iOS, macOS, tvOS, and watchOS
updates to the in-app purchase transactions, to make it easier to manage
Five main areas:
Products
Purchases
Transaction info
Transaction history
Subscription status
Products & Purchases
New
Productstructcontains additional data, such as the product type (
Product.ProductType) and extended subscription information (Product.SubscriptionInfo)future-compatible with new features via
BackingValue, which allows you to retrieve data contained in the product even on SDKs and devices running operating systems that have older versions of StoreKit 2uses
async/awaitfor requests and purchases
purchase is a
Productinstance method,purchase(options:)the options parameter lets you specify things like quantity, promotional offer, app account token (New)
the App account token is a way for you to keep track of which of your app’s user accounts began and completed a transaction.
it’s an opaque token (UUID format)
created by you
linked to the user in-app account
stored in transaction forever
Transaction info
individually signed object for every transaction
in-app purchase transaction info will now be provided in JSON Web signature
StoreKit 2 does transaction verification for you, but you can also add your verification on top
Transaction history
new set of APIs for querying completed transactions in the user’s transaction history
you can access all of the user’s past transactions with a single API call
you can also access the latest transaction for a product
get what products the user has paid for access via
currentEntitlementscontains all of the non-consumables in the user’s transaction history
contains all of the subscription transactions that are currently active
any transactions that have been revoked are not included
no consumable transactions
all transactions are available immediately upon app download
transactions automatically update on every device
real-time updates
thanks to transaction history, users no longer need to restore completed transactions when your app is reinstalled
you still need to provide a UI to restore purchases
all new StoreKit 2 transactions are available to the old StoreKit API
all old StoreKit transactions are available to the new StoreKit 2 API
Subscription status
A subscription status has three parts:
latest transaction
give you access to the last transaction that occurred for this subscription
renewal state
enumeration that tells you the current state of the subscription
base you app logic off this renewal state
renewal info
contains all details about a user’s subscription (e.g. whether auto-renew is on/off, product id of the renewal, expiration reason)
signed using JWS
StoreKit 2 will automatically validate the renewal info for you
Signature validation
More details in RFC7515
JSON Web Signature is comprised of three parts:
header
contains metadata about the object, such as which algorithm is used for signing and where to find the certificate used to validate the signature.
StoreKit 2 currently uses an
ECDSAalgorithm (supported natively in CryptoKit)For the certificate, StoreKit 2 uses the
x5cheaderthe entire certificate chain is included in the JWS data, no internet connection
payload
main transaction information such as transaction ID, product ID, purchase date
signature
generated using both the header and the payload
Demo
The session has two demos touching all the flows:
the first demo focuses on getting products, purchasing, and listening to transitions.
the second demo focuses on transaction history and subscription statuses
the final code can be found here
