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);
        }
Exemple #5
0
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
          Log.d(TAG, "Query inventory finished.");
          if (result.isFailure()) {
            complain("Failed to query inventory: " + result);
            return;
          }

          Log.d(TAG, "Query inventory was successful.");

          /*
           * Check for items we own. Notice that for each purchase, we check
           * the developer payload to see if it's correct! See
           * verifyDeveloperPayload().
           */

          // Do we have the premium upgrade?
          Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM);
          mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
          Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));

          // Do we have the infinite gas plan?
          Purchase infiniteGasPurchase = inventory.getPurchase(SKU_INFINITE_GAS);
          mSubscribedToInfiniteGas =
              (infiniteGasPurchase != null && verifyDeveloperPayload(infiniteGasPurchase));
          Log.d(
              TAG,
              "User "
                  + (mSubscribedToInfiniteGas ? "HAS" : "DOES NOT HAVE")
                  + " infinite gas subscription.");
          if (mSubscribedToInfiniteGas) mTank = TANK_MAX;

          // Check for gas delivery -- if we own gas, we should fill up the tank immediately
          Purchase gasPurchase = inventory.getPurchase(SKU_GAS);
          if (gasPurchase != null && verifyDeveloperPayload(gasPurchase)) {
            Log.d(TAG, "We have gas. Consuming it.");
            mHelper.consumeAsync(inventory.getPurchase(SKU_GAS), mConsumeFinishedListener);
            return;
          }

          updateUi();
          setWaitScreen(false);
          Log.d(TAG, "Initial inventory query finished; enabling main UI.");
        }
Exemple #6
0
        public void onConsumeFinished(Purchase purchase, IabResult result) {
          Log.d(TAG, "Consumption finished. Purchase: " + purchase + ", result: " + result);

          // We know this is the "gas" sku because it's the only one we consume,
          // so we don't check which sku was consumed. If you have more than one
          // sku, you probably should check...
          if (result.isSuccess()) {
            // successfully consumed, so we apply the effects of the item in our
            // game world's logic, which in our case means filling the gas tank a bit
            Log.d(TAG, "Consumption successful. Provisioning.");
            mTank = mTank == TANK_MAX ? TANK_MAX : mTank + 1;
            saveData();
            alert("You filled 1/4 tank. Your tank is now " + String.valueOf(mTank) + "/4 full!");
          } else {
            complain("Error while consuming: " + result);
          }
          updateUi();
          setWaitScreen(false);
          Log.d(TAG, "End consumption flow.");
        }
Exemple #7
0
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
          Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase);
          if (result.isFailure()) {
            complain("Error purchasing: " + result);
            setWaitScreen(false);
            return;
          }
          if (!verifyDeveloperPayload(purchase)) {
            complain("Error purchasing. Authenticity verification failed.");
            setWaitScreen(false);
            return;
          }

          Log.d(TAG, "Purchase successful.");

          if (purchase.getSku().equals(SKU_GAS)) {
            // bought 1/4 tank of gas. So consume it.
            Log.d(TAG, "Purchase is gas. Starting gas consumption.");
            mHelper.consumeAsync(purchase, mConsumeFinishedListener);
          } else if (purchase.getSku().equals(SKU_PREMIUM)) {
            // bought the premium upgrade!
            Log.d(TAG, "Purchase is premium upgrade. Congratulating user.");
            alert("Thank you for upgrading to premium!");
            mIsPremium = true;
            updateUi();
            setWaitScreen(false);
          } else if (purchase.getSku().equals(SKU_INFINITE_GAS)) {
            // bought the infinite gas subscription
            Log.d(TAG, "Infinite gas subscription purchased.");
            alert("Thank you for subscribing to infinite gas!");
            mSubscribedToInfiniteGas = true;
            mTank = TANK_MAX;
            updateUi();
            setWaitScreen(false);
          }
        }