简体   繁体   English

通过Google Play购买的按设备订购

[英]Per Device subscriptions for purchases through Google Play

I would like to setup subscription based billing for an app that will be sold through Google Play. 我想为将通过Google Play出售的应用设置基于订阅的结算方式。 Is it possible to sell the same subscription to the same user but on a different devices? 是否可以在不同设备上向同一用户出售相同的订阅? So that every device that user tries to use the app on would need an active subscription? 这样,用户尝试在其上使用该应用程序的每个设备都需要有效的订阅吗?

I was thinking I could store the device id and user id on my own server and authenticate it that way, but is it correct that a user can't purchase the same subscription more than once? 我本以为可以将设备ID和用户ID存储在我自己的服务器上,并以此方式进行身份验证,但是用户不能多次购买相同的订阅是否正确? So would I need a pool of basically the same subscriptions if the user wishes to purchase multiple "licenses"? 如果用户希望购买多个“许可证”,那么我是否需要一个基本相同的订阅池? Can Google Play Billing handle any of this natively? Google Play帐单可以本地处理吗?

Thanks 谢谢

The documentation from Google initially seems to make this impossible to achieve but digging deeper, I uncovered the following... 最初来自Google的文档似乎无法做到这一点,但需要更深入地研究,我发现了以下内容...

In the Google Play API version 2.0, you could create what was called an "unmanaged" product type that allowed the user to purchase the same thing multiple times. 在Google Play API版本2.0中,您可以创建所谓的“非托管”产品类型,该产品类型允许用户多次购买同一商品。 That seems to have partly disappeared in API 3.0 although the Gooogle Developer Console clearly supports this. 尽管Gooogle开发者控制台明确支持此功能,但在API 3.0中似乎已经部分消失了。 I assume it's still supported because apps that used the 2.0 API are still out there and Google just can't drop support for that. 我认为它仍然受支持,因为使用2.0 API的应用程序仍然存在,而Google不能放弃对此的支持。

In 3.0 however, the "unmanaged" product type is not listed in the API docs but the docs state the following about making multiple purchases for the same product type (one-time purchase or subscription): 但是,在3.0中,API文档中未列出“非托管”产品类型,但文档说明了以下有关同一产品类型的多次购买(一次性购买或订阅)的信息:

If you are using the Version 3 API, you can also consume managed items within your application. 如果使用版本3 API,则还可以使用应用程序中的托管项目。 You would typically implement consumption for items that can be purchased multiple times (such as in-game currency, fuel, or magic spells). 通常,您将对可以多次购买的物品(例如游戏中的货币,燃料或魔术)实施消费。 Once purchased, a managed item cannot be purchased again until you consume the item, by sending a consumption request to Google Play. 购买后,通过向Google Play发送消费请求,直到您消费了该托管商品,您才能再次购买该商品。 To learn more about in-app product consumption, see Consuming Items 要了解有关应用内商品消费的更多信息,请参见消耗物品

http://developer.android.com/google/play/billing/api.html#consume http://developer.android.com/google/play/billing/api.html#consume

IMPORTANT: Subscriptions CANNOT be consumed which means that if you want the customer to periodically renew their license, you will have to contact them and tell them that they must purchase the license again. 重要信息:无法使用订阅,这意味着,如果您希望客户定期更新其许可证,则必须与他们联系并告知他们必须再次购买许可证。 That's a downside if your service requires a periodic renewal. 如果您的服务需要定期更新,那将是不利的一面。

To obtain what you are after, you will need a backend server to handle the registration of devices and store tokens the apps receive from Google Play when purchasing. 要获得所需的服务,您将需要一个后端服务器来处理设备的注册并存储应用在购买时从Google Play接收的令牌。 When a user wants to purchase your license, feature, service (or whatever) from another device, the other device MUST first release its "ownership" of the product with Google Play, through a process known as "consuming". 当用户想要从另一台设备上购买您的许可,功能,服务(或其他任何东西)时,另一台设备必须首先通过称为“消费”的过程释放其对Google Play产品的“所有权”。 It would work something more or less like this: 它将或多或少像这样工作:

  1. The first device makes a purchase and receives a purchaseToken string from Google Play. 第一台设备进行购买,并从Google Play接收PurchaseToken字符串。
  2. The purchaseToken along with the device ID is sent from the app to your server and stored. PurchaseToken和设备ID将从应用程序发送到您的服务器并进行存储。
  3. The user goes to the second device and wants to purchase the license as well for that device. 用户转到第二台设备,并希望为该设备购买许可证。 The app first needs to go to your server and obtain the purchaseToken (that the first device uploaded) and then call Google Play with consumePurchase which releases the "ownership" of the product from the user. 该应用程序首先需要转到您的服务器,并获取purchaseToken(第一个设备已上传该文件),然后使用consumperPurchase调用Google Play,这会释放用户的产品“所有权”。
  4. The app then purchases the new license (or whatever) from Google Play, gets a new purchaseToken and stores it on your server along with its device ID. 然后,该应用从Google Play购买新许可(或其他任何许可),获取新的PurchaseToken并将其连同其设备ID存储在您的服务器上。

In essence, Google Play won't keep track of which device has the product. 本质上,Google Play不会跟踪哪个设备装有该产品。 It only associates the Google Account with the product being purchased. 它仅将Google帐户与所购买的产品相关联。 It's up to your app and server to manage the licenses. 由您的应用和服务器来管理许可证。

There is one potential problem I see that you need to address. 我看到您需要解决一个潜在的问题。 If for some reason the app fails to send the purchaseToken back to your server (your server is down, the user dropped their device and broke it, your app crashes before it saves the token on the device, etc.), then you may not know if the user paid for the service. 如果由于某种原因应用程序无法将purchaseToken发送回您的服务器(您的服务器已关闭,用户丢弃了设备并将其损坏,您的应用程序在将令牌保存到设备上之前崩溃了,等等),那么您可能不会知道用户是否为服务付费。 Google does provide a server API that lets your backend server query Google Play on Google's server for information about purchases, but I'm not familiar with it nor its limitations. Google确实提供了服务器API,可让您的后端服务器在Google的服务器上查询Google Play以获得有关购买的信息,但是我对此并不陌生,也不了解其局限性。

You will need to implement in app purchases as you would for any other in app item. 您需要像购买其他应用内商品一样实施应用内购买。

Make sure when you create your item in the Dev Console, it is unmanaged, as managed items can only be purchased once per account. 确保在开发人员控制台中创建项目时,该项目是非托管项目,因为每个帐户只能购买一次托管项目。

When you receive a confirmation on purchase of your unmanaged item, send the details like the unique ID to your server and store them there. 当您收到购买非托管商品的确认信息时,请将诸如唯一ID之类的详细信息发送到服务器,并将其存储在该服务器中。

Now whenever your app starts, check with your server if it is an authorized device. 现在,每当您的应用启动时,请与您的服务器联系,确认它是否为授权设备。 If it isn't, prompt the user to buy it. 如果不是,请提示用户购买。 If it is, let them continue to the app. 如果是这样,让他们继续使用该应用程序。

This only works if you need a one time payment. 这仅在您需要一次性付款时才有效。 If you need a subscription, you will have to make it up of multiple one time payments, as subscriptions are like managed purchases and can only be paid for once by any account. 如果您需要订阅,则必须由多次一次性付款组成,因为订阅就像托管购买一样,只能由任何帐户支付一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM