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 async Task <StripeList <PaymentMethod> > FetchPaymentMethodsAsync(string customer) { var options = new PaymentMethodListOptions { Customer = customer, Type = "card", Limit = 100 }; return(await this.ListAsync(options)); }
private Task <StripeList <PaymentMethod> > GetStripePaymentMethodsAsync(string customerId) { var options = new PaymentMethodListOptions { Customer = customerId, Type = "card", }; var service = new PaymentMethodService(); return(service.ListAsync(options)); }
public async Task <PaymentMethodDao> GetCustomerPaymentMethod(string paymentCustomerId, CancellationToken cancellationToken) { Guard.Argument(paymentCustomerId, nameof(paymentCustomerId)).NotNull().NotEmpty().NotWhiteSpace(); var options = new PaymentMethodListOptions { Customer = paymentCustomerId, Type = "card" }; var customerCards = await _paymentMethodService.ListAsync(options : options, cancellationToken : cancellationToken); return(customerCards.FirstOrDefault().ToPaymentMethodDao()); }
public async Task <PaymentMethod> GetDefaultCreditCardAsync(string customerId) { var options = new PaymentMethodListOptions { Customer = customerId, Type = "card", }; var service = new PaymentMethodService(); var paymentMethods = await service.ListAsync(options); return(paymentMethods.FirstOrDefault()); }
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 <IEnumerable <StripePaymentMethodResponse> > GetStripeCustomerPaymentMethods(int userId) { var user = await _userService.GetUserDevicesAsync(userId); var result = new List <StripePaymentMethodResponse>(); if (!string.IsNullOrEmpty(user.StripeCustomerId)) { var options = new PaymentMethodListOptions { Customer = user.StripeCustomerId, Type = "card" }; var service = new PaymentMethodService(); var paymentMethods = await service.ListAsync(options); foreach (var method in paymentMethods) { if (method.Type == "card" && method.Card != null) { var card = method.Card; var mapped = new StripePaymentMethodResponse { PaymentMethodId = method.Id, Last4 = card.Last4, Country = card.Country, Description = card.Description, ExpMonth = card.ExpMonth, ExpYear = card.ExpYear, Funding = card.Funding, Issuer = card.Issuer }; result.Add(mapped); } } } return(result); }
public PaymentMethodServiceTest( StripeMockFixture stripeMockFixture, MockHttpClientFixture mockHttpClientFixture) : base(stripeMockFixture, mockHttpClientFixture) { this.service = new PaymentMethodService(this.StripeClient); this.attachOptions = new PaymentMethodAttachOptions { Customer = "cus_123", }; this.createOptions = new PaymentMethodCreateOptions { Card = new PaymentMethodCardOptions { Token = "tok_123", }, Type = "card", }; this.detachOptions = new PaymentMethodDetachOptions { }; this.listOptions = new PaymentMethodListOptions { Customer = "cus_123", Type = "card", }; this.updateOptions = new PaymentMethodUpdateOptions { Metadata = new Dictionary <string, string> { { "key", "value" }, }, }; }
public async Task Refresh() { var selectedPaymentMethodId = PaymentMethods.FirstOrDefault(p => p.Selected)?.PaymentMethod.Id; PaymentMethods.Clear(); try { var stripeClient = await EphemeralService.Instance.GetClient(); var customerId = await EphemeralService.Instance.GetCustomerId(); var customerService = new CustomerService(stripeClient); _customer = await customerService.GetAsync(customerId); var paymentMethodService = new PaymentMethodService(stripeClient); var paymentMethodListOptions = new PaymentMethodListOptions { Customer = _customer.Id, Type = "card" }; var methods = await paymentMethodService.ListAsync(paymentMethodListOptions); foreach (var paymentMethod in methods) { PaymentMethods.Add(new PaymentMethodViewModel(paymentMethod, PaymentMethodSelected)); } if (PaymentMethods.Any()) { var toSelect = PaymentMethods.FirstOrDefault(pm => pm.PaymentMethod.Id == selectedPaymentMethodId) ?? PaymentMethods.First(); SelectPaymentMethod(toSelect); } } catch (Exception ex) { await Navigator.ShowMessage("Error", ex.Message); } }
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); } }
async public Task <StripeList <PaymentMethod> > GetPaymentMethodsAsync([FromBody] PaymentMethodListOptions paymentMethodListOptions) { return(await _paymentMethodService.ListAsync(paymentMethodListOptions, _requestOptions)); }