/** * 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; }
/** * 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 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()); } }
@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)); } }