Java Code Examples for com.android.vending.billing.IInAppBillingService#consumePurchase()

The following examples show how to use com.android.vending.billing.IInAppBillingService#consumePurchase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DonationService.java    From ghwatch with Apache License 2.0 6 votes vote down vote up
public static void consumeAllPurchases(Activity activity, SupportAppDevelopmentDialogFragment dialog, IInAppBillingService mService) {
  try {
    Bundle ownedItems = mService.getPurchases(3, activity.getPackageName(), IabHelper.ITEM_TYPE_INAPP, null);
    int response = ownedItems.getInt("RESPONSE_CODE");
    if (response == 0) {
      ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
      for (String purchaseData : purchaseDataList) {
        JSONObject jo = new JSONObject(purchaseData);
        mService.consumePurchase(3, activity.getPackageName(), jo.getString("purchaseToken"));
      }
    }
  } catch (Exception e) {
    ActivityTracker.sendEvent(activity, ActivityTracker.CAT_BE, "message_err_billing_check_error", e.getMessage(), 0L);
    Log.e(TAG, "InApp billing - exception " + e.getMessage());
  }
}
 
Example 2
Source File: DonationService.java    From ghwatch with Apache License 2.0 6 votes vote down vote up
public static void consumeDisposablePurchases(Activity activity, IInAppBillingService mService) {
  try {
    Bundle ownedItems = mService.getPurchases(3, activity.getPackageName(), IabHelper.ITEM_TYPE_INAPP, null);
    int response = ownedItems.getInt("RESPONSE_CODE");
    if (response == 0) {
      ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
      for (String purchaseData : purchaseDataList) {
        JSONObject jo = new JSONObject(purchaseData);
        if (INAPP_CODE_DONATION_3.equals(jo.getString("productId")))
          mService.consumePurchase(3, activity.getPackageName(), jo.getString("purchaseToken"));
      }
    }
  } catch (Exception e) {
    ActivityTracker.sendEvent(activity, ActivityTracker.CAT_BE, "message_err_billing_check_error", e.getMessage(), 0L);
    Log.e(TAG, "InApp billing - exception " + e.getMessage());
  }
}
 
Example 3
Source File: GoogleBillingHelper.java    From OPFIab with Apache License 2.0 6 votes vote down vote up
/**
 * Wraps {@link IInAppBillingService#consumePurchase(int, String, String)}
 *
 * @param token Token of a purchase to consume.
 *
 * @return Result of the operation. Can be null.
 */
@Nullable
Response consumePurchase(@NonNull final String token) {
    OPFLog.logMethod(token);
    final IInAppBillingService service = getService();
    if (service == null) {
        return null;
    }
    try {
        final int code = service.consumePurchase(API, packageName, token);
        final Response response = Response.fromCode(code);
        OPFLog.d("Response: %s", response);
        return response;
    } catch (RemoteException exception) {
        OPFLog.e("consumePurchase request failed.", exception);
    }
    return null;
}