public static StripeList <PaymentIntent> GetAllPayment(string paymentId) { var stripeKey = StripeApiKey(); //var options = new PaymentIntentListOptions //{ // Limit = 3, //}; var service = new PaymentIntentService(); StripeList <PaymentIntent> paymentIntents = service.List( //options ); return(paymentIntents); }
static void Main(string[] args) { Console.Write("Enter seret key: "); StripeConfiguration.ApiKey = Console.ReadLine(); Console.Write("Enter customer email: "); string email = Console.ReadLine(); // Create a customer var customer = Helper.CreateCustomer(email); var paymentMethodService = new PaymentMethodService(); var paymentIntentService = new PaymentIntentService(); Console.WriteLine(@"Create Transaction\Payment Intent:"); long amount = 0; Console.Write("Enter Amount (lowest denominator of currency):"); while (!long.TryParse(Console.ReadLine(), out amount)) { Console.WriteLine("Entered amount value cannot be converted to numeric. Please Try again."); Console.Write("Enter Amount (lowest denominator of currency):"); } Console.Write("Enter Currency (3 Letter ISO):"); string currency = Console.ReadLine(); //Create a paymentIntent/TransactionIntent for the customer var intent = Helper.CreatePaymentIntent(amount, currency, customer, paymentIntentService); Console.WriteLine($"Intent has been create with client secret: '{intent.ClientSecret}'.\nTo verify please check the Stripe payments dashboard."); Console.Write("You can exit the program now. Use the web server to complete the request via Stripe Elements. Or if you want to add the payment method here, you can press any key to coninue."); Console.ReadLine(); return; //If you want to add the payment method here Console.WriteLine("Do you want to enter a payment method? (y/n)"); char response = Console.ReadLine().Single(); if (response == 'y' || response == 'Y') { Console.WriteLine("Enter Card Details:"); Console.Write("Enter Card Number: "); string cardNumber = Console.ReadLine(); Console.Write("CVC: "); string cvc = Console.ReadLine(); Console.Write("Expiry (month):"); long expMonth = long.Parse(Console.ReadLine()); Console.Write("Expiry (year):"); long expYear = long.Parse(Console.ReadLine()); // Create and attach payment method to customer var cardPaymentMethod = Helper.CreateCardPaymentMethod(cardNumber, expMonth, expYear, cvc, paymentMethodService); Helper.AttachPaymentMethod(customer, cardPaymentMethod, paymentMethodService); // Retrieve the paymentintent/transactionIntent for a customer var paymentIntents = paymentIntentService.List( new PaymentIntentListOptions { Customer = customer.Id, }) .OrderBy(x => x.Created).ToList(); // Confirm the transaction var confirmOptions = new PaymentIntentConfirmOptions { PaymentMethod = cardPaymentMethod.Id, }; paymentIntentService.Confirm(intent.Id, confirmOptions); //paymentIntentService.Confirm(paymentIntents.Last().Id, confirmOptions); } return; }
private List <Payment> _ExportPayment(DateRangeOptions range) { var payments = new List <Payment>(); try { var options = new PaymentIntentListOptions { Limit = 100, Created = range, }; var paymentIntentService = new PaymentIntentService(); var transactionService = new BalanceTransactionService(); var customerService = new CustomerService(); var chargeService = new ChargeService(); StripeList <PaymentIntent> pis = paymentIntentService.List(options); for (int i = 0; i < pis.Data.Count; i++) { var pi = pis.Data[i]; var payment = new Payment() { Description = pi.Description, Created = pi.Created, Amount = Convert.ToDecimal(pi.Amount) / 100, Currency = pi.Currency, Status = pi.Status, StatementDescriptor = pi.StatementDescriptor, CustomerId = pi.CustomerId, CardId = pi.PaymentMethodId, InvoiceId = pi.InvoiceId }; if (pi.Charges.Data.Count > 0) { var charge = pi.Charges.Data[0]; try { charge.BalanceTransaction = transactionService.Get(charge.BalanceTransactionId); payment.Id = charge.Id; payment.ConvertedAmount = Convert.ToDecimal(charge.BalanceTransaction.Amount) / 100; payment.AmountRefunded = Convert.ToDecimal(charge.AmountRefunded) / 100; payment.Fee = Convert.ToDecimal(charge.BalanceTransaction.Fee) / 100; payment.ConvertedCurrency = charge.BalanceTransaction.Currency; payment.Tax = 0; payment.Captured = charge.Captured; payment.Transfer = charge.TransferId; try { if (charge.Refunds.Data.Count > 0) { var refundTx = transactionService.Get(charge.Refunds.Data[0].BalanceTransactionId); payment.ConvertedAmountRefunded = Convert.ToDecimal(refundTx.Amount) / 100; } } catch (Exception) { } } catch (Exception) { } } try { pi.Customer = customerService.Get(pi.CustomerId); payment.CustomerDescription = pi.Customer.Description; payment.CustomerEmail = pi.Customer.Email; } catch (Exception) { } payment.Description = pi.Description; payments.Add(payment); } var optionsC = new ChargeListOptions { Limit = 100, Created = range, }; StripeList <Charge> chs = chargeService.List(optionsC); for (int i = 0; i < chs.Data.Count; i++) { var ch = chs.Data[i]; if (FindPayment(payments, ch.Id)) { continue; } var payment = new Payment() { Id = ch.Id, Description = ch.Description, Created = ch.Created, Amount = Convert.ToDecimal(ch.Amount) / 100, Currency = ch.Currency, Status = ch.Status, StatementDescriptor = ch.StatementDescriptor, CustomerId = ch.CustomerId, Captured = ch.Captured, CardId = ch.PaymentMethod, InvoiceId = ch.InvoiceId, Transfer = ch.TransferId }; try { ch.BalanceTransaction = transactionService.Get(ch.BalanceTransactionId); payment.ConvertedAmount = Convert.ToDecimal(ch.BalanceTransaction.Amount) / 100; payment.AmountRefunded = Convert.ToDecimal(ch.AmountRefunded) / 100; payment.Fee = Convert.ToDecimal(ch.BalanceTransaction.Fee) / 100; payment.ConvertedCurrency = ch.BalanceTransaction.Currency; payment.Tax = 0; } catch (Exception) { } try { ch.Customer = customerService.Get(ch.CustomerId); payment.CustomerDescription = ch.Customer.Description; payment.CustomerEmail = ch.Customer.Email; } catch (Exception) { } payments.Add(payment); } } catch (Exception) { } payments.Sort( delegate(Payment a, Payment b) { return(b.Created.CompareTo(a.Created)); } ); return(payments); }