示例#1
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();
        }
示例#2
0
        /// <summary>
        /// Buy a product with specified productID and quantity.
        /// </summary>
        /// <remarks>
        /// This method starts a transaction with the server.
        /// If the DisplayActivityIndicator property is true, a semi-transparent native activity indicator view with label
        /// would cover the entire screen, blocking any user input from Unity.
        /// If you set the DisplayActivityIndicator property to false, you should provide a similar view blocking input
        /// during the purchase process so the user cannot start another purchase at the same time, for example.
        /// <p></p>
        /// On transaction complete, it raises either the TransactionCompleted or TransactionFailed event.
        /// On TransactionCompleted event, you should provide content to the user for what they have just bought.
        /// On TransactionFailed event, you can display an error message to the user.
        /// If the product has hosted download on Apple servers (available iOS 6.0 and later),
        /// the content would have been extracted and moved to app-storage:/downloads/[productID]/ by the time this event is raised.
        /// You can then move it somewhere else or use it as it is.
        /// </remarks>
        /// <returns><c>true</c> if a transaction has started; <c>false</c> otherwise.</returns>
        /// <param name="productID">The product to buy.</param>
        /// <param name="quantity">The quantity of the product to buy; it should be 1 for non-consumables.</param>
        public static bool Buy(string productID, int quantity = 1)
        {
            if (quantity <= 0)
            {
                return(false);
            }

            var product = GetProduct(productID);

            if (product == null)
            {
                return(false);
            }

            _ShowActivityIndicator("   Purchasing...");

            var payment = SKMutablePayment.Payment(product);

            payment.quantity = quantity;
            SKPaymentQueue.DefaultQueue().AddPayment(payment);

            return(true);
        }
示例#3
0
 /// <summary>
 /// Restores all completed products that the user has bought.
 /// It's similar to Buy() in that it starts transactions. So it raises to the same events on transaction completion.
 /// Additionally, it raises RestorationCompleted and RestorationFailed events on completion.
 /// </summary>
 /// <seealso cref="Buy"/>
 public static void RestoreCompletedTransactions()
 {
     SKPaymentQueue.DefaultQueue().RestoreCompletedTransactions();
 }
示例#4
0
//		/// <summary>
//		/// The array of pending transactions.
//		/// These are the transactions that have started but not yet called finished.
//		/// </summary>
//		/// <value>The pending transactions.</value>
//		[Obsolete("Use the pendingTransactions property.")]
//		public static SKPaymentTransaction[] PendingTransactions {
//			get {
//				return SKPaymentQueue.DefaultQueue().transactions.Cast<SKPaymentTransaction>().ToArray();
//			}
//		}

        private static void _Download(object[] downloads)
        {
            _ShowActivityIndicator("   Downloading...\n0%");
            SKPaymentQueue.DefaultQueue().StartDownloads(downloads);
        }
示例#5
0
        private static void _FinishTransaction(SKPaymentTransaction transaction)
        {
            SKPaymentQueue.DefaultQueue().FinishTransaction(transaction);

            _HideActivityIndicator();
        }