Apple Auto Renewable Subscriptions - 针对收据验证用户

时间:2021-10-07 10:28:16

I am a little confused about the process involved in the validation of receipts from users who have subscribed to my app.

我对订阅我的应用的用户的收据验证过程有点困惑。

At the minute a user joins and then purchases the subscription, the receipt is then base64 encoded and sent to my server. At midnight each night the server sends off the receipt stored in my db to Apple to be validated and the expiry date updated.

在用户加入然后购买订阅的那一刻,收据被base64编码并发送到我的服务器。每天午夜,服务器将存储在我的数据库中的收据发送给Apple进行验证并更新到期日期。

Now i'm a bit confused about how a receipt is updated each month. Please take a look at the following flow and let me know if this is correct.

现在我对每个月如何更新收据感到困惑。请查看以下流程,如果这是正确的,请告诉我。

  1. The user registers and subscribes to my app.( Lets say January).
  2. 用户注册并订阅我的应用程序。(让我们说一月)。
  3. The original receipt is sent to my server and then validated with Apple, the expiry date is returned and set on my server.
  4. 原始收据发送到我的服务器,然后通过Apple验证,返回到期日并在我的服务器上设置。
  5. A month later in February on the expiry date I send the original (January) receipt to Apple again to see if the subscription has been renewed and then I can set the new expiry date.
  6. 在一个月后的2月到期日,我再次将原始(1月)收据发送给Apple以查看订阅是否已续订,然后我可以设置新的到期日期。

Is this flow correct? Because I am sending the original (January) receipt each month will it still contain the latest renewal information or do I somehow have to refresh the receipt each month when the user logs in or opens the app?

这个流程是否正确?因为我每个月都会发送原始(1月)收据,它是否仍然包含最新的续订信息,或者当用户登录或打开应用程序时,我每个月都必须刷新收据?

1 个解决方案

#1


2  

Yes, your understanding is more or less correct. When a user's first renewal occurs a couple of things will happen:

是的,您的理解或多或少是正确的。当用户首次续订时,会发生以下几件事情:

  1. The next time the user launches the app, your SKPaymentQueue delegate will receive a new SKPaymentTransaction for the new transaction. You need to be ready to observe this transaction with your delegate and finish it. If you don't, transactions will just continue to pile up over the months.

    用户下次启动应用时,您的SKPaymentQueue代表将收到新交易的新SKPaymentTransaction。您需要准备好与代理人一起观察此事务并完成它。如果不这样做,交易将在几个月内继续堆积。

  2. The verifyReceipt response received from Apple for the first receipt will update the latest_receipt_info key to include the most update version of the receipt data. latest_receipt_info will originally just be a copy of the receipt.in_app field, but after the first renewal it will contain the most up to date transactions. You should use these latest_receipt_info transactions to update the expiration date.

    Apple收到的第一次收据的verifyReceipt响应将更新latest_receipt_info密钥以包含收据数据的最新版本。 latest_receipt_info最初只是receipt.in_app字段的副本,但在第一次续订后,它将包含最新的事务。您应该使用这些latest_receipt_info事务来更新到期日期。

My suggested behavior is that when you receive the new SKPaymentTransaction you send it to your server anyway (although you technically don't need to) and you use it to verify and update the expiration date before finishing the transaction. You can overwrite the old receipt with the new one.

我建议的行为是,当您收到新的SKPaymentTransaction时,无论如何都要将它发送到您的服务器(虽然您在技术上不需要),并且您在完成交易之前使用它来验证和更新到期日期。您可以使用新收据覆盖旧收据。

You can have a look at the RevenueCat iOS framework source code to see how I handle it. (You should also make sure you trigger a fetch receipt request if the receipt data is missing, which I do in the code.)

您可以查看RevenueCat iOS框架源代码,了解我如何处理它。 (如果缺少收据数据,您还应确保触发获取收据请求,我在代码中执行此操作。)

If you are interested in an out of the box solution, RevenueCat is a service I started to handle all these and many more edge cases automatically.

如果您对开箱即用的解决方案感兴趣,RevenueCat是一项服务,我开始自动处理所有这些和更多边缘情况。

#1


2  

Yes, your understanding is more or less correct. When a user's first renewal occurs a couple of things will happen:

是的,您的理解或多或少是正确的。当用户首次续订时,会发生以下几件事情:

  1. The next time the user launches the app, your SKPaymentQueue delegate will receive a new SKPaymentTransaction for the new transaction. You need to be ready to observe this transaction with your delegate and finish it. If you don't, transactions will just continue to pile up over the months.

    用户下次启动应用时,您的SKPaymentQueue代表将收到新交易的新SKPaymentTransaction。您需要准备好与代理人一起观察此事务并完成它。如果不这样做,交易将在几个月内继续堆积。

  2. The verifyReceipt response received from Apple for the first receipt will update the latest_receipt_info key to include the most update version of the receipt data. latest_receipt_info will originally just be a copy of the receipt.in_app field, but after the first renewal it will contain the most up to date transactions. You should use these latest_receipt_info transactions to update the expiration date.

    Apple收到的第一次收据的verifyReceipt响应将更新latest_receipt_info密钥以包含收据数据的最新版本。 latest_receipt_info最初只是receipt.in_app字段的副本,但在第一次续订后,它将包含最新的事务。您应该使用这些latest_receipt_info事务来更新到期日期。

My suggested behavior is that when you receive the new SKPaymentTransaction you send it to your server anyway (although you technically don't need to) and you use it to verify and update the expiration date before finishing the transaction. You can overwrite the old receipt with the new one.

我建议的行为是,当您收到新的SKPaymentTransaction时,无论如何都要将它发送到您的服务器(虽然您在技术上不需要),并且您在完成交易之前使用它来验证和更新到期日期。您可以使用新收据覆盖旧收据。

You can have a look at the RevenueCat iOS framework source code to see how I handle it. (You should also make sure you trigger a fetch receipt request if the receipt data is missing, which I do in the code.)

您可以查看RevenueCat iOS框架源代码,了解我如何处理它。 (如果缺少收据数据,您还应确保触发获取收据请求,我在代码中执行此操作。)

If you are interested in an out of the box solution, RevenueCat is a service I started to handle all these and many more edge cases automatically.

如果您对开箱即用的解决方案感兴趣,RevenueCat是一项服务,我开始自动处理所有这些和更多边缘情况。