Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple purchases #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions extension/iap/Inventory.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Inventory
{

public var productDetailsMap(default, null): Map<String, ProductDetails>;
public var purchaseMap(default, null): Map<String, Purchase>;
public var purchaseMap(default, null): Map<String, Array<Purchase>>;

public function new(?dynObj:Dynamic)
{
Expand All @@ -32,7 +32,10 @@ class Inventory

for (dynItm in dynPurchases) {
var p = new Purchase(Reflect.field(dynItm, "value"), Reflect.field(dynItm, "itemType"), Reflect.field(dynItm, "signature"));
purchaseMap.set(cast Reflect.field(dynItm, "key"), p);
var key = cast Reflect.field(dynItm, "key");
if(!purchaseMap.exists(key))
purchaseMap.set(key, []);
purchaseMap.get(key).push(p);
}

}
Expand All @@ -47,8 +50,13 @@ class Inventory
}

/** Returns purchase information for a given product, or null if there is no purchase. */
public function getPurchase(productId:String) :Purchase {
return purchaseMap.get(productId);
public function getPurchase(productId:String) :Array<Purchase> {
var p = purchaseMap.get(productId);
if(p == null) {
return p;
} else {
return [];
}
}

/** Returns whether or not there exists a purchase of the given product. */
Expand Down
7 changes: 5 additions & 2 deletions extension/iap/ios/IAP.hx
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,11 @@ import haxe.Json;
var evt:IAPEvent = new IAPEvent (IAPEvent.PURCHASE_SUCCESS);
evt.purchase = new Purchase(inEvent);
evt.productID = evt.purchase.productID;
inventory.purchaseMap.set(evt.purchase.productID, evt.purchase);

var id:String = evt.productID;
if(!inventory.purchaseMap.exists(id)) {
inventory.purchaseMap.set(id, []);
}
inventory.purchaseMap.get(id).push(evt.purchase);
dispatchEvent (evt);

case "failed":
Expand Down