public IActionResult PurchaseItem([FromBody] Order purchaseOrder) { //var tokenVar = purchaseOrder.tokenVar; //Item[] items = purchaseOrder.Items; //Get the customer id var customerId = "11111";// await GetCustomer(tokenVar); var pmlOptions = new PaymentMethodListOptions { Customer = customerId, Type = "card", }; //IF THERE ARENT ANY THAN THROW AN ERROR!!! var pmService = new PaymentMethodService(); var paymentMethods = pmService.List(pmlOptions); var paymentIntents = new PaymentIntentService(); var paymentIntent = paymentIntents.Create(new PaymentIntentCreateOptions { Customer = customerId, SetupFutureUsage = "off_session", Amount = 1000, Currency = "usd", PaymentMethod = paymentMethods.Data[0].Id, Description = "Name of items here" });;; return(Ok(new { client_secret = paymentIntent.ClientSecret })); }
public IActionResult OffSessionPayment(string customerId, long amount) { try { //var amountt=long.Parse(amount); var methodOptions = new PaymentMethodListOptions { Customer = customerId, Type = "card", }; var methodService = new PaymentMethodService(); var paymentMethods = methodService.List(methodOptions); //To get the first payment method var payment = paymentMethods.ToList().FirstOrDefault(); var service = new PaymentIntentService(); var options = new PaymentIntentCreateOptions { Amount = amount /*ProductAmount*//*1099*/, Currency = "usd", Customer = customerId, PaymentMethod = /*PaymentId*//*"card"*/ payment.Id, Confirm = true, OffSession = true, }; var paymentIntentt = service.Create(options); return(Ok()); //return View("ButtonsView"); } catch (StripeException e) { switch (e.StripeError.Error /*.ErrorType*/) { case "card_error": // Error code will be authentication_required if authentication is needed Console.WriteLine("Error code: " + e.StripeError.Code); var paymentIntentId = e.StripeError.PaymentIntent.Id; var service = new PaymentIntentService(); var paymentIntent = service.Get(paymentIntentId); Console.WriteLine(paymentIntent.Id); break; default: break; } //// return(null); } }
public static async Task <List <PaymentMethod> > GetPaymentMethods() { StripeConfiguration.ApiKey = Constants.StripeKey; if (App.PaymentId == null || App.PaymentId.Length == 0) { FirebaseUser userDetails = await FirebaseFirestoreHelper.GetUserInfo(App.UserEmail); App.PaymentId = userDetails.PaymentId; } var options = new PaymentMethodListOptions { Customer = App.PaymentId, Type = "card" }; var service = new PaymentMethodService(); List <PaymentMethod> paymentMethods = service.List(options).Data; return(paymentMethods); }
public async Task <bool> PaymentDeduct(PaymentDeductCommand command) { try { //var amountt=long.Parse(amount); var methodOptions = new PaymentMethodListOptions { Customer = command.StripeCustomerId, Type = "card", }; var methodService = new PaymentMethodService(); var paymentMethods = methodService.List(methodOptions); //To get the first payment method var payment = paymentMethods.ToList().FirstOrDefault(); var service = new PaymentIntentService(); var options = new PaymentIntentCreateOptions { Amount = command.Amount, Currency = "usd", Customer = command.StripeCustomerId, PaymentMethod = payment.Id, Confirm = true, OffSession = true, }; var paymentIntent = service.Create(options); return(true); } catch (StripeException e) { string errorMessage = ""; switch (e.StripeError.Error) { case "card_error": errorMessage = $"Card Error occurred on {e.StripeError.PaymentIntent.Id}, Error: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}"; break; case "api_error": errorMessage = $"API Error occurred: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}"; break; case "api_connection_error": errorMessage = $"API Connection Error occurred: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}"; break; case "invalid_request_error ": errorMessage = $"Invalid request Error occurred: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}"; break; default: errorMessage = $"Some Error occurred: {e.StripeError.Error}, Error Code: {e.StripeError.Code}, Error Description: {e.StripeError.ErrorDescription}"; break; } throw new InvalidOperationException(errorMessage); } }