use of com.soomla.store.events.ItemPurchaseStartedEvent in project android-store by soomla.
the class PurchaseWithVirtualItem method buy.
/**
* Buys the virtual item with other virtual items.
*
* @throws InsufficientFundsException
*/
@Override
public void buy(String payload) throws InsufficientFundsException {
SoomlaUtils.LogDebug(TAG, "Trying to buy a " + getAssociatedItem().getName() + " with " + mAmount + " pieces of " + mTargetItemId);
VirtualItem item = null;
try {
item = StoreInfo.getVirtualItem(mTargetItemId);
} catch (VirtualItemNotFoundException e) {
SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !");
return;
}
BusProvider.getInstance().post(new ItemPurchaseStartedEvent(getAssociatedItem().getItemId()));
VirtualItemStorage storage = StorageManager.getVirtualItemStorage(item);
assert storage != null;
int balance = storage.getBalance(item.getItemId());
if (balance < mAmount) {
throw new InsufficientFundsException(mTargetItemId);
}
storage.remove(item.getItemId(), mAmount);
getAssociatedItem().give(1);
BusProvider.getInstance().post(new ItemPurchasedEvent(getAssociatedItem().getItemId(), payload));
}
use of com.soomla.store.events.ItemPurchaseStartedEvent in project android-store by soomla.
the class PurchaseWithMarket method buy.
/**
* Buys the virtual item with real money (from the Market).
*
* @throws InsufficientFundsException
*/
@Override
public void buy(String payload) throws InsufficientFundsException {
SoomlaUtils.LogDebug(TAG, "Starting in-app purchase for productId: " + mMarketItem.getProductId());
BusProvider.getInstance().post(new ItemPurchaseStartedEvent(getAssociatedItem().getItemId()));
try {
SoomlaStore.getInstance().buyWithMarket(mMarketItem, mIsSubscription, payload);
} catch (IllegalStateException e) {
SoomlaUtils.LogError(TAG, "Error when purchasing item");
}
}
Aggregations