Exemple #1
0
        public override void ReceivedResponse(SKProductsRequest request, SKProductsResponse response)
        {
            try
            {
                Logger.Log("ReceivedResponse...");
                SKProduct[] products = response.Products;

                NSDictionary userInfo = null;
                if (products.Length > 0)
                {
                    NSObject[] productIdsArray = new NSObject[response.Products.Length];
                    NSObject[] productsArray   = new NSObject[response.Products.Length];
                    for (int i = 0; i < response.Products.Length; i++)
                    {
                        productIdsArray[i] = new NSString(response.Products[i].ProductIdentifier);
                        productsArray[i]   = response.Products[i];
                        Logger.Log("ReceivedResponse: Product ID: " + response.Products[i].ProductIdentifier);
                    }

                    userInfo = NSDictionary.FromObjectsAndKeys(productsArray, productIdsArray);
                }

                NSNotificationCenter.DefaultCenter.PostNotificationName(InAppPurchaseManagerProductsFetchedNotification, this, userInfo);
            }
            catch (Exception ex)
            {
                Logger.Log("ERROR: ReceivedResponse: " + ex);
            }
        }
        public async Task<SKProductsResponse> RequestProductData (params string[] productIds)
        {
            var array = new NSString[productIds.Length];
            for (var i = 0; i < productIds.Length; i++)
                array[i] = new NSString(productIds[i]);

            var tcs = new TaskCompletionSource<SKProductsResponse>();
            _productDataRequests.AddLast(tcs);

            try
            {
                var productIdentifiers = NSSet.MakeNSObjectSet<NSString>(array); //NSSet.MakeNSObjectSet<NSString>(array);​​​
                var productsRequest = new SKProductsRequest(productIdentifiers);
                productsRequest.ReceivedResponse += (sender, e) => tcs.SetResult(e.Response);
                productsRequest.RequestFailed += (sender, e) => tcs.SetException(new Exception(e.Error.LocalizedDescription));
                productsRequest.Start();
                if (await Task.WhenAny(tcs.Task, Task.Delay(TimeSpan.FromSeconds(30))) != tcs.Task)
                    throw new InvalidOperationException("Timeout waiting for Apple to respond");
                var ret = tcs.Task.Result;
                productsRequest.Dispose();
                return ret;
            }
            finally
            {
                _productDataRequests.Remove(tcs);
            }
        }
        public async Task <SKProductsResponse> RequestProductData(params string[] productIds)
        {
            var array = new NSString[productIds.Length];

            for (var i = 0; i < productIds.Length; i++)
            {
                array[i] = new NSString(productIds[i]);
            }

            var tcs = new TaskCompletionSource <SKProductsResponse>();

            _productDataRequests.AddLast(tcs);

            try
            {
                var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array); //NSSet.MakeNSObjectSet<NSString>(array);​​​
                var productsRequest    = new SKProductsRequest(productIdentifiers);
                productsRequest.ReceivedResponse += (sender, e) => tcs.SetResult(e.Response);
                productsRequest.RequestFailed    += (sender, e) => tcs.SetException(new Exception(e.Error.LocalizedDescription));
                productsRequest.Start();
                if (await Task.WhenAny(tcs.Task, Task.Delay(TimeSpan.FromSeconds(30))) != tcs.Task)
                {
                    throw new InvalidOperationException("Timeout waiting for Apple to respond");
                }
                var ret = tcs.Task.Result;
                productsRequest.Dispose();
                return(ret);
            }
            finally
            {
                _productDataRequests.Remove(tcs);
            }
        }
        public async Task <SKProductsResponse> RequestProductData(params string[] productIds)
        {
            var array = new NSString[productIds.Length];

            for (var i = 0; i < productIds.Length; i++)
            {
                array[i] = new NSString(productIds[i]);
            }

            var tcs = new TaskCompletionSource <SKProductsResponse>();

            _productDataRequests.AddLast(tcs);

            try
            {
                var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array); //NSSet.MakeNSObjectSet<NSString>(array);​​​
                var productsRequest    = new SKProductsRequest(productIdentifiers);
                productsRequest.ReceivedResponse += (sender, e) => tcs.SetResult(e.Response);
                productsRequest.RequestFailed    += (sender, e) => tcs.SetException(new Exception(e.Error.LocalizedDescription));
                productsRequest.Start();
                var ret = await tcs.Task;
                productsRequest.Dispose();
                return(ret);
            }
            finally
            {
                _productDataRequests.Remove(tcs);
                Console.WriteLine("Remaining: " + _productDataRequests.Count);
            }
        }
Exemple #5
0
    public void NewObject()
    {
        var obj = new SKProductsRequest("woot");

        Assert.AreNotEqual(IntPtr.Zero, obj.ClassHandle);
        Assert.AreNotEqual(IntPtr.Zero, obj.Handle);
    }
Exemple #6
0
        internal static void _OnProductRequestReceive(object sender, SKProductsRequest.DidReceiveEventArgs e)
        {
            foreach (var productObj in e.response.products)
            {
                var product = productObj as SKProduct;
                _products[product.productIdentifier] = product;
            }

            // raise event
            if ((e.response.invalidProductIdentifiers == null) || (e.response.invalidProductIdentifiers.Length == 0))
            {
                if (_initializationCompletedHandlers != null)
                {
                    _initializationCompletedHandlers(null, new InitializationEventArgs(e.response));
                }
            }
            else
            {
                if (_initializationFailedHandlers != null)
                {
                    _initializationFailedHandlers(null, new InitializationEventArgs(e.response));
                }
            }

            _request = null;
        }
Exemple #7
0
        public override void ReceivedResponse(SKProductsRequest request, SKProductsResponse response)
        {
#if !DIST
            foreach (SKProduct product in response.Products)
            {
                Console.WriteLine("Localised price:" + product.LocalizedPrice());
                Console.WriteLine("Product title: " + product.LocalizedTitle);
                Console.WriteLine("Product description: " + product.LocalizedDescription);
                Console.WriteLine("Product price: " + product.LocalizedPrice());
                Console.WriteLine("Product id: " + product.ProductIdentifier);
            }

            foreach (string invalidProductId in response.InvalidProducts)
            {
                Console.WriteLine("Invalid product id: " + invalidProductId);
            }
#endif

            if (responseDelegate != null)
            {
                responseDelegate(response.Products);
                responseDelegate = null;
            }

            productsRequest.Dispose();
            productsRequest = null;
        }
Exemple #8
0
        // Received response to RequestProductData - with price, title, description info
        public override void ReceivedResponse(SKProductsRequest request, SKProductsResponse response)
        {
            SKProduct[] products = response.Products;

            NSDictionary userInfo = null;

            if (products.Length > 0)
            {
                NSObject[] productIdsArray = new NSObject[response.Products.Length];
                NSObject[] productsArray   = new NSObject[response.Products.Length];
                for (int i = 0; i < response.Products.Length; i++)
                {
                    productIdsArray[i] = new NSString(response.Products[i].ProductIdentifier);
                    productsArray[i]   = response.Products[i];
                }
                userInfo = NSDictionary.FromObjectsAndKeys(productsArray, productIdsArray);
            }
            NSNotificationCenter.DefaultCenter.PostNotificationName(
                InAppQueryInventoryNotification,
                this,
                userInfo);

            foreach (string invalidProductId in response.InvalidProducts)
            {
                Debug.WriteLine("Invalid product id: " + invalidProductId);
            }
        }
Exemple #9
0
    public void ObjectSame()
    {
        var a = new SKProductsRequest("woot");
        var b = Runtime.GetNSObject <SKProductsRequest>(a.Handle);

        Assert.AreSame(a, b);
    }
Exemple #10
0
        public void Events()
        {
            using (var pr = new SKProductsRequest()) {
                Assert.Null(pr.WeakDelegate, "none");
                // event on SKProductsRequest itself
                pr.ReceivedResponse += (object sender, SKProductsRequestResponseEventArgs e) => {};

                var t = pr.WeakDelegate.GetType();
                Assert.That(t.Name, Is.EqualTo("_SKProductsRequestDelegate"), "delegate");

                var fi = t.GetField("receivedResponse", BindingFlags.NonPublic | BindingFlags.Instance);
                Assert.NotNull(fi, "receivedResponse");
                var value = fi.GetValue(pr.WeakDelegate);
                Assert.NotNull(value, "value");

#if XAMCORE_2_0
                // and on the SKRequest defined one
                pr.RequestFailed += (object sender, SKRequestErrorEventArgs e) => {};
                // and the existing (initial field) is still set
                fi = t.GetField("receivedResponse", BindingFlags.NonPublic | BindingFlags.Instance);
                Assert.NotNull(fi, "receivedResponse/SKRequest");
#else
                // In Classic SKRequest also defines a RequestFailed event, so make sure we get the SKRequest one
                // that's because event are re-defined (new) in classic
                ((SKRequest)pr).RequestFailed += (object sender, SKRequestErrorEventArgs e) => {};

                t = pr.WeakDelegate.GetType();
                Assert.That(t.Name, Is.EqualTo("_SKRequestDelegate"), "delegate-2");

                fi = t.GetField("receivedResponse", BindingFlags.NonPublic | BindingFlags.Instance);
                Assert.Null(fi, "receivedResponse/SKRequest");
#endif
            }
        }
Exemple #11
0
    public void GetIAPPrices()
    {
        if (Application.platform != RuntimePlatform.IPhonePlayer)
        {
            Debug.Log("Only supported on iOS!");
            return;
        }

        //NOTE: for this to work, your app's bundle ID should match what you have setup in iTunes Connect
        //	Each in-app purchase ID should be what you have setup in iTunes Connect also
        var request = new SKProductsRequest("com.yourcompany.iap1", "com.yourcompany.iap2");

        request.Failed += (sender, e) =>
        {
            Debug.Log("Error retrieviing prices: " + e.Error.LocalizedDescription);
        };
        request.ReceivedResponse += (sender, e) =>
        {
            //Invalid ones -- this will print out by default
            if (e.Response.InvalidProducts != null)
            {
                foreach (string invalidId in e.Response.InvalidProducts)
                {
                    Debug.Log("Invalid ID: " + invalidId);
                }
            }

            //Successful ones
            PrintProducts(e.Response.Products);
        };
        request.Start();
    }
        public async Task<SKProductsResponse> RequestProductData (params string[] productIds)
        {
            var array = new NSString[productIds.Length];
            for (var i = 0; i < productIds.Length; i++)
                array[i] = new NSString(productIds[i]);

            var tcs = new TaskCompletionSource<SKProductsResponse>();
            _productDataRequests.AddLast(tcs);

            try
            {
                var productIdentifiers = NSSet.MakeNSObjectSet<NSString>(array); //NSSet.MakeNSObjectSet<NSString>(array);​​​
                var productsRequest = new SKProductsRequest(productIdentifiers);
                productsRequest.ReceivedResponse += (sender, e) => tcs.SetResult(e.Response);
                productsRequest.RequestFailed += (sender, e) => tcs.SetException(new Exception(e.Error.LocalizedDescription));
                productsRequest.Start();
                var ret = await tcs.Task;
                productsRequest.Dispose();
                return ret;
            }
            finally
            {
                _productDataRequests.Remove(tcs);
                Console.WriteLine("Remaining: " + _productDataRequests.Count);
            }
        }
Exemple #13
0
        public void requestProUpgradeProductData()
        {
            NSSet productIdentifiers = NSSet.MakeNSObjectSet <NSString>(new NSString[] { new NSString(InAppPurchaseProUpgradeProductId) });

            productsRequest          = new SKProductsRequest(productIdentifiers);
            productsRequest.Delegate = this;
            productsRequest.Start();
        }
Exemple #14
0
        internal static void _OnProductRequestFail(object sender, SKRequest.DidFailEventArgs e)
        {
            if (_initializationFailedHandlers != null)
            {
                _initializationFailedHandlers(null, new InitializationEventArgs(_initializingProductIDs, e.error));
            }

            _request = null;
        }
Exemple #15
0
		public Task<SKProductsResponse> FetchProductInformationAsync (string[] ids)
		{
			var request = new SKProductsRequest (
				NSSet.MakeNSObjectSet (ids.Select (x => new NSString(x)).ToArray ()));
			var del = new TaskRequestDelegate ();
			request.Delegate = del;
			request.Start ();
			return del.Task;
		}
        public Task <SKProductsResponse> FetchProductInformationAsync(string[] ids)
        {
            var request = new SKProductsRequest(
                NSSet.MakeNSObjectSet(ids.Select(x => new NSString(x)).ToArray()));
            var del = new TaskRequestDelegate();

            request.Delegate = del;
            request.Start();
            return(del.Task);
        }
		// request multiple products at once
		public void RequestProductData (List<string> productIds)
		{
			NSString[] array = productIds.Select (pId => (NSString)pId).ToArray();
			NSSet productIdentifiers = NSSet.MakeNSObjectSet<NSString>(array);

			//set up product request for in-app purchase
			ProductsRequest  = new SKProductsRequest(productIdentifiers);
			ProductsRequest.Delegate = this; // SKProductsRequestDelegate.ReceivedResponse
			ProductsRequest.Start();
		}
Exemple #18
0
        // request multiple products at once
        public void RequestProductData(List <string> productIds)
        {
            NSString[] array = productIds.Select(pId => (NSString)pId).ToArray();
            NSSet      productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array);

            //set up product request for in-app purchase
            ProductsRequest          = new SKProductsRequest(productIdentifiers);
            ProductsRequest.Delegate = this;             // SKProductsRequestDelegate.ReceivedResponse
            ProductsRequest.Start();
        }
Exemple #19
0
            public override void ReceivedResponse(SKProductsRequest request, SKProductsResponse response)
            {
                SKProduct[] products = response.Products;

                foreach (string invalidProductId in response.InvalidProducts)
                {
                    Console.WriteLine("Invalid product id: {0}", invalidProductId);
                }

                _completionSource.SetResult(products);
            }
        public void ReceivedResponse(SKProductsRequest request, SKProductsResponse response)
        {
            var product = response.Products;

            if (product != null)
            {
                tcsResponse.TrySetResult(product);
                return;
            }

            tcsResponse.TrySetException(new InAppBillingPurchaseException(PurchaseError.InvalidProduct, "Invalid Product"));
        }
        public void ReceivedResponse(SKProductsRequest request, SKProductsResponse response)
        {
            var product = response.Products;

            if (product != null)
            {
                tcsResponse.TrySetResult(product);
                return;
            }

            tcsResponse.TrySetException(new Exception("Invalid Product"));
        }
		// received response to RequestProductData - with price,title,description info
		public override void ReceivedResponse (SKProductsRequest request, SKProductsResponse response)
		{
			SKProduct[] products = response.Products;

			NSMutableDictionary userInfo = new NSMutableDictionary ();
			for (int i = 0; i < products.Length; i++)
				userInfo.Add ((NSString)products [i].ProductIdentifier, products [i]);
			NSNotificationCenter.DefaultCenter.PostNotificationName (InAppPurchaseManagerProductsFetchedNotification, this, userInfo);

			foreach (string invalidProductId in response.InvalidProducts)
				Console.WriteLine ("Invalid product id: {0}", invalidProductId);
		}
 public async override Task <Purchase[]> GetPrices(params string[] ids)
 {
     using (var del = new RequestDelegate())
         using (var request = new SKProductsRequest(new NSSet(ids))
         {
             Delegate = del,
         })
         {
             request.Start();
             return(await del.Source.Task);
         }
 }
		public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
		{
			/*var vc = new MapKitViewController (this) {
				Autorotate = dvc.Autorotate
			};*/
			
			NetworkActivity = true;
			if ( SKPaymentQueue.CanMakePayments )
			{
				// Let's do it
				NSSet productIdentifiers  = NSSet.MakeNSObjectSet<NSString>(/*new NSString[]{new NSString("com.savagesoftwaresolutions.murdermap.subscription.monthly"), new NSString("com.savagesoftwaresolutions.com.murdermap.monthly")}*/ ProductIdentifiers);
				var request = new SKProductsRequest(productIdentifiers);
				
				request.ReceivedResponse += delegate(object sender, SKProductsRequestResponseEventArgs e) 
				{
					var root = new RootElement (Caption);
					var dvStore = new DialogViewController (root, true);
					var storeSection = new Section();
					
					root.Add(storeSection);
			
					
					foreach (var product in e.Response.Products) 
					{
						storeSection.Add(new StringElement(product.LocalizedTitle +":"+ product.PriceLocale ) );
					}
					
					dvc.ActivateController (dvStore);
				};
				
				request.RequestFailed += delegate(object sender, SKRequestErrorEventArgs e) 
				{					
					using (var msg = new UIAlertView ("Request Failed", e.Error.ToString(), null, "Ok")){
						msg.Show ();
					}
				};
				
				request.RequestFinished += delegate(object sender, EventArgs e) {
					NetworkActivity = false;
				};				
				
				request.Start();
			}
			else
			{
				using (var msg = new UIAlertView ("Unabled to Make Payments", "We are unable to connect to the Apple Store at this moment, to process your payments.\n Please try again later.", null, "Ok")){
					msg.Show ();
				}
			}
			
			NetworkActivity = false;
		}
        public override void Selected(DialogViewController dvc, UITableView tableView, NSIndexPath path)
        {
            /*var vc = new MapKitViewController (this) {
             *      Autorotate = dvc.Autorotate
             * };*/

            NetworkActivity = true;
            if (SKPaymentQueue.CanMakePayments)
            {
                // Let's do it
                NSSet productIdentifiers = NSSet.MakeNSObjectSet <NSString>(/*new NSString[]{new NSString("com.savagesoftwaresolutions.murdermap.subscription.monthly"), new NSString("com.savagesoftwaresolutions.com.murdermap.monthly")}*/ ProductIdentifiers);
                var   request            = new SKProductsRequest(productIdentifiers);

                request.ReceivedResponse += delegate(object sender, SKProductsRequestResponseEventArgs e)
                {
                    var root         = new RootElement(Caption);
                    var dvStore      = new DialogViewController(root, true);
                    var storeSection = new Section();

                    root.Add(storeSection);


                    foreach (var product in e.Response.Products)
                    {
                        storeSection.Add(new StringElement(product.LocalizedTitle + ":" + product.PriceLocale));
                    }

                    dvc.ActivateController(dvStore);
                };

                request.RequestFailed += delegate(object sender, SKRequestErrorEventArgs e)
                {
                    using (var msg = new UIAlertView("Request Failed", e.Error.ToString(), null, "Ok")){
                        msg.Show();
                    }
                };

                request.RequestFinished += delegate(object sender, EventArgs e) {
                    NetworkActivity = false;
                };

                request.Start();
            }
            else
            {
                using (var msg = new UIAlertView("Unabled to Make Payments", "We are unable to connect to the Apple Store at this moment, to process your payments.\n Please try again later.", null, "Ok")){
                    msg.Show();
                }
            }

            NetworkActivity = false;
        }
		// request multiple products at once
		public void RequestProductData (List<string> productIds)
		{
			var array = new NSString[productIds.Count];
			for (var i = 0; i < productIds.Count; i++) {
				array[i] = new NSString(productIds[i]);
			}
		 	NSSet productIdentifiers = NSSet.MakeNSObjectSet<NSString>(array);			

			//set up product request for in-app purchase
			productsRequest  = new SKProductsRequest(productIdentifiers);
			productsRequest.Delegate = this; // SKProductsRequestDelegate.ReceivedResponse
			productsRequest.Start();
		}
Exemple #27
0
        public void QueryInventory()
        {
            var array = new NSString[1];

            array[0] = new NSString(this.PracticeModeProductId);
            NSSet productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array);

            // Set up product request for in-app purchase to be handled in
            // SKProductsRequestDelegate.ReceivedResponse (see above)
            this._productsRequest          = new SKProductsRequest(productIdentifiers);
            this._productsRequest.Delegate = this;
            this._productsRequest.Start();
        }
        public virtual void ProductsRequestDidReceiveResponse(SKProductsRequest request, SKProductsResponse response)
        {
            NSArray products = response.Products;
            NSArray invalidProducts = response.InvalidProductIdentifiers;

            foreach(SKProduct product in products.GetEnumerator<SKProduct>()) {
                Console.WriteLine(product.ProductIdentifier);
                Console.WriteLine(product.LocalizedTitle);
                Console.WriteLine(product.LocalizedDescription);
                Console.WriteLine(product.Price);
            }

            request.Autorelease();
        }
Exemple #29
0
        Task <SKProduct> GetProductAsync(string productId)
        {
            var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(new NSString[] { new NSString(productId) });

            var productRequestDelegate = new ProductRequestDelegate();

            //set up product request for in-app purchase
            var productsRequest = new SKProductsRequest(productIdentifiers);

            productsRequest.Delegate = productRequestDelegate; // SKProductsRequestDelegate.ReceivedResponse
            productsRequest.Start();

            return(productRequestDelegate.WaitForResponse());
        }
        Task <IEnumerable <SKProduct> > GetProductAsync(string[] productId)
        {
            var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(productId.Select(i => new NSString(i)).ToArray());

            var productRequestDelegate = new ProductRequestDelegate();

            //set up product request for in-app purchase
            var productsRequest = new SKProductsRequest(productIdentifiers);

            productsRequest.Delegate = productRequestDelegate; // SKProductsRequestDelegate.ReceivedResponse
            productsRequest.Start();

            return(productRequestDelegate.WaitForResponse());
        }
Exemple #31
0
        public static async Task<SKProductsResponse> RequestProductData (params string[] productIds)
        {
            var array = new NSString[productIds.Length];
            for (var i = 0; i < productIds.Length; i++)
                array[i] = new NSString(productIds[i]);

            var tcs = new TaskCompletionSource<SKProductsResponse>();
            var productIdentifiers = NSSet.MakeNSObjectSet<NSString>(array); //NSSet.MakeNSObjectSet<NSString>(array);​​​
            var productsRequest = new SKProductsRequest(productIdentifiers);
            productsRequest.ReceivedResponse += (sender, e) => tcs.SetResult(e.Response);
            productsRequest.RequestFailed += (sender, e) => tcs.SetException(new Exception(e.Error.LocalizedDescription));
            productsRequest.Start();
            return await tcs.Task;
        }
Exemple #32
0
        public void RequestProductData(List <string> productIds)
        {
            var array = new NSString[productIds.Count];

            for (var i = 0; i < productIds.Count; i++)
            {
                array[i] = new NSString(productIds[i]);
            }
            NSSet productIdentifiers = NSSet.MakeNSObjectSet <NSString> (array);

            productsRequest          = new SKProductsRequest(productIdentifiers);
            productsRequest.Delegate = this;
            productsRequest.Start();
        }
Exemple #33
0
        // request multiple products at once
        public void RequestProductData(List <string> productIds)
        {
            var array = new NSString[productIds.Count];

            for (var i = 0; i < productIds.Count; i++)
            {
                array[i] = new NSString(productIds[i]);
            }
            NSSet productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array);

            //set up product request for in-app purchase
            productsRequest          = new SKProductsRequest(productIdentifiers);
            productsRequest.Delegate = this;             // SKProductsRequestDelegate.ReceivedResponse
            productsRequest.Start();
        }
Exemple #34
0
        public void RequestProductData(List <string> productIds, ProductResponseDelegate responseDelegate)
        {
            NSMutableSet setIds = new NSMutableSet();

            foreach (string s in productIds)
            {
                setIds.Add(new NSString(s));
            }

            this.responseDelegate = responseDelegate;

            productsRequest          = new SKProductsRequest(setIds);
            productsRequest.Delegate = this;
            productsRequest.Start();
        }
        /// <summary>
        /// Returns product info for the specified Ids
        /// </summary>
        /// <param name="productIds">Product Ids</param>
        /// <param name="productType">Product Type - not used for iOS</param>
        /// <returns></returns>
        public async Task <IEnumerable <Product> > LoadProductsAsync(string[] productIds, ProductType productType)
        {
            NSString[] nsProductIds = productIds.Select(i => new NSString(i)).ToArray();
            // Try to get Product List from the Store
            NSSet nsSetOfproductIds = NSSet.MakeNSObjectSet <NSString>(nsProductIds);

            // Create a Delegeate which will receieve product data.
            // The callback is async, so the TaskCompletionSource is used to wait for App Store to respond.
            ProductRequestDelegate productRequestDelegate = new ProductRequestDelegate();

            // Set up product request for in-app purchase
            SKProductsRequest productsRequest = new SKProductsRequest(nsSetOfproductIds);

            productsRequest.Delegate = productRequestDelegate;

            /* Here is how the EventHadler could be used instead of the Delegate
             * productsRequest.ReceivedResponse += (object sender, SKProductsRequestResponseEventArgs e) =>
             * {
             *  var products = e.Response.Products;
             *  var product = products[0];
             *  Console.WriteLine(
             *      $"{product.ProductIdentifier}, " +
             *      $"{product.LocalizedDescription}," +
             *      $"{product.PriceLocale.CurrencySymbol}{product.Price}");
             *
             *  //product.Discounts
             * };*/

            // Start the StoreKit Request. Products will be sent back to the Delegate function(s)
            productsRequest.Start();

            // Wait for the Delegate to get Products and signal the Task to be complete
            // For more about TaskCompletionSource read: https://devblogs.microsoft.com/pfxteam/the-nature-of-taskcompletionsourcetresult/
            SKProduct[] products = await productRequestDelegate.WaitForResponse();

            return(products.Select(p => new Product
            {
                FormattedPrice = p.LocalizedPrice(),
                MicrosPrice = (long)(p.Price.DoubleValue * 1000000d),
                Name = p.LocalizedTitle,
                ProductId = p.ProductIdentifier,
                Description = p.LocalizedDescription,
                CurrencyCode = p.PriceLocale?.CurrencyCode ?? string.Empty,
                LocalizedIntroductoryPrice = IsiOS112 ? (p.IntroductoryPrice?.LocalizedPrice() ?? string.Empty) : string.Empty,
                MicrosIntroductoryPrice = IsiOS112 ? (long)((p.IntroductoryPrice?.Price?.DoubleValue ?? 0) * 1000000d) : 0,
            }));
        }
        // received response to RequestProductData - with price,title,description info
        public override void ReceivedResponse(SKProductsRequest request, SKProductsResponse response)
        {
            SKProduct[] products = response.Products;

            if (products != null && products.Length > 0)
            {
                if (OnReceivedProductInformation != null)
                {
                    OnReceivedProductInformation(this, products);
                }
            }

            foreach (string invalidProductId in response.InvalidProducts)
            {
                Console.WriteLine("Invalid product id: {0}", invalidProductId);
            }
        }
Exemple #37
0
        // received response to RequestProductData - with price,title,description info
        public override void ReceivedResponse(SKProductsRequest request, SKProductsResponse response)
        {
            SKProduct[] products = response.Products;

            NSMutableDictionary userInfo = new NSMutableDictionary();

            for (int i = 0; i < products.Length; i++)
            {
                userInfo.Add((NSString)products [i].ProductIdentifier, products [i]);
            }
            NSNotificationCenter.DefaultCenter.PostNotificationName(InAppPurchaseManagerProductsFetchedNotification, this, userInfo);

            foreach (string invalidProductId in response.InvalidProducts)
            {
                Console.WriteLine("Invalid product id: {0}", invalidProductId);
            }
        }
Exemple #38
0
        /// <summary>
        /// Initializes IAPXT with an array of product IDs.
        /// </summary>
        /// <remarks>Raises InitializationCompleted event when completed, or InitializationFailed event when failed.</remarks>
        /// <param name="productIDs">Product IDs.</param>
        public static void Init(string[] productIDs)
        {
            // init observer here so the observer is observing only if the user wants to use the high-level API
            // add observer only once
            if (!_initd)
            {
                SKPaymentQueue.DefaultQueue().AddTransactionObserver(PaymentTransactionObserver.instance);
                _initd = true;
            }

            _initializingProductIDs = productIDs;
            _request = new SKProductsRequest(productIDs);
//			_request.Delegate = ProductsRequestDelegate.instance;
            _request.DidReceive += _OnProductRequestReceive;
            _request.DidFail    += _OnProductRequestFail;
            _request.Start();
        }
Exemple #39
0
        public static async Task <SKProductsResponse> RequestProductData(params string[] productIds)
        {
            var array = new NSString[productIds.Length];

            for (var i = 0; i < productIds.Length; i++)
            {
                array[i] = new NSString(productIds[i]);
            }

            var tcs = new TaskCompletionSource <SKProductsResponse>();
            var productIdentifiers = NSSet.MakeNSObjectSet <NSString>(array); //NSSet.MakeNSObjectSet<NSString>(array);​​​
            var productsRequest    = new SKProductsRequest(productIdentifiers);

            productsRequest.ReceivedResponse += (sender, e) => tcs.SetResult(e.Response);
            productsRequest.RequestFailed    += (sender, e) => tcs.SetException(new Exception(e.Error.LocalizedDescription));
            productsRequest.Start();
            return(await tcs.Task);
        }
		// received response to RequestProductData - with price,title,description info
		public override void ReceivedResponse (SKProductsRequest request, SKProductsResponse response)
		{
			SKProduct[] products = response.Products;

			NSDictionary userInfo = null;
			if (products.Length > 0) {
				NSObject[] productIdsArray = new NSObject[response.Products.Length];
				NSObject[] productsArray = new NSObject[response.Products.Length];
				for (int i = 0; i < response.Products.Length; i++) {
					productIdsArray[i] = new NSString(response.Products[i].ProductIdentifier);
					productsArray[i] = response.Products[i];
				}
				userInfo = NSDictionary.FromObjectsAndKeys (productsArray, productIdsArray);
			}
			NSNotificationCenter.DefaultCenter.PostNotificationName(InAppPurchaseManagerProductsFetchedNotification,this,userInfo);

			foreach (string invalidProductId in response.InvalidProducts) {
				Console.WriteLine("Invalid product id: " + invalidProductId );
			}
		}
		// request multiple products at once
		public void RequestProductData (List<string> productIds)
		{
			NetworkStatus internetStatus = Reachability.InternetConnectionStatus ();
			if (internetStatus == NetworkStatus.NotReachable) {

				NSNotificationCenter.DefaultCenter.PostNotificationName (NoInternetNotification, null);
				Console.WriteLine ("No Internet");
			} else {
				var array = new NSString[productIds.Count];
				for (var i = 0; i < productIds.Count; i++) {
					array [i] = new NSString (productIds [i]);
				}
				NSSet productIdentifiers = NSSet.MakeNSObjectSet<NSString> (array);			

				//set up product request for in-app purchase

				productsRequest = new SKProductsRequest (productIdentifiers);
				productsRequest.Delegate = this; // SKProductsRequestDelegate.ReceivedResponse
				productsRequest.Start ();
			}
		}
Exemple #42
0
        internal static void _OnProductRequestReceive(object sender, SKProductsRequest.DidReceiveEventArgs e)
        {
            foreach (var productObj in e.response.products) {
                var product = productObj as SKProduct;
                _products[product.productIdentifier] = product;
            }

            // raise event
            if ((e.response.invalidProductIdentifiers == null) || (e.response.invalidProductIdentifiers.Length == 0)) {
                if (_initializationCompletedHandlers != null)
                    _initializationCompletedHandlers(null, new InitializationEventArgs(e.response));
            } else {
                if (_initializationFailedHandlers != null)
                    _initializationFailedHandlers(null, new InitializationEventArgs(e.response));
            }

            _request = null;
        }
 private void RequestProducts()
 {
     // List all the products to retrieve
     SKProductsRequest request = new SKProductsRequest(NSSet.SetWithObjects((NSString)"CONSUMABLE", (NSString)"NON_CONSUMABLE", null));
     request.Delegate = this;
     request.Start();
 }
        public override void RequestProductInformation(string[] productIds, ProductInformationDelegate onSucceed, RequestFailedDelegate onFailed)
        {
            if (productIds == null || productIds.Length == 0)
                throw new ArgumentException("InAppPurchaseManager: At least one product id is required.");

            try
            {
                var products = new NSString[productIds.Length];
                for (int i = 0; i < productIds.Length; i++)
                {
                    products[i] = new NSString(productIds[i]);
                }
                NSSet productIdentifiers = NSSet.MakeNSObjectSet<NSString>(products);

                if (productsRequestDelegate == null)
                {
                    productsRequestDelegate = new ProductsRequestDelegate(onSucceed, onFailed);
                }

                SKProductsRequest productsRequest = new SKProductsRequest(productIdentifiers);
                productsRequest.Delegate = productsRequestDelegate;
                productsRequest.Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                if (onFailed != null)
                {
                    onFailed(new InAppPurchaseException("Error while requesting product information.", 0, ex));
                }
            }
        }
            public override void ReceivedResponse(SKProductsRequest request, SKProductsResponse response)
            {
                try
                {
                    if (response == null && onFailed != null)
                    {
                        onFailed(new InAppPurchaseException("Invalid response", 0));
                        Console.WriteLine("InAppPurchaseManager: ReceivedResponse: SKProductsResponse is null!");
                    }
                    else
                    {
                        List<ProductInformation> products = new List<ProductInformation>();

                        foreach (SKProduct product in response.Products)
                        {
                            SKProductInformation pi = new SKProductInformation(product);
                            pi.Title = product.LocalizedTitle;
                            pi.Description = product.Description;
                            pi.Price = product.Price.FloatValue;
                            pi.LocalizedPrice = product.LocalizedPrice();
                            //pi.IsDownloadable = product.Downloadable;
                            //pi.DownloadContentVersion = product.DownloadContentVersion;
                            products.Add(pi);
                        }

                        if (onSucceed != null)
                        {
                            onSucceed(products.ToArray(), response.InvalidProducts);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (onFailed != null)
                    {
                        onFailed(new InAppPurchaseException("Error while requesting product information.", 0, ex));
                    }
                }
            }
Exemple #46
0
			public override void ReceivedResponse (SKProductsRequest request, SKProductsResponse response)
			{
				tcs.SetResult (response);
			}
        private void RequestProductDetails()
        {
            if (this.products.Values.All(o => o.HasValidCache() || o.State == ProductState.Invalid || o.State == ProductState.Purchased))
                return;

            // If an existing request is in then progress cancel it
            var currentRequest = this.productsRequest;
            if (currentRequest != null)
                currentRequest.Cancel();

            var productIdentifiers = NSSet.MakeNSObjectSet<NSString>(
                this.products.Where(o => o.Value.State == ProductState.Loaded || o.Value.State == ProductState.Unknown).Select(o => new NSString(o.Key)).ToArray());                        

            this.productsRequest = new SKProductsRequest(productIdentifiers);
            this.productsRequest.Delegate = this.productsRequestDelegate; // SKProductsRequestDelegate.ReceivedResponse
            this.productsRequest.Start();
        }
Exemple #48
0
        /// <summary>
        /// Initializes IAPXT with an array of product IDs.
        /// </summary>
        /// <remarks>Raises InitializationCompleted event when completed, or InitializationFailed event when failed.</remarks>
        /// <param name="productIDs">Product IDs.</param>
        public static void Init(string[] productIDs)
        {
            // init observer here so the observer is observing only if the user wants to use the high-level API
            // add observer only once
            if (!_initd) {
                SKPaymentQueue.DefaultQueue().AddTransactionObserver(PaymentTransactionObserver.instance);
                _initd = true;
            }

            _initializingProductIDs = productIDs;
            _request = new SKProductsRequest(productIDs);
            //			_request.Delegate = ProductsRequestDelegate.instance;
            _request.DidReceive += _OnProductRequestReceive;
            _request.DidFail += _OnProductRequestFail;
            _request.Start();
        }
            public override void ReceivedResponse(SKProductsRequest request, SKProductsResponse response)
            {
                if (SingleManager.productsRequest == request)
                    SingleManager.productsRequest = null;

                var changed = false;
                foreach (var product in response.Products)
                {
                    ProductDetails details;
                    if (SingleManager.products.TryGetValue(product.ProductIdentifier, out details))
                    {
                        details.SetDetails(product);
                        changed = true;
                    }
                }

                foreach (var product in response.InvalidProducts)
                {
                    ProductDetails details;
                    if (SingleManager.products.TryGetValue(product, out details))
                    {
                        details.SetInvalid();
                        changed = true;
                    }
                }

                // Check that all products have details - if not reload
                SingleManager.RequestProductDetails();

                if (changed)
                    SingleManager.RaiseDetailsChanged();
            }
Exemple #50
0
        internal static void _OnProductRequestFail(object sender, SKRequest.DidFailEventArgs e)
        {
            if (_initializationFailedHandlers != null)
                _initializationFailedHandlers(null, new InitializationEventArgs(_initializingProductIDs, e.error));

            _request = null;
        }
        public override void ReceivedResponse(SKProductsRequest request, SKProductsResponse response)
        {
            SKProduct[] products = response.Products;
            proUpgradeProduct = products.Length == 1 ? products[0] : null;
            if (proUpgradeProduct != null)
            {
                proUpgradeProduct.LocalizedPrice();
                Console.WriteLine("Product title: " + proUpgradeProduct.LocalizedTitle);
                Console.WriteLine("Product description: " + proUpgradeProduct.LocalizedDescription);
                Console.WriteLine("Product price: " + proUpgradeProduct.LocalizedPrice());
                Console.WriteLine("Product id: " + proUpgradeProduct.ProductIdentifier);
            }

            foreach(string invalidProductId in response.InvalidProducts)
            {
                Console.WriteLine("Invalid product id: " + invalidProductId );
            }

            // finally release the reqest we alloc/init’ed in requestProUpgradeProductData
            productsRequest.Dispose();

            NSNotificationCenter.DefaultCenter.PostNotificationName(InAppPurchaseManagerProductsFetchedNotification,this,null);
        }
 public void requestProUpgradeProductData()
 {
     NSSet productIdentifiers  = NSSet.MakeNSObjectSet<NSString>(new NSString[]{new NSString(InAppPurchaseProUpgradeProductId)});
     productsRequest  = new SKProductsRequest(productIdentifiers);
     productsRequest.Delegate = this;
     productsRequest.Start();
 }
Exemple #53
0
        public void QueryInventory()
        {
            var array = new NSString[1];
            array[0] = new NSString(this.PracticeModeProductId);
            NSSet productIdentifiers = NSSet.MakeNSObjectSet<NSString>(array);

            // Set up product request for in-app purchase to be handled in
            // SKProductsRequestDelegate.ReceivedResponse (see above)
            this._productsRequest = new SKProductsRequest(productIdentifiers);
            this._productsRequest.Delegate = this;
            this._productsRequest.Start();
        }
 public override void DidReceive(SKProductsRequest request, SKProductsResponse response)
 {
     //			IAPXT._OnProductResponse(response);
 }