示例#1
0
  int querySkuDetails(Inventory inv, List<String> moreSkus) throws RemoteException, JSONException {
    ArrayList<String> skuList = new ArrayList<String>();
    skuList.addAll(inv.getAllOwnedSkus(ITEM_TYPE_INAPP));
    if (moreSkus != null) skuList.addAll(moreSkus);

    if (skuList.size() == 0) {
      return BILLING_RESPONSE_RESULT_OK;
    }

    Bundle querySkus = new Bundle();
    querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuList);
    Bundle skuDetails = connection.getSkuDetails(querySkus);

    if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
      int response = getResponseCodeFromBundle(skuDetails);
      if (response != BILLING_RESPONSE_RESULT_OK) {
        return response;
      } else {
        return HELPER_BAD_RESPONSE;
      }
    }

    ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

    for (String thisResponse : responseList) {
      SkuDetails d = new SkuDetails(thisResponse);
      inv.addSkuDetails(d);
    }
    return BILLING_RESPONSE_RESULT_OK;
  }
示例#2
0
  int queryPurchases(Inventory inv) throws JSONException, RemoteException {
    boolean verificationFailed = false;
    String continueToken = null;

    do {
      Bundle ownedItems = connection.getPurchases(continueToken);

      int response = getResponseCodeFromBundle(ownedItems);
      if (response != BILLING_RESPONSE_RESULT_OK) {
        return response;
      }
      if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST)
          || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST)
          || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) {
        return HELPER_BAD_RESPONSE;
      }

      ArrayList<String> purchaseDataList =
          ownedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST);
      ArrayList<String> signatureList =
          ownedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST);

      for (int i = 0; i < purchaseDataList.size(); ++i) {
        String purchaseData = purchaseDataList.get(i);
        String signature = signatureList.get(i);
        if (security.verifyPurchase(purchaseData, signature)) {
          Purchase purchase = new Purchase(purchaseData, signature);
          inv.addPurchase(purchase);
        } else {
          verificationFailed = true;
        }
      }

      continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN);
    } while (!TextUtils.isEmpty(continueToken));

    return verificationFailed ? HELPER_VERIFICATION_FAILED : BILLING_RESPONSE_RESULT_OK;
  }