Wednesday, December 21, 2011

[Android in-app billing第4篇]Testing In-app Billing測試應用程式內金流機制(中文翻譯)

了解iap測試工具是如何運作,並學習如何測試你實作出來的iap機制。

原文連結︰Testing In-app Billing
翻譯︰小鰻
翻譯版本號︰v.1.0
如需轉載請註明出處「小鰻的Android學習筆記
讓我參與最直接的討論以及錯誤修正, 謝謝!

In this document

  1. Testing in-app purchases with static responses
  2. Testing in-app purchases using your own product IDs

Downloads

  1. Sample Application

See also

  1. Overview of In-app Billing
  2. Implementing In-app Billing
  3. Security and Design
  4. Administering In-app Billing
  5. In-app Billing Reference
The Android Market publisher site provides several tools that help you test your in-app billing implementation before it is published. You can use these tools to create test accounts and purchase special reserved items that send static billing responses to your application.
Android市集軟體發佈網站提供了數個工具,幫助您在發佈APP以前,針對您實作的iap機制做測試。您可以使用這些工具來建立測試帳戶以及透過發送靜態性質的金流回應(static billing responses)至您的APP來購買那些已已先設置在網站內的特殊商品。

To test in-app billing in an application you must install the application on an Android-powered device. You cannot use the Android emulator to test in-app billing. The device you use for testing must run a standard version of the Android 1.6 or later platform (API level 4 or higher), and have the most current version of the Android Market application installed. If a device is not running the most current Android Market application, your application won't be able to send in-app billing requests to Android Market. For general information about how to set up a device for use in developing Android applications, see Using Hardware Devices.
如果要在您的APP裡測試iap機制,您必須在實際裝置上安裝您的APP,因為您無法使用模擬器來測試iap機制。並且,您用來測試的裝置也有以下條件︰Android1.6以上的標準Android版本、安裝了最新版的Android市集。如果您的Android市集軟體並非最新,也許您的APP就無法透過Android市集軟體發送出iap金流請求。關於如何設定一個用來開發Android軟體的裝置,請參見Using Hardware Devices這篇文章。

The following section shows you how to set up and use the in-app billing test tools.
接下來的章節將會教您如何設定並且使用iap金流測試工具。

Testing in-app purchases with static responses使用靜態回應的方式測試iap購買機制

We recommend that you first test your in-app billing implementation using static responses from Android Market. This enables you to verify that your application is handling the primary Android Market responses correctly and that your application is able to verify signatures correctly.
我們建議您在第1次使用iap機制時,跑一下靜態回應(static responses)這個流程。這能幫助您去驗証您的APP是否有對Android市集傳來的主要回應做出正確的處理,以及您的APP是否能正確的驗証數位簽章。

To test your implementation with static responses, you make an in-app billing request using a special item that has a reserved product ID. Each reserved product ID returns a specific static response from Android Market. No money is transferred when you make in-app billing requests with the reserved product IDs. Also, you cannot specify the form of payment when you make a billing request with a reserved product ID. Figure 1 shows the checkout flow for the reserved item that has the product ID android.test.purchased.
如果要在靜態回應的環境底下去實作iap機制,您必須使用一些已預先設置的產品ID來做金流請求測試。每個已預先設置的產品ID皆會回傳一個特殊的靜態回應,而且不會有任何金錢上的交易發生。並且,您如果使用金流機制去請求購買這個已預先設置的產品ID,您就無法指定付款的方式。圖1顯示購買已預先設置的商品、產品ID為android.test.purchased的付費流程。

Figure 1. Checkout flow for the special reserved item android.test.purchased. 
圖1. 這是已預先設置的特殊商品︰android.test.purchased的付費流程。

You do not need to list the reserved products in your application's product list. Android Market already knows about the reserved product IDs. Also, you do not need to upload your application to the publisher site to perform static response tests with the reserved product IDs. You can simply install your application on a device, log into the device, and make billing requests using the reserved product IDs.
您不需要在您軟體發佈網站上的APP產品列表裡列出這些已預先設置的商品,Android市集已經知道這些商品了。 您也不需要在您執行靜態回應測試這些已預設的商品ID上,將您的APP真實的發佈出去。您可以很簡單的僅將APP安裝在裝置上,寫出裝置的log,並且發出這些已預設的商品的金流請求。

There are four reserved product IDs for testing static in-app billing responses:
底下有4組已預先設置好的產品ID,提供您做靜態iap機制回應的測試︰
  • android.test.purchased When you make an in-app billing request with this product ID, Android Market responds as though you successfully purchased an item. The response includes a JSON string, which contains fake purchase information (for example, a fake order ID). In some cases, the JSON string is signed and the response includes the signature so you can test your signature verification implementation using these responses.
    android.test.purchased
    當您使用這個產品ID來發出金流請求時,Android市集會發出一個虛擬的購買商品成功回應給您。這個回應包含了JSON字串,這個字串含蓋了假的購買資訊(舉例︰一個假的訂單ID)。在一些例子中,JSON字串是被簽署並且會回應一個含有數位簽章的字串給您的,因此您可以透過這些虛擬的回應,來完成您想要測試驗証數位簽章的動作。
  • android.test.canceled When you make an in-app billing request with this product ID Android Market responds as though the purchase was canceled. This can occur when an error is encountered in the order process, such as an invalid credit card, or when you cancel a user's order before it is charged.
    android.test.canceled
    當您使用了這個產品ID來發送金流請求時,Android市集會回應一個類似真正購買過程遭取消的反應給您。這可能發生當使用者在訂單流程中,發生了錯誤的狀況下。像是使用者使用了錯誤的信用卡、或者在付費之前,使用者按下了取消按鈕。
  • android.test.refunded When you make an in-app billing request with this product ID, Android Market responds as though the purchase was refunded. Refunds cannot be initiated through Android Market's in-app billing service. Refunds must be initiated by you (the merchant). After you process a refund request through your Google Checkout account, a refund message is sent to your application by Android Market. This occurs only when Android Market gets notification from Google Checkout that a refund has been made. For more information about refunds, see Handling IN_APP_NOTIFY messages and In-app Billing Pricing.
    android.test.refunded
    當您使用了這個產品ID來發送金流請求時,Android市集會回應一個類似真實的產品被退費的反應給您。商品退費是無法透過Android市集的iap機制服務來完成的(需使用merchant網站來退費)。在您透過Google Checkout 帳戶跑完商品退費流程,退費訊息就會經由Android市集發送至您的APP裡。這只會發生在Google Checkout網站退費動作發生的情況下,Android市集才有可能會接收到此退費的訊息通知。更多關於退費的資訊,請參照Handling IN_APP_NOTIFY messagesIn-app Billing Pricing

  • android.test.item_unavailable When you make an in-app billing request with this product ID, Android Market responds as though the item being purchased was not listed in your application's product list.
    android.test.item_unavailable
    當您使用這個產品ID做出金流請求時,Android市集會回應類似您發送了一個發佈網站裡沒有列出的內部商品的購買請求的反應給您。
In some cases, the reserved items may return signed static responses, which lets you test signature verification in your application. To test signature verification with the special reserved product IDs, you may need to set up test accounts or upload your application as a unpublished draft application. Table 1 shows you the conditions under which static responses are signed.
在一些案例中,這些已預先設置的商品也許會返回靜態回應簽署,提供您在您APP當中,以測試的方式驗証您的數位簽章。如果想要測試驗証數位簽章和這些已預先設置的產品ID,您必須先設定好您的測試帳戶或者上傳您的APP草稿版本。表1顯示那些被簽署過的靜態回應底下的狀況。

Table 1. Conditions under which static responses are signed.
表1.在被簽署過後的靜態回應底下的狀況。
Application ever been published?
APP是否曾經發佈過?
Draft application uploaded and unpublished?
草稿APP上傳了且無須發佈?
User who is running the application
執行APP的人是誰
Static response signature
靜態回應簽章
No No Any任何人 Unsigned未簽署
No No Developer開發者 Signed已簽署
Yes No Any任何人 Unsigned未簽署
Yes No Developer開發者 Signed已簽署
Yes No Test account測試帳戶 Signed已簽署
Yes Yes Any任何人 Signed已簽署
To make an in-app billing request with a reserved product ID, you simply construct a normal REQUEST_PURCHASE request, but instead of using a real product ID from your application's product list you use one of the reserved product IDs.
如果要針對已預先設置的產品ID發送iap金流請求, 您只要簡單的建構一般REQUEST_PURCHASE的請求即可。但是請不要使用您真實的產品列表上的產品ID。

To test your application using the reserved product IDs, follow these steps:
若要在您的APP裡使用這些已預先設置的產品ID,請照著底下的步驟走︰
  1. Install your application on an Android-powered device. You cannot use the emulator to test in-app billing; you must install your application on a device to test in-app billing.
    To learn how to install an application on a device, see Running on a device.
  2. 安裝您的APP至實際裝置上。您不能使用模擬器來測試iap機制,您必須安裝您的APP至裝置上,方可測試使用iap機制。
  3. Sign in to your device with your developer account. You do not need to use a test account if you are testing only with the reserved product IDs.
  4. 將您的裝置登入成您的開發者帳戶。如果您只是想要測試已預先設置的產品ID,您就不需要一定將您的手機設成測試帳戶。
  5. Verify that your device is running a supported version of the Android Market application or the MyApps application. If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the version of the Android Market application, see Updating Android Market.
  6. 請去驗証您的裝置安裝的Android市集或MyApps的版本號有支援iap機制。如果您的裝置運行Android3.0版,需要MyApps軟體版號在5.1.12(或更高)。如果您的裝置運行其它Android的版本,iap機會需要Android市集軟體版號在2.3.4(或更高)。如果想學習如何查看您Android市集軟體的版號,請參見Updating Android Market
  7. Run your application and purchase the reserved product IDs.
  8. 運行您的APP並且購買這些已預先設置好的產品IDs。
Note: Making in-app billing requests with the reserved product IDs overrides the usual Android Market production system. When you send an in-app billing request for a reserved product ID, the quality of service will not be comparable to the production environment.
註︰已預設產品ID的iap請求發送不屬於Android市集產品系統的涵蓋範圍內。當您發送一筆已預設產品ID的iap請求時,統計數據不會被納入產品統計服務裡。(譯者註︰此段僅供參考><看不太懂)

Testing In-app Purchases Using Your Own Product IDs

使用您自己的產品ID來測試iap購買機制

After you finish your static response testing, and you verify that signature verification is working in your application, you can test your in-app billing implementation by making actual in-app purchases. Testing real in-app purchases enables you to test the end-to-end in-app billing experience, including the actual responses from Android Market and the actual checkout flow that users will experience in your application.
當您完成了靜態回應測試,您也驗証了數位簽章,一切就緒後,您就可以開始實際上的發出您實作iap購買請求了。 測試實際的iap購買機制能夠讓您有一個端點(end-to-end)的iap體驗,包含從Android市集來的真實回應、以及使用者真正您APP裡經驗到的真實的付款流程。

Note: You do not need to publish your application to do end-to-end testing. You only need to upload your application as a draft application to perform end-to-end testing.
To test your in-app billing implementation with actual in-app purchases, you will need to register at least one test account on the Android Market publisher site. You cannot use your developer account to test the complete in-app purchase process because Google Checkout does not let you buy items from yourself. If you have not set up test accounts before, see Setting up test accounts.
註︰您不需要發佈您的APP來做點對點測試(end-to-end teseting),您只需要以草稿的型式來上傳您的APP。如果要測試您APP真實的iap機制,您會需要註冊至少一組的測試帳戶至Android市集發佈網站。您無法使用您的開發者帳號來測試完整的iap購買流程,因為Google Checkout無法讓您購買您自己的商品。如果您之前沒有設定過測試帳戶,那麼請看Setting up test accounts這篇。

Also, a test account can purchase an item in your product list only if the item is published. The application does not need to be published, but the item does need to be published.
而且,測試帳戶只能購買那些您商品列表中已被發佈的商品。您的APP不需要真的被發佈,但是商品絕對需要被發佈。
When you use a test account to purchase items, the test account is billed through Google Checkout and your Google Checkout Merchant account receives a payout for the purchase. Therefore, you may want to refund purchases that are made with test accounts, otherwise the purchases will show up as actual payouts to your merchant account.
To test your in-app billing implementation with actual purchases, follow these steps:
當您使用測試帳戶來購買商品,測試帳戶就會透過Google Checkout產生消費,您的Google Checkout Merchant帳戶接著會收到購買的付款款項。因此,您也許會想要將剛才在測試帳戶裡的消費做退款動作,否則您的測試用的消費記錄會真的記在您merchant帳戶裡。如果要測試您實作出來的iap機制的真實購買情形,可以照著以下的步驟做︰
  1. Upload your application as a draft application to the publisher site. You do not need to publish your application to perform end-to-end testing with real product IDs; you only need to upload your application as a draft application. However, you must sign your application with your release key before you upload it as a draft application. Also, the version number of the uploaded application must match the version number of the application you load to your device for testing. To learn how to upload an application to Android Market, see Uploading applications.
  2. 上傳您的草稿APP至發佈網站。您無需發佈您的APP才能執行端點測試和真實產品ID的消費。您僅需以草稿的方式將您的APP上傳。然而,您必須將您的APP簽署上那把你平時釋出APP時,專用的金鑰。而且,您上傳的APP版號必須和你裝置上要執行測試的APP的版號一致。如果想知道關於如何上傳APP至Android市集,請見 Uploading applications
  3. Add items to the application's product list. Make sure that you publish the items (the application can remain unpublished). See Creating a product list to learn how to do this.
  4. 新增商品至APP產品列表上。請確定您已將商品發佈(APP可保持未發佈狀態)。請見Creating a product list學習如何新增商品。
  5. Install your application on an Android-powered device. You cannot use the emulator to test in-app billing; you must install your application on a device to test in-app billing.
    To learn how to install an application on a device, see Running on a device.
  6. 安裝您的APP至Android實機上。您無法使用模擬器來測試iap機制。
  7. Make one of your test accounts the primary account on your device. To perform end-to-end testing of in-app billing, the primary account on your device must be one of the test accounts that you registered on the Android Market site. If the primary account on your device is not a test account, you must do a factory reset of the device and then sign in with one of your test accounts. To perform a factory reset, do the following:
  8. 設定一組測試帳戶至您的裝置上,且該帳戶要是裝置的主要帳戶。如果要執行iap的端點測試,您就必須將一組您已註冊至Android市集網站的測試帳戶設定至裝置上,且要是主要帳戶。如果目前您的裝置上,測試帳戶不是主要的帳戶,那麼請您使用回復原廠設定,並重新做測試帳戶的登入設定。如困要執行回復原廠設定,請照著以下做︰
    1. Open Settings on your device.
    2. 開啟裝置上的設定
    3. Touch Privacy.
    4. 點擊隱私設定
    5. Touch Factory data reset.
    6. 點擊重設為原廠設定
    7. Touch Reset phone.
    8. 點擊重設手機
    9. After the phone resets, be sure to sign in with one of your test accounts during the device setup process.
    10. 在您的手機重設後,請確認已在裝置的設定流程裡,將測試帳戶設定進去了。
  9. Verify that your device is running a supported version of the Android Market application or the MyApps application. If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the version of the Android Market application, see Updating Android Market.  
  10. 請驗証您的裝置運行的Android市集軟體或MyApps軟體版號有支援iap機制。如果您的裝置運行Android3.0,請確認版號在5.0.12(或更高),如果是其它的Android版本,Android市集軟體版號需求是2.3.4(或更高)。如果想知道如何查看Android市集軟體的版號,請見Updating Android Market
  11. Make in-app purchases in your application.
  12. 在您的APP裡運行iap購買。
Note: The only way to change the primary account on a device is to do a factory reset, making sure you log on with your primary account first.
When you are finished testing your in-app billing implementation, you are ready to publish your application on Android Market. You can follow the normal steps for preparing, signing, and publishing your application
註︰唯一將裝置上帳戶設成主要帳戶的方式就是重設為原廠設定,請務必確定您將測試帳戶登入成主要帳戶了。
當您完成了您實作的iap金流測試,您就可以開始準備將您的APP發佈至Android市集了。您可以照著一般流程來完成發佈︰preparing, signingpublishing your application

相關文章︰
1.[Android in-app billing前言]In-app Billing應用程式內部付費機制(中文翻譯)
2.[Android in-app billing第1篇]In-app Billing Overview應用程式內部付費機制概述(中文翻譯)
3.[Android in-app billing第2篇]Implementing In-app Billing實作應用程式內部金流機制(中文翻譯)
4.[Android in-app billing第3篇]Security and Design安全與設計(中文翻譯)
5.[Android in-app billing第4篇]Testing In-app Billing測試應用程式內金流機制(中文翻譯)
6.[Android in-app billing第5篇]Administering In-app Billing應用程式內金流機制的管理(中文翻譯)
7.[Android in-app billing第6篇(末)]In-app Billing Reference應用程式金流的相關API(中文翻譯)
8.[Android in-app billing筆記]串接Google play in-app billing易犯的錯誤

1 comment:

  1. 請問要怎麼新增產品
    我在實機測試時
    他顯示找不到項目

    ReplyDelete