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 getOfferForStore (String storeName, String identifierForStore) { // search matching offer and return it for (int i = 0; i < offers.size(); i++) { if (offers.get(i).getIdentifierForStore(storeName).equals(identifierForStore)) { 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()); } }
public static Offer offerFullEditionEntitlement() { Offer offer = new Offer(); offer.setIdentifier(PRODUCT_IDENTIFIER_FULL_EDITION); offer.setType(OfferType.ENTITLEMENT); return offer; }
private OfferType getOfferType(String identifier) { Offer offer = purchaseManagerConfig.getOffer(identifier); if (offer == null || offer.getType() == null) { throw new IllegalStateException("No offer or offerType configured for identifier: " + identifier + ", offer: " + offer); } return offer.getType(); }
public static Offer offerSubscription() { Offer offer = new Offer(); offer.setIdentifier("com.appname.subscription"); offer.setType(OfferType.SUBSCRIPTION); return offer; }
if (purchasedOffer != null && purchasedOffer.getType().equals(OfferType.CONSUMABLE)) { mBillingClient.consumeAsync(purchase.getPurchaseToken(), new ConsumeResponseListener() { @Override
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 getOfferForStore (String storeName, String identifierForStore) { // search matching offer and return it for (int i = 0; i < offers.size(); i++) { if (offers.get(i).getIdentifierForStore(storeName).equals(identifierForStore)) { return offers.get(i); } } // no matching offer found return null; }
public static Offer offerConsumable() { Offer offer = new Offer(); offer.setIdentifier("com.appname.consumable.100.coins"); offer.setType(OfferType.CONSUMABLE); return offer; } }
private static ArrayList<String> itemIdList(Offer offer) { ArrayList<String> skuList = new ArrayList<>(); skuList.add(offer.getIdentifier()); return skuList; }
@Override public void purchase(String identifier) { String identifierForStore = config.getOffer(identifier).getIdentifierForStore(storeName()); PurchasingService.purchase(identifierForStore); }
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(); } }
@Override public void install (final PurchaseObserver observer, PurchaseManagerConfig config, boolean autoFetchInformation) { this.observer = observer; this.config = config; // --- copy all available products to the list of productIdentifiers int offerSize = config.getOfferCount(); productIdentifiers = new HashSet<>(offerSize); for (int z = 0; z < config.getOfferCount(); z++) { productIdentifiers.add(config.getOffer(z).getIdentifierForStore(storeName())); } PurchasingService.registerListener(activity.getApplicationContext(), this); // PurchasingService.IS_SANDBOX_MODE returns a boolean value. // Use this boolean value to check whether your app is running in test mode under the App Tester // or in the live production environment. Gdx.app.log(TAG, "Amazon IAP: sandbox mode is:" + PurchasingService.IS_SANDBOX_MODE); PurchasingService.getUserData(); if (autoFetchInformation) PurchasingService.getProductData(productIdentifiers); else productDataRetrieved = true; }
private void verifyBillingGetSkuDetailsCalled() throws android.os.RemoteException { verify(googleInAppBillingService).getProductsDetails(singletonList(offerFullEditionEntitlement().getIdentifier()), PURCHASE_TYPE_IN_APP); }
List<String> skuList = new ArrayList<>(offerSize); for (int z = 0; z < config.getOfferCount(); z++) { skuList.add(config.getOffer(z).getIdentifierForStore(storeName()));
private void bindConnectAndStartPurchaseRequest(Offer offer) throws android.os.RemoteException { activityBindAndConnect(); whenGetBuyIntentForIdentifierReturn(offer.getIdentifier(), buyIntentResponseOk()); v3InAppbillingService.startPurchaseRequest(offer.getIdentifier(), PURCHASE_TYPE_IN_APP, purchaseRequestCallback); }
/** * @param autoFetchInformation is not used, because without product information on ios it's not possible to fill * {@link Transaction} object on successful purchase **/ @Override public void install (PurchaseObserver observer, PurchaseManagerConfig config, boolean autoFetchInformation) { this.observer = observer; this.config = config; log(LOGTYPELOG, "Installing purchase observer..."); // Check if the device is configured for purchases. if (SKPaymentQueue.canMakePayments()) { // Create string set from offer identifiers. int size = config.getOfferCount(); Set<String> productIdentifiers = new HashSet<String>(size); for (int i = 0; i < size; i++) { productIdentifiers.add(config.getOffer(i).getIdentifierForStore(PurchaseManagerConfig.STORE_NAME_IOS_APPLE)); } // Request configured offers/products. log(LOGTYPELOG, "Requesting products..."); productsRequest = new SKProductsRequest(productIdentifiers); productsRequest.setDelegate(new IosFetchProductsAndInstallDelegate()); productsRequest.start(); } else { log(LOGTYPEERROR, "Error setting up in-app-billing: Device not configured for purchases!"); observer.handleInstallError(new RuntimeException( "Error installing purchase observer: Device not configured for purchases!")); } }
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(); }
@Override public void purchase (String identifier) { // Find the SKProduct for this identifier. String identifierForStore = config.getOffer(identifier).getIdentifierForStore(PurchaseManagerConfig.STORE_NAME_IOS_APPLE); SKProduct product = getProductByStoreIdentifier(identifierForStore); if (product == null) { // Product with this identifier not found: load product info first and try to purchase again log(LOGTYPELOG, "Requesting product info for " + identifierForStore); Set<String> identifierForStoreSet = new HashSet<String>(1); identifierForStoreSet.add(identifierForStore); productsRequest = new SKProductsRequest(identifierForStoreSet); productsRequest.setDelegate(new AppleProductsDelegatePurchase()); productsRequest.start(); } else { // Create a SKPayment from the product and start purchase flow log(LOGTYPELOG, "Purchasing product " + identifier + " ..."); SKPayment payment = new SKPayment(product); SKPaymentQueue.getDefaultQueue().addPayment(payment); } }