Beispiel #1
0
        public static async Task Pay(StripeBackendResponse intent, PaymentMethodCardCreateOptions card)
        {
            try
            {
                var Client = new StripeClient("pk_test_TYooMQauvdEDq54NiTphI7jx");

                var payIntent = new PaymentIntentService(Client);
                var payResult = await payIntent.ConfirmAsync(intent.IntentID, new PaymentIntentConfirmOptions
                {
                    ClientSecret      = intent.ClientSecret,
                    PaymentMethodData = new PaymentIntentPaymentMethodDataOptions
                    {
                        Type           = "card",
                        Card           = card,
                        BillingDetails = new BillingDetailsOptions
                        {
                            // Add Extra Info
                            Name = "User Full Name",
                        }
                    },
                    ReturnUrl = string.Format("{0}/result-payment", BackendUrl) // Change this with your Return URL
                });

                if (payResult.NextAction != null)
                {
                    if (payResult.NextAction.Type == "redirect_to_url")
                    {
                        var webView = new WebView
                        {
                            Source = new UrlWebViewSource {
                                Url = payResult.NextAction.RedirectToUrl.Url
                            }
                        };

                        webView.Navigating += (s, e) =>
                        {
                            if (e.Url.StartsWith("close://"))
                            {
                                e.Cancel = true;

                                Xamarin.Forms.Application.Current.MainPage.Navigation.PopModalAsync();
                            }
                        };

                        await Xamarin.Forms.Application.Current.MainPage.Navigation.PushModalAsync(new NavigationPage(new ContentPage
                        {
                            Title = "3D Secure",
                            Content = webView
                        }));
                    }
                    else if (payResult.NextAction.Type == "use_stripe_sdk")
                    {
                        await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Stripe", "Use Stripe SDK", "OK");
                    }
                }
            }
            catch (Exception ex)
            {
                await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
            }
        }
Beispiel #2
0
 async Task InitializeIntent()
 {
     PaymentIntentResponse = await Payment.Methods.StartCheckout();
 }