Пример #1
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;
			}
Пример #2
0
		/**
		 * 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 {@link BillingReceiver} and passed to this service, where they are
		 * handled in {@link #purchaseStateChanged(int, string, string)}.
		 * @param requestId a number that identifies a request, assigned at the
		 * time the request was made to Android Market
		 * @param responseCode a response code from Android Market to indicate the state
		 * of the request
		 */
		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);
		}
Пример #3
0
		public override void responseCodeReceived(Consts.ResponseCode responseCode) 
		{
			ResponseHandler.responseCodeReceived(this.Service, this, responseCode);
        }
Пример #4
0
		/**
		 * Notifies the application of purchase state changes. The application
		 * can offer an item for sale to the user via
		 * {@link 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.
		 * @param purchaseState the state of the purchase request (PURCHASED,
		 *     CANCELED, or REFUNDED)
		 * @param productId a string identifying a product for sale
		 * @param orderId a string identifying the order
		 * @param purchaseTime the time the product was purchased, in milliseconds
		 *     since the epoch (Jan 1, 1970)
		 * @param developerPayload the developer provided "payload" associated with
		 *     the order
		 */
		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.

			new System.Threading.Tasks.TaskFactory().StartNew(() =>
			    {
					var db = new Db(context);
					var quantity = db.updatePurchase(
							orderId, productId, purchaseState, purchaseTime, developerPayload);
					db.close();
			
					if (sPurchaseObserver != null) 
						sPurchaseObserver.onPurchaseStateChange(purchaseState, productId, quantity, purchaseTime, developerPayload);
				});
		}
Пример #5
0
		/**
		 * This is called when we receive a response code from Android Market for a
		 * RestoreTransactions request.
		 * @param context the context
		 * @param request the RestoreTransactions request for which we received a
		 *     response code
		 * @param responseCode a response code from Market to indicate the state
		 *     of the request
		 */
		public static void responseCodeReceived(Context context, RestoreTransactions request, Consts.ResponseCode responseCode) 
		{
			if (sPurchaseObserver != null)
				sPurchaseObserver.onRestoreTransactionsResponse(request, responseCode);			
		}
Пример #6
0
		/**
		 * 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.
		 * @param orderId the order ID (matches the value in the product list)
		 * @param productId the product ID (sku)
		 * @param state the state of the purchase
		 * @param purchaseTime the purchase time (in milliseconds since the epoch)
		 * @param developerPayload the developer provided "payload" associated with
		 *     the order.
		 */
		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 /* nullColumnHack */, values);
		}
Пример #7
0
		/**
		 * Adds the given purchase information to the database and returns the total
		 * number of times that the given product has been purchased.
		 * @param orderId a string identifying the order
		 * @param productId the product ID (sku)
		 * @param purchaseState the purchase state of the product
		 * @param purchaseTime the time the product was purchased, in milliseconds
		 * since the epoch (Jan 1, 1970)
		 * @param developerPayload the developer provided "payload" associated with
		 *     the order
		 * @return the number of times the given product has been purchased.
		 */
		public 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;
		}
Пример #8
0
        /**
         * This is called when Android Market sends a response code for this
         * request.
         * @param responseCode the response code
         */
        public virtual void responseCodeReceived(Consts.ResponseCode responseCode) 
		{
        }
Пример #9
0
		public void onRestoreTransactionsResponse(RestoreTransactions request, Consts.ResponseCode responseCode)
		{
			Toast.MakeText(m_activity, string.Format("Restore response code: {0}", responseCode.ToString()), ToastLength.Long).Show();
		}
Пример #10
0
		public void onPurchaseStateChange(Consts.PurchaseState purchaseState, string itemId, int quantity, long purchaseTime, string developerPayload) //bool fromBackgroundTHread = false)
		{
			m_activity.RunOnUiThread(() =>
				{
					Toast.MakeText(m_activity, string.Format("PurchaseState: {0}", purchaseState.ToString()), ToastLength.Long).Show();
				});
		}