public async Task <string> TokenizeCard(string panNumber = "4111111111111111", string expirationMonth = "12", string expirationYear = "2018", string cvv = null)
        {
            payTcs = new TaskCompletionSource <string>();
            if (CanPay)
            {
                var cardClient = new BTCardClient(apiClient: braintreeClient);
                var card       = new BTCard(panNumber, expirationMonth, expirationYear, cvv);

                cardClient.TokenizeCard(card, (BTCardNonce tokenizedCard, Foundation.NSError error) =>
                {
                    if (error == null)
                    {
                        OnTokenizationSuccessful?.Invoke(this, tokenizedCard.Nonce);
                        payTcs.TrySetResult(tokenizedCard.Nonce);
                    }
                    else
                    {
                        OnTokenizationError?.Invoke(this, error.Description);
                        payTcs.TrySetException(new Exception(error.Description));
                    }
                });
            }
            else
            {
                OnTokenizationError?.Invoke(this, "Platform is not ready to accept payments");
                payTcs.TrySetException(new Exception("Platform is not ready to accept payments"));
            }

            return(await payTcs.Task);
        }
Exemple #2
0
        public async Task <string> TokenizePlatform(double totalPrice, string merchantId)
        {
            payTcs = new TaskCompletionSource <string>();
            if (isReady)
            {
                var applePayClient = new BTApplePayClient(braintreeClient);
                applePayClient.PaymentRequest((request, error) =>
                {
                    if (error == null)
                    {
                        RequestPaymentAuthorization(request, new Dictionary <string, double> {
                            { "My App", totalPrice }
                        }, merchantId);
                    }
                    else
                    {
                        OnTokenizationError?.Invoke(this, "Error: Couldn't create payment request.");
                        payTcs.TrySetException(new Exception("Error: Couldn't create payment request."));
                    }
                });
            }
            else
            {
                OnTokenizationError?.Invoke(this, "Platform is not ready to accept payments");
                payTcs.TrySetException(new Exception("Platform is not ready to accept payments"));
            }

            return(await payTcs.Task);
        }
Exemple #3
0
        public override void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action <PKPaymentAuthorizationStatus> completion)
        {
            var applePayClient = new BTApplePayClient(braintreeClient);

            applePayClient.TokenizeApplePayPayment(payment, (tokenizedApplePayPayment, error) =>
            {
                if (error == null)
                {
                    if (string.IsNullOrEmpty(tokenizedApplePayPayment.Nonce))
                    {
                        payTcs?.SetCanceled();
                    }
                    else
                    {
                        OnTokenizationSuccessful?.Invoke(this, tokenizedApplePayPayment.Nonce);
                        payTcs?.TrySetResult(tokenizedApplePayPayment.Nonce);
                    }

                    completion(PKPaymentAuthorizationStatus.Success);
                }
                else
                {
                    OnTokenizationError?.Invoke(this, "Error - Payment tokenization failed");
                    payTcs?.TrySetException(new Exception("Error - Payment tokenization failed"));

                    completion(PKPaymentAuthorizationStatus.Failure);
                }
            });
        }
Exemple #4
0
        public async Task <string> TokenizePayPal()
        {
            payTcs = new TaskCompletionSource <string>();
            if (isReady)
            {
                mBraintreeFragment.AddListener(this);
                PayPal.RequestOneTimePayment(mBraintreeFragment, new PayPalRequest());
            }
            else
            {
                OnTokenizationError?.Invoke(this, "Platform is not ready to accept payments");
                payTcs.TrySetException(new System.Exception("Platform is not ready to accept payments"));
            }

            return(await payTcs.Task);
        }
        void RequestPaymentAuthorization(PKPaymentRequest paymentRequest, IDictionary <string, double> summaryItems, string merchantId)
        {
            UserDialogs.Instance.ShowLoading("Loading");

            paymentRequest.MerchantIdentifier   = merchantId;
            paymentRequest.MerchantCapabilities = PKMerchantCapability.ThreeDS;
            paymentRequest.CountryCode          = "US";
            paymentRequest.CurrencyCode         = "USD";

            if (summaryItems != null)
            {
                paymentRequest.PaymentSummaryItems = summaryItems.Select(i => new PKPaymentSummaryItem()
                {
                    Label  = i.Key,
                    Amount = new NSDecimalNumber(i.Value)
                }).ToArray();
            }

            var window          = UIApplication.SharedApplication.KeyWindow;
            var _viewController = window.RootViewController;

            while (_viewController.PresentedViewController != null)
            {
                _viewController = _viewController.PresentedViewController;
            }


            pKPaymentAuthorizationViewController = new PKPaymentAuthorizationViewController(paymentRequest);
            UserDialogs.Instance.HideLoading();
            if (pKPaymentAuthorizationViewController != null)
            {
                pKPaymentAuthorizationViewController.Delegate = this;
                _viewController?.PresentViewController(pKPaymentAuthorizationViewController, true, null);
            }
            else
            {
                if (!isDropUI)
                {
                    OnTokenizationError?.Invoke(this, "Error: Payment request is invalid.");
                }

                payTcs?.SetException(new Exception("Error: Payment request is invalid."));
            }
        }
Exemple #6
0
        public async Task <string> TokenizeCard(string panNumber = "4111111111111111", string expirationMonth = "12", string expirationYear = "2018", string cvv = null)
        {
            if (isReady)
            {
                payTcs = new TaskCompletionSource <string>();
                CardBuilder cardBuilder = new CardBuilder()
                                          .CardNumber(panNumber).JavaCast <CardBuilder>()
                                          .ExpirationMonth(expirationMonth).JavaCast <CardBuilder>()
                                          .ExpirationYear(expirationYear).JavaCast <CardBuilder>()
                                          .Cvv(cvv).JavaCast <CardBuilder>();

                mBraintreeFragment.AddListener(this);

                Com.Braintreepayments.Api.Card.Tokenize(mBraintreeFragment, cardBuilder);
            }
            else
            {
                OnTokenizationError?.Invoke(this, "Platform is not ready to accept payments");
                payTcs.TrySetException(new System.Exception("Platform is not ready to accept payments"));
            }
            return(await payTcs.Task);
        }
        public async Task <string> TokenizePayPal()
        {
            payTcs = new TaskCompletionSource <string>();
            if (CanPay)
            {
                var payPalDriver = new BTPayPalDriver(braintreeClient);
                payPalDriver.ViewControllerPresentingDelegate = new BTViewControllerPresenter();
                payPalDriver.AppSwitchDelegate = new BTSwitchDelegate();
                payPalDriver.AuthorizeAccountWithCompletion((BTPayPalAccountNonce payPalAccountNonce, NSError error) =>
                {
                    if (error == null)
                    {
                        if (payPalAccountNonce == null || string.IsNullOrEmpty(payPalAccountNonce.Nonce))
                        {
                            payTcs.SetCanceled();
                        }
                        else
                        {
                            OnTokenizationSuccessful?.Invoke(this, payPalAccountNonce.Nonce);
                            payTcs.TrySetResult(payPalAccountNonce.Nonce);
                        }
                    }
                    else
                    {
                        OnTokenizationError?.Invoke(this, error.Description);
                        payTcs.TrySetException(new Exception(error.Description));
                    }
                });
            }
            else
            {
                OnTokenizationError?.Invoke(this, "Platform is not ready to accept payments");
                payTcs.TrySetException(new Exception("Platform is not ready to accept payments"));
            }

            return(await payTcs.Task);
        }
Exemple #8
0
        public void OnError(Java.Lang.Exception error)
        {
            if (error is ErrorWithResponse)
            {
                ErrorWithResponse errorWithResponse = (ErrorWithResponse)error;
                BraintreeError    cardErrors        = errorWithResponse.ErrorFor("creditCard");
                if (cardErrors != null)
                {
                    BraintreeError expirationMonthError = cardErrors.ErrorFor("expirationMonth");
                    if (expirationMonthError != null)
                    {
                        OnTokenizationError?.Invoke(this, expirationMonthError.Message);
                        payTcs?.TrySetException(new System.Exception(expirationMonthError.Message));
                    }
                    else
                    {
                        OnTokenizationError?.Invoke(this, cardErrors.Message);
                        payTcs?.TrySetException(new System.Exception(cardErrors.Message));
                    }
                }
            }

            mBraintreeFragment.RemoveListener(this);
        }
Exemple #9
0
        public async Task <string> TokenizePlatform(double totalPrice, string merchantId)
        {
            payTcs = new TaskCompletionSource <string>();
            if (isReady)
            {
                GooglePaymentRequest googlePaymentRequest = new GooglePaymentRequest();

                googlePaymentRequest.InvokeTransactionInfo(TransactionInfo.NewBuilder()
                                                           .SetTotalPrice($"{totalPrice}")
                                                           .SetTotalPriceStatus(WalletConstants.TotalPriceStatusFinal)
                                                           .SetCurrencyCode("USD")
                                                           .Build());

                mBraintreeFragment.AddListener(this);
                GooglePayment.RequestPayment(mBraintreeFragment, googlePaymentRequest);
            }
            else
            {
                OnTokenizationError?.Invoke(this, "Platform is not ready to accept payments");
                payTcs.TrySetException(new System.Exception("Platform is not ready to accept payments"));
            }

            return(await payTcs.Task);
        }