Transaction transaction (SKPaymentTransaction t) { SKPayment payment = t.getPayment(); String productIdentifier = payment.getProductIdentifier(); SKProduct product = getProductByStoreIdentifier(productIdentifier); if (product == null) { if (payment.getRequestData() != null) { final String transactionData; if (Foundation.getMajorSystemVersion() >= 7) { transactionData = payment.getRequestData().toBase64EncodedString(NSDataBase64EncodingOptions.None); } else { transactionData = Base64.encode(payment.getRequestData().getBytes());
@Override public void purchaseProduct(Product product) { Util.requireNonNull(product, "product"); if (requestedProducts == null) { BillingError error = new BillingError(ErrorType.PRODUCTS_NOT_REQUESTED, "Product data not requested! Need to call requestProductData() first."); for (BillingObserver observer : billingObservers) { observer.onPurchaseError(null, error); } return; } String id = product.getIdentifier(getType()); if (!requestedProducts.containsKey(id)) { BillingError error = new BillingError(ErrorType.UNKNOWN_PRODUCT_IDENTIFIER, "Product identifier cannot be found for this store!"); for (BillingObserver observer : billingObservers) { observer.onPurchaseError(null, error); } return; } SKPayment payment = new SKPayment(requestedProducts.get(id)); SKPaymentQueue.getDefaultQueue().addPayment(payment); }
private Transaction transactionFromSKPaymentTransaction(SKPaymentTransaction skTransaction) { String id = skTransaction.getPayment().getProductIdentifier(); Product product = productCatalog.getProduct(getType(), id); if (product == null) { product = productCatalog.getProduct(id); } return new IOSTransaction(skTransaction, product, transactionVerificator); }
@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); } }
@Override public void didReceiveResponse (SKProductsRequest request, SKProductsResponse response) { // Received the registered products from AppStore. products = response.getProducts(); if (products.size() == 1) { // Create a SKPayment from the product and start purchase flow SKProduct product = products.get(0); log(LOGTYPELOG, "Product info received/purchasing product " + product.getProductIdentifier() + " ..."); SKPayment payment = new SKPayment(product); SKPaymentQueue.getDefaultQueue().addPayment(payment); } else { // wrong product count returned String errorMessage = "Error purchasing product (wrong product info count returned: " + products.size() + ")!"; log(LOGTYPEERROR, errorMessage); observer.handlePurchaseError(new RuntimeException(errorMessage)); } }