This class holds global constants that are used throughout the application to support in-app billing.
コード例 #1
0
        public override void OnRequestPurchaseResponse(BillingService.RequestPurchase request, Consts.ResponseCode responseCode)
        {
            if (Consts.DEBUG)
                Log.Debug(Activity1.TAG, request.mProductId + ": " + responseCode);

            if (responseCode == Consts.ResponseCode.RESULT_OK)
            {
                if (Consts.DEBUG)
                    Log.Info(Activity1.TAG, "purchase was successfully sent to server");
            }
            else if (responseCode == Consts.ResponseCode.RESULT_USER_CANCELED)
            {
                if (Consts.DEBUG)
                    Log.Info(Activity1.TAG, "user canceled purchase");
            }
            else
            {
                if (Consts.DEBUG)
                    Log.Info(Activity1.TAG, "purchase failed");
            }
        }
コード例 #2
0
        public override void OnRestoreTransactionsResponse(BillingService.RestoreTransactions request, Consts.ResponseCode responseCode)
        {
            if (responseCode == Consts.ResponseCode.RESULT_OK)
            {
                if (Consts.DEBUG)
                    Log.Debug(Activity1.TAG, "completed RestoreTransactions request");

                // Update the shared preferences so that we don't perform
                // a RestoreTransactions again.
                ISharedPreferences prefs = _activity.GetPreferences(FileCreationMode.Private);
                ISharedPreferencesEditor edit = prefs.Edit();
                edit.PutBoolean(Activity1.DB_INITIALIZED, true);
                edit.Commit();
            }
            else
            {
                if (Consts.DEBUG)
                    Log.Debug(Activity1.TAG, "RestoreTransactions error: " + responseCode);
            }
        }
コード例 #3
0
 /// <summary>
 /// This is called when we receive a response code from Android Market for a
 /// RestoreTransactions request that we made.  A response code of
 /// RESULT_OK means that the request was successfully sent to the server.
 /// </summary>
 public abstract void OnRestoreTransactionsResponse(BillingService.RestoreTransactions request, Consts.ResponseCode responseCode);
コード例 #4
0
        public override void OnPurchaseStateChange(Consts.PurchaseState purchaseState, string itemId,
            int quantity, long purchaseTime, string developerPayload)
        {
            if (Consts.DEBUG)
            {
                Log.Info(Activity1.TAG, "OnPurchaseStateChange() itemId: " + itemId + " " + purchaseState);
            }

            if (developerPayload == null)
            {
            }
            else
            {
            }

            if (purchaseState == Consts.PurchaseState.PURCHASED)
            {
                _activity.OwnedItems.Add(itemId);
                _activity.ItemName.Text = itemId;
            }

            if (purchaseState == Consts.PurchaseState.REFUNDED)
            {
            }

            if (purchaseState == Consts.PurchaseState.CANCELED)
            {
            }

            _activity.OwnedItemsCursor.Requery();
        }
コード例 #5
0
 /// <summary>
 /// This is the callback that is invoked when an item is purchased,
 /// refunded, or canceled.  It is the callback invoked in response to
 /// calling <seealso cref="BillingService#requestPurchase(String)"/>.  It may also
 /// be invoked asynchronously when a purchase is made on another device
 /// (if the purchase was for a Market-managed item), or if the purchase
 /// was refunded, or the charge was canceled.  This handles the UI
 /// update.  The database update is handled in
 /// {@link ResponseHandler#purchaseResponse(Context, PurchaseState,
 /// String, String, long)}. </summary>
 /// <param name="purchaseState"> the purchase state of the item </param>
 /// <param name="itemId"> a string identifying the item (the "SKU") </param>
 /// <param name="quantity"> the current quantity of this item after the purchase </param>
 /// <param name="purchaseTime"> the time the product was purchased, in
 /// milliseconds since the epoch (Jan 1, 1970) </param>
 public abstract void OnPurchaseStateChange(Consts.PurchaseState purchaseState, string itemId, int quantity, long purchaseTime, string developerPayload);
コード例 #6
0
 /// <summary>
 /// This is called when we receive a response code from Market for a
 /// RequestPurchase request that we made.  This is NOT used for any
 /// purchase state changes.  All purchase state changes are received in
 /// <seealso cref="#onPurchaseStateChange(PurchaseState, String, int, long)"/>.
 /// This is used for reporting various errors, or if the user backed out
 /// and didn't purchase the item.  The possible response codes are:
 ///   RESULT_OK means that the order was sent successfully to the server.
 ///       The onPurchaseStateChange() will be invoked later (with a
 ///       purchase state of PURCHASED or CANCELED) when the order is
 ///       charged or canceled.  This response code can also happen if an
 ///       order for a Market-managed item was already sent to the server.
 ///   RESULT_USER_CANCELED means that the user didn't buy the item.
 ///   RESULT_SERVICE_UNAVAILABLE means that we couldn't connect to the
 ///       Android Market server (for example if the data connection is down).
 ///   RESULT_BILLING_UNAVAILABLE means that in-app billing is not
 ///       supported yet.
 ///   RESULT_ITEM_UNAVAILABLE means that the item this app offered for
 ///       sale does not exist (or is not published) in the server-side
 ///       catalog.
 ///   RESULT_ERROR is used for any other errors (such as a server error).
 /// </summary>
 public abstract void OnRequestPurchaseResponse(BillingService.RequestPurchase request, Consts.ResponseCode responseCode);
コード例 #7
0
 protected internal override void ResponseCodeReceived(Consts.ResponseCode responseCode)
 {
     ResponseHandler.ResponseCodeReceived(this.outerInstance.ApplicationContext, this, responseCode);
 }
コード例 #8
0
 /// <summary>
 /// Updates the UI after the database has been updated.  This method runs
 /// in a background thread so it has to post a Runnable to run on the UI
 /// thread. </summary>
 /// <param name="purchaseState"> the purchase state of the item </param>
 /// <param name="itemId"> a string identifying the item </param>
 /// <param name="quantity"> the quantity of items in this purchase </param>
 //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
 //ORIGINAL LINE: void postPurchaseStateChange(final com.example.dungeons.Consts.PurchaseState purchaseState, final String itemId, final int quantity, final long purchaseTime, final String developerPayload)
 internal virtual void PostPurchaseStateChange(Consts.PurchaseState purchaseState, string itemId, int quantity, long purchaseTime, string developerPayload)
 {
     mHandler.Post(() =>
             {
                 OnPurchaseStateChange(purchaseState, itemId, quantity, purchaseTime, developerPayload);
             });
 }
コード例 #9
0
 /// <summary>
 /// This is called when we receive a response code from Android Market for a request
 /// that we made. This is used for reporting various errors and for
 /// acknowledging that an order was sent to the server. This is NOT used
 /// for any purchase state changes.  All purchase state changes are received
 /// in the <seealso cref="BillingReceiver"/> and passed to this service, where they are
 /// handled in <seealso cref="#purchaseStateChanged(int, String, String)"/>. </summary>
 /// <param name="requestId"> a number that identifies a request, assigned at the
 /// time the request was made to Android Market </param>
 /// <param name="responseCode"> a response code from Android Market to indicate the state
 /// of the request </param>
 private void CheckResponseCode(long requestId, Consts.ResponseCode responseCode)
 {
     BillingRequest request = mSentRequests[requestId];
     if (request != null)
     {
         if (Consts.DEBUG)
         {
             Log.Debug(TAG, request.GetType().Name + ": " + responseCode);
         }
         request.ResponseCodeReceived(responseCode);
     }
     mSentRequests.Remove(requestId);
 }
コード例 #10
0
 /// <summary>
 /// This is called when Android Market sends a response code for this
 /// request. </summary>
 /// <param name="responseCode"> the response code </param>
 protected internal virtual void ResponseCodeReceived(Consts.ResponseCode responseCode)
 {
 }
コード例 #11
0
        /// <summary>
        /// Notifies the application of purchase state changes. The application
        /// can offer an item for sale to the user via
        /// <seealso cref="BillingService#requestPurchase(String)"/>. The BillingService
        /// calls this method after it gets the response. Another way this method
        /// can be called is if the user bought something on another device running
        /// this same app. Then Android Market notifies the other devices that
        /// the user has purchased an item, in which case the BillingService will
        /// also call this method. Finally, this method can be called if the item
        /// was refunded. </summary>
        /// <param name="purchaseState"> the state of the purchase request (PURCHASED,
        ///     CANCELED, or REFUNDED) </param>
        /// <param name="productId"> a string identifying a product for sale </param>
        /// <param name="orderId"> a string identifying the order </param>
        /// <param name="purchaseTime"> the time the product was purchased, in milliseconds
        ///     since the epoch (Jan 1, 1970) </param>
        /// <param name="developerPayload"> the developer provided "payload" associated with
        ///     the order </param>
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
        //ORIGINAL LINE: public static void purchaseResponse(final android.content.Context context, final com.example.dungeons.Consts.PurchaseState purchaseState, final String productId, final String orderId, final long purchaseTime, final String developerPayload)
        public static void PurchaseResponse(Context context, Consts.PurchaseState purchaseState, string productId, string orderId, long purchaseTime, string developerPayload)
        {
            // Update the database with the purchase state. We shouldn't do that
            // from the main thread so we do the work in a background thread.
            // We don't update the UI here. We will update the UI after we update
            // the database because we need to read and update the current quantity
            // first.
            //JAVA TO C# CONVERTER TODO TASK: Anonymous inner classes are not converted to C# if the base type is not defined in the code being converted:
            new Thread(new Runnable(() =>
                {
                    PurchaseDatabase db = new PurchaseDatabase(context);
                    int quantity = db.UpdatePurchase(orderId, productId, purchaseState, purchaseTime, developerPayload);
                    db.Close();

                    // This needs to be synchronized because the UI thread can change the
                    // value of sPurchaseObserver.
                    lock (context)
                    {
                        if (sPurchaseObserver != null)
                        {
                            sPurchaseObserver.PostPurchaseStateChange(purchaseState, productId, quantity, purchaseTime, developerPayload);
                        }
                    }
                })).Start();
        }
コード例 #12
0
 /// <summary>
 /// This is called when we receive a response code from Android Market for a
 /// RestoreTransactions request. </summary>
 /// <param name="context"> the context </param>
 /// <param name="request"> the RestoreTransactions request for which we received a
 ///     response code </param>
 /// <param name="responseCode"> a response code from Market to indicate the state
 ///     of the request </param>
 public static void ResponseCodeReceived(Context context, BillingService.RestoreTransactions request, Consts.ResponseCode responseCode)
 {
     if (sPurchaseObserver != null)
     {
         sPurchaseObserver.OnRestoreTransactionsResponse(request, responseCode);
     }
 }
コード例 #13
0
 /// <summary>
 /// Inserts a purchased product into the database. There may be multiple
 /// rows in the table for the same product if it was purchased multiple times
 /// or if it was refunded. </summary>
 /// <param name="orderId"> the order ID (matches the value in the product list) </param>
 /// <param name="productId"> the product ID (sku) </param>
 /// <param name="state"> the state of the purchase </param>
 /// <param name="purchaseTime"> the purchase time (in milliseconds since the epoch) </param>
 /// <param name="developerPayload"> the developer provided "payload" associated with
 ///     the order. </param>
 private void InsertOrder(string orderId, string productId, Consts.PurchaseState state, long purchaseTime, string developerPayload)
 {
     ContentValues values = new ContentValues();
     values.Put(HISTORY_ORDER_ID_COL, orderId);
     values.Put(HISTORY_PRODUCT_ID_COL, productId);
     values.Put(HISTORY_STATE_COL, (int)state);
     values.Put(HISTORY_PURCHASE_TIME_COL, purchaseTime);
     values.Put(HISTORY_DEVELOPER_PAYLOAD_COL, developerPayload);
     mDb.Replace(PURCHASE_HISTORY_TABLE_NAME, null, values); // nullColumnHack
 }
コード例 #14
0
        public virtual int UpdatePurchase(string orderId, string productId, Consts.PurchaseState purchaseState, long purchaseTime, string developerPayload)
        {
            InsertOrder(orderId, productId, purchaseState, purchaseTime, developerPayload);
            ICursor cursor = mDb.Query(PURCHASE_HISTORY_TABLE_NAME, HISTORY_COLUMNS, HISTORY_PRODUCT_ID_COL + "=?", new string[] { productId }, null, null, null, null);
            if (cursor == null)
            {
                return 0;
            }
            int quantity = 0;
            try
            {
                // Count the number of times the product was purchased
                while (cursor.MoveToNext())
                {
                    int stateIndex = cursor.GetInt(2);
                    Consts.PurchaseState state = (Consts.PurchaseState)stateIndex;
                    // Note that a refunded purchase is treated as a purchase. Such
                    // a friendly refund policy is nice for the user.
                    if (state == Consts.PurchaseState.PURCHASED || state == Consts.PurchaseState.REFUNDED)
                    {
                        quantity += 1;
                    }
                }

                // Update the "purchased items" table
                UpdatePurchasedItem(productId, quantity);
            }
            finally
            {
                if (cursor != null)
                {
                    cursor.Close();
                }
            }
            return quantity;
        }
コード例 #15
0
 public VerifiedPurchase(Consts.PurchaseState purchaseState, string notificationId, string productId, string orderId, long purchaseTime, string developerPayload)
 {
     this.purchaseState = purchaseState;
     this.notificationId = notificationId;
     this.productId = productId;
     this.orderId = orderId;
     this.purchaseTime = purchaseTime;
     this.developerPayload = developerPayload;
 }