public synchronized Offer getOffer (String identifier) { // search matching offer and return it for (int i = 0; i < offers.size(); i++) { if (offers.get(i).getIdentifier().equals(identifier)) { return offers.get(i); } } // no matching offer found return null; }
public synchronized Offer getOffer (String identifier) { // search matching offer and return it for (int i = 0; i < offers.size(); i++) { if (offers.get(i).getIdentifier().equals(identifier)) { return offers.get(i); } } // no matching offer found return null; }
private void getPurchaseIdsByType(List<String> inAppPurchasesIds, List<String> subsPurchasesIds) { for (int i = 0; i < purchaseManagerConfig.getOfferCount(); i++) { Offer offer = purchaseManagerConfig.getOffer(i); if (offer.getType().equals(OfferType.SUBSCRIPTION)) subsPurchasesIds.add(offer.getIdentifier()); else inAppPurchasesIds.add(offer.getIdentifier()); } }
private static ArrayList<String> itemIdList(Offer offer) { ArrayList<String> skuList = new ArrayList<>(); skuList.add(offer.getIdentifier()); return skuList; }
private static String makeJsonObjectForOffer(Offer offer) throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put(GoogleBillingConstants.PRODUCT_ID, offer.getIdentifier()); jsonObject.put(GoogleBillingConstants.PURCHASE_TIME, System.currentTimeMillis()); jsonObject.put(GoogleBillingConstants.ORDER_ID, "GPA.1234-5678-9012-34567"); return jsonObject.toString(); } }
private void verifyBillingGetSkuDetailsCalled() throws android.os.RemoteException { verify(googleInAppBillingService).getProductsDetails(singletonList(offerFullEditionEntitlement().getIdentifier()), PURCHASE_TYPE_IN_APP); }
private void bindConnectAndStartPurchaseRequest(Offer offer) throws android.os.RemoteException { activityBindAndConnect(); whenGetBuyIntentForIdentifierReturn(offer.getIdentifier(), buyIntentResponseOk()); v3InAppbillingService.startPurchaseRequest(offer.getIdentifier(), PURCHASE_TYPE_IN_APP, purchaseRequestCallback); }
private PurchaseRequestCallback connectBindAndPurchaseRequestForFullEditionEntitlement() throws android.os.RemoteException { Offer offer = offerFullEditionEntitlement(); Information information = informationFullEditionEntitlement(); whenGetProductsDetailsReturn(offer.getIdentifier(), information); bindFetchNewConnectionAndInstallPurchaseSystem(); String productIdentifier = offerFullEditionEntitlement().getIdentifier(); purchaseManager.purchase(productIdentifier); verify(googleInAppBillingService).startPurchaseRequest(Mockito.eq(productIdentifier), Mockito.eq(PURCHASE_TYPE_IN_APP), purchaseRequestListenerArgumentCaptor.capture()); return purchaseRequestListenerArgumentCaptor.getValue(); }
@Test public void shouldStartSenderIntentForBuyIntentResponseOk() throws Exception { activityBindAndConnect(); Offer offer = offerFullEditionEntitlement(); whenGetBuyIntentForIdentifierReturn(offer.getIdentifier(), buyIntentResponseOk()); v3InAppbillingService.startPurchaseRequest(offer.getIdentifier(), PURCHASE_TYPE_IN_APP, purchaseRequestCallback); verify(applicationProxy).startIntentSenderForResult(isA(IntentSender.class), eq(ACTIVITY_REQUEST_CODE), isA(Intent.class), eq(0), eq(0), eq(0)); }
@Test public void convertsConfigWithOneOffer() throws Exception { Offer offer = offerFullEditionEntitlement(); Bundle bundle = convertProductIdsToItemIdList(singletonList(offer.getIdentifier())); assertEquals(1, bundle.size()); ArrayList<String> actualList = bundle.getStringArrayList(ITEM_ID_LIST); ArrayList<String> expectedArrayList = new ArrayList<>(singletonList(offerFullEditionEntitlement().getIdentifier())); assertEquals(expectedArrayList, actualList); } }
@Test public void shouldCallPurchaseCallbackErrorWhenPurcharseIntentSenderForResultFails() throws Exception { activityBindAndConnect(); Offer offer = offerFullEditionEntitlement(); whenGetBuyIntentForIdentifierReturn(offer.getIdentifier(), buyIntentResponseOk()); doThrow(new IntentSender.SendIntentException("Intent cancelled")).when(applicationProxy) .startIntentSenderForResult(isA(IntentSender.class), eq(ACTIVITY_REQUEST_CODE), isA(Intent.class), eq(0), eq(0), eq(0)); v3InAppbillingService.startPurchaseRequest(offer.getIdentifier(), PURCHASE_TYPE_IN_APP, purchaseRequestCallback); verify(applicationProxy).startIntentSenderForResult(isA(IntentSender.class), eq(ACTIVITY_REQUEST_CODE), isA(Intent.class), eq(0), eq(0), eq(0)); verify(purchaseRequestCallback).purchaseError(isA(GdxPayException.class)); }
@Test public void shouldReturnSkusWhenResponseIsOk() throws Exception { whenBillingServiceGetSkuDetailsReturn(skuDetailsResponseResultOkProductFullEditionEntitlement()); activityBindAndConnect(); Offer offer = offerFullEditionEntitlement(); Map<String, Information> details = v3InAppbillingService.getProductsDetails(singletonList(offer.getIdentifier()), PURCHASE_TYPE_IN_APP); assertEquals(details, Collections.singletonMap(offer.getIdentifier(), informationFullEditionEntitlement())); }
@Test public void shoulReconnectAndRetryWhenGetBuyIntentFailsWithDeadObjectException() throws Exception { activityBindAndConnect(); Offer offer = offerFullEditionEntitlement(); whenGetBuyIntentForIdentifierThrow(offer.getIdentifier(), new DeadObjectException("Purchase service died.")); v3InAppbillingService.startPurchaseRequest(offer.getIdentifier(), PURCHASE_TYPE_IN_APP, purchaseRequestCallback); verify(applicationProxy).unbindService(isA(ServiceConnection.class)); verifyAndroidApplicationBindService(2); verify(asyncExecutor).executeAsync(isA(Runnable.class), eq(RETRY_PURCHASE_DELAY_IN_MS)); }
@Test public void shouldCallGdxPurchaseCallbackErrorAndReconnectWhenGetBuyIntentFailsWithDeadObjectException() throws Exception { activityBindAndConnect(); Offer offer = offerFullEditionEntitlement(); whenGetBuyIntentForIdentifierThrow(offer.getIdentifier(), new DeadObjectException("Purchase service died.")); v3InAppbillingService.startPurchaseRequest(offer.getIdentifier(), PURCHASE_TYPE_IN_APP, purchaseRequestCallback); verifyAsyncExecutorWasCalledForRetryAndRetryRun(); verify(purchaseRequestCallback).purchaseError(isA(GdxPayException.class)); verify(applicationProxy).unbindService(isA(ServiceConnection.class)); verifyAndroidApplicationBindService(2); }
private void connectBindAndForFullEditionEntitlement() throws android.os.RemoteException { Offer offer = offerFullEditionEntitlement(); Information information = informationFullEditionEntitlement(); whenGetProductsDetailsReturn(offer.getIdentifier(), information); bindFetchNewConnectionAndInstallPurchaseSystem(); }
@Test public void getInformationForExistingSkuShouldReturnIt() throws Exception { String identifier = offerFullEditionEntitlement().getIdentifier(); Information expectedInformation = informationFullEditionEntitlement(); whenGetProductsDetailsReturn(identifier, expectedInformation); bindFetchNewConnectionAndInstallPurchaseSystem(); Information actualInformation = purchaseManager.getInformation(identifier); verify(googleInAppBillingService).getProductsDetails(singletonList(identifier), PURCHASE_TYPE_IN_APP); assertEquals(expectedInformation, actualInformation); }
@Test public void getSubscriptionPurchasesWithResultOkShouldReturnPurchaseTransactions() throws Exception { activityBindAndConnect(); whenGetPurchasesRequestReturn(purchasesResponseOneTransactionFullEdition()); List<Transaction> transactions = v3InAppbillingService.getPurchases(); verify(nativeInAppBillingService).getPurchases(BILLING_API_VERSION, PACKAGE_NAME_GOOD, PURCHASE_TYPE_SUBSCRIPTION, null); assertEquals(1, transactions.size()); assertEquals(offerFullEditionEntitlement().getIdentifier(), transactions.get(0).getIdentifier()); }
@Test public void getPurchasesWithResultOkShouldReturnPurchaseTransactions() throws Exception { activityBindAndConnect(); whenGetPurchasesRequestReturn(purchasesResponseOneTransactionFullEdition()); List<Transaction> transactions = v3InAppbillingService.getPurchases(); verify(nativeInAppBillingService).getPurchases(BILLING_API_VERSION, PACKAGE_NAME_GOOD, PURCHASE_TYPE_IN_APP, null); assertEquals(1, transactions.size()); assertEquals(offerFullEditionEntitlement().getIdentifier(), transactions.get(0).getIdentifier()); }
transaction.setIdentifier(offerForStore.getIdentifier());
transaction.setIdentifier(offerForStore.getIdentifier());