/**
   * docs in {@link PurchaseObserver#onPurchaseStateChange(com.soomla.billing.Consts.PurchaseState,
   * String, long, String)}.
   */
  @Override
  public void onPurchaseStateChange(
      Consts.PurchaseState purchaseState,
      String productId,
      long purchaseTime,
      String developerPayload) {
    try {
      PurchasableVirtualItem purchasableVirtualItem = StoreInfo.getPurchasableItem(productId);

      BusProvider.getInstance()
          .post(new PlayPurchaseEvent(purchasableVirtualItem, developerPayload));

      if (purchaseState == Consts.PurchaseState.PURCHASED) {
        purchasableVirtualItem.give(1);
      }

      if (purchaseState == Consts.PurchaseState.REFUNDED) {
        if (!StoreConfig.friendlyRefunds) {
          purchasableVirtualItem.take(1);
        }
      }

      BusProvider.getInstance().post(new ItemPurchasedEvent(purchasableVirtualItem));
    } catch (VirtualItemNotFoundException e) {
      StoreUtils.LogError(
          TAG,
          "ERROR : Couldn't find the "
              + purchaseState.name()
              + " VirtualCurrencyPack OR GoogleMarketItem  with productId: "
              + productId
              + ". It's unexpected so an unexpected error is being emitted.");
      BusProvider.getInstance().post(new UnexpectedStoreErrorEvent());
    }
  }
 @Override
 protected void onPostExecute(String result) {
   Log.d(TAG, "Response was: " + result);
   BusProvider.getInstance().register(this);
   BusProvider.getInstance().post(result);
   BusProvider.getInstance().unregister(this);
 }
  /**
   * docs in {@link
   * PurchaseObserver#onRequestPurchaseResponse(com.soomla.billing.BillingService.RequestPurchase,
   * com.soomla.billing.Consts.ResponseCode)}.
   */
  @Override
  public void onRequestPurchaseResponse(
      BillingService.RequestPurchase request, Consts.ResponseCode responseCode) {
    if (responseCode == Consts.ResponseCode.RESULT_OK) {
      // purchase was sent to server
    } else if (responseCode == Consts.ResponseCode.RESULT_USER_CANCELED) {

      try {
        BusProvider.getInstance()
            .post(new PlayPurchaseCancelledEvent(StoreInfo.getPurchasableItem(request.mProductId)));
      } catch (VirtualItemNotFoundException e) {
        StoreUtils.LogError(
            TAG,
            "ERROR : Couldn't find the CANCELLED VirtualCurrencyPack OR GoogleMarketItem  with productId: "
                + request.mProductId
                + ". It's unexpected so an unexpected error is being emitted.");
        BusProvider.getInstance().post(new UnexpectedStoreErrorEvent());
      }

    } else {
      // purchase failed !

      BusProvider.getInstance().post(new UnexpectedStoreErrorEvent());
      StoreUtils.LogError(TAG, "ERROR : Purchase failed for productId: " + request.mProductId);
    }
  }
  /**
   * docs in {@link
   * PurchaseObserver#onRestoreTransactionsResponse(com.soomla.billing.BillingService.RestoreTransactions,
   * com.soomla.billing.Consts.ResponseCode)}.
   */
  @Override
  public void onRestoreTransactionsResponse(
      BillingService.RestoreTransactions request, Consts.ResponseCode responseCode) {

    if (responseCode == Consts.ResponseCode.RESULT_OK) {
      StoreUtils.LogDebug(TAG, "RestoreTransactions succeeded");

      SharedPreferences prefs =
          new ObscuredSharedPreferences(
              SoomlaApp.getAppContext(),
              SoomlaApp.getAppContext()
                  .getSharedPreferences(StoreConfig.PREFS_NAME, Context.MODE_PRIVATE));
      SharedPreferences.Editor edit = prefs.edit();

      edit.putBoolean("RESTORED", true);
      edit.commit();

      BusProvider.getInstance().post(new RestoreTransactionsEvent(true));
    } else {
      StoreUtils.LogDebug(TAG, "RestoreTransactions error: " + responseCode);

      BusProvider.getInstance().post(new RestoreTransactionsEvent(false));
    }

    // we're stopping the billing service only if the store was not opened while the request was
    // sent
    if (!mStoreOpen) {
      stopBillingService();
    }
  }
  /**
   * Start a purchase process with Google Play.
   *
   * @param googleMarketItem is the item to purchase. This item has to be defined EXACTLY the same
   *     in Google Play.
   * @param payload a payload to get back when this purchase is finished.
   */
  public boolean buyWithGooglePlay(GoogleMarketItem googleMarketItem, String payload) {
    if (!checkInit()) return false;

    SharedPreferences prefs =
        new ObscuredSharedPreferences(
            SoomlaApp.getAppContext(),
            SoomlaApp.getAppContext()
                .getSharedPreferences(StoreConfig.PREFS_NAME, Context.MODE_PRIVATE));
    String publicKey = prefs.getString(StoreConfig.PUBLIC_KEY, "");
    if (publicKey.isEmpty() || publicKey.equals("[YOUR PUBLIC KEY FROM GOOGLE PLAY]")) {
      StoreUtils.LogError(TAG, "You didn't provide a public key! You can't make purchases.");
      return false;
    }

    if (!mBillingService.requestPurchase(
        googleMarketItem.getProductId(), Consts.ITEM_TYPE_INAPP, payload)) {
      return false;
    }
    try {
      BusProvider.getInstance()
          .post(
              new PlayPurchaseStartedEvent(
                  StoreInfo.getPurchasableItem(googleMarketItem.getProductId())));
    } catch (VirtualItemNotFoundException e) {
      StoreUtils.LogError(
          TAG,
          "Couldn't find a purchasable item with productId: " + googleMarketItem.getProductId());
    }
    return true;
  }
  /** Initiate the restoreTransactions process */
  public void restoreTransactions() {
    if (!checkInit()) return;

    StoreUtils.LogDebug(TAG, "Sending restore transaction request");
    mBillingService.restoreTransactions();

    BusProvider.getInstance().post(new RestoreTransactionsStartedEvent());
  }
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   View view = inflater.inflate(R.layout.layout_fragment_ottobus, container, false);
   button = (Button) view.findViewById(R.id.button);
   button.setOnClickListener(v -> BusProvider.getInstance().post(new OnLocationEvent(123, 123)));
   return view;
 }
Exemplo n.º 8
0
 public void onGotAccount(String userId) {
   User user = TrailBookState.getCurrentUser();
   if (user == null) {
     user = new User();
   }
   user.userId = userId;
   BusProvider.getInstance().post(new UserUpdatedEvent(user));
   if (mActionOnAccountReceived != null) mActionOnAccountReceived.execute();
 }
  /** Call this function when you close the actual store window. */
  public void storeClosing() {
    if (!mStoreOpen) return;

    mStoreOpen = false;

    BusProvider.getInstance().post(new ClosingStoreEvent());

    stopBillingService();
    //        ResponseHandler.unregister(this);
  }
Exemplo n.º 10
0
  /** docs in {@link PurchaseObserver#onBillingSupported(boolean supported, String type)}. */
  @Override
  public void onBillingSupported(boolean supported, String type) {
    if (type == null || type.equals(Consts.ITEM_TYPE_INAPP)) {
      if (supported) {
        StoreUtils.LogDebug(TAG, "billing is supported !");

        BusProvider.getInstance().post(new BillingSupportedEvent());
      } else {
        // purchase is not supported. just send a message to JS to disable the "get more ..."
        // button.

        StoreUtils.LogDebug(TAG, "billing is not supported !");

        BusProvider.getInstance().post(new BillingNotSupportedEvent());
      }
    } else if (type.equals(Consts.ITEM_TYPE_SUBSCRIPTION)) {
      // subscription is not supported
      // Soomla doesn't support subscriptions yet. doing nothing here ...
    } else {
      // subscription is not supported
      // Soomla doesn't support subscriptions yet. doing nothing here ...
    }
  }
Exemplo n.º 11
0
  /**
   * Call this function when you open the actual store window
   *
   * @param activity is the activity being opened (or the activity that contains the store)/
   */
  public void storeOpening(Activity activity) {
    if (!checkInit()) return;

    mLock.lock();
    if (mStoreOpen) {
      StoreUtils.LogError(TAG, "Store is already open !");
      mLock.unlock();
      return;
    }

    initCompatibilityLayer(activity);

    /* Initialize StoreInfo from database in case any changes were done to it while the store was closed */
    StoreInfo.initializeFromDB();

    /* Billing */
    startBillingService();

    BusProvider.getInstance().post(new OpeningStoreEvent());

    mStoreOpen = true;
    mLock.unlock();
  }
Exemplo n.º 12
0
 public static void disconnectNetwork(int networkId) {
   BusProvider.getInstance().post(new ManageNetworkEvent(networkId, NetworkAction.DISCONNECT));
 }
Exemplo n.º 13
0
 public static void deleteChannel(int bufferId) {
   BusProvider.getInstance().post(new ManageChannelEvent(bufferId, ChannelAction.DELETE));
 }
Exemplo n.º 14
0
 public static void unhideChannel(int bufferId) {
   BusProvider.getInstance().post(new ManageChannelEvent(bufferId, ChannelAction.UNHIDE));
 }
 @Override
 public void onResume() {
   super.onResume();
   BusProvider.getInstance().register(this);
 }
Exemplo n.º 16
0
 public static void partChannel(int bufferId, NetworkCollection networks) {
   BusProvider.getInstance()
       .post(
           new SendMessageEvent(
               bufferId, "/part " + networks.getBufferById(bufferId).getInfo().name));
 }
 @Override
 public void onPause() {
   super.onPause();
   BusProvider.getInstance().unregister(this);
 }
 protected void registerToBus() {
   BusProvider.register(this);
 }
 protected void unregisterFromBus() {
   BusProvider.unregister(this);
 }
 protected void post(Object busEvent) {
   BusProvider.post(busEvent);
 }
 protected void postSticky(Object busEvent) {
   BusProvider.postSticky(busEvent);
 }