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; }
@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()); } }
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; }
@Before public void setUp() throws Exception { Billing billing = newBilling(); billing.connect(); mService = ((TestServiceConnector) billing.getConnector()).mService; when(mService.isBillingSupported(eq(3), anyString(), eq(IN_APP))).thenReturn(OK); when(mService.isBillingSupported(eq(3), anyString(), eq(SUBSCRIPTION))).thenReturn(OK); mCheckout = Checkout.forApplication(billing); }
@Override @Before public void setUp() throws Exception { SQLiteDatabase db = RuntimeEnvironment.application.openOrCreateDatabase(RobotmediaDatabase.NAME, 0, null); db.close(); super.setUp(); final IInAppBillingService service = ((TestServiceConnector) mBilling.getConnector()).mService; when(service.isBillingSupported(anyInt(), anyString(), eq(SUBSCRIPTION))).thenReturn(ResponseCodes.ERROR); }
@Test public void testShouldError() throws Exception { final Request request = newRequest(); final RequestListener l = mock(RequestListener.class); request.setListener(l); final Bundle bundle = newBundle(BILLING_UNAVAILABLE); final IInAppBillingService service = mock(IInAppBillingService.class); when(service.isBillingSupported(anyInt(), anyString(), anyString())).thenReturn(BILLING_UNAVAILABLE); when(service.consumePurchase(anyInt(), anyString(), anyString())).thenReturn(BILLING_UNAVAILABLE); when(service.getPurchases(anyInt(), anyString(), anyString(), anyString())).thenReturn(bundle); when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), anyString(), any(Bundle.class))).thenReturn(bundle); when(service.getSkuDetails(anyInt(), anyString(), anyString(), any(Bundle.class))).thenReturn(bundle); when(service.getBuyIntent(anyInt(), anyString(), anyString(), anyString(), anyString())).thenReturn(bundle); request.start(service, "testse"); verify(l).onError(eq(BILLING_UNAVAILABLE), any(Exception.class)); verify(l, never()).onSuccess(any()); }
@Test public void testShouldExecuteRequestIfConnected() throws Exception { final Billing.ServiceConnector connector = mock(Billing.ServiceConnector.class); final IInAppBillingService service = mock(IInAppBillingService.class); when(service.isBillingSupported(anyInt(), anyString(), anyString())).thenReturn(OK); when(connector.connect()).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { mBilling.setService(service, true); return true; } }); mBilling.setConnector(connector); final RequestListener<Object> l = mock(RequestListener.class); mBilling.getRequests().isBillingSupported("p", l); verify(l, times(0)).onError(anyInt(), any(BillingException.class)); verify(l, times(1)).onSuccess(any()); }
@Test public void testShouldSuccess() throws Exception { final Request r = newRequest(); final RequestListener l = mock(RequestListener.class); r.setListener(l); final IInAppBillingService service = mock(IInAppBillingService.class); when(service.isBillingSupported(anyInt(), anyString(), anyString())).thenReturn(OK); when(service.consumePurchase(anyInt(), anyString(), anyString())).thenReturn(OK); final Bundle purchases = new Bundle(); purchases.putStringArrayList("INAPP_PURCHASE_DATA_LIST", new ArrayList<String>()); when(service.getPurchases(anyInt(), anyString(), anyString(), anyString())).thenReturn(purchases); when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), anyString(), any(Bundle.class))).thenReturn(purchases); final Bundle skuDetails = new Bundle(); skuDetails.putStringArrayList("DETAILS_LIST", new ArrayList<String>()); when(service.getSkuDetails(anyInt(), anyString(), anyString(), any(Bundle.class))).thenReturn(skuDetails); final Bundle buyIntent = new Bundle(); buyIntent.putParcelable("BUY_INTENT", PendingIntent.getActivity(RuntimeEnvironment.application, 100, new Intent(), 0)); when(service.getBuyIntent(anyInt(), anyString(), anyString(), anyString(), anyString())).thenReturn(buyIntent); r.start(service, ""); verify(l).onSuccess(anyObject()); verify(l, never()).onError(anyInt(), any(Exception.class)); }
@Test public void testShouldLoadPurchasesWhenProductsBecameSupported() throws Exception { when(mService.isBillingSupported(eq(3), anyString(), eq(IN_APP))).thenReturn(BILLING_UNAVAILABLE); when(mService.isBillingSupported(eq(3), anyString(), eq(SUBSCRIPTION))).thenReturn(BILLING_UNAVAILABLE); when(mService.getPurchases(anyInt(), anyString(), anyString(), isNull(String.class))).thenReturn(newPurchasesBundle(0, false)); mCheckout.start(); final AwaitingCallback c1 = new AwaitingCallback(); mCheckout.loadInventory(Inventory.Request.create().loadAllPurchases(), c1); c1.waitWhileLoading(); assertFalse(c1.mProducts.get(IN_APP).supported); assertFalse(c1.mProducts.get(SUBSCRIPTION).supported); assertTrue(c1.mProducts.get(IN_APP).getPurchases().isEmpty()); when(mService.isBillingSupported(eq(3), anyString(), eq(IN_APP))).thenReturn(OK); when(mService.isBillingSupported(eq(3), anyString(), eq(SUBSCRIPTION))).thenReturn(OK); final AwaitingCallback c2 = new AwaitingCallback(); mCheckout.loadInventory(Inventory.Request.create().loadAllPurchases(), c2); c2.waitWhileLoading(); assertTrue(c2.mProducts.get(IN_APP).supported); assertTrue(c2.mProducts.get(SUBSCRIPTION).supported); assertTrue(c2.mProducts.get(IN_APP).getPurchases().size() == 1); }
int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP); if (response != BILLING_RESPONSE_RESULT_OK) { if (listener != null) listener.onIabSetupFinished(new IabResult(response, response = mService.isBillingSupported(5, packageName, ITEM_TYPE_SUBS); if (response == BILLING_RESPONSE_RESULT_OK) { logDebug("Subscription re-signup AVAILABLE."); } else { response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS); if (response == BILLING_RESPONSE_RESULT_OK) { logDebug("Subscriptions AVAILABLE.");
@Override public boolean isBillingSupported() { try { final int response = service.isBillingSupported(3, packageName, BILLING_TYPE); return response == BILLING_RESPONSE_RESULT_OK; } catch (RemoteException ignore) { } return false; }
public Response isBillingSupported(PurchaseType purchaseType) throws RemoteException { ReactiveBilling.log(null, "Is billing supported - request (thread %s)", Thread.currentThread().getName()); int response = billingService.isBillingSupported(BillingService.API_VERSION, context.getPackageName(), purchaseType.getIdentifier()); ReactiveBilling.log(null, "Is billing supported - response: %d", response); return new Response(response); }
public void onServiceConnected(ComponentName name, IBinder service) { final IInAppBillingService mService = IInAppBillingService.Stub.asInterface(service); try { final int response = mService.isBillingSupported(3, packageName, IabHelper.ITEM_TYPE_INAPP); result[0] = response == IabHelper.BILLING_RESPONSE_RESULT_OK; } catch (RemoteException e) { result[0] = false; Logger.e("isBillingAvailable() RemoteException while setting up in-app billing", e); } finally { latch.countDown(); context.unbindService(this); } Logger.d("isBillingAvailable() Google Play result: ", result[0]); }
/** * Check if the device supports InAppBilling * * @param service * @return true if it is supported */ protected boolean isSupported(PurchaseType purchaseType, IInAppBillingService service) throws RemoteException { String type; if (purchaseType == PurchaseType.SUBSCRIPTION) { type = Constants.TYPE_SUBSCRIPTION; } else { type = Constants.TYPE_IN_APP; } int response = service.isBillingSupported( mContext.getApiVersion(), mContext.getContext().getPackageName(), type); if (response == Constants.BILLING_RESPONSE_RESULT_OK) { mLogger.d(Logger.TAG, "Subscription is AVAILABLE."); return true; } mLogger.w(Logger.TAG, String.format(Locale.US, "Subscription is NOT AVAILABLE. Response: %d", response)); return false; }
try { logDebug("Checking for in-app billing 3 support."); int response = mService.isBillingSupported(API_VERSION, packageName, INAPP.toString()); if (response == OK.code) { logDebug("In-app billing version 3 supported for " + packageName); mInAppSupported = true; logDebug("Checking for in-app billing 3 subscription support."); response = mService.isBillingSupported(API_VERSION, packageName, SUBS.toString()); if (response == OK.code) { logDebug("Subscriptions AVAILABLE.");
try { logDebug("Checking for in-app billing 3 support."); int response = mService.isBillingSupported(API_VERSION, packageName, INAPP.toString()); if (response == OK.code) { logDebug("In-app billing version 3 supported for " + packageName); mInAppSupported = true; logDebug("Checking for in-app billing 3 subscription support."); response = mService.isBillingSupported(API_VERSION, packageName, SUBS.toString()); if (response == OK.code) { logDebug("Subscriptions AVAILABLE.");
int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP); if (response != BILLING_RESPONSE_RESULT_OK) { if (listener != null) listener.onIabSetupFinished(new IabResult(response, response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS); if (response == BILLING_RESPONSE_RESULT_OK) { logDebug("Subscriptions AVAILABLE.");
int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP); if (response != BILLING_RESPONSE_RESULT_OK) { if (listener != null) listener.onIabSetupFinished(new IabResult(response, response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS); if (response == BILLING_RESPONSE_RESULT_OK) { logDebug("Subscriptions AVAILABLE.");
int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP); if (response != BILLING_RESPONSE_RESULT_OK) { if (listener != null) listener.onIabSetupFinished(new IabResult(response, response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS); if (response == BILLING_RESPONSE_RESULT_OK) { logDebug("Subscriptions AVAILABLE.");
int response = mService.isBillingSupported(3, packageName, ITEM_TYPE_INAPP); if (response != BILLING_RESPONSE_RESULT_OK) { if (listener != null) listener.onIabSetupFinished(new IabResult(response, response = mService.isBillingSupported(3, packageName, ITEM_TYPE_SUBS); if (response == BILLING_RESPONSE_RESULT_OK) { logDebug("Subscriptions AVAILABLE.");