Esempio n. 1
0
		public void launchSubscriptionPurchaseFlow(Activity act, string sku, int requestCode, OnIabPurchaseFinishedListener listener, string extraData)
		{
			launchPurchaseFlow(act, sku, ITEM_TYPE_SUBS, requestCode, listener, extraData);
		}
Esempio n. 2
0
		/// <summary>
		/// Initiate the UI flow for an in-app purchase. Call this method to initiate an in-app purchase,
		/// which will involve bringing up the Google Play screen. The calling activity will be paused while
		/// the user interacts with Google Play, and the result will be delivered via the activity's
		/// <seealso cref="android.app.Activity#onActivityResult"/> method, at which point you must call
		/// this object's <seealso cref="#handleActivityResult"/> method to continue the purchase flow. This method
		/// MUST be called from the UI thread of the Activity.
		/// </summary>
		/// <param name="act"> The calling activity. </param>
		/// <param name="sku"> The sku of the item to purchase. </param>
		/// <param name="itemType"> indicates if it's a product or a subscription (ITEM_TYPE_INAPP or ITEM_TYPE_SUBS) </param>
		/// <param name="requestCode"> A request code (to differentiate from other responses --
		///     as in <seealso cref="android.app.Activity#startActivityForResult"/>). </param>
		/// <param name="listener"> The listener to notify when the purchase process finishes </param>
		/// <param name="extraData"> Extra data (developer payload), which will be returned with the purchase data
		///     when the purchase completes. This extra data will be permanently bound to that purchase
		///     and will always be returned when the purchase is queried. </param>
		public void launchPurchaseFlow(Activity act, string sku, string itemType, int requestCode, OnIabPurchaseFinishedListener listener, string extraData)
		{
			checkNotDisposed();
			checkSetupDone("launchPurchaseFlow");
			flagStartAsync("launchPurchaseFlow");
			IabResult result;

			if (itemType.Equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported)
			{
				IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE, "Subscriptions are not available.");
				flagEndAsync();
				if (listener != null)
				{
					listener.onIabPurchaseFinished(r, null);
				}
				return;
			}

			try
			{
				logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
				Bundle buyIntentBundle = mService.GetBuyIntent(3, mContext.PackageName, sku, itemType, extraData);
				int response = getResponseCodeFromBundle(buyIntentBundle);
				if (response != BILLING_RESPONSE_RESULT_OK)
				{
					logError("Unable to buy item, Error response: " + getResponseDesc(response));
					flagEndAsync();
					result = new IabResult(response, "Unable to buy item");
					if (listener != null)
					{
						listener.onIabPurchaseFinished(result, null);
					}
					return;
				}

				PendingIntent pendingIntent = (PendingIntent)buyIntentBundle.GetParcelable(RESPONSE_BUY_INTENT);
				logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
				mRequestCode = requestCode;
				mPurchaseListener = listener;
				mPurchasingItemType = itemType;
                act.StartIntentSenderForResult(pendingIntent.IntentSender, requestCode, new Intent(), ActivityFlags.BroughtToFront, ActivityFlags.BroughtToFront, Convert.ToInt32(0));
			}
			catch (Android.Content.IntentSender.SendIntentException e)
			{
				logError("SendIntentException while launching purchase flow for sku " + sku);
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				flagEndAsync();

				result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
				if (listener != null)
				{
					listener.onIabPurchaseFinished(result, null);
				}
			}
			catch (RemoteException e)
			{
				logError("RemoteException while launching purchase flow for sku " + sku);
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				flagEndAsync();

				result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
				if (listener != null)
				{
					listener.onIabPurchaseFinished(result, null);
				}
			}
		}
Esempio n. 3
0
		public void launchSubscriptionPurchaseFlow(Activity act, string sku, int requestCode, OnIabPurchaseFinishedListener listener)
		{
			launchSubscriptionPurchaseFlow(act, sku, requestCode, listener, "");
		}