Bundle skuDetails = billingService.getSkuDetails(Constants.GOOGLE_API_VERSION, contextPackageName, purchaseType,
@Nullable private Skus getSkuDetails(@Nonnull IInAppBillingService service, @Nonnull String packageName, ArrayList<String> skuBatch) throws RemoteException, RequestException { Check.isTrue(skuBatch.size() <= MAX_SIZE_PER_REQUEST, "SKU list is too big"); final Bundle skusBundle = new Bundle(); skusBundle.putStringArrayList("ITEM_ID_LIST", skuBatch); final Bundle bundle = service.getSkuDetails(Billing.V3, packageName, mProduct, skusBundle); if (!handleError(bundle)) { return Skus.fromBundle(bundle, mProduct); } return null; }
Bundle querySkus = new Bundle(); querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuPartList); Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus);
static void mockGetSkuDetails(@Nonnull Billing billing, @Nonnull String product, @Nonnull final List<Sku> skus) throws RemoteException { final IInAppBillingService service = ((TestServiceConnector) billing.getConnector()).mService; when(service.getSkuDetails(anyInt(), anyString(), eq(product), any(Bundle.class))) .thenAnswer(new Answer<Bundle>() { @Override public Bundle answer(InvocationOnMock invocation) throws Throwable { final Bundle in = (Bundle) invocation.getArguments()[3]; final ArrayList<String> skuIds = in.getStringArrayList("ITEM_ID_LIST"); final Bundle bundle = newBundle(OK); final ArrayList<String> list = new ArrayList<String>(); for (Sku sku : skus) { if (skuIds.contains(sku.id.code)) { list.add(sku.toJson()); } } bundle.putStringArrayList(Skus.BUNDLE_LIST, list); return bundle; } }); } }
@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 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)); }
final RequestListenerSpy l = new RequestListenerSpy(); request.setListener(l); when(service.getSkuDetails(anyInt(), anyString(), anyString(), any(Bundle.class))).thenAnswer(new Answer<Bundle>() { @Override public Bundle answer(InvocationOnMock invocation) throws Throwable {
private Bundle executeGetSkuDetails(Bundle skusRequest, String type) { try { return billingService().getSkuDetails(BILLING_API_VERSION, installerPackageName, type, skusRequest); } catch (RemoteException e) { // TODO: unit test this. throw new GdxPayException("getProductsDetails failed for bundle:" + skusRequest, e); } }
protected Void doInBackground(Void... params) { Log.d(LOG_TAG, "getPremiumTask:"); Bundle skuDetails; ArrayList<String> skuList = new ArrayList<String> (); skuList.add(PREMIUM); Bundle querySkus = new Bundle(); querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuList); try { skuDetails = billingService.getSkuDetails(3, context.getPackageName(), ITEM_TYPE_INAPP, querySkus); int response = skuDetails.getInt(RESPONSE_CODE); if(response == BILLING_RESPONSE_RESULT_OK) { ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST); for(String thisResponse : responseList) { JSONObject object = new JSONObject(thisResponse); PREMIUM_SKU = object.getString("productId"); PREMIUM_PRICE = object.getString("price"); Log.d(LOG_TAG, "ProductId: " + PREMIUM_SKU); } } } catch(Exception e) { Log.e(LOG_TAG, "getPremiumTask failed: " + e.getMessage()); } return null; } }
@Override public SkuDetails skuDetails(@NonNull String sku) { try { final Bundle skus = new Bundle(1); skus.putStringArrayList(REQUEST_ITEM_ID_LIST, arrayList(sku)); final Bundle bundle = service.getSkuDetails(3, packageName, BILLING_TYPE, skus); if (responseOk(bundle)) { final ArrayList<String> list = bundle.getStringArrayList(RESPONSE_DETAILS_LIST); if (list != null && !list.isEmpty()) { final String json = list.get(0); return new SkuDetails(json); } } } catch (RemoteException | JSONException ignore) { } return null; }
public GetSkuDetailsResponse getSkuDetails(PurchaseType purchaseType, List<String> productIds) throws RemoteException { if (productIds == null || productIds.size() == 0) { throw new IllegalArgumentException("Product ids cannot be blank"); } ReactiveBilling.log(null, "Get sku details - request: %s (thread %s)", TextUtils.join(", ", productIds), Thread.currentThread().getName()); Bundle bundle = new Bundle(); bundle.putStringArrayList("ITEM_ID_LIST", new ArrayList<>(productIds)); bundle = billingService.getSkuDetails(BillingService.API_VERSION, context.getPackageName(), purchaseType.getIdentifier(), bundle); int response = bundle.getInt("RESPONSE_CODE", -1); ReactiveBilling.log(null, "Get sku details - response code: %s", response); if (response != 0) { return new GetSkuDetailsResponse(response, null); } List<String> detailsJson = bundle.getStringArrayList("DETAILS_LIST"); List<SkuDetails> skuDetailsList = new ArrayList<>(); if (detailsJson == null || detailsJson.isEmpty()) { ReactiveBilling.log(null, "Get sku details - empty list"); return new GetSkuDetailsResponse(response, skuDetailsList); } SkuDetails skuDetails; for (int i = 0; i < detailsJson.size(); i++) { skuDetails = SkuDetailsParser.parse(detailsJson.get(i)); if (skuDetails != null) { skuDetailsList.add(skuDetails); } } ReactiveBilling.log(null, "Get sku details - list size: %s", skuDetailsList.size()); return new GetSkuDetailsResponse(response, skuDetailsList); }
private void whenBillingServiceGetSkuDetailsReturn(Bundle skuDetailsResponse) throws android.os.RemoteException { when(nativeInAppBillingService.getSkuDetails( eq(BILLING_API_VERSION), isA(String.class), eq(PURCHASE_TYPE_IN_APP), isA(Bundle.class)) ).thenReturn(skuDetailsResponse); }
Bundle skuDetails = mService.getSkuDetails(API_VERSION, mContext.getPackageName(), itemType.toString(), querySkus); if (skuDetails == null) return IABHELPER_BAD_RESPONSE.code;
Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus);
Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus);
Bundle skuDetails = mService.getSkuDetails(API_VERSION, mContext.getPackageName(), itemType.toString(), querySkus); if (skuDetails == null) return IABHELPER_BAD_RESPONSE.code;
Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), itemType, querySkus);
@Test public void remoteException() throws RemoteException { int size = 10; ArrayList<String> itemIds = mDataConverter.convertToItemIdArrayList(size); when(mService.getSkuDetails( anyInt(), anyString(), anyString(), any(Bundle.class) )).thenThrow(RemoteException.class); ItemDetails itemDetails = null; try { itemDetails = mGetter.get(mService, Constants.TYPE_IN_APP, itemIds); } catch (BillingException e) { assertThat(e.getErrorCode()).isEqualTo(Constants.ERROR_REMOTE_EXCEPTION); } finally { assertThat(itemDetails).isNull(); verify(mService, times(1)).getSkuDetails( anyInt(), anyString(), anyString(), any(Bundle.class) ); } }
private void getItemDetails(ArrayList<String> itemIds, Bundle responseBundle, int errorCode, String errorMessage) throws RemoteException { when(mService.getSkuDetails( anyInt(), anyString(), anyString(), any(Bundle.class) )).thenReturn(responseBundle); ItemDetails itemDetails = null; try { itemDetails = mGetter.get(mService, Constants.TYPE_IN_APP, itemIds); } catch (BillingException e) { assertThat(e.getErrorCode()).isEqualTo(errorCode); assertThat(e.getMessage()).isEqualTo(errorMessage); } finally { assertThat(itemDetails).isNull(); verify(mService).getSkuDetails( anyInt(), anyString(), anyString(), any(Bundle.class) ); } } }
ItemDetails itemDetails = null; when(mService.getSkuDetails( anyInt(), anyString(), assertThat(itemDetails.getByItemId(p.getSku())).isNotNull(); verify(mService, times(1)).getSkuDetails( anyInt(), anyString(),