在沙盒环境中工作的应用内购买,但Appstore版本金额从用户帐户中扣除,但内容未解锁。
我不认为编码存在问题。否则,它将无法在沙箱环境中工作。我认为交易收据可能是零。
当我点击再次购买它显示"您已经订阅"。但是,它还没有解锁应用内容。即使我点击恢复购买,但它也无法正常工作。我很惊讶为什么一切都在沙盒环境中工作。
订阅类型:自动续订。 内容解锁:音频,视频和pdf教程 我检查了后端日志。 API从未执行过,我填写的唯一问题是,即使用户成功购买,我也没有收到应用商店收据。一切都在沙盒环境中完美运行。
代码:
public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
switch transaction.transactionState {
case .purchasing:
handlePurchasingState(for: transaction, in: queue)
case .purchased:
handlePurchasedState(for: transaction, in: queue)
case .restored:
handleRestoredState(for: transaction, queue: queue)
case .failed:
handleFailedState(for: transaction, in: queue)
case .deferred:
handleDeferredState(for: transaction, in: queue)
}
}
}
//On transaction state changed to purchased:
func handlePurchasedState(for transaction: SKPaymentTransaction, in queue: SKPaymentQueue) {
print("User purchased product id: \(transaction.payment.productIdentifier)")
print("User purchased product id: \(transaction)")
queue.finishTransaction(transaction)
self.completeTransaction(transaction:transaction)
}
//In completeTransaction Method:
func completeTransaction(transaction:SKPaymentTransaction)
{
if let receiptURL = Bundle.main.appStoreReceiptURL,FileManager.default.fileExists(atPath: receiptURL.path)
{
let receipt:Data = try! Data(contentsOf: receiptURL)
let jsonObjectString = receipt.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: 0))
var strIdentifier:String = transaction.transactionIdentifier!
if let identifier = transaction.original?.transactionIdentifier
{
strIdentifier = identifier
}
//API call to save receipt to validate later and unlock the content
//In case API calling failed then I stored data and called API again on app home page.
}
}
答案 0 :(得分:0)
请在验证收据queue.finishTransaction(transaction)
后完成交易apple还建议"在完成交易之前下载所有Apple托管的内容。事务完成后,将无法再使用其下载对象。"