Skip to content

Commit

Permalink
Merge pull request #1 from vedidev/restoring-flag
Browse files Browse the repository at this point in the history
Add `isRestoring` flag for purchase events
  • Loading branch information
EugeneButusov committed Jan 27, 2016
2 parents bd9fa07 + 5391b7a commit 4562e46
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
18 changes: 9 additions & 9 deletions SoomlaAndroidStore/src/com/soomla/store/SoomlaStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void success(List<IabPurchase> purchases) {
SoomlaUtils.LogDebug(TAG, "Got owned items: " + ownedSkus);
}

handleSuccessfulPurchases(purchases, new HandleSuccessfulPurchasesFinishedHandler() {
handleSuccessfulPurchases(purchases, true, new HandleSuccessfulPurchasesFinishedHandler() {
@Override
public void onFinished() {

Expand Down Expand Up @@ -397,7 +397,7 @@ public void success(boolean alreadyInBg) {

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

@Override
Expand Down Expand Up @@ -535,9 +535,9 @@ private interface HandleSuccessfulPurchasesFinishedHandler {
void onFinished();
}

private void handleSuccessfulPurchases(List<IabPurchase> purchases, HandleSuccessfulPurchasesFinishedHandler handler) {
private void handleSuccessfulPurchases(List<IabPurchase> purchases, boolean isRestoring, HandleSuccessfulPurchasesFinishedHandler handler) {
for (IabPurchase purchase : purchases) {
handleSuccessfulPurchase(purchase);
handleSuccessfulPurchase(purchase, isRestoring);
}

if (handler != null) {
Expand All @@ -552,7 +552,7 @@ private void handleSuccessfulPurchases(List<IabPurchase> purchases, HandleSucces
*
* @param purchase purchase whose state is to be checked.
*/
private void handleSuccessfulPurchase(IabPurchase purchase) {
private void handleSuccessfulPurchase(IabPurchase purchase, boolean isRestoring) {
String sku = purchase.getSku();

PurchasableVirtualItem pvi;
Expand All @@ -571,7 +571,7 @@ private void handleSuccessfulPurchase(IabPurchase purchase) {
switch (purchase.getPurchaseState()) {
case 0: {
if (purchase.isServerVerified()) {
this.finalizeTransaction(purchase, pvi);
this.finalizeTransaction(purchase, pvi, isRestoring);
} else {
BusProvider.getInstance().post(
new UnexpectedStoreErrorEvent(
Expand Down Expand Up @@ -690,7 +690,7 @@ private void handleErrorResult(UnexpectedStoreErrorEvent.ErrorCode errorCode, St
SoomlaUtils.LogError(TAG, "ERROR: SoomlaStore failure: " + message);
}

private void finalizeTransaction(IabPurchase purchase, PurchasableVirtualItem pvi) {
private void finalizeTransaction(IabPurchase purchase, PurchasableVirtualItem pvi, boolean isRestoring) {
SoomlaUtils.LogDebug(TAG, "IabPurchase successful. Finalizing transaction");

// if the purchasable item is non-consumable and it already exists then we
Expand All @@ -711,7 +711,7 @@ private void finalizeTransaction(IabPurchase purchase, PurchasableVirtualItem pv
final String signature = purchase.getSignature();
final String userId = purchase.getUserId();

BusProvider.getInstance().post(new MarketPurchaseEvent(pvi, developerPayload, new HashMap<String, String>() {{
BusProvider.getInstance().post(new MarketPurchaseEvent(pvi, isRestoring, developerPayload, new HashMap<String, String>() {{
put("token", token);
put("orderId", orderId);
put("originalJson", originalJson);
Expand All @@ -720,7 +720,7 @@ private void finalizeTransaction(IabPurchase purchase, PurchasableVirtualItem pv
}}, null));

pvi.give(1);
BusProvider.getInstance().post(new ItemPurchasedEvent(pvi.getItemId(), developerPayload));
BusProvider.getInstance().post(new ItemPurchasedEvent(pvi.getItemId(), isRestoring, developerPayload));

consumeIfConsumable(purchase, pvi);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ public ItemPurchasedEvent(String itemId, String payload) {
this(itemId, payload, null);
}

public ItemPurchasedEvent(String itemId, boolean isRestored, String payload) {
this(itemId, isRestored, payload, null);
}

public ItemPurchasedEvent(String itemId, String payload, Object sender) {
this(itemId, false, payload, sender);
}

public ItemPurchasedEvent(String itemId, boolean isRestored, String payload, Object sender) {
super(sender);
mItemId = itemId;
mRestored = isRestored;
mPayload = payload;
}


/** Setters and Getters */

public String getItemId() {
Expand All @@ -49,8 +57,13 @@ public String getPayload() {
return mPayload;
}

public boolean isRestored() {
return mRestored;
}

/** Private Members */

private String mItemId;
private String mPayload;
private boolean mRestored;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ public MarketPurchaseEvent(PurchasableVirtualItem purchasableVirtualItem, String

public MarketPurchaseEvent(PurchasableVirtualItem purchasableVirtualItem, String payload,
HashMap<String, String> extraInfo, Object sender) {
this(purchasableVirtualItem, false, payload, extraInfo, sender);

}

public MarketPurchaseEvent(PurchasableVirtualItem purchasableVirtualItem, boolean isRestored, String payload, HashMap<String, String> extraInfo, Object sender) {
super(sender);
PurchasableVirtualItem = purchasableVirtualItem;
IsRestored = isRestored;
Payload = payload;
ExtraInfo = extraInfo;
}
Expand All @@ -50,6 +56,8 @@ public MarketPurchaseEvent(PurchasableVirtualItem purchasableVirtualItem, String

public final PurchasableVirtualItem PurchasableVirtualItem;

public final boolean IsRestored;

public final String Payload;

public final HashMap<String, String> ExtraInfo;
Expand Down

0 comments on commit 4562e46

Please sign in to comment.