Ejemplo n.º 1
0
  /** Get sku details for an item that is not in the inventory. */
  public SkuDetails getSkuDetails(String sku) throws IabException {
    logDebug("Querying SKU details for one item.");
    SYSLOG("MoSync Querying SKU details for one item: " + sku);
    Bundle querySkus = new Bundle();
    ArrayList<String> skuList = new ArrayList<String>();
    skuList.add(sku);
    querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuList);
    try {
      Bundle skuDetails =
          mService.getSkuDetails(
              BILLING_API_VERSION, mContext.getPackageName(), ITEM_TYPE_INAPP, querySkus);

      if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
        int response = getResponseCodeFromBundle(skuDetails);
        SYSLOG("@@MoSync maPurchaseCreate querySkuDetails response error  " + response);
        if (response != BILLING_RESPONSE_RESULT_OK) {
          logDebug("getSkuDetails() failed: " + getResponseDesc(response));
        } else {
          logError("getSkuDetails() returned a bundle with neither an error nor a detail list.");
        }
        return null;
      }

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

      for (String thisResponse : responseList) {
        SkuDetails details = new SkuDetails(thisResponse);
        logDebug("Got sku details: " + details);
        return details;
      }
      return null;

    } catch (RemoteException e) {
      SYSLOG("@@MoSync remote exception while getting sku details");
      throw new IabException(
          IABHELPER_REMOTE_EXCEPTION, "Remote exception while getting sku details.", e);
    } catch (JSONException e) {
      SYSLOG("@@MoSync JSON exception while getting sku details");
      throw new IabException(
          IABHELPER_BAD_RESPONSE, "Error parsing JSON response while getting sku details.", e);
    }
  }
Ejemplo n.º 2
0
  int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus)
      throws RemoteException, JSONException {
    logDebug("Querying SKU details.");
    ArrayList<String> skuList = new ArrayList<String>();
    skuList.addAll(inv.getAllOwnedSkus(itemType));
    if (moreSkus != null) {
      for (String sku : moreSkus) {
        if (!skuList.contains(sku)) {
          skuList.add(sku);
        }
      }
    }

    if (skuList.size() == 0) {
      logDebug("queryPrices: nothing to do because there are no SKUs.");
      return BILLING_RESPONSE_RESULT_OK;
    }

    Bundle querySkus = new Bundle();
    querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuList);
    Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus);

    if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
      int response = getResponseCodeFromBundle(skuDetails);
      if (response != BILLING_RESPONSE_RESULT_OK) {
        logDebug("getSkuDetails() failed: " + getResponseDesc(response));
        return response;
      } else {
        logError("getSkuDetails() returned a bundle with neither an error nor a detail list.");
        return IABHELPER_BAD_RESPONSE;
      }
    }

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

    for (String thisResponse : responseList) {
      SkuDetails d = new SkuDetails(itemType, thisResponse);
      logDebug("Got sku details: " + d);
      inv.addSkuDetails(d);
    }
    return BILLING_RESPONSE_RESULT_OK;
  }
Ejemplo n.º 3
0
  @Click(R.id.get_sku_details_button)
  public void getSkuDetails(View v) {
    try {
      ArrayList<String> itemList = new ArrayList<String>();
      itemList.add(skuName);

      Bundle skusBundle = new Bundle();
      skusBundle.putStringArrayList("ITEM_ID_LIST", itemList);

      Bundle details =
          billingService.getSkuDetails(apiLevel, getPackageName(), "inapp", skusBundle);

      int responseCode = details.getInt("RESPONSE_CODE");
      ArrayList<String> responseList = details.getStringArrayList("DETAILS_LIST");

      if (responseList.size() == 0) {
        String msg = "getSkuDetails: empty" + "\n";
        ;
        logView.append(msg);

        Log.d(TAG, msg);
      }
      for (String info : responseList) {
        String msg = "getSkuDetails: " + info + "\n";
        ;
        logView.append(msg);

        Log.d(TAG, msg);
      }

    } catch (RemoteException e) {
      String msg = "getSkuDetails: " + e.getMessage() + "\n";
      logView.append(msg);

      Log.e(TAG, msg);
      e.printStackTrace();
    }
  }
  @NonNull
  @Override
  public List<Product> getProductDetails(@NonNull @ProductType String type, List<String> skuList)
      throws BillingException {
    try {
      Bundle skuBundle = new Bundle();
      skuBundle.putStringArrayList("ITEM_ID_LIST", new ArrayList<>(skuList));
      Bundle response = delegate.getSkuDetails(API_VERSION, packageName, type, skuBundle);
      checkBundle(response);

      List<String> jsons = response.getStringArrayList("DETAILS_LIST");
      if (jsons == null) {
        return Collections.emptyList();
      }
      List<Product> products = new ArrayList<>(jsons.size());
      for (String json : jsons) {
        Product product = gson.fromJson(json, Product.class);
        products.add(product);
      }
      return products;
    } catch (RemoteException e) {
      throw new BillingException(e);
    }
  }
Ejemplo n.º 5
0
 public Bundle getSkuDetails(Bundle querySkus) throws RemoteException {
   return billingService.getSkuDetails(3, context.getPackageName(), ITEM_TYPE_INAPP, querySkus);
 }