/** * @since Available in iOS 3.0 and later. */ public SKProductsRequest(@org.robovm.rt.bro.annotation.Marshaler(NSSet.AsStringSetMarshaler.class) Set<String> productIdentifiers) { super((SkipInit) null); initObject(init(productIdentifiers)); } /*</constructors>*/
@Override public void requestProductData() { if (productsRequest != null) { BillingError error = new BillingError(ErrorType.ALREADY_REQUESTING_PRODUCTS, "Already requesting product data!"); for (BillingObserver observer : billingObservers) { observer.onProductsRequestError(error); } return; } List<Product> products = productCatalog.getProducts(); Set<String> productIds = new HashSet<>(); for (Product product : products) { String id = product.getIdentifier(getType()); if (id != null) { productIds.add(id); } else { Log.err("Product identifier not found for product: " + product); } } productsRequest = new SKProductsRequest(productIds); productsRequest.setDelegate(new ProductsRequestDelegate()); productsRequest.start(); }
@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); } }
/** * @since Available in iOS 3.0 and later. */ @Method(selector = "initWithProductIdentifiers:") public SKProductsRequest(@org.robovm.rt.bro.annotation.Marshaler(NSSet.AsStringSetMarshaler.class) Set<String> productIdentifiers) { super((SkipInit) null); initObject(init(productIdentifiers)); } /*</constructors>*/
/** * @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!")); } }
/** * @since Available in iOS 3.0 and later. */ @Method(selector = "initWithProductIdentifiers:") public SKProductsRequest(@org.robovm.rt.bro.annotation.Marshaler(NSSet.AsStringSetMarshaler.class) Set<String> productIdentifiers) { super((SkipInit) null); initObject(init(productIdentifiers)); } /*</constructors>*/