Exemple #1
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 #2
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);
                }
            });
        }