We are using server side validation to verify our iTunes in app purchases. When a transaction is sent to the SKPaymentTransactionObserver, we grab the receipt from appStoreReceiptURL in order to validate it.
if let receiptPath = NSBundle.mainBundle().appStoreReceiptURL?.path where
NSFileManager.defaultManager().fileExistsAtPath(receiptPath),
let receiptData = NSData(contentsOfURL:NSBundle.mainBundle().appStoreReceiptURL!) {
return receiptData
}
But in some cases, such as when we are restoring purchases, receive multiple transactions to the method:
public func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction])
It seems rather odd to use the same receipt data to verify each transaction. Does the single receipt contain data about each transaction?
Does the single receipt contain data about each transaction?
Yes. The receipt accessed from appStoreReceiptURL
is a single receipt for all persistable transactions for the user and app.
Docs on In-app purchase receipt
The in-app purchase receipt for a consumable product is added to the receipt when the purchase is made. It is kept in the receipt until your app finishes that transaction. After that point, it is removed from the receipt the next time the receipt is updated—for example, when the user makes another purchase or if your app explicitly refreshes the receipt.
The in-app purchase receipt for a non-consumable product, auto-renewable subscription, non-renewing subscription, or free subscription remains in the receipt indefinitely.
I.e. all in-app purchases including subscription renewals and restored purchases and excluding consumed purchases create a new transaction and are stored in the receipt.
Docs on Working with Subscriptions:
After a subscription is successfully renewed, Store Kit adds a transaction for the renewal to the transaction queue. Your app checks the transaction queue on launch and handles the renewal the same way as any other transaction.
Docs on Restoring Purchased Products:
Restoring completed transactions creates a new transaction for every completed transaction the user made.
Note that the original transaction id will be the same for restored purchases and subscription renewals.
The receipt is essentially a file stored on the device that the app updates when ever a new transaction is added.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With