private void consumePurchase(String packageName, String token) { try { int consumeResponse = inAppBillingService.consumePurchase( IN_APP_PURCHASE_VERSION, packageName, token); if (consumeResponse == 0) { Log.d(TAG, "Successfully consumed package: " + packageName); } else { Log.d(TAG, "Faileds to consume package: " + packageName + " " + consumeResponse); } } catch (RemoteException e) { Log.e(TAG, "Consuming purchase remote exception.", e); } }
public boolean isSubscriptionUpdateSupported() { // Avoid calling the service again if this value is true if (isSubsUpdateSupported) { return true; } try { int response = billingService.isBillingSupported(Constants.GOOGLE_API_SUBSCRIPTION_CHANGE_VERSION, contextPackageName, Constants.PRODUCT_TYPE_SUBSCRIPTION); isSubsUpdateSupported = response == Constants.BILLING_RESPONSE_RESULT_OK; } catch (RemoteException e) { e.printStackTrace(); } return isSubsUpdateSupported; }
/** * Check API v7 support for subscriptions * * @param extraParams * @return {@code true} if the current API supports calling getBuyIntentExtraParams() for * subscriptions, {@code false} otherwise. */ public boolean isSubscriptionWithExtraParamsSupported(Bundle extraParams) { if (isSubscriptionExtraParamsSupported) { return true; } try { int response = billingService.isBillingSupportedExtraParams(Constants.GOOGLE_API_VR_SUPPORTED_VERSION, contextPackageName, Constants.PRODUCT_TYPE_SUBSCRIPTION, extraParams); isSubscriptionExtraParamsSupported = response == Constants.BILLING_RESPONSE_RESULT_OK; } catch (RemoteException e) { e.printStackTrace(); } return isSubscriptionExtraParamsSupported; }
ComponentName name, IBinder service) { inAppBillingService = IInAppBillingService.Stub.asInterface(service); Utility.logd(TAG, "In app billing service connected"); try { Bundle ownedItems = inAppBillingService.getPurchases( IN_APP_PURCHASE_VERSION, context.getPackageName(),
bundle = billingService.getBuyIntentToReplaceSkus(Constants.GOOGLE_API_SUBSCRIPTION_CHANGE_VERSION, contextPackageName, oldProductIds, bundle = billingService.getBuyIntentExtraParams(Constants.GOOGLE_API_VR_SUPPORTED_VERSION, contextPackageName, productId, bundle = billingService.getBuyIntent(Constants.GOOGLE_API_VERSION, contextPackageName, productId, bundle = billingService.getBuyIntentExtraParams(Constants.GOOGLE_API_VR_SUPPORTED_VERSION, contextPackageName, productId,
Bundle bundle = billingService.getPurchases(Constants.GOOGLE_API_VERSION, contextPackageName, type, null); if (bundle.getInt(Constants.RESPONSE_CODE) == Constants.BILLING_RESPONSE_RESULT_OK)
private void makePurchase(boolean isSubscription) { try { Bundle buyIntentBundle = inAppBillingService.getBuyIntent( 3, getActivity().getPackageName(), TEST_SKU, isSubscription ? "subs" : "inapp", "this is a test"); int response = getResponseCodeFromBundle(buyIntentBundle); if (response != BILLING_RESPONSE_RESULT_OK) { Log.e(TAG, "Unable to buy item, Error response: " + response); return; } PendingIntent pendingIntent = buyIntentBundle.getParcelable(BUY_INTENT); getActivity().startIntentSenderForResult( pendingIntent.getIntentSender(), IN_APP_PURCHASE_RESULT, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0)); } catch (IntentSender.SendIntentException e) { Log.e(TAG, "In app purchase send intent exception.", e); } catch (RemoteException e) { Log.e(TAG, "In app purchase remote exception.", e); } }
@Override public void onServiceConnected(ComponentName name, IBinder service) { billingService = IInAppBillingService.Stub.asInterface(service); new HistoryInitializationTask().execute(); } };
@Override void start(@Nonnull IInAppBillingService service, @Nonnull String packageName) throws RemoteException, RequestException { final String payload = mPayload == null ? "" : mPayload; final Bundle bundle = mExtraParams != null ? service.getBuyIntentExtraParams(mApiVersion, packageName, mSku, mProduct, payload, mExtraParams) : service.getBuyIntent(mApiVersion, packageName, mSku, mProduct, payload); if (handleError(bundle)) { return; } final PendingIntent pendingIntent = bundle.getParcelable("BUY_INTENT"); Check.isNotNull(pendingIntent); onSuccess(pendingIntent); }
Bundle skuDetails = billingService.getSkuDetails(Constants.GOOGLE_API_VERSION, contextPackageName, purchaseType,
@Override public void start(@Nonnull IInAppBillingService service, @Nonnull String packageName) throws RemoteException { final int response = mExtraParams != null ? service.isBillingSupportedExtraParams(mApiVersion, packageName, mProduct, mExtraParams) : service.isBillingSupported(mApiVersion, packageName, mProduct); if (!handleError(response)) { onSuccess(new Object()); } }
@Override void start(@Nonnull IInAppBillingService service, @Nonnull String packageName) throws RemoteException, RequestException { final Bundle bundle = service.getBuyIntentToReplaceSkus(mApiVersion, packageName, mOldSkus, mNewSku, mProduct, mPayload == null ? "" : mPayload); if (handleError(bundle)) { return; } final PendingIntent pendingIntent = bundle.getParcelable("BUY_INTENT"); Check.isNotNull(pendingIntent); onSuccess(pendingIntent); }
@Nullable @Override protected Bundle request(@Nonnull IInAppBillingService service, @Nonnull String packageName) throws RemoteException { return service.getPurchaseHistory(mApiVersion, packageName, mProduct, mContinuationToken, mExtraParams); }
if (transaction != null && !TextUtils.isEmpty(transaction.purchaseToken)) int response = billingService.consumePurchase(Constants.GOOGLE_API_VERSION, contextPackageName, transaction.purchaseToken);
@Override protected Bundle request(@Nonnull IInAppBillingService service, @Nonnull String packageName) throws RemoteException { return service.getPurchases(mApiVersion, packageName, mProduct, mContinuationToken); }
@Override public void onServiceConnected(ComponentName name, IBinder service) { setService(IInAppBillingService.Stub.asInterface(service), true); } };
public boolean isOneTimePurchaseSupported() { if(!isInitialized()) { Log.e(LOG_TAG, "Make sure BillingProcessor was initialized before calling isOneTimePurchaseSupported()"); return false; } if (isOneTimePurchasesSupported) { return true; } try { int response = billingService.isBillingSupported(Constants.GOOGLE_API_VERSION, contextPackageName, Constants.PRODUCT_TYPE_MANAGED); isOneTimePurchasesSupported = response == Constants.BILLING_RESPONSE_RESULT_OK; } catch (RemoteException e) { e.printStackTrace(); } return isOneTimePurchasesSupported; }
/** * Check API v7 support for one-time purchases * * @param extraParams * @return {@code true} if the current API supports calling getBuyIntentExtraParams() for * one-time purchases, {@code false} otherwise. */ public boolean isOneTimePurchaseWithExtraParamsSupported(Bundle extraParams) { if (isOneTimePurchaseExtraParamsSupported) { return true; } try { int response = billingService.isBillingSupportedExtraParams(Constants.GOOGLE_API_VR_SUPPORTED_VERSION, contextPackageName, Constants.PRODUCT_TYPE_MANAGED, extraParams); isOneTimePurchaseExtraParamsSupported = response == Constants.BILLING_RESPONSE_RESULT_OK; } catch (RemoteException e) { e.printStackTrace(); } return isOneTimePurchaseExtraParamsSupported; }
@Override void start(@Nonnull IInAppBillingService service, @Nonnull String packageName) throws RemoteException, RequestException { final int response = service.consumePurchase(mApiVersion, packageName, mToken); if (!handleError(response)) { Billing.waitGooglePlay(); onSuccess(new Object()); } }
@Test public void testShouldUseExtraParams() throws Exception { final Bundle extraParams = new Bundle(); extraParams.putString("extra", "test"); final BillingSupportedRequest request = new BillingSupportedRequest("product", Billing.V7, extraParams); final IInAppBillingService service = mock(IInAppBillingService.class); request.start(service, "package"); verify(service).isBillingSupportedExtraParams(eq(Billing.V7), eq("package"), eq("product"), eq(extraParams)); } }