Transaction
Information that represents the customer’s purchase of a product in your app.
Declaration
struct TransactionMentioned in
- Supporting offer codes in your app
- Supporting subscription offer codes in your app
- Supporting monthly subscriptions with a 12-month commitment
- Supporting win-back offers in your app
- Managing the life cycle of monthly subscriptions with a 12-month commitment
- Testing purchases made outside your app
- Testing refund requests
- Testing win-back offers in the sandbox environment
- Choosing a receipt validation technique
- Choosing a StoreKit API for In-App Purchases
- Implementing offer codes in your app
- Validating receipts with the App Store
Overview
A transaction represents a successful In-App Purchase. The App Store generates a transaction each time a customer purchases an In-App Purchase product or renews a subscription. For each transaction that represents a current purchase, your app unlocks the purchased content or service and finishes the transaction.
Use the Transaction type to perform these transaction-related tasks:
Get the customer’s transaction history, latest transactions, and current entitlements to unlock content and services.
Access transaction properties.
Finish a transaction after your app delivers the purchased content or service.
Access the raw JSON Web Signature (JWS) string and supporting values to verify the transaction information.
Listen for new transactions while the app is running.
Begin a refund request from within your app.
Access transaction history and current entitlements
Your app doesn’t create transaction objects. Instead, StoreKit automatically makes up-to-date transactions available to your app, including when someone launches the app for the first time.
You access transactions in several ways:
Get transaction history anytime by accessing the static all sequence, or get just the most recent transaction for a product with the latestTransaction property of Product.
Receive notifications for new transactions while your app is running when customers complete a purchase outside of the app, including on another device, through the transaction listener, updates.
Access the latest transaction for a subscription group through the subscription status API, using transaction.
After a successful In-App Purchase, StoreKit returns the transaction through Product.PurchaseResult.success(_:).
The most important use of transaction information is for determining which In-App Purchases the customer has paid access to, so your app can unlock the content or service. The currentEntitlements API provides the information you need to unlock all of the customer’s paid content in your app. Use currentEntitlements to get a list of transactions for all the products the customer is currently entitled to, including non-consumable In-App Purchases and currently active subscriptions.
Verify transactions
The App Store cryptographically signs transaction information in JWS format. StoreKit automatically validates and returns the signed information, wrapped in a VerificationResult. When the VerificationResult wraps a Transaction value, it provides the raw JWS string in the jwsRepresentation property. If you get a transaction through VerificationResult.verified(_:), the information passed validation. If you get it through VerificationResult.unverified(_:_:), the information didn’t pass StoreKit’s automatic validation. Your app can immediately access the transaction information in the Transaction properties.
To perform your own validation on the device, use the verification result’s jwsRepresentation string, and use the provided convenience properties headerData, payloadData, and signatureData. For added control and security, send the jwsRepresentation to your server to verify. Consider using the App Store Server Library to implement your verification. The library provides the functions verifyAndDecodeTransaction and verifyAndDecodeRenewalInfo in each language the library supports. For more information, see Simplifying your implementation by using the App Store Server Library.
If StoreKit returns a transaction as verified, the transaction is valid for the device. For information about performing your own verification for a device, see deviceVerification.
For more information about JWS, see the IETF RFC 7515 specification.
Access purchases made with the original API
All In-App Purchases that customers make are equally available to your app in this Transaction API, and in receipts using the Original API for In-App Purchase, as follows:
New purchases that customers make with the original API are available immediately using the
TransactionAPI.Purchases that customers make with the purchase(options:) method are available in the original API when your app refreshes the receipt. For more information, see SKReceiptRefreshRequest.
Topics
Transaction properties
Monitoring transaction-related changes
Getting transaction history
Getting current entitlements
Getting transactions for a product
Finishing the transaction
Verifying transactions
Getting transaction info in JSON format
Requesting refunds
Testing refund requestsbeginRefundRequest(in:)beginRefundRequest(in:)beginRefundRequest(for:in:)beginRefundRequest(for:in:)Transaction.RefundRequestErrorTransaction.RefundRequestStatus