admin管理员组文章数量:1417684
I am using Storekit-2 for InApp purchase. The product is consumable. After the purchase is successful, I need to call API and backend will grant 200 coins to that user.
Now, users can try to access the data with no subscription by simply executing requests to the server. For this reason, I will have to validate receipt on server side.
I have done some R&D and get to know that I need to pass the following receiptData
to server.
// Get the receipt if it's available.
if let appStoreReceiptURL = Bundle.main.appStoreReceiptURL,
FileManager.default.fileExists(atPath: appStoreReceiptURL.path) {
do {
let receiptData = try Data(contentsOf: appStoreReceiptURL, options: .alwaysMapped)
print(receiptData)
let receiptString = receiptData.base64EncodedString(options: [])
// Read receiptData.
}
catch { print("Couldn't read receipt data with error: " + error.localizedDescription)
}
}
Then the server should send a request to Apple’s verification server at the following URL:
Production:
Sandbox:
I also read one article and they suggest to use following:
switch try await product.purchase() {
case .success(let result):
let jws = result.jwsRepresentation
// send jws to your backend
Is that the right way to do? Also my question is, the following receiptData
is not for specific transaction, i.e it is not generated from a transaction. Then how specific transaction is verified?
本文标签: iosHow to validate a receipt on server side with StoreKit 2Stack Overflow
版权声明:本文标题:ios - How to validate a receipt on server side with StoreKit 2? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745275617a2651166.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论