将耗材的应用内购买与服务器同步

[英]Syncing a consumable in-app purchase with a server


I am trying to figure out the best way to ensure that a user will not lose their consumable in app purchase.

我试图找出确保用户在购买应用程序时不会丢失耗材的最佳方法。

However, I am starting to feel like this StackOverflow user.

但是,我开始觉得这个StackOverflow用户。

After a complete transaction I want to send to a server that the user bought a consumable in app. However, the connection might fail at that point (the server is down or the user loses connection).

完成一笔交易后,我想发送给用户在应用程序中购买耗材的服务器。但是,此时连接可能会失败(服务器已关闭或用户失去连接)。

I was considering in that scenario to send the receipt as soon as the connection can be made again. However, from what I have read the receipt contains all in app purchases and I can't send only the receipt for the last bought item.

我正在考虑在那种情况下,一旦连接再次发送就发送收据。但是,从我所看到的收据包含所有应用程序内购买,我不能只发送最后购买的项目的收据。

How can I ensure that the purchase made by the user was synced with the server?

如何确保用户购买的产品与服务器同步?

1 个解决方案

#1


14  

The solution is to not call

解决方案是不打电话

[[SKPaymentQueue defaultQueue] finishTransaction:transaction];

[[SKPaymentQueue defaultQueue] finishTransaction:transaction];

on the consumable purchase until it has been synced with the server. This way, the transaction will be delivered again to your observer every time it is set to observe the payment queue. You will need manage app side whether it's a purchase that has been delivered but not synced, or a new purchase.

在消耗品购买之前,直到它与服务器同步。这样,每次将事务设置为观察支付队列时,事务将再次传递给您的观察者。您需要管理应用程序端,无论是已交付但未同步的购买,还是新购买。

Once you have synced the transaction with the server. You can call -finishTransaction:. See the "Finishing The Transaction" in the docs here:

一旦与服务器同步了事务。你可以调用-finishTransaction:。请参阅此处文档中的“完成交易”:

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/DeliverProduct.html#//apple_ref/doc/uid/TP40008267-CH5-SW3

EDIT

So the user is charged by Apple, and Apple send you a SKPaymentTransaction object that represents the transaction. If the transactionState property of that transaction is SKPaymentTransactionStatePurchased, then it means Apple has processed the payment and the user has been charged.

因此Apple向用户收费,Apple向您发送代表交易的SKPaymentTransaction对象。如果该事务的transactionState属性是SKPaymentTransactionStatePurchased,则表示Apple已处理付款并且用户已被收费。

Once you have received this SKPaymentTransaction object from the paymentQueue, you deliver the content to the user, and sync the transaction with your server. Once both of those have been successfully completed, you call -finishTransaction. Calling -finishTransaction tells StoreKit that you have successfully completed everything you need to do. -finishTransaction is a synchronous call, you are handing responsibility back to StoreKit, and you don't need to concern yourself with how that is communicated back to iTunes/Apple, StoreKit handles it all for you.

从paymentQueue收到此SKPaymentTransaction对象后,您将内容传递给用户,并将事务与您的服务器同步。一旦成功完成这两个,就调用-finishTransaction。调用-finishTransaction告诉StoreKit您已成功完成了所需的一切。 -finishTransaction是一个同步调用,你将责任交还给StoreKit,你不需要关心如何将它传回iTunes / Apple,StoreKit会为你处理这一切。

You should not call -finishTransaction until you have done everything you need to do. If something goes wrong (device battery dies, loss of internet connection, app crash), you will be delivered the same SKPaymentTransaction from the payment queue next time your observer is registered with the queue, and can try to sync again with your server. This will keep happening until you call -finishTransaction.

在完成了所有需要的工作之前,不应该调用-finishTransaction。如果出现问题(设备电池耗尽,互联网连接中断,应用程序崩溃),下次观察员在队列中注册时,您将从支付队列中获得相同的SKPaymentTransaction,并且可以尝试再次与您的服务器同步。这将继续发生,直到你调用-finishTransaction。

There is a scenario where the user is never able to sync with your server, never connects to internet again etc. That is out of your control, and at that point it is the responsibility of Apple to decide whether they charge the user.

有一种情况是用户永远无法与您的服务器同步,再也无法再连接到互联网等。这是您无法控制的,此时Apple决定是否向用户收费。

It's also worth noting that the user can contact Apple and request a refund if they wish to.

值得注意的是,如果用户愿意,用户可以联系Apple并要求退款。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2014/07/21/54cec6011ac1ce9df9d70478c675c2c9.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告