Search in sources :

Example 1 with Product

use of com.amazon.purchase.model.Product in project zype-firebuilder by zype.

the class ProductsAction method onResponse.

/**
 * Inform the user of the request completion.
 *
 * @param requestId The request id of this call.
 */
private void onResponse(String requestId) {
    Log.d(TAG, "onResponse():  request=" + requestId);
    Response response = mPurchaseManager.responseMap.get(requestId);
    Map<String, Product> products = mPurchaseManager.productsDataMap.get(requestId);
    if (mPurchaseManagerListener != null) {
        mPurchaseManagerListener.onProductDataResponse(response, products);
    }
    cleanUp(requestId);
}
Also used : Response(com.amazon.purchase.model.Response) Product(com.amazon.purchase.model.Product)

Example 2 with Product

use of com.amazon.purchase.model.Product in project zype-firebuilder by zype.

the class AmazonInAppPurchase method createIapPurchasingListener.

/**
 * Creates IAP purchase listener from PurchaseListener.
 */
/*package private*/
PurchasingListener createIapPurchasingListener(final PurchaseListener listener) {
    Log.d(TAG, "PurchasingListener registered");
    return new PurchasingListener() {

        @Override
        public void onUserDataResponse(UserDataResponse userDataResponse) {
            Log.d(TAG, "UserDataResponse received " + userDataResponse.toString());
            Response response = createResponse(isSuccessful(userDataResponse), userDataResponse.getRequestId().toString());
            UserData userData = createUserDataFromIapUserData(userDataResponse.getUserData());
            listener.onGetUserDataResponse(response, userData);
        }

        @Override
        public void onProductDataResponse(ProductDataResponse productDataResponse) {
            Log.d(TAG, "ProductDataResponse received " + productDataResponse.toString());
            Response response = createResponse(isSuccessful(productDataResponse), productDataResponse.getRequestId().toString());
            Map<String, Product> productMap = createProductMapFromProductDataResponse(productDataResponse.getProductData());
            listener.onProductDataResponse(response, productMap, productDataResponse.getUnavailableSkus());
        }

        @Override
        public void onPurchaseResponse(PurchaseResponse purchaseResponse) {
            Log.d(TAG, "purchaseResponse received " + purchaseResponse.toString());
            Response response = createResponse(isSuccessful(purchaseResponse), purchaseResponse.getRequestId().toString());
            com.amazon.device.iap.model.Receipt iapReceipt = purchaseResponse.getReceipt();
            String sku = null;
            if (iapReceipt != null) {
                sku = iapReceipt.getSku();
            }
            listener.onPurchaseResponse(response, sku, createReceipt(iapReceipt), createUserDataFromIapUserData(purchaseResponse.getUserData()));
        }

        @Override
        public void onPurchaseUpdatesResponse(PurchaseUpdatesResponse purchaseUpdatesResponse) {
            Log.d(TAG, "purchaseUpdatesResponse received " + purchaseUpdatesResponse.toString());
            Response response = createResponse(isSuccessful(purchaseUpdatesResponse), purchaseUpdatesResponse.getRequestId().toString());
            List<Receipt> receipts = createReceiptList(purchaseUpdatesResponse.getReceipts());
            UserData userData = createUserDataFromIapUserData(purchaseUpdatesResponse.getUserData());
            listener.onUserDataResponse(response, receipts, userData, purchaseUpdatesResponse.hasMore());
        }
    };
}
Also used : UserDataResponse(com.amazon.device.iap.model.UserDataResponse) PurchasingListener(com.amazon.device.iap.PurchasingListener) Receipt(com.amazon.purchase.model.Receipt) UserData(com.amazon.purchase.model.UserData) Product(com.amazon.purchase.model.Product) PurchaseResponse(com.amazon.device.iap.model.PurchaseResponse) ProductDataResponse(com.amazon.device.iap.model.ProductDataResponse) Response(com.amazon.purchase.model.Response) PurchaseUpdatesResponse(com.amazon.device.iap.model.PurchaseUpdatesResponse) PurchaseResponse(com.amazon.device.iap.model.PurchaseResponse) UserDataResponse(com.amazon.device.iap.model.UserDataResponse) ProductDataResponse(com.amazon.device.iap.model.ProductDataResponse) PurchaseUpdatesResponse(com.amazon.device.iap.model.PurchaseUpdatesResponse)

Example 3 with Product

use of com.amazon.purchase.model.Product in project zype-firebuilder by zype.

the class PurchaseHelper method initializePurchaseSystem.

/**
 * Method to initialize purchase system
 */
private void initializePurchaseSystem() {
    // The purchase system should be initialized by the module initializer, if there is no
    // initializer available that means the purchase system is not needed.
    IPurchase purchaseSystem = (IPurchase) ModuleManager.getInstance().getModule(IPurchase.class.getSimpleName()).getImpl(true);
    if (purchaseSystem == null) {
        Log.i(TAG, "Purchase system not registered.");
        return;
    }
    try {
        registerSkuForActions();
    } catch (Exception e) {
        Log.e(TAG, "Could not register actions!!", e);
    }
    // Register the purchase system received via ModuleManager and configure the purchase
    // listener.
    this.mPurchaseManager = PurchaseManager.getInstance(mContext.getApplicationContext());
    try {
        mPurchaseManager.init(purchaseSystem, new PurchaseManagerListener() {

            @Override
            public void onRegisterSkusResponse(Response response) {
                if (response == null || !Response.Status.SUCCESSFUL.equals(response.getStatus())) {
                    Log.e(TAG, "Register products failed " + response);
                } else {
                    // If there is a valid receipt available in the system, set content browser
                    // variable as true.
                    String sku = mPurchaseManager.getPurchasedSku();
                    if (sku == null) {
                        setSubscription(false, null);
                    } else {
                        setSubscription(true, sku);
                    }
                    Log.d(TAG, "Register products complete.");
                }
                mContentBrowser.updateContentActions();
            }

            @Override
            public void onValidPurchaseResponse(Response response, boolean validity, String sku) {
                Log.e(TAG, "You should not hit here!!!");
            }

            /* Zype, Evgeny Cherkasov
                 * begin */
            @Override
            public void onProductDataResponse(Response response, Map<String, Product> products) {
                Log.e(TAG, "You should not hit here!!!");
            }

            // @Override
            // public String getVideoId() {
            // Log.e(TAG, "You should not hit here!!!");
            // return null;
            // }
            @Override
            public Bundle getPurchaseExtras() {
                Log.e(TAG, "You should not hit here!!!");
                return null;
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "Could not configure the purchase system. ", e);
    }
}
Also used : Response(com.amazon.purchase.model.Response) Bundle(android.os.Bundle) Product(com.amazon.purchase.model.Product) IPurchase(com.amazon.purchase.IPurchase) IOException(java.io.IOException) PurchaseManagerListener(com.amazon.purchase.PurchaseManagerListener)

Example 4 with Product

use of com.amazon.purchase.model.Product in project zype-firebuilder by zype.

the class AmazonInAppPurchase method createProductFromIapProduct.

/**
 * Converts an IAP product to a purchase product.
 *
 * @param iapProduct The IAP product to be converted.
 * @return The purchase product.
 */
private Product createProductFromIapProduct(com.amazon.device.iap.model.Product iapProduct) {
    if (iapProduct == null) {
        return null;
    }
    Product product = new Product();
    product.setPrice(iapProduct.getPrice());
    product.setSku(iapProduct.getSku());
    product.setTitle(iapProduct.getTitle());
    product.setDescription(iapProduct.getDescription());
    product.setIconUrl(iapProduct.getSmallIconUrl());
    product.setProductType(getProductType(iapProduct.getProductType()));
    return product;
}
Also used : Product(com.amazon.purchase.model.Product)

Aggregations

Product (com.amazon.purchase.model.Product)4 Response (com.amazon.purchase.model.Response)3 Bundle (android.os.Bundle)1 PurchasingListener (com.amazon.device.iap.PurchasingListener)1 ProductDataResponse (com.amazon.device.iap.model.ProductDataResponse)1 PurchaseResponse (com.amazon.device.iap.model.PurchaseResponse)1 PurchaseUpdatesResponse (com.amazon.device.iap.model.PurchaseUpdatesResponse)1 UserDataResponse (com.amazon.device.iap.model.UserDataResponse)1 IPurchase (com.amazon.purchase.IPurchase)1 PurchaseManagerListener (com.amazon.purchase.PurchaseManagerListener)1 Receipt (com.amazon.purchase.model.Receipt)1 UserData (com.amazon.purchase.model.UserData)1 IOException (java.io.IOException)1