Skip to content

Commit

Permalink
updated overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
jarnik committed Jul 26, 2013
1 parent b016840 commit 55ec8cc
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
2 changes: 1 addition & 1 deletion project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<assets path="assets" exclude="nme.svg" />
<assets path="assets" include="*.der" type="binary" />

<icon path="assets/nme.svg" />
<certificate path="bin/jarnik.keystore" password="N4_51ca!" />

</project>
26 changes: 15 additions & 11 deletions src/IAPHandler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class IAPHandler
public var requestReceiptsCall:Dynamic;
public var getReceiptProductIDsCall:Dynamic;
public var requestPurchaseCall:Dynamic;
public var getLastPurchasedProductIDCall:Dynamic;
public var ouyaFacadeObject:Dynamic;

public function new( ouyaFacadeObject:Dynamic, DERKeyPath:String )
Expand All @@ -44,6 +45,8 @@ class IAPHandler
("com.jarnik.iaptest.OUYA_IAP", "getReceiptProductIDs", "()Ljava/lang/String;", true);
requestPurchaseCall = openfl.utils.JNI.createStaticMethod
("com.jarnik.iaptest.OUYA_IAP", "requestPurchase", "(Ljava/lang/String;)V", true);
getLastPurchasedProductIDCall = openfl.utils.JNI.createStaticMethod
("com.jarnik.iaptest.OUYA_IAP", "getLastPurchasedProductID", "()Ljava/lang/String;", true);
trace("=================== JNI methods linked!");
var appKey:ByteArray = Assets.getBytes( DERKeyPath );

Expand Down Expand Up @@ -73,22 +76,23 @@ class IAPHandler
requestReceiptsCall( [] );
}

public function getProductListIDs():String {
// will return list of received product identifiers, delimited by space character
return getProductListIDsCall();
// I don't know how to send any values from JNI back to Haxe, therefore I use the getters
public function getLastPurchasedProductID():String {
return getLastPurchasedProductIDCall();
}

public function getReceiptProductIDs():String {
// will return list of purchased products identifiers, delimited by space character
return getReceiptProductIDsCall();
public function getProductListIDs():Array<String> {
return getProductListIDsCall().split(" ");
}
public function getReceiptProductIDs():Array<String> {
return getReceiptProductIDsCall().split(" ");
}

// ==================================== CALLBACKS - OVERRIDE THESE! =======================

// ==== Product List
public function onProductListReceived()
{
var p:Array<String> = getProductListIDs().split(" ");
var p:Array<String> = getProductListIDs();
trace("=== onProductListReceived! " + p.join(" "));

requestReceipts();
Expand All @@ -99,9 +103,9 @@ class IAPHandler
}

// ==== Purchasing
public function onPurchaseSuccess(productID:String)
public function onPurchaseSuccess()
{
trace("=== onPurchaseSuccess! "+productID);
trace("=== onPurchaseSuccess! "+getLastPurchasedProductID());
}
public function onPurchaseFailed(error:String)
{
Expand All @@ -115,7 +119,7 @@ class IAPHandler
// ==== Receipt List
public function onReceiptsReceived()
{
var p:Array<String> = getReceiptProductIDs().split(" ");
var p:Array<String> = getReceiptProductIDs();
trace("=== onReceiptsReceived! "+p.join("x"));
}
public function onReceiptsFailed( error:String )
Expand Down
28 changes: 25 additions & 3 deletions src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Main extends Sprite {
#end

private var handler:MyIAPHandler;
private var testProductPurchased:Bool;
private var icon:Bitmap;

public function new () {

Expand All @@ -34,26 +36,46 @@ class Main extends Sprite {

super ();

testProductPurchased = false;
addChild( icon = new Bitmap( Assets.getBitmapData("assets/OUYA_O.png" ) ) );
icon.visible = false;

#if android
var getContext = JNI.createStaticMethod ("org.haxe.nme.GameActivity", "getContext", "()Landroid/content/Context;", true);
OuyaController.init ( getContext () );
ouyaFacade = OuyaFacade.getInstance();
ouyaFacade.init( getContext(), OUYA_DEVELOPER_ID );
trace("OUYA controller & facade inited!");

handler = new MyIAPHandler( ouyaFacade.__jobject, DER_KEY_PATH );
handler.requestProductList(["test_sss_full", "__DECLINED__THIS_PURCHASE"]);
handler = new MyIAPHandler( ouyaFacade.__jobject, DER_KEY_PATH, receiptsReceived );
handler.requestProductList([
PRODUCT_IDENTIFIER
//, enter more product IDs here...
]);

addChild( new Bitmap( Assets.getBitmapData("assets/OUYA_O.png" ) ) );
stage.addEventListener (JoystickEvent.BUTTON_DOWN, stage_onJoystickButtonDown);
#end
}

#if android
private function stage_onJoystickButtonDown( e:JoystickEvent ):Void {
if ( testProductPurchased )
return;

trace("OUYA button pressed, starting purchase");
handler.requestPurchase( PRODUCT_IDENTIFIER );
}
#end

private function receiptsReceived( products:Array<String> ):Void {
trace("===== Main - Receipts received");
icon.visible = true;
for ( p in products )
if ( p == PRODUCT_IDENTIFIER ) {
trace("===== Main - product purchased");
icon.visible = false;
testProductPurchased = true;
}
}

}
18 changes: 18 additions & 0 deletions src/MyIAPHandler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
class MyIAPHandler extends IAPHandler
{

private var receiptsReceivedCallback:Array<String>->Void;

public function new( ouyaFacadeObject:Dynamic, DERKeyPath:String, receiptsReceivedCallback:Array<String>->Void )
{
super( ouyaFacadeObject, DERKeyPath );
this.receiptsReceivedCallback = receiptsReceivedCallback;
}

override public function onPurchaseSuccess()
{
trace("=== onPurchaseSuccess! " + getLastPurchasedProductID());
requestReceipts();
}

override public function onReceiptsReceived()
{
receiptsReceivedCallback( getReceiptProductIDs() );
}

}

Expand Down
8 changes: 7 additions & 1 deletion src/java/com/jarnik/iaptest/OUYA_IAP.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class OUYA_IAP
public static List<Purchasable> PRODUCT_IDENTIFIER_LIST;
private static List<Product> mProductList;
private static List<Receipt> mReceiptList;
private static String mLastPurchasedProductID;

public static HaxeObject mCallback;
private static OuyaFacade mOuyaFacade;
Expand Down Expand Up @@ -160,6 +161,10 @@ public static void requestPurchase( String productName )
mOuyaFacade.requestPurchase(purchasable, new PurchaseListener(product));
}

public static String getLastPurchasedProductID() {
return mLastPurchasedProductID;
}

/**
* The callback for when the user attempts to purchase something. We're not worried about
* the user cancelling the purchase so we extend CancelIgnoringOuyaResponseListener, if
Expand Down Expand Up @@ -243,7 +248,8 @@ public void onSuccess(String result) {
return;
}

mCallback.call("onPurchaseSuccess", new Object[] { mProduct.getIdentifier() } );
mLastPurchasedProductID = mProduct.getIdentifier();
mCallback.call("onPurchaseSuccess", new Object[] { } );
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion uploadOUYA.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
adb install -r bin/android/bin/bin/ouya_iap-release.apk
adb install -r bin/android/bin/bin/ouya_iap-debug.apk

0 comments on commit 55ec8cc

Please sign in to comment.