public async Task <string> MakePayment(string apiSecretKey, string currencyCode, double amount, string cardToken, string description, string memberName) { StripeClient client = new StripeClient(apiSecretKey); PaymentIntentService intentService = new PaymentIntentService(client); PaymentIntent intent = await intentService.CreateAsync(new PaymentIntentCreateOptions { Amount = (int)(amount * 100), Currency = currencyCode.ToLowerInvariant(), Description = $"{memberName}: {description}", ExtraParams = new Dictionary <string, object> { { "payment_method_data", new Dictionary <string, object> { { "type", "card" }, { "card", new Dictionary <string, object> { { "token", cardToken } } } } } } }); intent = await intentService.ConfirmAsync(intent.Id); return(intent.Id); }
public async Task <IActionResult> Pay([FromBody] PayDto dto) { var paymentIntentService = new PaymentIntentService(); PaymentIntent paymentIntent = null; try { if (dto.ConfirmPaymentRequest.PaymentMethodId != null) { var createOptions = new PaymentIntentCreateOptions { PaymentMethod = dto.ConfirmPaymentRequest.PaymentMethodId, Amount = (int)(dto.Amount * 100), Currency = "usd", ConfirmationMethod = "manual", Confirm = true }; if (!string.IsNullOrEmpty(dto.ConfirmPaymentRequest.CustomerId)) { createOptions.Customer = dto.ConfirmPaymentRequest.CustomerId; } paymentIntent = await paymentIntentService.CreateAsync(createOptions); } if (dto.ConfirmPaymentRequest.PaymentIntentId != null) { var confirmOptions = new PaymentIntentConfirmOptions { }; paymentIntent = await paymentIntentService.ConfirmAsync( dto.ConfirmPaymentRequest.PaymentIntentId, confirmOptions ); } } catch (StripeException e) { return(BadRequest(new { error = e.StripeError.Message })); } return(GeneratePaymentResponse(paymentIntent)); }
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"); } }