Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2013
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.71 KB | None | 0 0
  1. public void launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode,
  2.                         OnIabPurchaseFinishedListener listener, String extraData) {
  3.         checkNotDisposed();
  4.         checkSetupDone("launchPurchaseFlow");
  5.         flagStartAsync("launchPurchaseFlow");
  6.         IabResult result;
  7.        
  8.         if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
  9.             IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE,
  10.                     "Subscriptions are not available.");
  11.             flagEndAsync();
  12.             if (listener != null) listener.onIabPurchaseFinished(r, null);
  13.             return;
  14.         }
  15.  
  16.         try {
  17.             logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
  18.             Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
  19.             int response = getResponseCodeFromBundle(buyIntentBundle);
  20.             if (response != BILLING_RESPONSE_RESULT_OK) {
  21.                 logError("Unable to buy item, Error response: " + getResponseDesc(response));
  22.                 flagEndAsync();
  23.                 result = new IabResult(response, "Unable to buy item");
  24.                 if (listener != null) listener.onIabPurchaseFinished(result, null);
  25.                 return;
  26.             }
  27.  
  28.             PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
  29.             logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
  30.             mRequestCode = requestCode;
  31.             mPurchaseListener = listener;
  32.             mPurchasingItemType = itemType;
  33.             act.startIntentSenderForResult(pendingIntent.getIntentSender(),
  34.                                            requestCode, new Intent(),
  35.                                            Integer.valueOf(0), Integer.valueOf(0),
  36.                                            Integer.valueOf(0));
  37.         }
  38.         catch (SendIntentException e) {
  39.             logError("SendIntentException while launching purchase flow for sku " + sku);
  40.             e.printStackTrace();
  41.             flagEndAsync();
  42.  
  43.             result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
  44.             if (listener != null) listener.onIabPurchaseFinished(result, null);
  45.         }
  46.         catch (RemoteException e) {
  47.             logError("RemoteException while launching purchase flow for sku " + sku);
  48.             e.printStackTrace();
  49.             flagEndAsync();
  50.  
  51.             result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
  52.             if (listener != null) listener.onIabPurchaseFinished(result, null);
  53.         }
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement