void SetDropResult(DropUIResult dropResult) { OnDropUISuccessful?.Invoke(this, dropResult); dropUiPayTcs?.TrySetResult(dropResult); }
public async Task <DropUIResult> ShowDropUI(double totalPrice, string merchantId, int resultCode = 1234) { dropUiPayTcs = new TaskCompletionSource <DropUIResult>(); if (CanPay) { BTDropInRequest request = new BTDropInRequest(); request.Amount = $"{totalPrice}"; BTDropInController bTDropInController = new BTDropInController(_clientToken, request, async(controller, result, error) => { if (error == null) { if (result.Cancelled) { dropUiPayTcs.SetCanceled(); } else if (result.PaymentOptionType == BTUIKPaymentOptionType.ApplePay) { try { isDropUI = true; var nonce = await TokenizePlatform(totalPrice, merchantId); var dropResult = new DropUIResult() { Nonce = nonce ?? string.Empty, Type = $"{BTUIKPaymentOptionType.ApplePay}" }; OnDropUISuccessful?.Invoke(this, dropResult); dropUiPayTcs.TrySetResult(dropResult); } catch (TaskCanceledException) { dropUiPayTcs.SetCanceled(); } catch (Exception exception) { OnDropUIError?.Invoke(this, exception.Message); dropUiPayTcs.TrySetException(exception); } finally { pKPaymentAuthorizationViewController?.DismissViewController(true, null); isDropUI = false; } } else { var dropResult = new DropUIResult() { Nonce = result.PaymentMethod?.Nonce ?? string.Empty, Type = $"{result.PaymentOptionType}" }; OnDropUISuccessful?.Invoke(this, dropResult); dropUiPayTcs.TrySetResult(dropResult); } } else { OnDropUIError?.Invoke(this, error.Description); dropUiPayTcs.TrySetException(new Exception(error.Description)); } controller.DismissViewController(true, null); }); var window = UIApplication.SharedApplication.KeyWindow; var _viewController = window.RootViewController; while (_viewController.PresentedViewController != null) { _viewController = _viewController.PresentedViewController; } _viewController?.PresentViewController(bTDropInController, true, null); } else { OnDropUIError?.Invoke(this, "Platform is not ready to accept payments"); dropUiPayTcs.TrySetException(new Exception("Platform is not ready to accept payments")); } return(await dropUiPayTcs.Task); }