public async Task <DropUIResult> ShowDropUI(double totalPrice, string merchantId, int requestCode = 1234) { if (isReady) { CurrentInstance = this; _requestCode = requestCode; dropUiPayTcs = new TaskCompletionSource <DropUIResult>(); GooglePaymentRequest googlePaymentRequest = new GooglePaymentRequest(); googlePaymentRequest.InvokeTransactionInfo(TransactionInfo.NewBuilder() .SetTotalPrice($"{totalPrice}") .SetTotalPriceStatus(WalletConstants.TotalPriceStatusFinal) .SetCurrencyCode("USD") .Build()); DropInRequest dropInRequest = new DropInRequest().ClientToken(_clientToken) .InvokeGooglePaymentRequest(googlePaymentRequest); Xamarin.Essentials.Platform.CurrentActivity.StartActivityForResult(dropInRequest.GetIntent(Xamarin.Essentials.Platform.CurrentActivity), requestCode); } else { OnDropUIError?.Invoke(this, "Platform is not ready to accept payments"); dropUiPayTcs.TrySetException(new System.Exception("Platform is not ready to accept payments")); } return(await dropUiPayTcs.Task); }
void SetDropException(Exception exception) { OnDropUIError?.Invoke(this, exception.Message); dropUiPayTcs?.TrySetException(exception); }
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); }