vendredi 3 février 2017

Implementing Milkman Games iOS StoreKit In-App Purchase Native Extension for Adobe AIR

I am trying to implement Milkman Game's iOS StoreKit In-App Purchase Native Extension for Adobe AIR (using Adobe Flash). I copied most of the code from the Getting Started document. When I put the app on my iPad to test it, it asks me to log-in (which I log in to my sandbox test account), but after logging in I cannot click the "Purchase" button in my game and purchase the in-app product. (Button is named "buybt" in code) I should also mention that had previously used your Google In-App Purchase Native Extension in this same app and it was successful. I am basically trying to convert this completed Android game to an iOS version. So the coding of the game itself should be all set, it is just the implementing the iOS aspect that is giving me trouble. It seems that after logging into my sandbox account after I click the $2.99 button, the o2 = 2 code is not activating, since the button should change to a "Thanks for purchasing" text. (o2 normally = 1, but changing it to 2 unlocks the additionally features) I have pasted the code below that relates to this issue.

Any ideas on what I could be doing wrong? (I changed my company and game name in the bundle ID to generic company/app for privacy purposes)

Thanks for any help!

import com.milkmangames.nativeextensions.ios.*;
import com.milkmangames.nativeextensions.ios.events.*;


// Step 2: Initialize API
if(StoreKit.isSupported())
{
             StoreKit.create();
} 
else {
                        trace("StoreKit only works on iOS!");
                        return; 
}

// Step 3: Check if device supports In-App purchases
 if(!StoreKit.storeKit.isStoreKitAvailable())
       {
                        trace("This device has purchases disabled.");
                        return; 
                }

// Step 4: Load deatils about In-App Products
 // the first thing to do is to supply a list of product ids you want to display,
      // and Apple's server will respond with a list of their details (titles, price, etc)
      // assuming the ids you pass in are valid.  Even if you don't need to use this
      // information, you must make the details request before doing a purchase.
      // the list of ids is passed in as an as3 vector (typed Array.)
                
      var productIdList:Vector.<String>=new Vector.<String>();
      productIdList.push("com.company.app.adremoval");
                
      // when this is done, we'll get a PRODUCT_DETAILS_LOADED or PRODUCT_DETAILS_FAILED event and go on from there
                
      StoreKit.storeKit.loadProductDetails(productIdList);


// Step 5
// listen for a response from loadProductDetails():
                
StoreKit.storeKit.addEventListener(StoreKitEvent.PRODUCT_DETAILS_LOADED,onProducts);
function onProducts(e:StoreKitEvent):void
{
for each(var product:StoreKitProduct in e.validProducts)
{
      trace("ID: "+product.productId);
      trace("Title: "+product.title);
      trace("Description: "+product.description);
      trace("String Price: "+product.localizedPrice);
      trace("Price: "+product.price);
}
trace("Loaded "+e.validProducts.length+" Products.");
if (e.invalidProductIds.length>0)
{
      trace("[ERR]: invalid product ids:"+e.invalidProductIds.join(","));
}
}


// Step 6
//  // listen for ERROR response from loadProductDetails():
   StoreKit.storeKit.addEventListener(StoreKitErrorEvent.PRODUCT_DETAILS_FAILED,
   onProductsFailed);
   function onProductsFailed(e:StoreKitErrorEvent):void
   {
      trace("Error loading products: "+e.text);
        }


// Step 7  Purchasing a product
// this call purchases a product.  The second parameter is an
      // optional quantity- if you want to purchase more than one item at a time.
        
buybt.addEventListener(MouseEvent.CLICK,buybtx);
function buybtx(evt:MouseEvent):void {
        if(o2 == 1){
                if(mutesfx == 1){ myChannel4= clicksfx.play(0, 1); }
      StoreKit.storeKit.purchaseProduct("com.company.app.adremoval");
        }
}

// Step 8 Purchase succeeded
// this event is fired when a purchase goes through ok
      StoreKit.storeKit.addEventListener(StoreKitEvent.PURCHASE_SUCCEEDED,onPurchaseSuccess);
      function onPurchaseSuccess(e:StoreKitEvent):void
{
         // your app is now responsible for 'giving' the user whatever they bought!
                o2 = 2;
                        savegame = 2;
   }


// Step 9 User Cancels Purchase
// this event is fired when a purchase gets cancelled
   StoreKit.storeKit.addEventListener(StoreKitEvent.PURCHASE_CANCELLED,onPurchaseCancel);
   function onPurchaseCancel(e:StoreKitEvent):void
   {
         trace("The user decided not to buy: "+e.productId);
        }
   

// Step 10 If parental permissions required
 // this event is fired when a purchase gets deferred
   StoreKit.storeKit.addEventListener(StoreKitEvent.PURCHASE_DEFERRED,onPurchaseDeferred);
   function onPurchaseDeferred(e:StoreKitEvent):void
   {
         trace("Waiting for permission to buy: "+e.productId);
   }
   
   
// Step 11 If error in purchase
 // listen for ERROR response from purchaseProduct():
   StoreKit.storeKit.addEventListener(StoreKitErrorEvent.PURCHASE_FAILED,
   onPurchaseFailed);
   function onPurchaseFailed(e:StoreKitErrorEvent):void
        {        
                trace("Error purchasing product: "+e.text);
        }
   

// Steps 12-14 Restoring purchases
restorepurchasebt.addEventListener(MouseEvent.CLICK,restorepurchasebtx);
function restorepurchasebtx(evt:MouseEvent):void {
        if(o2 == 1){
                if(mutesfx == 1){ myChannel4= clicksfx.play(0, 1); }
                
        // this will make a PURCHASE_SUCCEEDED event happen again for
      // anything non-consumable the user has bought previously for your app.
      // When it's all done, the TRANSACTIONS_RESTORED event will occur.
      StoreKit.storeKit.restoreTransactions();
                
        // this event is fired when all the old PURCHASE_SUCCEEDED events were replayed
   StoreKit.storeKit.addEventListener(StoreKitEvent.TRANSACTIONS_RESTORED,
   onTransactionsRestoreComplete);
   function onTransactionsRestoreComplete(e:StoreKitEvent):void
   {
         // your app got PURCHASE_SUCCEEDED for each old purchase, and should've
         // give the items to the user.
         trace("Restore complete!");
        }
        
                
        // listen for ERROR response from purchaseProduct():
   StoreKit.storeKit.addEventListener(StoreKitErrorEvent.TRANSACTION_RESTORE_FAILED,
   onRestoreFailed);
   function onRestoreFailed(e:StoreKitErrorEvent):void
   {

                trace("Something went wrong restoring transactions: "+e.text);
        }
        
        }   
}
   

Aucun commentaire:

Enregistrer un commentaire