如果iOS购买收据验证失败怎么办? [英] What if iOS purchase receipt verification failed?

查看:116
本文介绍了如果iOS购买收据验证失败怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS购买收据服务器验证通常是这样的:

The iOS purchase receipt server verification usually works like this:

  1. 在iPhone上的用户购买

  1. User purchase on iPhone

您的应用将购买通知发送到服务器

Your app sent the purchase recipt to server

服务器收到该食谱并将其发送给Apple进行验证

Server receive the recipt and send it to Apple to verify

服务器从Apple获得验证结果.

Server gets the verify results from Apple .

服务器将验证结果发送到应用

Server sents the verify result to app

但是,如果仅第1步成功,该怎么办?例如,在步骤2中,应用程序无法向服务器发送请求,或者在步骤5中,应用程序无法获得服务器的响应.问题是用户已经付款.解决此问题的最佳方法是什么?

BUT what if only Step 1 is successful? For example, The app can't send request to the server in Step 2 or app can't get response from server in Step 5. The problem is user already paid. What is the best way to handle this problem?

推荐答案

如果您使用的是 SKPaymentQueue ,那么这很容易.您要做的就是在服务器上成功/失败验证结果后,在SKPaymentQueue中保持保持交易,直到"第5步".

If you are using SKPaymentQueue, then it's easy. All you have to do is to keep the transaction in SKPaymentQueue until 'step 5' when you get a success/failure verify result from your server.

如果在第1步到第5步中发生任何问题,您的应用仍然可以访问SKPaymentQueue中的交易,并且可以对其进行"重新处理".
未完成交易的重新处理可以在应用程序的开始(或您希望的某个时间间隔)内开始.
只需检查SKPaymentQueue即可获得待处理/未完成交易并将它们发送到您的服务器(就像"第2步"一样​​).如果您的服务器仍然无法访问,显然您将无法执行第5步,因此您不会从队列中删除事务,并且每次下一次启动应用程序时,都会再次再次进行此重新处理(或下一个队列检查时间间隔)直到已实现.

If anything goes wrong in between step 1 to 5 your app still has access to the transaction in the SKPaymentQueue and can 'reprocess' it.
The reprocessing of incomplete transactions could kick in at start of your app (or some time interval as you prefer).
Just check SKPaymentQueue to get the pending/incomplete transactions and send them to your server (just like 'step 2'). If your server is still not accessible obviously you won't get to step 5, therefore you don't remove the transaction from the queue and this reprocessing happens again and again every time at the next app start (or next queue check time interval) until is fulfilled.

实现也很容易,您需要具有 SKPaymentTransactionObserver 的'交易观察器类'.
在应用启动时,创建事务观察器类"的实例,该实例应通过调用以下内容进行注册:

The implementation is also easy, you need to have a 'transaction observer class' of SKPaymentTransactionObserver.
At app start create an instance of the 'transaction observer class' and that should register itself by call to:

[[SKPaymentQueue defaultQueue] addTransactionObserver:self]

然后,交易观察者类"在方法中获取交易:

Then 'transaction observer class' gets the transactions in method:

(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions

您可以在此方法处理和重新处理所有未完成的交易.

This method is where you can handle and reprocess all incomplete transactions.

请注意,您的服务器必须是幂等(即如果已处理重复交易,则能够处理重复交易)
服务器处理并完成第2步至第4步后,它就会出现具有成功/失败结果的应用程序,这是您要删除的唯一时间strong>通过调用以下命令从队列中进行交易:

Note that your server must be idempotent (i.e able to handle repeated transactions if they already been processed)
Once the server processes and completes steps 2 to 4, then it comes to app with success/failure result and that's the only time when you want to remove that transaction from the queue by call to:

[[SKPaymentQueue defaultQueue] finishTransaction: transaction]

最后为您的用户提供他们此时购买的高级功能.

And finally give your user the premium feature they purchased at this point.

这篇关于如果iOS购买收据验证失败怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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