2013-07-18 42 views
1

這個問題以前可能已經問過了,但我無法在任何地方找到答案,也不知道Amazon IAP SDK是否可行。 當我取消購買時,我將收到失敗購買回應。 如果是這樣,我該如何顯示FAILED是由取消還是引起的其他外來的情況錯誤如何檢測用戶是否已經點燃了IAP?

private class PurchaseAsyncTask extends 
     AsyncTask<PurchaseResponse, Void, Boolean> { 

    private String [] purchaseResult = null; 
    @Override 
    protected Boolean doInBackground(final PurchaseResponse... params) { 
     final PurchaseResponse purchaseResponse = params[0]; 
     final String userId = microTrans.getCurrentUser(); 
     switch (purchaseResponse.getPurchaseRequestStatus()) { 
     case SUCCESSFUL: 
      /* 
      * You can verify the receipt and fulfill the purchase on 
      * successful responses. 
      */ 
      final Receipt receipt = purchaseResponse.getReceipt(); 
      switch (receipt.getItemType()) { 
      case CONSUMABLE: 
       break; 
      case ENTITLED: 
       break; 
      case SUBSCRIPTION: 
       break; 
      } 

      return true; 
     case ALREADY_ENTITLED: 
      /* 
      * If the customer has already been entitled to the item, a 
      * receipt is not returned. Fulfillment is done unconditionally, 
      * we determine which item should be fulfilled by matching the 
      * request id returned from the initial request with the request 
      * id stored in the response. 
      */ 
      // TODO handle already entitled 
      Log.v(TAG, "already entitled!"); 
      return true; 
     case FAILED: 
      /* 
      * If the purchase failed for some reason, (The customer 
      * canceled the order, or some other extraneous circumstance 
      * happens) the application ignores the request and logs the 
      * failure. 
      */ 
      // TODO handle failed of purchase 
      Log.v(TAG, 
        "Failed purchase for request" 
          + purchaseResponse.getRequestId()); 
      return false; 
     case INVALID_SKU: 
      /* 
      * If the sku that was purchased was invalid, the application 
      * ignores the request and logs the failure. This can happen 
      * when there is a sku mismatch between what is sent from the 
      * application and what currently exists on the dev portal. 
      */ 
      // TODO handle invalid sku 
      Log.v(TAG, 
        "Invalid Sku for request " 
          + purchaseResponse.getRequestId()); 
      return false; 
     } 
     return false; 
    } 

    @Override 
    protected void onPostExecute(final Boolean success) { 
     super.onPostExecute(success); 
    } 
} 

回答

1

無法區分取消和其他類型的故障。

然而,每Amazon IAP UX guidelines

您的應用程序不應該試圖消息的交易狀態或者狀態 給客戶。應用內購買API將處理所有確認 和發送給客戶的消息,包括交易成功和 失敗消息。

相關問題