Beispiel #1
0
        /**
         * @{inheritDoc}
         */
        public override JObject toJSONObject()
        {
            JObject parentJsonObject = base.toJSONObject();
            JObject jsonObject       = new JObject();

            try {
                foreach (var entry in parentJsonObject)
                {
                    jsonObject.Add(entry.Key, entry.Value);
                }

                JObject purchasableObj = new JObject();

                if (mPurchaseType is PurchaseWithMarket)
                {
                    purchasableObj.Add(StoreJSONConsts.PURCHASE_TYPE, StoreJSONConsts.PURCHASE_TYPE_MARKET);

                    MarketItem mi = ((PurchaseWithMarket)mPurchaseType).getMarketItem();
                    purchasableObj.Add(StoreJSONConsts.PURCHASE_MARKET_ITEM, mi.toJSONObject());
                }
                else if (mPurchaseType is PurchaseWithVirtualItem)
                {
                    purchasableObj.Add(StoreJSONConsts.PURCHASE_TYPE, StoreJSONConsts.PURCHASE_TYPE_VI);

                    purchasableObj.Add(StoreJSONConsts.PURCHASE_VI_ITEMID, ((PurchaseWithVirtualItem)mPurchaseType).getTargetItemId());
                    purchasableObj.Add(StoreJSONConsts.PURCHASE_VI_AMOUNT, ((PurchaseWithVirtualItem)mPurchaseType).getAmount());
                }

                jsonObject.Add(StoreJSONConsts.PURCHASABLE_ITEM, purchasableObj);
            } catch (Exception e) {
                SoomlaUtils.LogError(TAG, "An error occurred while generating JSON object." + " " + e.Message);
            }

            return(jsonObject);
        }
Beispiel #2
0
        /**
         * Starts a purchase process in the market.
         *
         * @param marketItem The item to purchase - this item has to be defined EXACTLY the same in
         *                   the market
         * @param payload A payload to get back when this purchase is finished.
         * @throws IllegalStateException
         */
        public void buyWithMarket(MarketItem marketItem, String payload)
        {
            SoomlaUtils.LogDebug(TAG, "TODO buyWithMarket");

            PurchasableVirtualItem pvi;
            try
            {
                pvi = StoreInfo.getPurchasableItem(marketItem.getProductId());
            }
            catch (VirtualItemNotFoundException e)
            {
                String msg = "Couldn't find a purchasable item associated with: " + marketItem.getProductId() + " " + e.Message;
                SoomlaUtils.LogError(TAG, msg);
                BusProvider.Instance.Post(new UnexpectedStoreErrorEvent(msg));
                return;
            }

            BusProvider.Instance.Post(new MarketPurchaseStartedEvent(pvi));
            StoreManager.GetInstance().PurchaseProduct(marketItem.getProductId());
            /*
            mInAppBillingService.initializeBillingService
                    (new IabCallbacks.IabInitListener() {

                        @Override
                        public void success(boolean alreadyInBg) {
                            if (!alreadyInBg) {
                                notifyIabServiceStarted();
                            }

                            IabCallbacks.OnPurchaseListener purchaseListener =
                                    new IabCallbacks.OnPurchaseListener() {

                                        @Override
                                        public void success(IabPurchase purchase) {
                                            handleSuccessfulPurchase(purchase);
                                        }

                                        @Override
                                        public void cancelled(IabPurchase purchase) {
                                            handleCancelledPurchase(purchase);
                                        }

                                        @Override
                                        public void alreadyOwned(IabPurchase purchase) {
                                            String sku = purchase.getSku();
                                            SoomlaUtils.LogDebug(TAG, "Tried to buy an item that was not" +
                                                    " consumed (maybe it's an already owned " +
                                                    "NonConsumable). productId: " + sku);

                                            try {
                                                PurchasableVirtualItem pvi = StoreInfo.getPurchasableItem(sku);
                                                consumeIfConsumable(purchase, pvi);

                                                if (pvi instanceof NonConsumableItem) {
                                                    String message = "(alreadyOwned) the user tried to " +
                                                            "buy a NonConsumableItem that was already " +
                                                            "owned. itemId: " + pvi.getItemId() +
                                                            "    productId: " + sku;
                                                    SoomlaUtils.LogDebug(TAG, message);
                                                    BusProvider.getInstance().post(new OnUnexpectedStoreErrorEvent(message));
                                                }
                                            } catch (VirtualItemNotFoundException e) {
                                                String message = "(alreadyOwned) ERROR : Couldn't find the "
                                                        + "VirtualCurrencyPack with productId: " + sku
                                                        + ". It's unexpected so an unexpected error is being emitted.";
                                                SoomlaUtils.LogError(TAG, message);
                                                BusProvider.getInstance().post(new OnUnexpectedStoreErrorEvent(message));
                                            }
                                        }

                                        @Override
                                        public void fail(String message) {
                                            handleErrorResult(message);
                                        }
                                    };
                            mInAppBillingService.launchPurchaseFlow(marketItem.getProductId(),
                                    purchaseListener, payload);
                            BusProvider.getInstance().post(new OnMarketPurchaseStartedEvent(pvi));
                        }

                        @Override
                        public void fail(String message) {
                            reportIabInitFailure(message);
                        }

                    });
             */
        }
 /**
  * Constructor.
  *
  * @param marketItem the representation of the item in the market
  */
 public PurchaseWithMarket(MarketItem marketItem) {
     mMarketItem = marketItem;
 }
 /**
  * Constructor.
  * Constructs a PurchaseWithMarket object by constructing a new <code>MarketItem</code> object
  * with the given <code>productId</code> and price, and declaring it as UNMANAGED.
  *
  * @param productId the productId as it appears in the Market.
  * @param price the price in the Market.
  */
 public PurchaseWithMarket(String productId, double price) {
     mMarketItem = new MarketItem(productId, MarketItem.Managed.UNMANAGED, price);
 }
Beispiel #5
0
 /**
  * Starts a purchase process in the market.
  *
  * @param marketItem The item to purchase - this item has to be defined EXACTLY the same in
  *                   the market
  * @param payload A payload to get back when this purchase is finished.
  * @throws IllegalStateException
  */
 public void buyWithMarket(MarketItem marketItem, String payload)
 {
 }