Ejemplo n.º 1
0
        public void paymentQueue_updatedTransactions_(SKPaymentQueue queue, NSArray <SKPaymentTransaction> transactions)
        {
            LOG("paymentQueue:updatedTransactions: ");

            foreach (var transaction in transactions)
            {
                var productId = transaction.Payment.ProductIdentifier.ToString();
                var state     = transaction.TransactionState;
                if (state == SKPaymentTransaction.SKPaymentTransactionStatePurchased)
                {
                    LOG("SKPaymentTransactionStatePurchased, " + productId);
                    queue.FinishTransaction(transaction);
                }
                else if (state == SKPaymentTransaction.SKPaymentTransactionStateRestored)
                {
                    LOG("SKPaymentTransactionStateRestored, " + productId);
                    queue.FinishTransaction(transaction);
                }
                else if (state == SKPaymentTransaction.SKPaymentTransactionStateFailed)
                {
                    LOG("SKPaymentTransactionStateFailed, " + productId + ", " + transaction.Error.LocalizedDescription);
                    queue.FinishTransaction(transaction);
                }
            }
        }
Ejemplo n.º 2
0
		public override async void UpdatedTransactions (SKPaymentQueue queue, SKPaymentTransaction[] transactions)
		{
			if (transactions == null)
				return;
			try {
				foreach (var t in transactions) {
					try {
						Console.WriteLine ("STORE Transaction: {0} {1} {2} {3} {4}", t.Payment.ProductIdentifier, t.TransactionState, t.TransactionIdentifier, t.TransactionDate, t.Error);
						switch (t.TransactionState) {
						case SKPaymentTransactionState.Purchased:
							productsPurchased.Add (t);
							await CompleteTransactionAsync (t);
							break;
						case SKPaymentTransactionState.Restored:
							productsRestored.Add (t);
							await CompleteTransactionAsync (t);
							break;
						case SKPaymentTransactionState.Failed:
							await CompleteTransactionAsync (t);
							break;
						}
					} catch (Exception ex) {
						Log.Error (ex);
					}
				}
			} catch (Exception ex) {
				Log.Error (ex);
			}
		}
Ejemplo n.º 3
0
        UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
        {
            foreach (SKPaymentTransaction transaction in transactions)
            {
                switch (transaction.TransactionState)
                {
                case SKPaymentTransactionState.Purchased:

                    TransactionStatusChanged?.Invoke(
                        this,
                        new TransactionStatusArgs(
                            transaction.TransactionIdentifier,
                            transaction.Payment.ProductIdentifier,
                            TransactionStatus.Purchased));

                    // remove the transaction from the payment queue.
                    SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                    break;

                case SKPaymentTransactionState.Failed:
                    TransactionStatusChanged?.Invoke(
                        this,
                        new TransactionStatusArgs(
                            transaction.TransactionIdentifier,
                            transaction.Payment.ProductIdentifier,
                            TransactionStatus.Failed));
                    SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 4
0
            public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
            {
                foreach (SKPaymentTransaction transaction in transactions)
                {
                    try
                    {
                        switch (transaction.TransactionState)
                        {
                        case SKPaymentTransactionState.Purchased:
                            _inAppPurchases.CompleteTransaction(transaction);
                            break;

                        case SKPaymentTransactionState.Failed:
                            _inAppPurchases.FailedTransaction(transaction);
                            break;

                        case SKPaymentTransactionState.Restored:
                            _inAppPurchases.RestoreTransaction(transaction);
                            break;

                        default:
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        MonoTouch.Utilities.ShowAlert("Error", "Unable to process transaction: " + e.Message);
                        e.Report();
                    }
                }
            }
Ejemplo n.º 5
0
 public override void RestoreCompletedTransactionsFailedWithError(SKPaymentQueue queue, NSError error)
 {
     if (error.Code != 2)
     {
         _inAppPurchases._actionSource?.TrySetException(new Exception(error.LocalizedDescription));
     }
 }
		// called when the transaction status is updated
		public override void UpdatedTransactions (SKPaymentQueue queue, SKPaymentTransaction[] transactions)
		{
			Console.WriteLine ("Updating Transactions in Custom Payment Observer");
			foreach (SKPaymentTransaction transaction in transactions)
			{
			    switch (transaction.TransactionState)
			    {
				case SKPaymentTransactionState.Purchased:
					theManager.CompleteTransaction (transaction);
					Console.WriteLine ("purchased status");
			            break;
				case SKPaymentTransactionState.Failed:
					theManager.FailedTransaction (transaction);
					Console.WriteLine ("failed status");
			            break;
				case SKPaymentTransactionState.Restored:
					theManager.RestoreTransaction (transaction);
					Console.WriteLine ("restored status");
			            break;
				default:
					Console.WriteLine ("other status");
			            break;
			    }
			}
		}
Ejemplo n.º 7
0
            public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
            {
                foreach (SKPaymentTransaction transaction in transactions)
                {
                    try
                    {
                        switch (transaction.TransactionState)
                        {
                        case SKPaymentTransactionState.Purchased:
                            _inAppPurchases.CompleteTransaction(transaction);
                            SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                            break;

                        case SKPaymentTransactionState.Failed:
                            _inAppPurchases.FailedTransaction(transaction);
                            SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                            break;

                        case SKPaymentTransactionState.Restored:
                            _inAppPurchases.RestoreTransaction(transaction);
                            SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                            break;

                        default:
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        IoC.Resolve <IAlertDialogService>().Alert("Error", "Unable to process transaction: " + e.Message);
                    }
                }
            }
		/// <Docs>
		/// New iOS 6 method to track downloads of hosted-content
		/// </Docs>
		public override void UpdatedDownloads (SKPaymentQueue queue, SKDownload[] downloads)
		{
			Console.WriteLine (" -- PaymentQueueUpdatedDownloads");
			foreach (SKDownload download in downloads) {
				switch (download.DownloadState) {
				case SKDownloadState.Active:
					Console.WriteLine ("Download progress:" + download.Progress);
					Console.WriteLine ("Time remaining:   " + download.TimeRemaining);
					break;
				case SKDownloadState.Finished:
					Console.WriteLine ("Finished!!!!");
					Console.WriteLine ("Content URL:" + download.ContentUrl);

					// UNPACK HERE!
					theManager.SaveDownload (download);

					break;
				case SKDownloadState.Failed:
					Console.WriteLine ("Failed");
					break;
				case SKDownloadState.Cancelled:
					Console.WriteLine ("Cancelled");
					break;
				case SKDownloadState.Paused:
				case SKDownloadState.Waiting:
					break;
				default:
					break;
				}
			}
		}
        public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
        {
            var rt = transactions.Where(pt => pt.TransactionState == SKPaymentTransactionState.Restored);

            // Add our restored transactions to the list
            // We might still get more from the initial request so we won't raise the event until
            // RestoreCompletedTransactionsFinished is called
            if (rt?.Any() ?? false)
            {
                restoredTransactions.AddRange(rt);
            }

            foreach (SKPaymentTransaction transaction in transactions)
            {
                switch (transaction.TransactionState)
                {
                case SKPaymentTransactionState.Purchased:
                    TransactionCompleted?.Invoke(transaction, true);
                    break;

                case SKPaymentTransactionState.Failed:
                    TransactionCompleted?.Invoke(transaction, false);
                    break;

                default:
                    break;
                }
            }
        }
		/// <summary>
		/// Called when the transaction status is updated
		/// </summary>
		public override void UpdatedTransactions (SKPaymentQueue queue, SKPaymentTransaction[] transactions)
		{
			Console.WriteLine ("UpdatedTransactions");
			foreach (SKPaymentTransaction transaction in transactions) {
			    switch (transaction.TransactionState) {
			        case SKPaymentTransactionState.Purchased:
						if (transaction.Downloads != null && transaction.Downloads.Length > 0) {
							// complete the transaction AFTER downloading
							SKPaymentQueue.DefaultQueue.StartDownloads (transaction.Downloads);
						} else {
							// complete the transaction now
			         	  theManager.CompleteTransaction(transaction);
						}
			            break;
			        case SKPaymentTransactionState.Failed:
			           theManager.FailedTransaction(transaction);
			            break;
			        case SKPaymentTransactionState.Restored:
			            theManager.RestoreTransaction(transaction);
			            break;
			        default:
			            break;
			    }
			}
		}
Ejemplo n.º 11
0
        // called when the transaction status is updated
        public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
        {
            Console.WriteLine("UpdatedTransactions");
            foreach (SKPaymentTransaction transaction in transactions)
            {
                switch (transaction.TransactionState)
                {
                case SKPaymentTransactionState.Purchasing:
                    Console.WriteLine("Purchasing");
                    break;

                case SKPaymentTransactionState.Purchased:
                    theManager.CompleteTransaction(transaction);
                    break;

                case SKPaymentTransactionState.Deferred:
                    Console.WriteLine("Deferred");
                    break;

                case SKPaymentTransactionState.Failed:
                    theManager.FailedTransaction(transaction);
                    break;

                case SKPaymentTransactionState.Restored:
                    theManager.RestoreTransaction(transaction);
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 12
0
            public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
            {
                foreach (SKPaymentTransaction transaction in transactions)
                {
                    try
                    {
                        switch (transaction.TransactionState)
                        {
                        case SKPaymentTransactionState.Purchased:
                            _inAppPurchases.CompleteTransaction(transaction);
                            SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                            break;

                        case SKPaymentTransactionState.Failed:
                            _inAppPurchases.FailedTransaction(transaction);
                            SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                            break;

                        case SKPaymentTransactionState.Restored:
                            _inAppPurchases.RestoreTransaction(transaction);
                            SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                            break;

                        default:
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        _inAppPurchases._errorSubject.OnNext(e);
                    }
                }
            }
        public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
        {
            foreach (var transaction in transactions)
            {
                if (transaction?.TransactionState == null)
                {
                    break;
                }

                switch (transaction.TransactionState)
                {
                case SKPaymentTransactionState.Restored:
                case SKPaymentTransactionState.Purchased:
                    this.TransactionCompleted?.Invoke(transaction, true);
                    SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                    break;

                case SKPaymentTransactionState.Failed:
                    this.TransactionCompleted?.Invoke(transaction, false);
                    SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                    break;

                default: break;
                }
            }
        }
Ejemplo n.º 14
0
 public override void RemovedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
 {
     foreach (var transaction in transactions)
     {
         SingleManager.PaymentQueue.FinishTransaction(transaction);
     }
 }
        public override void RestoreCompletedTransactionsFinished(SKPaymentQueue queue)
        {
            Debug.WriteLine("RestoreCompletedTransactionsFinished called...");

            try
            {
                // This is called after all restored transactions have hit UpdatedTransactions and are removed from the Queue
                // Convert all Restored transactions to the InAppBillingPurchases and return
                List <InAppPurchaseResult> purchases = _restoredTransactions.Select(rt =>
                                                                                    rt.ToInAppPurchase()).ToList();

                // Clear out the list of incoming restore transactions for future requests
                _restoredTransactions.Clear();

                _transactionsRestored?.TrySetResult(purchases);
                _transactionsRestored = null;
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception {ex.ToString()}");

                _transactionsRestored?.TrySetException(new InAppPurchaseException(PurchaseError.Unknown, ex.ToString()));
                _transactionsRestored = null;
            }
        }
Ejemplo n.º 16
0
        public static bool RestoreTransaction(SKPaymentQueue queue)
        {
            var    count         = queue.Transactions.Length;
            string restoredItems = "";

            foreach (var trans in queue.Transactions)
            {
                Console.WriteLine(" ** RESTORE {0} ", trans.Payment.ProductIdentifier);
                string restoredID = ProcessRestoredItem(trans);
                if (string.IsNullOrEmpty(restoredID))
                {
                    continue;
                }
                MarkPurchased(restoredID);

                if (!string.IsNullOrWhiteSpace(restoredItems))
                {
                    restoredItems += ",";
                }
                restoredItems += restoredID;
            }
            IAPOK?.Invoke(restoredItems);

            return(count > 0);
        }
        /// <summary>
        /// Called when the transaction status is updated
        /// </summary>
        public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
        {
            Console.WriteLine("UpdatedTransactions");
            foreach (SKPaymentTransaction transaction in transactions)
            {
                switch (transaction.TransactionState)
                {
                case SKPaymentTransactionState.Purchased:
                    if (transaction.Downloads != null && transaction.Downloads.Length > 0)
                    {
                        // complete the transaction AFTER downloading
                        SKPaymentQueue.DefaultQueue.StartDownloads(transaction.Downloads);
                    }
                    else
                    {
                        // complete the transaction now
                        theManager.CompleteTransaction(transaction);
                    }
                    break;

                case SKPaymentTransactionState.Failed:
                    theManager.FailedTransaction(transaction);
                    break;

                case SKPaymentTransactionState.Restored:
                    theManager.RestoreTransaction(transaction);
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 18
0
 public override void RestoreCompletedTransactionsFailedWithError(SKPaymentQueue queue, NSError error)
 {
     Console.WriteLine(" ** RESTORE RestoreCompletedTransactionsFailedWithError " + error.LocalizedDescription);
     if (_inAppPurchases._actionSource != null)
     {
         _inAppPurchases._actionSource.TrySetResult(true);
     }
 }
Ejemplo n.º 19
0
 public override void RestoreCompletedTransactionsFailedWithError(SKPaymentQueue queue, NSError error)
 {
     _completionSource.TrySetResult(new PurchaseResponse()
     {
         Success = false,
         Error   = error.LocalizedDescription
     });
 }
Ejemplo n.º 20
0
            //            public override void RemovedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
            //            {
            //                foreach (var t in transactions)
            //                {
            //                    Console.WriteLine("Uh oh: " + t.TransactionState);
            //
            //                }
            //            }

            public override void PaymentQueueRestoreCompletedTransactionsFinished(SKPaymentQueue queue)
            {
                Console.WriteLine(" ** RESTORE PaymentQueueRestoreCompletedTransactionsFinished ");
                if (_inAppPurchases._actionSource != null)
                {
                    _inAppPurchases._actionSource.TrySetResult(true);
                }
            }
 //public override void PaymentQueueRestoreCompletedTransactionsFinished (SKPaymentQueue queue)
 //{
 //    // Restore succeeded
 //    Console.WriteLine(" ** RESTORE PaymentQueueRestoreCompletedTransactionsFinished ");
 //    if (CompleteTransactionCallback != null)
 //    {
 //        CompleteTransactionCallback("", true);
 //    }
 //}
 public override void RestoreCompletedTransactionsFailedWithError(SKPaymentQueue queue, NSError error)
 {
     // Restore failed somewhere...
     Console.WriteLine(" ** RESTORE RestoreCompletedTransactionsFailedWithError " + error.LocalizedDescription);
     if (CompleteTransactionCallback != null)
     {
         CompleteTransactionCallback(error.LocalizedDescription, false);
     }
 }
Ejemplo n.º 22
0
 public override void RestoreCompletedTransactionsFinished(SKPaymentQueue queue)
 {
     // If it restored, it should have already been set (so this call will do nothing). Otherwise, there was nothing to restore.
     _completionSource.TrySetResult(new PurchaseResponse()
     {
         Success = false,
         Error   = "No previous purchases to restore."
     });
 }
Ejemplo n.º 23
0
 public override void RestoreCompletedTransactionsFailedWithError(SKPaymentQueue queue, NSError error)
 {
     InvokeOnMainThread(() => {
         UIAlertView alert = new UIAlertView("Error",
                                             "Unable to restore purchase.",
                                             null, "Ok", null);
         alert.Show();
     });
 }
        public override void RestoreCompletedTransactionsFinished(SKPaymentQueue queue)
        {
            // This is called after all restored transactions have hit UpdatedTransactions
            // at this point we are done with the restore request so let's fire up the event
            var rt = restoredTransactions.ToArray();

            // Clear out the list of incoming restore transactions for future requests
            restoredTransactions.Clear();

            TransactionsRestored?.Invoke(rt);
        }
        public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
        {
            foreach (var transaction in transactions)
            {
                //NOTE: you have to call "Finish" on every state
                if (transaction.TransactionState != SKPaymentTransactionState.Purchasing)
                {
                    SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                }

                TaskCompletionSource <Receipt> source;
                if (Sources.TryGetValue(transaction.Payment.ProductIdentifier, out source))
                {
                    switch (transaction.TransactionState)
                    {
                    case SKPaymentTransactionState.Failed:
                        source.TrySetException(new Exception(transaction.Error?.LocalizedDescription ?? "Unknown Error"));
                        break;

                    case SKPaymentTransactionState.Purchased:
                    case SKPaymentTransactionState.Restored:

                        //First make sure the receipt exists
                        var url = NSBundle.MainBundle.AppStoreReceiptUrl;
                        if (!NSFileManager.DefaultManager.FileExists(url.Path))
                        {
                            source.TrySetException(new Exception("No app store receipt file found!"));
                            return;
                        }

                        //If the NSData is null
                        var data = NSData.FromUrl(url);
                        if (data == null)
                        {
                            source.TrySetException(new Exception("Could not load app store receipt!"));
                            return;
                        }

                        var receipt = new AppleReceipt
                        {
                            BundleId      = NSBundle.MainBundle.BundleIdentifier,
                            Id            = transaction.Payment.ProductIdentifier,
                            TransactionId = transaction.TransactionIdentifier,
                            Data          = data.ToArray(),
                        };
                        source.TrySetResult(receipt);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Ejemplo n.º 26
0
            public override void RestoreCompletedTransactionsFailedWithError(SKPaymentQueue queue, NSError error)
            {
                this.Log().Debug("Restore completed with error: " + error);

                if (error.Code == 2)
                {
                    _inAppPurchases._restoreSource?.TrySetCanceled();
                }
                else
                {
                    var errorMessage = error.LocalizedDescription ?? "Unable to restore purchase due to unknown reason.";
                    _inAppPurchases._restoreSource?.TrySetException(new Exception(errorMessage));
                }
            }
Ejemplo n.º 27
0
            /// <summary>
            /// Called when the transaction status is updated
            /// </summary>
            /// <param name="queue"></param>
            /// <param name="transactions"></param>
            public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
            {
                foreach (var t in transactions)
                {
                    if ((t.OriginalTransaction?.Payment?.ProductIdentifier != null && t.OriginalTransaction.Payment.ProductIdentifier.Equals(_appStoreProductId)) ||
                        (t.Payment?.ProductIdentifier != null && t.Payment.ProductIdentifier.Equals(_appStoreProductId)))
                    {
                        if (t.TransactionState == SKPaymentTransactionState.Purchased || t.TransactionState == SKPaymentTransactionState.Restored)
                        {
                            SKPaymentQueue.DefaultQueue.FinishTransaction(t);

                            // Persist on iOS, since we didn't implement looking up purchases
                            PowerPlannerAppDataLibrary.Helpers.Settings.OwnsInAppPurchase = true;

                            var currAccount = PowerPlannerApp.Current.GetCurrentAccount();

                            if (currAccount != null)
                            {
                                var dontBlock = Sync.SetAsPremiumAccount(currAccount);
                            }

                            _completionSource.TrySetResult(new PurchaseResponse()
                            {
                                Success = true
                            });
                            return;
                        }

                        else if (t.TransactionState == SKPaymentTransactionState.Failed)
                        {
                            SKPaymentQueue.DefaultQueue.FinishTransaction(t);
                            _completionSource.TrySetResult(new PurchaseResponse()
                            {
                                Success = false,
                                Error   = t.Error.LocalizedDescription
                            });
                        }
                    }
                }

                if (transactions.Length == 0)
                {
                    _completionSource.TrySetResult(new PurchaseResponse()
                    {
                        Success = false,
                        Error   = "No previous purchases to restore."
                    });
                }
            }
 public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
 {
     foreach (var transaction in transactions)
     {
         switch (transaction.TransactionState)
         {
             case SKPaymentTransactionState.Purchased:
             case SKPaymentTransactionState.Restored:
                 OnTransactionPurchased(transaction);
                 break;
             case SKPaymentTransactionState.Failed:
                 OnTransactionFailed(transaction);
                 break;
         }
     }
 }
Ejemplo n.º 29
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 UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
        {
            var rt = transactions.Where(pt => pt.TransactionState == SKPaymentTransactionState.Restored);

            // Add our restored transactions to the list
            // We might still get more from the initial request so we won't raise the event until
            // RestoreCompletedTransactionsFinished is called
            if (rt?.Any() ?? false)
            {
                restoredTransactions.AddRange(rt);
            }

            foreach (var transaction in transactions)
            {
                if (transaction?.TransactionState == null)
                {
                    break;
                }

                Debug.WriteLine($"Updated Transaction | {transaction.ToStatusString()}");

                switch (transaction.TransactionState)
                {
                case SKPaymentTransactionState.Restored:
                case SKPaymentTransactionState.Purchased:
                    TransactionCompleted?.Invoke(transaction, true);

                    if (TransactionCompleted != null)
                    {
                        onPurchaseSuccess?.Invoke(transaction.ToIABPurchase());
                    }

                    SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                    break;

                case SKPaymentTransactionState.Failed:
                    TransactionCompleted?.Invoke(transaction, false);
                    SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 31
0
        // called when the transaction status is updated
        public override async void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
        {
            foreach (var transaction in transactions)
            {
                switch (transaction.TransactionState)
                {
                case SKPaymentTransactionState.Purchased:
                    _result.Add(
                        new PurchaseResult {
                        Result            = TransactionResult.Purchased,
                        PurchaseDate      = transaction.TransactionDate.ToDateTime(),
                        AppStoreProductID = transaction.Payment.ProductIdentifier
                    }
                        );
                    break;

                case SKPaymentTransactionState.Failed:
                    _result.Add(
                        new PurchaseResult {
                        Result            = TransactionResult.Failed,
                        AppStoreProductID = transaction.Payment.ProductIdentifier
                    }
                        );
                    break;

                case SKPaymentTransactionState.Restored:
                    _result.Add(
                        new PurchaseResult {
                        Result            = TransactionResult.Restored,
                        AppStoreProductID = transaction.Payment.ProductIdentifier,
                        PurchaseDate      = transaction.OriginalTransaction.TransactionDate.ToNullableDateTime()
                    }
                        );
                    break;

                default:
                    break;
                }
                SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
            }
            _waiter.Set();
        }
        // called when the transaction status is updated
        public override async void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
        {
            try
            {
                Logger.Log("UpdatedTransactions thread: " + System.Threading.Thread.CurrentThread.Name + " ID:" + System.Threading.Thread.CurrentThread.ManagedThreadId);
                foreach (SKPaymentTransaction transaction in transactions)
                {
                    string logMessage = "UpdatedTransaction: State: " + transaction.TransactionState.ToString();
                    if (transaction.TransactionReceipt != null)
                    {
                        logMessage += ". Transaction: " + transaction.TransactionReceipt.ToString();
                    }

                    Logger.Log(logMessage);

                    string identifier = transaction.TransactionIdentifier;
                    if (!string.IsNullOrEmpty(identifier))
                    {
                        Logger.Log("UpdatedTransaction: Transaction Identifier: " + identifier);
                    }

                    switch (transaction.TransactionState)
                    {
                    case SKPaymentTransactionState.Purchased:
                        await theManager.CompleteTransaction(transaction);

                        break;

                    case SKPaymentTransactionState.Failed:
                        theManager.FailedTransaction(transaction);
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log("ERROR: UpdatedTransactions: " + ex);
            }
        }
        public override void RestoreCompletedTransactionsFinished(SKPaymentQueue queue)
        {
            if (restoredTransactions == null)
            {
                return;
            }

            // This is called after all restored transactions have hit UpdatedTransactions
            // at this point we are done with the restore request so let's fire up the event
            var allTransactions = restoredTransactions.ToArray();

            // Clear out the list of incoming restore transactions for future requests
            restoredTransactions.Clear();

            TransactionsRestored?.Invoke(allTransactions);

            foreach (var transaction in allTransactions)
            {
                SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
            }
        }
 // called when the transaction status is updated
 public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
 {
     Console.WriteLine("UpdatedTransactions");
     foreach (SKPaymentTransaction transaction in transactions)
     {
         switch (transaction.TransactionState)
         {
             case SKPaymentTransactionState.Purchased:
                 theManager.CompleteTransaction(transaction);
                 break;
             case SKPaymentTransactionState.Failed:
                 theManager.FailedTransaction(transaction);
                 break;
             case SKPaymentTransactionState.Restored:
                 theManager.RestoreTransaction(transaction);
                 break;
             default:
                 break;
         }
     }
 }
        public override void RestoreCompletedTransactionsFailedWithError(SKPaymentQueue queue, NSError error)
        {
            Debug.WriteLine($"RestoreCompletedTransactionsFailedWithError called... _transactionsRestored is null = {_transactionsRestored==null}");

            try
            {
                // Get Info for the Exception
                string        description   = error?.LocalizedDescription ?? string.Empty;
                PurchaseError purchaseError = error.ToPurchaseError();

                // Failed to Restore. Set the Exception to the Task, so the caller can react to the issue
                _transactionsRestored?.TrySetException(new InAppPurchaseException(purchaseError, description));
                _transactionsRestored = null;
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception {ex.ToString()}");

                _transactionsRestored?.TrySetException(new InAppPurchaseException(PurchaseError.Unknown, ex.ToString()));
                _transactionsRestored = null;
            }
        }
Ejemplo n.º 36
0
 public override void PaymentQueueRestoreCompletedTransactionsFinished(SKPaymentQueue queue)
 {
     if (queue.Transactions.Count() > 0)
     {
         InvokeOnMainThread(() => {
             AdViewController.Purchase(AdViewController.adRemovalProductId);
             UIAlertView alert = new UIAlertView("Note!",
                                                 "It may take a few moments for the ad removal to register as purchased.",
                                                 null, "OK", null);
             alert.Show();
         });
     }
     else
     {
         InvokeOnMainThread(() => {
             UIAlertView alert = new UIAlertView("Error",
                                                 "No prior purchase to restore.",
                                                 null, "Ok", null);
             alert.Show();
         });
     }
 }
		// called when the transaction status is updated
		public override void UpdatedTransactions (SKPaymentQueue queue, SKPaymentTransaction[] transactions)
		{
			Console.WriteLine ("UpdatedTransactions");
			foreach (SKPaymentTransaction transaction in transactions)
			{
			    switch (transaction.TransactionState)
			    {
			        case SKPaymentTransactionState.Purchased:
			           theManager.CompleteTransaction(transaction);
			            break;
			        case SKPaymentTransactionState.Failed:
			           theManager.FailedTransaction(transaction);
			            break;
// Consumable products do not get Restored, so this is not implemented in this sample.
//			        case SKPaymentTransactionState.Restored:
//			            theManager.RestoreTransaction(transaction);
//			            break;
			        default:
			            break;
			    }
			}
		}
        /// <Docs>
        /// New iOS 6 method to track downloads of hosted-content
        /// </Docs>
        public override void UpdatedDownloads(SKPaymentQueue queue, SKDownload[] downloads)
        {
            Console.WriteLine(" -- PaymentQueueUpdatedDownloads");
            foreach (SKDownload download in downloads)
            {
                switch (download.DownloadState)
                {
                case SKDownloadState.Active:
                    Console.WriteLine("Download progress:" + download.Progress);
                    Console.WriteLine("Time remaining:   " + download.TimeRemaining);
                    break;

                case SKDownloadState.Finished:
                    Console.WriteLine("Finished!!!!");
                    Console.WriteLine("Content URL:" + download.ContentUrl);

                    // UNPACK HERE!
                    theManager.SaveDownload(download);

                    break;

                case SKDownloadState.Failed:
                    Console.WriteLine("Failed");
                    break;

                case SKDownloadState.Cancelled:
                    Console.WriteLine("Cancelled");
                    break;

                case SKDownloadState.Paused:
                case SKDownloadState.Waiting:
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 39
0
 public virtual void PaymentQueueRestoreCompletedTransactionsFinished(SKPaymentQueue queue)
 {
     RestoreCompletedTransactionsFinished (queue);
 }
Ejemplo n.º 40
0
 public override void RestoreCompletedTransactionsFailedWithError (SKPaymentQueue queue, NSError error)
 {
     Console.WriteLine(" ** RESTORE RestoreCompletedTransactionsFailedWithError " + error.LocalizedDescription);
     if (_inAppPurchases._actionSource != null)
         _inAppPurchases._actionSource.TrySetResult(true);
 }
Ejemplo n.º 41
0
 public override void PaymentQueueRestoreCompletedTransactionsFinished (SKPaymentQueue queue)
 {
     Console.WriteLine(" ** RESTORE PaymentQueueRestoreCompletedTransactionsFinished ");
     if (_inAppPurchases._actionSource != null)
         _inAppPurchases._actionSource.TrySetResult(true);
 }
Ejemplo n.º 42
0
            public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
            {
                foreach (SKPaymentTransaction transaction in transactions)
                {
                    try
                    {

                        switch (transaction.TransactionState)
                        {
                            case SKPaymentTransactionState.Purchased:
                                _inAppPurchases.CompleteTransaction(transaction);
                                SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                                break;
                            case SKPaymentTransactionState.Failed:
                                _inAppPurchases.FailedTransaction(transaction);
                                SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                                break;
                            case SKPaymentTransactionState.Restored:
                                _inAppPurchases.RestoreTransaction(transaction);
                                SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                                break;
                            default:
                                break;
                        }
                    }
                    catch (Exception e)
                    {
                        _inAppPurchases._errorSubject.OnNext(e);
                    }
                }
            }
Ejemplo n.º 43
0
 public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
 {
     foreach (SKPaymentTransaction transaction in transactions)
     {
         switch (transaction.TransactionState)
         {
             case SKPaymentTransactionState.Purchased:
                 this._inAppService.PurchaseTransaction(transaction);
                 break;
             case SKPaymentTransactionState.Failed:
                 this._inAppService.FailedTransaction(transaction);
                 break;
             case SKPaymentTransactionState.Restored:
                 this._inAppService.RestoreTransaction(transaction);
                 break;
             default:
                 break;
         }
     }
 }
Ejemplo n.º 44
0
 public override void UpdatedDownloads(SKPaymentQueue queue, object[] downloads)
 {
     IAPXT._OnUpdatedDownload(downloads);
 }
Ejemplo n.º 45
0
 public override void RestoreCompletedTransactionsFailedWithError(SKPaymentQueue queue, NSError error) { }
Ejemplo n.º 46
0
 public override void RestoreCompletedTransactionsFailedWithError(SKPaymentQueue queue, NSError error)
 {
     // RestoreProducts failed somewhere...
     Debug.WriteLine(" ** RESTORE RestoreCompletedTransactionsFailedWithError " + error.LocalizedDescription);
 }
Ejemplo n.º 47
0
		public override void RestoreCompletedTransactionsFailedWithError (SKPaymentQueue queue, NSError error)
		{
			Console.WriteLine ("STORE ERROR RestoreError ({0})", error);
		}
Ejemplo n.º 48
0
 public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
 {
     foreach (SKPaymentTransaction transaction in transactions)
     {
         try
         {
             switch (transaction.TransactionState)
             {
                 case SKPaymentTransactionState.Purchased:
                     _inAppPurchases.CompleteTransaction(transaction);
                     break;
                 case SKPaymentTransactionState.Failed:
                     _inAppPurchases.FailedTransaction(transaction);
                     break;
                 case SKPaymentTransactionState.Restored:
                     _inAppPurchases.RestoreTransaction(transaction);
                     break;
                 default:
                     break;
             }
         }
         catch (Exception e)
         {
             MonoTouch.Utilities.ShowAlert("Error", "Unable to process transaction: " + e.Message);
             e.Report();
         }
     }
 }
Ejemplo n.º 49
0
 public override void RestoreCompletedTransactionsFailedWithError (SKPaymentQueue queue, NSError error)
 {
     Console.WriteLine(" ** RESTORE RestoreCompletedTransactionsFailedWithError " + error.LocalizedDescription);
 }
Ejemplo n.º 50
0
            public override void RestoreCompletedTransactionsFailedWithError (SKPaymentQueue queue, NSError error)
            {
                this.Log().Debug("Restore completed with error: " + error);

                if (error.Code == 2)
                {
                    _inAppPurchases._restoreSource?.TrySetCanceled();
                }
                else
                {
                    var errorMessage = error.LocalizedDescription ?? "Unable to restore purchase due to unknown reason.";
                    _inAppPurchases._restoreSource?.TrySetException(new Exception(errorMessage));
                }
            }
 public override void PaymentQueueRestoreCompletedTransactionsFinished(SKPaymentQueue queue)
 {
     // Restore succeeded
     Console.WriteLine(" ** RESTORE PaymentQueueRestoreCompletedTransactionsFinished ");
 }
Ejemplo n.º 52
0
 public override void RemovedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
 {
     foreach (var transaction in transactions)
         SingleManager.PaymentQueue.FinishTransaction(transaction);
 }
Ejemplo n.º 53
0
 public override void UpdatedTransactions(SKPaymentQueue queue, object[] transactions)
 {
     IAPXT._OnUpdatedTransactions(transactions);
 }
Ejemplo n.º 54
0
            public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
            {
                var purchaseChanged = false;
                foreach (var transaction in transactions)
                {
                    switch (transaction.TransactionState)
                    {
                        case SKPaymentTransactionState.Purchased:
                            {
                                ProductDetails details;
                                if (SingleManager.products.TryGetValue(transaction.Payment.ProductIdentifier, out details))
                                {
                                    purchaseChanged = true;
                                    details.SetPurchased();
                                }

                                SingleManager.PaymentQueue.FinishTransaction(transaction);
                                break;
                            }
                        case SKPaymentTransactionState.Restored:
                            {
                                ProductDetails details;
                                if (SingleManager.products.TryGetValue(transaction.OriginalTransaction.Payment.ProductIdentifier, out details))
                                {
                                    purchaseChanged = true;
                                    details.SetPurchased();
                                }

                                SingleManager.PaymentQueue.FinishTransaction(transaction);
                                break;
                            }
                        case SKPaymentTransactionState.Failed:
                            {
                                ProductDetails details;
                                if (SingleManager.products.TryGetValue(transaction.Payment.ProductIdentifier, out details))
                                {
                                    purchaseChanged = true;
                                    details.SetFailed();
                                }

                                if ((SKError)transaction.Error.Code != SKError.PaymentCancelled)
                                    SingleManager.RaiseTransactionFailed(transaction.Error);

                                SingleManager.PaymentQueue.FinishTransaction(transaction);
                                break;
                            }
                        case SKPaymentTransactionState.Purchasing:
                            {
                                ProductDetails details;
                                if (SingleManager.products.TryGetValue(transaction.Payment.ProductIdentifier, out details))
                                {
                                    purchaseChanged = true;
                                    details.SetPurchasing();
                                }

                                break;
                            }
                    }
                }

                if (purchaseChanged)
                    SingleManager.RaiseDetailsChanged();
            }
Ejemplo n.º 55
0
 public override void PaymentQueueRestoreCompletedTransactionsFinished(SKPaymentQueue queue)
 {
     this.Log().Debug("Payment queue restore complete");
     _inAppPurchases._restoreSource?.TrySetResult(true);
 }
		public override void PaymentQueueRestoreCompletedTransactionsFinished(SKPaymentQueue queue)
		{
			throw new NotImplementedException("Consumable product purchases do not get Restored, so this is not implemented in this sample.");
		}
Ejemplo n.º 57
0
		public override void PaymentQueueRestoreCompletedTransactionsFinished (SKPaymentQueue queue)
		{
			Console.WriteLine ("STORE RestoreCompleted()");
		}
Ejemplo n.º 58
0
            public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
            {
                foreach (var transaction in transactions.Where(x => x != null))
                {
                    this.Log().Debug("UpdatedTransactions: " + transaction.TransactionState);

                    try
                    {
                        switch (transaction.TransactionState)
                        {
                            case SKPaymentTransactionState.Purchased:
                                _inAppPurchases.CompleteTransaction(transaction);
                                SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                                break;
                            case SKPaymentTransactionState.Failed:
                                _inAppPurchases.FailedTransaction(transaction);
                                SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                                break;
                            case SKPaymentTransactionState.Restored:
                                _inAppPurchases.RestoreTransaction(transaction);
                                SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                                break;
                            case SKPaymentTransactionState.Deferred:
                                _inAppPurchases.DeferedTransaction();
                                SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                                break;
                        }
                    }
                    catch (Exception e)
                    {
                        _inAppPurchases._errorSubject.OnNext(e);
                    }
                }
            }
Ejemplo n.º 59
0
 public static void PaymentQueueRestoreCompletedTransactionsFinished(ISKPaymentTransactionObserver This, SKPaymentQueue queue)
 {
     RestoreCompletedTransactionsFinished (This, queue);
 }
Ejemplo n.º 60
0
 public override void PaymentQueueRestoreCompletedTransactionsFinished(SKPaymentQueue queue) { }