Search in sources :

Example 1 with ItemPurchasedEvent

use of com.soomla.store.events.ItemPurchasedEvent 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));
}
Also used : ItemPurchaseStartedEvent(com.soomla.store.events.ItemPurchaseStartedEvent) VirtualItemNotFoundException(com.soomla.store.exceptions.VirtualItemNotFoundException) VirtualItem(com.soomla.store.domain.VirtualItem) VirtualItemStorage(com.soomla.store.data.VirtualItemStorage) InsufficientFundsException(com.soomla.store.exceptions.InsufficientFundsException) ItemPurchasedEvent(com.soomla.store.events.ItemPurchasedEvent)

Example 2 with ItemPurchasedEvent

use of com.soomla.store.events.ItemPurchasedEvent in project android-store by soomla.

the class SoomlaStore method finalizeTransaction.

private void finalizeTransaction(IabPurchase purchase, PurchasableVirtualItem pvi, boolean isRestoring) {
    SoomlaUtils.LogDebug(TAG, "IabPurchase successful. Finalizing transaction");
    // TODO: update on the issue in github
    if (StoreInfo.isItemNonConsumable(pvi)) {
        if (StorageManager.getVirtualItemStorage(pvi).getBalance(pvi.getItemId()) == 1) {
            return;
        }
    }
    String developerPayload = purchase.getDeveloperPayload();
    final String token = purchase.getToken();
    final String orderId = purchase.getOrderId();
    final String originalJson = purchase.getOriginalJson();
    final String signature = purchase.getSignature();
    final String userId = purchase.getUserId();
    BusProvider.getInstance().post(new MarketPurchaseEvent(pvi, isRestoring, developerPayload, new HashMap<String, String>() {

        {
            put("token", token);
            put("orderId", orderId);
            put("originalJson", originalJson);
            put("signature", signature);
            put("userId", userId);
        }
    }, null));
    pvi.give(1);
    BusProvider.getInstance().post(new ItemPurchasedEvent(pvi.getItemId(), isRestoring, developerPayload));
    consumeIfConsumable(purchase, pvi);
}
Also used : MarketPurchaseEvent(com.soomla.store.events.MarketPurchaseEvent) HashMap(java.util.HashMap) ItemPurchasedEvent(com.soomla.store.events.ItemPurchasedEvent)

Aggregations

ItemPurchasedEvent (com.soomla.store.events.ItemPurchasedEvent)2 VirtualItemStorage (com.soomla.store.data.VirtualItemStorage)1 VirtualItem (com.soomla.store.domain.VirtualItem)1 ItemPurchaseStartedEvent (com.soomla.store.events.ItemPurchaseStartedEvent)1 MarketPurchaseEvent (com.soomla.store.events.MarketPurchaseEvent)1 InsufficientFundsException (com.soomla.store.exceptions.InsufficientFundsException)1 VirtualItemNotFoundException (com.soomla.store.exceptions.VirtualItemNotFoundException)1 HashMap (java.util.HashMap)1