public override void ViewDidLoad() { base.ViewDidLoad(); TableView.SeparatorColor = UIColor.Clear; if (UIDevice.CurrentDevice.UserInterfaceIdiom != UIUserInterfaceIdiom.Pad) { NSNotificationCenter defaultCenter = NSNotificationCenter.DefaultCenter; defaultCenter.AddObserver(UIKeyboard.WillHideNotification, OnKeyboardNotification); defaultCenter.AddObserver(UIKeyboard.WillShowNotification, OnKeyboardNotification); } if (String.IsNullOrEmpty(tokenPayment.Token)) { DispatchQueue.MainQueue.DispatchAfter(DispatchTime.Now, () => { UIAlertView _error = new UIAlertView("Missing Token", "No Card Token found. Please provide application with token via Pre-Authentication or Payment", null, "ok", null); _error.Show(); _error.Clicked += (sender, args) => { PaymentButton.Disable(); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { this.DismissViewController(true, null); } else { this.NavigationController.PopViewController(true); } }; }); } else { SetUpTableView(); UITapGestureRecognizer tapRecognizer = new UITapGestureRecognizer(); tapRecognizer.AddTarget(() => { if (KeyboardVisible) { DismissKeyboardAction(); } }); tapRecognizer.NumberOfTapsRequired = 1; tapRecognizer.NumberOfTouchesRequired = 1; EncapsulatingView.AddGestureRecognizer(tapRecognizer); PaymentButton.Disable(); PaymentButton.SetTitleColor(UIColor.Black, UIControlState.Application); PaymentButton.TouchUpInside += (sender, ev) => { MakeTokenPayment(); }; if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { FormClose.TouchUpInside += (sender, ev) => { this.DismissViewController(true, null); }; } } }
public void MakeTokenPayment() { try { LoadingScreen.ShowLoading(this.View); var instance = JudoConfiguration.Instance; tokenPayment.CV2 = tokenCell.CCV; PaymentButton.Disable(); _paymentService.MakeTokenPreAuthorisation(tokenPayment, new ClientService()).ContinueWith(reponse => { if (reponse.Exception != null) { LoadingScreen.HideLoading(); DispatchQueue.MainQueue.DispatchAfter(DispatchTime.Now, () => { NavigationController.CloseView(); reponse.Exception.FlattenToJudoFailure(failureCallback); }); } else { var result = reponse.Result; if (result != null && !result.HasError && result.Response.Result != "Declined") { PaymentReceiptModel paymentreceipt = result.Response as PaymentReceiptModel; // call success callback if (successCallback != null) { DispatchQueue.MainQueue.DispatchAfter(DispatchTime.Now, () => { NavigationController.CloseView(); successCallback(paymentreceipt); }); } } else { // Failure callback if (failureCallback != null) { var judoError = new JudoError { ApiError = result != null ? result.Error : null }; var paymentreceipt = result != null ? result.Response as PaymentReceiptModel : null; if (paymentreceipt != null) { // send receipt even we got card declined DispatchQueue.MainQueue.DispatchAfter(DispatchTime.Now, () => { NavigationController.CloseView(); failureCallback(judoError, paymentreceipt); }); } else { DispatchQueue.MainQueue.DispatchAfter(DispatchTime.Now, () => { NavigationController.CloseView(); failureCallback(judoError); }); } } } } LoadingScreen.HideLoading(); }); } catch (Exception ex) { LoadingScreen.HideLoading(); // Failure callback if (failureCallback != null) { var judoError = new JudoError { Exception = ex }; DispatchQueue.MainQueue.DispatchAfter(DispatchTime.Now, () => { NavigationController.CloseView(); failureCallback(judoError); }); } } }