iOS应用内购买中的收据验证会返回多个交易 [英] Receipt validation on iOS In-App-Purchase returns multiple transaction

查看:141
本文介绍了iOS应用内购买中的收据验证会返回多个交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在沙盒模式下进行应用内购买会返回具有相同产品ID的多个交易.

In-app purchase on sandbox mode returns multiple transactions on same product id.

使用的语言:Swift 4.0

Language Used: Swift 4.0

func validateAppReceipt(_ receipt: Data) {
    let base64encodedReceipt = receipt.base64EncodedString()
    print(base64encodedReceipt)
    let requestDictionary = ["receipt-data":base64encodedReceipt]
    guard JSONSerialization.isValidJSONObject(requestDictionary) else {  print("requestDictionary is not valid JSON");  return }
    do {
        let requestData = try JSONSerialization.data(withJSONObject: requestDictionary)
        let validationURLString = "https://sandbox.itunes.apple.com/verifyReceipt"  // this works but as noted above it's best to use your own trusted server
        guard let validationURL = URL(string: validationURLString) else { print("the validation url could not be created, unlikely error"); return }
        let session = URLSession(configuration: URLSessionConfiguration.default)
        var request = URLRequest(url: validationURL)
        request.httpMethod = "POST"
        request.cachePolicy = URLRequest.CachePolicy.reloadIgnoringCacheData
        let task = session.uploadTask(with: request, from: requestData) { (data, response, error) in
            if let data = data , error == nil {
                do {
                    print(data)
                    let appReceiptJSON = try JSONSerialization.jsonObject(with: data)
                    print("success. here is the json representation of the app receipt: \(appReceiptJSON)")
                    self.getAppReceipt()
                } catch let error as NSError {
                    print("json serialization failed with error: \(error)")
                }
            } else {
                print("the upload task returned an error: \(error)")
            }
        }
        task.resume()
    } catch let error as NSError {
        print("json serialization failed with error: \(error)")
    }
}

响应:

问题:

  • 为什么我在同一个ID上获得多个交易

  • Why I am getting multiple transaction on same ID

此响应是否正确

如果正确,则要验证哪个ID

If it is correct, which ID to validate

我尝试了一些来自苹果和堆栈溢出的链接,但在理解这一点上仍存有疑问.有人可以描述一下我吗?

I tried some links from apple and stack overflow but still have doubts in understanding this. Can someone please describe me about all these.

推荐答案

我认为您已经在应用购买中实现了自动更新. 您的回答是正确的.

I think you have implemented auto renewable in app purchase. Your response is proper.

为什么我要使用相同的ID进行多次交易

就像您在每5分钟执行一次自动更新产品的响应交易中一样(沙盒环境在5分钟内更新产品,而不是在App Store中为1个月).

As in your response transaction performed for auto renew product at every 5 minutes(Sandbox environment renew product in 5 minutes instead of 1 month in App Store).

此响应是否正确

如果正确,则要验证哪个ID

您必须获取商品ID为tfc.premium.subscription的所有交易,然后获取最后一个对象并将其用作您的最新/最后交易.

You have to get all the transaction for your product id tfc.premium.subscription and then grab last object and use it as your latest/last transaction.

阅读此

Read this Apple Document for proper understanding.

自动续订订阅的行为在 测试环境和生产环境.

The behavior of auto-renewable subscriptions differs between the testing environment and the production environment.

在测试环境中,订阅续订发生在 加速费率,并且自动续订的订阅最多可以续订 每天六次.这使您能够测试您的应用如何处理 订阅续订,订阅失效和订阅历史记录 包括差距.请参阅 iTunes Connect的应用内购买配置指南,以了解有关 测试的订阅期限.

In the testing environment, subscription renewals happen at an accelerated rate, and auto-renewable subscriptions renew a maximum of six times per day. This enables you to test how your app handles a subscription renewal, a subscription lapse, and a subscription history that includes gaps. See Testing Auto-Renewable Subscriptions in the In-App Purchase Configuration Guide for iTunes Connect to learn about the subscription durations for testing.

由于加快了过期和续订速度, 订阅可以在系统尝试续订之前到期 订阅,因此在订阅期间会出现一些延迟.这样的 由于多种原因,生产中也可能发生失误 确保您的应用正确处理了它们.

Because of the accelerated expiration and renewal rates, a subscription can expire before the system tries to renew the subscription, leaving a small lapse in the subscription period. Such lapses are also possible in production for a variety of reasons—make sure your app handles them correctly.

这篇关于iOS应用内购买中的收据验证会返回多个交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆