Exemple #1
0
 public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
   Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
   if (result.isFailure()) {
     Log.e(TAG, "Error purchasing: " + result);
     UnityPlayer.UnitySendMessage(
         EVENT_MANAGER, PURCHASE_FAILED_CALLBACK, result.getMessage());
     return;
   }
   Log.d(TAG, "Purchase successful.");
   String jsonPurchase;
   try {
     jsonPurchase = purchaseToJson(purchase);
   } catch (JSONException e) {
     UnityPlayer.UnitySendMessage(
         EVENT_MANAGER, PURCHASE_FAILED_CALLBACK, "Couldn't serialize the purchase");
     return;
   }
   UnityPlayer.UnitySendMessage(EVENT_MANAGER, PURCHASE_SUCCEEDED_CALLBACK, jsonPurchase);
 }
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
          Log.d(TAG, "Query inventory finished.");
          if (result.isFailure()) {
            UnityPlayer.UnitySendMessage(
                EVENT_MANAGER, QUERY_INVENTORY_FAILED_CALLBACK, result.getMessage());
            return;
          }

          Log.d(TAG, "Query inventory was successful.");
          String jsonInventory;
          try {
            jsonInventory = inventoryToJson(inventory);
          } catch (JSONException e) {
            UnityPlayer.UnitySendMessage(
                EVENT_MANAGER, QUERY_INVENTORY_FAILED_CALLBACK, "Couldn't serialize the inventory");
            return;
          }
          UnityPlayer.UnitySendMessage(
              EVENT_MANAGER, QUERY_INVENTORY_SUCCEEDED_CALLBACK, jsonInventory);
        }
 public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
   UnityPlayer.currentActivity.sendBroadcast(new Intent(UnityProxyActivity.ACTION_FINISH));
   Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
   if (result.isFailure()) {
     Log.e(TAG, "Error purchasing: " + result);
     UnityPlayer.UnitySendMessage(
         EVENT_MANAGER,
         PURCHASE_FAILED_CALLBACK,
         result.getResponse() + "|" + result.getMessage());
     return;
   }
   Log.d(TAG, "Purchase successful.");
   String jsonPurchase;
   try {
     jsonPurchase = purchaseToJson(purchase);
   } catch (JSONException e) {
     UnityPlayer.UnitySendMessage(
         EVENT_MANAGER, PURCHASE_FAILED_CALLBACK, "-1|Couldn't serialize the purchase");
     return;
   }
   UnityPlayer.UnitySendMessage(EVENT_MANAGER, PURCHASE_SUCCEEDED_CALLBACK, jsonPurchase);
 }
        public void onConsumeFinished(Purchase purchase, IabResult result) {
          Log.d(TAG, "Consumption finished. Purchase: " + purchase + ", result: " + result);

          purchase.setSku(
              SkuManager.getInstance().getSku(purchase.getAppstoreName(), purchase.getSku()));

          if (result.isFailure()) {
            Log.e(TAG, "Error while consuming: " + result);
            UnityPlayer.UnitySendMessage(
                EVENT_MANAGER, CONSUME_PURCHASE_FAILED_CALLBACK, result.getMessage());
            return;
          }
          Log.d(TAG, "Consumption successful. Provisioning.");
          String jsonPurchase;
          try {
            jsonPurchase = purchaseToJson(purchase);
          } catch (JSONException e) {
            UnityPlayer.UnitySendMessage(
                EVENT_MANAGER, CONSUME_PURCHASE_FAILED_CALLBACK, "Couldn't serialize the purchase");
            return;
          }
          UnityPlayer.UnitySendMessage(
              EVENT_MANAGER, CONSUME_PURCHASE_SUCCEEDED_CALLBACK, jsonPurchase);
        }