android-Purchasing In-app Billing Products,Testing Your In-app Billing Application
2016-02-01 21:55
429 查看
>Purchasing In-app Billing Products
Once your application is connected to Google Play, you can initiate purchase requests for in-app products. Google Play provides a checkout interface for users to enter their payment
method, so your application does not need to handle payment transactions directly.
You can also query Google Play to quickly retrieve the list of purchases that were made by the user. This is useful, for example, when you want to restore the user's purchases
when your user launches your app.
>To start a purchase request from your app, call
your
Here’s an explaination of the
The first argument is the calling
The second argument is the product ID (also called its SKU) of the item to purchase. Make sure that you are providing the ID and not the product name. You must have previously defined and activated the item in the Developer Console,
otherwise it won’t be recognized.
The third argument is a request code value. This value can be any positive integer. Google Play reurns this request code to the calling
response.
The fourth argument is a listener that is notified when the purchase operation has completed and handles the purchase response from Google Play.
The fifth argument contains a ‘developer payload’ string that you can use to send supplemental information about an order (it can be an empty string). Typically, this is used to pass in a string token that uniquely identifies
this purchase request. If you specify a string value, Google Play returns this string along with the purchase response. Subsequently, when you make queries about this purchase, Google Play returns this string together with the purchase details.
Security Recommendation: It’s good practice to pass in a string that helps your application to identify the user who made the purchase, so that you can later verify that this is a legitimate purchase by that user. For consumable items, you
can use a randomly generated string, but for non-consumable items you should use a string that uniquely identifies the user.
Security Recommendation: When you receive the purchase response from Google Play, make sure to check the returned data signature, the
to make sure that you are getting the expected values. You should verify that the
previously with the purchase request. As a further security precaution, you should perform the verification on your own secure server.
Security Recommendation: You must send a consumption request before provisioning the benefit
of the consumable in-app purchase to the user. Make sure that you have received a successful consumption response from Google Play before you provision the item.
>Testing Your In-app Billing Application
Early testing also helps to ensure that the user flow for purchasing in-app items is not confusing or slow, and that users can see their newly purchased items in a timely way.
>To test your In-app Billing Version 3 application using your own product IDs:
In the Developer Console, add one or more tester accounts to the developer account that you are using to publish your application.
Login to the Developer Console with your developer account.
Click Settings > Account details, then in the License Testing section, add the Google email addresses for your tester accounts.
Build a signed APK file for your In-app Billing application. To learn how to build and sign your APK, seeBuilding
Your Application for Release. Make sure that you are using your final (not debug) certificate and private key to sign your application.
Make sure that you have uploaded the signed APK for your application to the Developer Console, and associated one or more in-app products with your application. You don't need to publish the application on Google Play to test
it.
Warning: It may take up to 2-3 hours after uploading the APK for Google Play to recognize your updated APK version. If you try to test your application before your uploaded APK is recognized by Google Play, your application will receive a ‘purchase
cancelled’ response with an error message “This version of the application is not enabled for In-app Billing.”
Install the APK file to your physical test device by using the
on a Device. Make sure that:
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
APK in the Developer Console.
Your application is signed with the same certificate that you used for the APK that you uploaded to the Developer Console, before installing it on your device.
Login to the test device by using a tester account. Test your In-app Billing application by purchasing a few items, and fix any issues that you encounter. To learn more about how you can perform large-scale testing of your In-app
Billing app, see Test Purchases (In-app Billing Sandbox).
Once your application is connected to Google Play, you can initiate purchase requests for in-app products. Google Play provides a checkout interface for users to enter their payment
method, so your application does not need to handle payment transactions directly.
You can also query Google Play to quickly retrieve the list of purchases that were made by the user. This is useful, for example, when you want to restore the user's purchases
when your user launches your app.
>To start a purchase request from your app, call
launchPurchaseFlow(Activity, String, int, OnIabPurchaseFinishedListener, String)on
your
IabHelperinstance. You must make this call from the main thread of your
Activity.
Here’s an explaination of the
launchPurchaseFlowmethod parameters:
The first argument is the calling
Activity.
The second argument is the product ID (also called its SKU) of the item to purchase. Make sure that you are providing the ID and not the product name. You must have previously defined and activated the item in the Developer Console,
otherwise it won’t be recognized.
The third argument is a request code value. This value can be any positive integer. Google Play reurns this request code to the calling
Activity’s
onActivityResultalong with the purchase
response.
The fourth argument is a listener that is notified when the purchase operation has completed and handles the purchase response from Google Play.
The fifth argument contains a ‘developer payload’ string that you can use to send supplemental information about an order (it can be an empty string). Typically, this is used to pass in a string token that uniquely identifies
this purchase request. If you specify a string value, Google Play returns this string along with the purchase response. Subsequently, when you make queries about this purchase, Google Play returns this string together with the purchase details.
Security Recommendation: It’s good practice to pass in a string that helps your application to identify the user who made the purchase, so that you can later verify that this is a legitimate purchase by that user. For consumable items, you
can use a randomly generated string, but for non-consumable items you should use a string that uniquely identifies the user.
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { public void onIabPurchaseFinished(IabResult result, Purchase purchase) { if (result.isFailure()) { Log.d(TAG, "Error purchasing: " + result); return; } else if (purchase.getSku().equals(SKU_GAS)) { // consume the gas and update the UI } else if (purchase.getSku().equals(SKU_PREMIUM)) { // give user access to premium content and update the UI } } };
Security Recommendation: When you receive the purchase response from Google Play, make sure to check the returned data signature, the
orderId, and the
developerPayloadstring in the
Purchaseobject
to make sure that you are getting the expected values. You should verify that the
orderIdis a unique value that you have not previously processed, and the
developerPayloadstring matches the token that you sent
previously with the purchase request. As a further security precaution, you should perform the verification on your own secure server.
Security Recommendation: You must send a consumption request before provisioning the benefit
of the consumable in-app purchase to the user. Make sure that you have received a successful consumption response from Google Play before you provision the item.
>Testing Your In-app Billing Application
Early testing also helps to ensure that the user flow for purchasing in-app items is not confusing or slow, and that users can see their newly purchased items in a timely way.
>To test your In-app Billing Version 3 application using your own product IDs:
In the Developer Console, add one or more tester accounts to the developer account that you are using to publish your application.
Login to the Developer Console with your developer account.
Click Settings > Account details, then in the License Testing section, add the Google email addresses for your tester accounts.
Build a signed APK file for your In-app Billing application. To learn how to build and sign your APK, seeBuilding
Your Application for Release. Make sure that you are using your final (not debug) certificate and private key to sign your application.
Make sure that you have uploaded the signed APK for your application to the Developer Console, and associated one or more in-app products with your application. You don't need to publish the application on Google Play to test
it.
Warning: It may take up to 2-3 hours after uploading the APK for Google Play to recognize your updated APK version. If you try to test your application before your uploaded APK is recognized by Google Play, your application will receive a ‘purchase
cancelled’ response with an error message “This version of the application is not enabled for In-app Billing.”
Install the APK file to your physical test device by using the
adbtool. To learn how to install the application, see Running
on a Device. Make sure that:
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:versionCodeand
android:versionNameattributes values in the
AndroidManifest.xmlof the application that you are installing matches the values of your
APK in the Developer Console.
Your application is signed with the same certificate that you used for the APK that you uploaded to the Developer Console, before installing it on your device.
Login to the test device by using a tester account. Test your In-app Billing application by purchasing a few items, and fix any issues that you encounter. To learn more about how you can perform large-scale testing of your In-app
Billing app, see Test Purchases (In-app Billing Sandbox).
相关文章推荐
- 导入xUtils_3 工程到Android Studio
- 刻苦学习Android开发
- Android Socket编程学习笔记
- 一种Android换肤机制的实现
- 11.Swift 中的类和结构体
- ios9系统图片显示不出来
- Android 实现夜间模式
- 微信好友检测
- android-Preparing Your In-app Billing Application,Establishing In-app Billing Products for Sale
- Android 总结:AS入门,性能优化,性能专项测试,分析工具的使用
- iOS开发:NSNotification的使用
- android *** Layout 12 Spinner
- iOS—TableView之Cell的Style属性
- js 报错:object is not a function
- 【Android高级】DexClassloader和PathClassloader动态加载插件的实现
- iOS—收起虚拟键盘的各种方法
- Unity问答第4期
- cocos2d-x3.6 连连看连通画线
- (6)Cocos2d-x 3.0坐标系详解
- Android中的异步通信类AsyncTast