Search in sources :

Example 1 with IPurchase

use of com.amazon.purchase.IPurchase 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)

Aggregations

Bundle (android.os.Bundle)1 IPurchase (com.amazon.purchase.IPurchase)1 PurchaseManagerListener (com.amazon.purchase.PurchaseManagerListener)1 Product (com.amazon.purchase.model.Product)1 Response (com.amazon.purchase.model.Response)1 IOException (java.io.IOException)1