prime31 Iap 部分

原文:点击打开链接

In App Billing Plugin

In order for your app to be able to access Google's billing version 3 (which this plugin uses) you must use Googles new Developer Console web page. If you are still using the old version there will be a link at the top of the page allowing you to switch to the updated console. All products must be setup as Managed with the new billing system. Managed products can only be purchased once. For them to act like consumables you can now call the consumeProduct method which will then allow you to purchased the same product again.

You cannot test billing at all if you are logged into your device with your Google developer account. All testing must be done with a test account setup in the Developer Console. If the billingNotSupportedEvent fires with the error: "Error checking for billing v3 support. (response: 3:Billing Unavailable)" it could mean that your app was not setup in the new Developer Console, that you are not signed in with a test user on your device or many other undocumented things. There are some open bugs with regard to billing in the normal Google bug reporting system. One important one to take note of while testing here. If you experience any issues you should consult the bug reporter to see if they have already been reported.

The first thing you should do is call the init method passing it your public key (available in the Google Developer Console and now different for each app. This call will check to see if billing is supported and fire the billingSupportedEvent if it is. If billing is not supported the billingNotSupportedEvent will fire and you should not call any other methods. It is invalid and will cause a crash if you call any method other than init or enableLogging before the billingSupportedEvent fires!

After you know that billing is supported, you will want to call queryInventory with all your available skus. When the queryInventorySucceededEvent fires it will contain a list of all the current purchases and a list of all your project details. You can use this information to setup your store. The list is also handy when you want to consume an purchase. Any GooglePurchases returned are available for consumption. If you do not call queryInventory many of the checks that the plugin does to ensure proper operation cannot be done. It is highly recommended to always call queryInventory and only attempt to purchase items that Google returns as valid. Important note: subscriptions require that you call queryInventory and that the subscription that you want to purchase is properly returned by Google's servers!

Key points required for in-app billing to work (and associated documentation):

  • you must use a test account setup in the Play dashboard (in the Settings -> Account Details section)
  • your test device is running on Android SDK Version 2.2 (API level 8) or higher, and is installed with Google Play client Version 3.9.16 or higher
  • the android:versionCode and android:versionName attributes values in the AndroidManifest.xml of the application that you are installing matches the values of your apk in the Developer Console
  • you must upload your apk to Google Play (but do not publish it until you are ready to release!) Only the current version of the apk will work!
  • your application is signed with the same certificate that you used for the apk that you uploaded to the Developer Console

GoogleIAB exposes the following methods:

// Toggles high detail logging on/off
public static void enableLogging( bool shouldEnable )

// Toggles automatic signature verification on/off
public static void setAutoVerifySignatures( bool shouldVerify )

// Initializes the billing system
public static void init( string publicKey )

// Unbinds and shuts down the billing service
public static void unbindService()

// Returns whether subscriptions are supported on the current device
public static bool areSubscriptionsSupported()

// Sends a request to get all completed purchases and product information as setup in the Play dashboard about the provided skus
public static void queryInventory( string[] skus )

// Sends our a request to purchase the product
public static void purchaseProduct( string sku )
public static void purchaseProduct( string sku, string developerPayload )

// Sends out a request to consume the product
public static void consumeProduct( string sku )

// Sends out a request to consume all of the provided products
public static void consumeProducts( string[] skus )

GoogleIABManager fires the following events:

// Fired after init is called when billing is supported on the device
public static event Action billingSupportedEvent;

// Fired after init is called when billing is not supported on the device
public static event Action<string> billingNotSupportedEvent;

// Fired when the inventory and purchase history query has returned
public static event Action<List<GooglePurchase>,List<GoogleSkuInfo>> queryInventorySucceededEvent;

// Fired when the inventory and purchase history query fails
public static event Action<string> queryInventoryFailedEvent;

// Fired when a purchase completes allowing you to verify the signature on an external server if you would like
public static event Action<string,string> purchaseCompleteAwaitingVerificationEvent;

// Fired when a purchase succeeds
public static event Action<GooglePurchase> purchaseSucceededEvent;

// Fired when a purchase fails
public static event Action<string> purchaseFailedEvent;

// Fired when a call to consume a product succeeds
public static event Action<GooglePurchase> consumePurchaseSucceededEvent;

// Fired when a call to consume a product fails
public static event Action<string> consumePurchaseFailedEvent;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值