Skip to content

Commit

Permalink
getting receipts
Browse files Browse the repository at this point in the history
  • Loading branch information
jarnik committed Jul 26, 2013
1 parent f7e395a commit 6e2de9d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
22 changes: 15 additions & 7 deletions src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ class IAP_Handler

public var initCall:Dynamic;
public var requestProductListCall:Dynamic;
public var requestPurchaseCall:Dynamic;
public var getProductListIDsCall:Dynamic;
public var requestReceiptsCall:Dynamic;
public var getReceiptProductIDsCall:Dynamic;
public var requestPurchaseCall:Dynamic;
public var ouyaFacadeObject:Dynamic;

public function new( ouyaFacadeObject:Dynamic )
Expand All @@ -81,10 +83,14 @@ class IAP_Handler
// (Lorg/haxe/nme/HaxeObject;Ltv/ouya/console/api/OuyaFacade;[B)V
requestProductListCall = openfl.utils.JNI.createStaticMethod
("com.jarnik.iaptest.OUYA_IAP", "requestProductList", "([Ljava/lang/String;)V", true);
getProductListIDsCall = openfl.utils.JNI.createStaticMethod
("com.jarnik.iaptest.OUYA_IAP", "getProductListIDs", "()Ljava/lang/String;", true);
requestPurchaseCall = openfl.utils.JNI.createStaticMethod
("com.jarnik.iaptest.OUYA_IAP", "requestPurchase", "(Ljava/lang/String;)V", true);
requestReceiptsCall = openfl.utils.JNI.createStaticMethod
("com.jarnik.iaptest.OUYA_IAP", "requestReceipts", "()V", true);
getReceiptProductIDsCall = openfl.utils.JNI.createStaticMethod
("com.jarnik.iaptest.OUYA_IAP", "getReceiptProductIDs", "()Ljava/lang/String;", true);
trace("=================== JNI linked!");
var appKey:ByteArray = Assets.getBytes("assets/key.der");

Expand Down Expand Up @@ -116,11 +122,12 @@ class IAP_Handler

// ==================================== CALLBACKS =======================

public function onProductListReceived(products:String)
public function onProductListReceived()
{
//trace("=== onProductListReceived! "+products.join(" "));
var p:Array<String> = products.split(" ");
trace("=== onProductListReceived! "+products+" >> "+p.join("x"));
var p:Array<String> = getProductListIDsCall().split(" ");
trace("=== onProductListReceived! >> " + p.join("x"));

requestReceipts();
}
public function onProductListFailed(error:String)
{
Expand All @@ -140,9 +147,10 @@ class IAP_Handler
trace("=== onPurchaseCancelled! ");
}

public function onReceiptsReceived(receipts:Array<String>)
public function onReceiptsReceived()
{
trace("=== onReceiptsReceived! "+receipts.join(" "));
var p:Array<String> = getReceiptProductIDsCall().split(" ");
trace("=== onReceiptsReceived! >> "+p.join("x"));
}
public function onReceiptsFailed( error:String )
{
Expand Down
21 changes: 15 additions & 6 deletions src/java/com/jarnik/iaptest/OUYA_IAP.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ public void onSuccess(final ArrayList<Product> products) {
Log.d("IAP", p.getName() + " costs " + p.getPriceInCents());
}
Log.d("IAP", "========== requestProductList SUCCESS "+products.size() );
//callback.call("onPurchase", new Object[] {"junk"});
String product_ids = "";
//for ( int i = 0; i < mProductList.size(); i++ )
//product_ids += mProductList.get( i ).getIdentifier()+" ";
product_ids = "kocka leze dirou";
mCallback.call("onProductListReceived", new Object[] { product_ids } );
mCallback.call("onProductListReceived", new Object[] {} );
}

@Override
Expand All @@ -131,6 +126,13 @@ public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
//callback.call("onPurchase", new Object[] {"junk"});
}

public static String getProductListIDs() {
String product_ids = "";
for ( int i = 0; i < mProductList.size(); i++ )
product_ids += ( i > 0 ? " ": "" ) + mProductList.get( i ).getIdentifier();
return product_ids;
}

// ======================================= PURCHASE =====================================================

public static void requestPurchase( String productName )
Expand Down Expand Up @@ -401,5 +403,12 @@ public void onCancel()
}
}

public static String getReceiptProductIDs() {
String product_ids = "";
for ( int i = 0; i < mReceiptList.size(); i++ )
product_ids += ( i > 0 ? " ": "" ) + mReceiptList.get( i ).getIdentifier();
return product_ids;
}

}

0 comments on commit 6e2de9d

Please sign in to comment.